Skip to content

Commit

Permalink
test: evaluation of SemanticVisuals metric #54
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomrebelo committed Aug 10, 2023
1 parent f21f5a4 commit c2d4402
Show file tree
Hide file tree
Showing 7 changed files with 468 additions and 27 deletions.
9 changes: 7 additions & 2 deletions src/@evoposter/evaluator/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@

import * as Legibility from "./metrics/Legibility.mjs";
import * as GridAppropriateSize from "./metrics/GridAppropriateSize.mjs";
import * as LayoutSemantics from "./metrics/LayoutSemantics.mjs";
import * as SemanticsLayout from "./metrics/SemanticsLayout.mjs";
import * as SemanticsEmphasis from "./metrics/SemanticsEmphasis.mjs";
import * as SemanticsVisuals from "./metrics/SemanticVisuals.mjs";

export const info = () => {
console.log ("Evaluator working");
}

// constraints
export const legibility = Legibility.compute;
export const gridAppropriateSize = GridAppropriateSize.compute;
export const layoutSemantics = LayoutSemantics.compute;

// semantics
export const semanticsLayout = SemanticsLayout.compute;
export const semanticsEmphasis = SemanticsEmphasis.compute;
export const semanticsVisuals = SemanticsVisuals.compute;

// aesthetics

export { info as default };
17 changes: 10 additions & 7 deletions src/@evoposter/evaluator/src/metrics/SemanticVisuals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

const MAX_COLOR_DISTANCE = 441.67;


import * as config from "../../visual-semantics.config.js";
import * as configurationFile from "../../visual-semantics.config.js";
import {arrMean, colorDistance, hexToRGB, constraint} from "../utils.js";


export const compute = async (data, textboxes, globalFeatures, typefaceData) => {
const emotion = data.predominant.emotion;
export const compute = async (data, textboxes, background, typefaceData, config = configurationFile) => {

let emotion = data.predominant.emotion;

if (config["default"][emotion] === undefined) return 1;

Expand All @@ -49,17 +49,18 @@ export const compute = async (data, textboxes, globalFeatures, typefaceData) =>
}
typefaceColorsDistances.push(typefaceColorsDist);
}

meanTypefaceColorDistance = typefaceColorsDistances.length < 1 ? 1 : arrMean(typefaceColorsDistances);
meanTypefaceColorDistance /= MAX_COLOR_DISTANCE;
meanTypefaceColorDistance = constraint(meanTypefaceColorDistance, 0, 1);
meanTypefaceColorDistance = constraint(1-meanTypefaceColorDistance, 0, 1);
}

// background colour
let meanTypefaceBackgroundDistance = 1;
if (targetBackgroundColors !== undefined && targetBackgroundColors.length !== 0) {
let backgroundColorsDistances = [];
meanTypefaceBackgroundDistance = 0;
for (let c of globalFeatures) {
for (let c of background) {
c = hexToRGB(c);
let backgroundColorsDist = Number.MAX_VALUE;
for (let targetColor of targetBackgroundColors) {
Expand All @@ -74,7 +75,7 @@ export const compute = async (data, textboxes, globalFeatures, typefaceData) =>

meanTypefaceBackgroundDistance = meanTypefaceBackgroundDistance.length < 1 ? 1 : arrMean(backgroundColorsDistances);
meanTypefaceBackgroundDistance /= MAX_COLOR_DISTANCE;
meanTypefaceBackgroundDistance = constraint(meanTypefaceBackgroundDistance, 0, 1);
meanTypefaceBackgroundDistance = constraint(1-meanTypefaceBackgroundDistance, 0, 1);
}

// typeface
Expand All @@ -98,6 +99,8 @@ export const compute = async (data, textboxes, globalFeatures, typefaceData) =>
}

return (meanTypefaceColorDistance + meanTypefaceBackgroundDistance + meanTypefaceError)/3;


}


Expand Down
4 changes: 2 additions & 2 deletions src/@evoposter/evaluator/test/unit/LayoutSemantics.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {layoutSemantics} from '../../src/index.mjs'
import {semanticsLayout} from '../../src/index.mjs'

const TESTING_PARAMS = [
{
Expand Down Expand Up @@ -95,7 +95,7 @@ describe(`Testing Layout Semantics metric`, () => {
for (let i in TESTING_PARAMS) {
let params = TESTING_PARAMS[i];
test(`Test ${i}`, async () => {
const res = layoutSemantics(
const res = semanticsLayout(
params.textboxesHeights, params.dist,
params.type, params.genotype
);
Expand Down
Loading

0 comments on commit c2d4402

Please sign in to comment.