Skip to content

Commit 079a921

Browse files
authored
test(renderer): give weldVertices' fixture Y and Z axes to weld on (#2909)
Both existing tests in snap-weld.test.ts vary only the X coordinate, holding Y and Z at 0 for every point in the batch. weldVertices' squared-distance comparison is dx*dx + dy*dy + dz*dz; with dy and dz fixed at 0 across all fixture points, dropping either term from the sum (or duplicating dx in its place) leaves every existing assertion unaffected. Mutation confirmed: replacing the sum with dx*dx + dz*dz (dy dropped) or dx*dx + dy*dy (dz dropped) survived both pre-existing tests unmodified. Adds three tests that vary Y or Z independently of X, at a separation (1.5*tol) chosen to stay inside the hash-grid's probe window so only the final squared-distance check -- not the grid bucket lookup -- can reject or accept the pair. Re-verified: both mutations above are now caught (RED), and the suite is green against the unmodified source.
1 parent 1d208fc commit 079a921

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

packages/renderer/src/snap-weld.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,51 @@ test('#2199 a chain of distinct near-tolerance vertices does not collapse into o
106106
// and 3.6 tol, members joining the nearest leader within tol.
107107
assert.equal(clusters.size, 3);
108108
});
109+
110+
/**
111+
* Both tests above only ever vary the X coordinate (Y and Z sit at a shared
112+
* 0 for every point in the batch), so the squared-distance sum `dx*dx +
113+
* dy*dy + dz*dz` cannot be observed component-by-component: dropping the
114+
* `dy` or `dz` term entirely (or duplicating `dx` in its place) leaves both
115+
* suites green, since the dropped term's contribution was already zero.
116+
* These pin each axis independently, the way `aabb.test.ts` and
117+
* `spatial-index-builder.test.ts` already do for their own distance/bounds
118+
* math.
119+
*
120+
* Separation is deliberately 1.5*tol, not something larger: the hash-grid
121+
* probe already widens by +-tol around each point (`cell = 2*tol`), so a
122+
* separation of, say, 3*tol lands the two points in non-overlapping buckets
123+
* and gets rejected by the grid lookup alone -- before the (possibly
124+
* mutated) squared-distance check ever runs. 1.5*tol stays inside the
125+
* probed bucket range while still exceeding tol, so only the final `dSq`
126+
* comparison can reject it.
127+
*/
128+
test('#2199 a Y-only separation beyond tolerance keeps points apart', () => {
129+
// x and z identical; only y differs, past tol but within the grid probe
130+
// range. If dy dropped out of the squared distance, this pair would
131+
// incorrectly weld.
132+
const flat = [5, 0, -5, 5, 1.5 * TOL, -5];
133+
const { ids } = weldVertices(flat, 0, 0, 0, TOL);
134+
assert.notEqual(ids[0], ids[1], 'points 1.5*TOL apart on Y alone must not weld');
135+
});
136+
137+
test('#2199 a Z-only separation beyond tolerance keeps points apart', () => {
138+
// x and y identical; only z differs, past tol but within the grid probe
139+
// range. If dz dropped out of the squared distance, this pair would
140+
// incorrectly weld.
141+
const flat = [5, -5, 0, 5, -5, 1.5 * TOL];
142+
const { ids } = weldVertices(flat, 0, 0, 0, TOL);
143+
assert.notEqual(ids[0], ids[1], 'points 1.5*TOL apart on Z alone must not weld');
144+
});
145+
146+
test('#2199 a Y-only or Z-only separation within tolerance still welds', () => {
147+
// The positive sibling of the two tests above: small enough on Y or Z
148+
// alone that a correct 3-axis distance welds them.
149+
const flatY = [5, 0, -5, 5, 0.5 * TOL, -5];
150+
const { ids: idsY } = weldVertices(flatY, 0, 0, 0, TOL);
151+
assert.equal(idsY[0], idsY[1], 'points 0.5*TOL apart on Y alone must weld');
152+
153+
const flatZ = [5, -5, 0, 5, -5, 0.5 * TOL];
154+
const { ids: idsZ } = weldVertices(flatZ, 0, 0, 0, TOL);
155+
assert.equal(idsZ[0], idsZ[1], 'points 0.5*TOL apart on Z alone must weld');
156+
});

0 commit comments

Comments
 (0)