-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added isRange and color outputs to Match Alpha node
fixed incorrect precision test updated tests for new outputs added Gray color preset to utils
- Loading branch information
Showing
4 changed files
with
146 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 50 additions & 51 deletions
101
packages/graph-engine/tests/suites/nodes/color/matchAlpha.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,101 @@ | ||
import { Graph } from '../../../../src/graph/graph.js'; | ||
import { describe, expect, test } from 'vitest'; | ||
import { getAllOutputs } from '../../../../src/utils/node.js'; | ||
import Color from 'colorjs.io'; | ||
import Node from '../../../../src/nodes/color/matchAlpha.js'; | ||
|
||
describe('color/matchAlpha', () => { | ||
test('all colors are valid and a result that makes sense can be found', async () => { | ||
const graph = new Graph(); | ||
const node = new Node({ graph }); | ||
|
||
node.inputs.foreground.setValue({ | ||
space: 'srgb', | ||
channels: [0.96, 0, 0] | ||
}); | ||
node.inputs.background.setValue({ | ||
space: 'srgb', | ||
channels: [0, 0, 0] | ||
}); | ||
node.inputs.reference.setValue({ | ||
space: 'srgb', | ||
channels: [0.48, 0, 0] | ||
}); | ||
const fg = [0.96, 0, 0]; | ||
const bg = [0, 0, 0]; | ||
const ref = [0.48, 0, 0]; | ||
|
||
node.inputs.foreground.setValue({ space: 'srgb', channels: fg }); | ||
node.inputs.background.setValue({ space: 'srgb', channels: bg }); | ||
node.inputs.reference.setValue({ space: 'srgb', channels: ref }); | ||
|
||
await node.run(); | ||
|
||
const output = getAllOutputs(node); | ||
|
||
expect(output.alpha).to.equal(0.5); | ||
const expAlpha = 0.5; | ||
const expColor = { space: 'srgb', channels: fg, alpha: expAlpha }; | ||
|
||
expect(output.inRange).to.equal(true); | ||
expect(output.color as Color).to.deep.equal(expColor); | ||
expect(output.alpha).to.equal(expAlpha); | ||
}); | ||
|
||
test('the hues of fg and bg are too different and no result makes sense', async () => { | ||
const graph = new Graph(); | ||
const node = new Node({ graph }); | ||
|
||
node.inputs.foreground.setValue({ | ||
space: 'srgb', | ||
channels: [0.96, 0, 0] | ||
}); | ||
node.inputs.background.setValue({ | ||
space: 'srgb', | ||
channels: [0, 0.2, 0] | ||
}); | ||
node.inputs.reference.setValue({ | ||
space: 'srgb', | ||
channels: [0.48, 0, 0] | ||
}); | ||
const fg = [0.96, 0, 0]; | ||
const bg = [0, 0.2, 0]; | ||
const ref = [0.48, 0, 0]; | ||
|
||
node.inputs.foreground.setValue({ space: 'srgb', channels: fg }); | ||
node.inputs.background.setValue({ space: 'srgb', channels: bg }); | ||
node.inputs.reference.setValue({ space: 'srgb', channels: ref }); | ||
|
||
await node.run(); | ||
|
||
const output = getAllOutputs(node); | ||
|
||
const expColor = { space: 'srgb', channels: fg, alpha: 1 }; | ||
|
||
expect(output.inRange).to.equal(false); | ||
expect(output.color as Color).to.deep.equal(expColor); | ||
expect(Number.isNaN(output.alpha)).toEqual(true); | ||
}); | ||
|
||
test('bg and ref are the same (within precision)', async () => { | ||
test('bg and ref are the same (within threshold)', async () => { | ||
const graph = new Graph(); | ||
const node = new Node({ graph }); | ||
|
||
node.inputs.foreground.setValue({ | ||
space: 'srgb', | ||
channels: [0.96, 0.96, 0] | ||
}); | ||
node.inputs.background.setValue({ | ||
space: 'srgb', | ||
channels: [0.33, 0.33, 0] | ||
}); | ||
node.inputs.reference.setValue({ | ||
space: 'srgb', | ||
channels: [0.325, 0.335, 0] | ||
}); | ||
const fg = [0.96, 0.96, 0]; | ||
const bg = [0.33, 0.33, 0]; | ||
const ref = [0.325, 0.335, 0]; | ||
|
||
node.inputs.foreground.setValue({ space: 'srgb', channels: fg }); | ||
node.inputs.background.setValue({ space: 'srgb', channels: bg }); | ||
node.inputs.reference.setValue({ space: 'srgb', channels: ref }); | ||
|
||
await node.run(); | ||
|
||
const output = getAllOutputs(node); | ||
|
||
expect(output.alpha).to.equal(0); | ||
const expAlpha = 0; | ||
const expColor = { space: 'srgb', channels: fg, alpha: expAlpha }; | ||
|
||
expect(output.inRange).to.equal(true); | ||
expect(output.color as Color).to.deep.equal(expColor); | ||
expect(output.alpha).to.equal(expAlpha); | ||
}); | ||
|
||
test('ref is further from bg than fg, so the result is outside the valid alpha range (0-1)', async () => { | ||
const graph = new Graph(); | ||
const node = new Node({ graph }); | ||
|
||
node.inputs.foreground.setValue({ | ||
space: 'srgb', | ||
channels: [0, 0.5, 0.5] | ||
}); | ||
node.inputs.background.setValue({ | ||
space: 'srgb', | ||
channels: [0, 0, 0] | ||
}); | ||
node.inputs.reference.setValue({ | ||
space: 'srgb', | ||
channels: [0, 1, 1] | ||
}); | ||
const fg = [0, 0.5, 0.5]; | ||
const bg = [0, 0, 0]; | ||
const ref = [0, 1, 1]; | ||
|
||
node.inputs.foreground.setValue({ space: 'srgb', channels: fg }); | ||
node.inputs.background.setValue({ space: 'srgb', channels: bg }); | ||
node.inputs.reference.setValue({ space: 'srgb', channels: ref }); | ||
|
||
await node.run(); | ||
|
||
const output = getAllOutputs(node); | ||
|
||
const expColor = { space: 'srgb', channels: fg, alpha: 1 }; | ||
|
||
expect(output.inRange).to.equal(false); | ||
expect(output.color as Color).to.deep.equal(expColor); | ||
expect(Number.isNaN(output.alpha)).toEqual(true); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/graph-engine/vitest.config.ts.timestamp-1732108255012-05584d17095ba.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// vitest.config.ts | ||
import { defineConfig } from "file:///C:/Users/Alex%20(Hyma)/Documents/GitHub/graph-engine/packages/graph-engine/node_modules/vite/dist/node/index.js"; | ||
import tsconfigPaths from "file:///C:/Users/Alex%20(Hyma)/Documents/GitHub/graph-engine/node_modules/vite-tsconfig-paths/dist/index.mjs"; | ||
var vitest_config_default = defineConfig({ | ||
test: { | ||
// ... Specify options here. | ||
}, | ||
plugins: [tsconfigPaths()] | ||
}); | ||
export { | ||
vitest_config_default as default | ||
}; | ||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZXN0LmNvbmZpZy50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiY29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2Rpcm5hbWUgPSBcIkM6XFxcXFVzZXJzXFxcXEFsZXggKEh5bWEpXFxcXERvY3VtZW50c1xcXFxHaXRIdWJcXFxcZ3JhcGgtZW5naW5lXFxcXHBhY2thZ2VzXFxcXGdyYXBoLWVuZ2luZVwiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9maWxlbmFtZSA9IFwiQzpcXFxcVXNlcnNcXFxcQWxleCAoSHltYSlcXFxcRG9jdW1lbnRzXFxcXEdpdEh1YlxcXFxncmFwaC1lbmdpbmVcXFxccGFja2FnZXNcXFxcZ3JhcGgtZW5naW5lXFxcXHZpdGVzdC5jb25maWcudHNcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfaW1wb3J0X21ldGFfdXJsID0gXCJmaWxlOi8vL0M6L1VzZXJzL0FsZXglMjAoSHltYSkvRG9jdW1lbnRzL0dpdEh1Yi9ncmFwaC1lbmdpbmUvcGFja2FnZXMvZ3JhcGgtZW5naW5lL3ZpdGVzdC5jb25maWcudHNcIjsvLy8gPHJlZmVyZW5jZSB0eXBlcz1cInZpdGV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