AI-native design editor. Open-source Figma alternative.
test(vector): add normalizeVectorNetwork tests
Danila Poyarkov3727fa19d051
diff --git a/tests/engine/vector.test.ts b/tests/engine/vector.test.tsindex 48ee4000e..474d17db9 100644--- a/tests/engine/vector.test.ts+++ b/tests/engine/vector.test.ts@@ -4,6 +4,7 @@ import {encodeVectorNetworkBlob,decodeVectorNetworkBlob,computeVectorBounds,+ normalizeVectorNetwork,type VectorNetwork,} from '@open-pencil/core'@@ -127,6 +128,69 @@ describe('vectorNetworkBlob round-trip', () => {})})+describe('normalizeVectorNetwork', () => {+ test('passes through segments that already have tangents', () => {+ const network: VectorNetwork = {+ vertices: [{ x: 0, y: 0 }, { x: 10, y: 10 }],+ segments: [{ start: 0, end: 1, tangentStart: { x: 5, y: 0 }, tangentEnd: { x: -5, y: 0 } }],+ regions: []+ }+ const result = normalizeVectorNetwork(network)+ expect(result.segments[0].tangentStart).toEqual({ x: 5, y: 0 })+ expect(result.segments[0].tangentEnd).toEqual({ x: -5, y: 0 })+ })++ test('defaults missing tangentStart and tangentEnd to zero', () => {+ const network = {+ vertices: [{ x: 0, y: 0 }, { x: 10, y: 10 }],+ segments: [{ start: 0, end: 1 }],+ regions: []+ } as unknown as VectorNetwork+ const result = normalizeVectorNetwork(network)+ expect(result.segments[0].tangentStart).toEqual({ x: 0, y: 0 })+ expect(result.segments[0].tangentEnd).toEqual({ x: 0, y: 0 })+ })++ test('defaults only the missing tangent', () => {+ const network = {+ vertices: [{ x: 0, y: 0 }, { x: 10, y: 10 }],+ segments: [{ start: 0, end: 1, tangentStart: { x: 3, y: 4 } }],+ regions: []+ } as unknown as VectorNetwork+ const result = normalizeVectorNetwork(network)+ expect(result.segments[0].tangentStart).toEqual({ x: 3, y: 4 })+ expect(result.segments[0].tangentEnd).toEqual({ x: 0, y: 0 })+ })++ test('normalized network survives encode/decode round-trip', () => {+ const raw = {+ vertices: [+ { x: 0, y: 0, handleMirroring: 'NONE' },+ { x: 80, y: 0, handleMirroring: 'NONE' },+ { x: 40, y: 80, handleMirroring: 'NONE' }+ ],+ segments: [+ { start: 0, end: 1 },+ { start: 1, end: 2 },+ { start: 2, end: 0 }+ ],+ regions: [{ windingRule: 'NONZERO', loops: [[0, 1, 2]] }]+ } as unknown as VectorNetwork++ const normalized = normalizeVectorNetwork(raw)+ const blob = encodeVectorNetworkBlob(normalized)+ const decoded = decodeVectorNetworkBlob(blob)++ expect(decoded.vertices).toHaveLength(3)+ expect(decoded.segments).toHaveLength(3)+ for (const seg of decoded.segments) {+ expect(seg.tangentStart).toEqual({ x: 0, y: 0 })+ expect(seg.tangentEnd).toEqual({ x: 0, y: 0 })+ }+ expect(decoded.regions[0].loops).toEqual([[0, 1, 2]])+ })+})+describe('computeVectorBounds', () => {test('empty network', () => {expect(computeVectorBounds({ vertices: [], segments: [], regions: [] })).toEqual({