Skip to content

Commit

Permalink
eval: white space fraction #56
Browse files Browse the repository at this point in the history
sergiomrebelo committed Aug 11, 2023
1 parent d4ee5af commit 3c52f05
Showing 3 changed files with 73 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/@evoposter/evaluator/src/metrics/WhiteSpaceFraction.mjs
Original file line number Diff line number Diff line change
@@ -24,13 +24,11 @@ import {colorDistance, hexToRGB} from "../utils.js";
const OPTIMAL = .5;
const MIN_DISTANCE = 10;

export const compute = (img, color, optimal = OPTIMAL) => {

console.log ("img", img);
console.log ("color", color);

color = hexToRGB(color);
const amount = percentTypographyColor(img, color, img.pixelDensity());
export const compute = (img, color, amount = null, optimal = OPTIMAL) => {
if (amount === null) {
color = hexToRGB(color);
amount = percentTypographyColor(img, color, img.pixelDensity());
}

const res = 1-4*Math.pow((amount - optimal), 2);

59 changes: 59 additions & 0 deletions src/@evoposter/evaluator/test/unit/WhiteSpaceFraction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {whiteSpaceFraction} from '../../src/index.mjs'

const OPTIMAL = .5;
const TESTING_PARAMS = [
{
amount: 0.046897163120567374,
res: 0.17879127684724105,
valid: true,
},
{
amount: 0.5,
res: 1,
valid: true,
},
{
amount: 0,
res: 0,
valid: true,
},
{
amount: 0.19705673758865247,
res: 0.6329015190382778,
valid: true,
},
{
amount: 0.1,
res: 1,
valid: false,
},
{
amount: 0,
res: 1,
valid: false,
},
{
amount: 0,
res: 1,
valid: false,
},
{
amount: 0.21930851063829787,
res: 0.6848491511996379,
valid: true,
},
];

describe(`Testing White Space Fraction metric`, () => {
for (let i in TESTING_PARAMS) {
let params = TESTING_PARAMS[i];
test(`Test ${i}`, async () => {
const res = whiteSpaceFraction(null, null, params.amount, OPTIMAL);
if (params.valid) {
expect(res).toBe(params.res);
} else {
expect(res).not.toBe(params.res);
}
});
}
});
13 changes: 9 additions & 4 deletions src/public/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c52f05

Please sign in to comment.