Skip to content

Commit 3aedfdd

Browse files
authored
Added logs for verifyVoronoiTopology (#8639)
1 parent 160a28f commit 3aedfdd

File tree

2 files changed

+71
-34
lines changed

2 files changed

+71
-34
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@itwin/core-geometry",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@itwin/core-geometry"
10+
}

core/geometry/src/test/topology/Voronoi.test.ts

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,20 @@ function visualizeGraphEdges(allGeometry: GeometryQuery[], graph: HalfEdgeGraph,
6262
* @param showDelaunay whether to visualize the Delaunay triangulation.
6363
* @param showClippers whether to visualize the curve-based Voronoi super faces as UnionRegions derived from the clippers instead.
6464
*/
65-
function visualizeAndVerifyCurveBasedVoronoiDiagram(ck: Checker, allGeometry: GeometryQuery[], path: CurveChain, strokeOptions?: StrokeOptions, distanceTol?: number, bbox?: LowAndHighXY, showDelaunay?: boolean, showClippers?: boolean): void {
65+
function visualizeAndVerifyCurveBasedVoronoiDiagram(
66+
ck: Checker,
67+
allGeometry: GeometryQuery[],
68+
path: CurveChain,
69+
strokeOptions?: StrokeOptions,
70+
distanceTol?: number,
71+
bbox?: LowAndHighXY,
72+
showDelaunay?: boolean,
73+
showClippers?: boolean,
74+
testName?: string,
75+
): void {
6676
const voronoi = Voronoi.createFromCurveChain(path, strokeOptions, distanceTol, bbox);
6777
if (ck.testDefined(voronoi, "created Voronoi instance")) {
68-
verifyVoronoiTopology(ck, voronoi);
78+
verifyVoronoiTopology(ck, voronoi, testName);
6979
ck.testTrue(voronoi.isCurveBased, "Voronoi instance is curve-based");
7080
if (showDelaunay)
7181
GeometryCoreTestIO.captureCloneGeometry(allGeometry, PolyfaceBuilder.graphToPolyface(voronoi.getInputGraph, undefined, undefined, () => true));
@@ -98,24 +108,41 @@ function visualizeAndVerifyCurveBasedVoronoiDiagram(ck: Checker, allGeometry: Ge
98108
}
99109

100110
/** Verify the faces of the Voronoi graph consist of points closest to the expected Delaunay vertex. */
101-
function verifyVoronoiTopology(ck: Checker, v: Voronoi): void {
111+
function verifyVoronoiTopology(ck: Checker, v: Voronoi, testName?: string): void {
102112
const dVertices = v.getInputGraph.collectVertexLoops();
103113
const searcher = Point3dArrayRangeTreeContext.createCapture(dVertices, undefined, undefined, true);
104114
if (ck.testDefined(searcher, "searcher for Delaunay vertices is defined")) {
105115
const vRange = HalfEdgeGraphOps.graphRangeXY(v.getVoronoiGraph);
106116
const dRange = v.getInputGraphRange;
107117
const testPoints: Point2d[] = [];
108-
for (let i = 0; i < 50; i++) { // concentrate test points in the input graph range
109-
testPoints.push(Point2d.create(getRandomNumber(vRange.low.x, vRange.high.x), getRandomNumber(vRange.low.y, vRange.high.y)));
110-
testPoints.push(Point2d.create(getRandomNumber(dRange.low.x, dRange.high.x), getRandomNumber(dRange.low.y, dRange.high.y)));
118+
if (GeometryCoreTestIO.enableLongTests) {
119+
for (let i = 0; i < 50; i++) { // concentrate random test points in the input graph range
120+
testPoints.push(
121+
Point2d.create(getRandomNumber(vRange.low.x, vRange.high.x), getRandomNumber(vRange.low.y, vRange.high.y)),
122+
);
123+
testPoints.push(
124+
Point2d.create(getRandomNumber(dRange.low.x, dRange.high.x), getRandomNumber(dRange.low.y, dRange.high.y)),
125+
);
126+
}
127+
} else { // concentrate fixed test points in the input graph range
128+
for (let i = 0.1; i <= 0.9; i += 0.1) {
129+
for (let j = 0.1; j <= 0.9; j += 0.1) {
130+
testPoints.push(vRange.fractionToPoint(i, j));
131+
testPoints.push(dRange.fractionToPoint(i, j));
132+
}
133+
}
111134
}
112135
// verify the Voronoi condition via Monte Carlo method
113136
const vFaces = HalfEdgeGraphSearch.findContainingFaceXY(v.getVoronoiGraph, testPoints) as (HalfEdge | undefined)[] | undefined;
114137
if (ck.testDefined(vFaces, "findContainingFaceXY succeeded")) {
115138
if (ck.testExactNumber(vFaces.length, testPoints.length, "findContainingFaceXY returned one entry per point")) {
116139
for (let i = 0; i < vFaces.length; i++) {
117140
const vFace = vFaces[i];
118-
if (ck.testDefined(vFace, "interior point containing face found")) {
141+
const errorMessage =
142+
testName ?
143+
`expect point ${JSON.stringify(testPoints[i].toJSON())} to be found in an interior Voronoi face for test ${testName}` :
144+
`expect point ${JSON.stringify(testPoints[i].toJSON())} to be found in an interior Voronoi face`;
145+
if (ck.testDefined(vFace, errorMessage)) {
119146
const dGenerator = v.getInputGraph.allHalfEdges[vFace.faceTag];
120147
let closestPoints = searcher.searchForClosestPoint(testPoints[i], Number.POSITIVE_INFINITY) as CurveLocationDetail[] | undefined;
121148
if (ck.testDefined(closestPoints, "closest Delaunay vertex found")) {
@@ -212,7 +239,7 @@ describe("Voronoi", () => {
212239
visualizeGraphEdges(allGeometry, voronoiGraph);
213240
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 3, "voronoiGraph should have 3 faces");
214241
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 7, "voronoiGraph should have 7 edges");
215-
verifyVoronoiTopology(ck, voronoi);
242+
verifyVoronoiTopology(ck, voronoi, "ColinearPoints0");
216243
}
217244

218245
let dx = 6;
@@ -229,7 +256,7 @@ describe("Voronoi", () => {
229256
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
230257
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 3, "voronoiGraph should have 3 faces");
231258
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 7, "voronoiGraph should have 7 edges");
232-
verifyVoronoiTopology(ck, voronoi);
259+
verifyVoronoiTopology(ck, voronoi, "ColinearPoints1");
233260
}
234261

235262
dx += 5;
@@ -246,7 +273,7 @@ describe("Voronoi", () => {
246273
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
247274
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 3, "voronoiGraph should have 3 faces");
248275
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 5, "voronoiGraph should have 5 edges");
249-
verifyVoronoiTopology(ck, voronoi);
276+
verifyVoronoiTopology(ck, voronoi, "ColinearPoints2");
250277
}
251278

252279
dx += 6;
@@ -263,7 +290,7 @@ describe("Voronoi", () => {
263290
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
264291
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 3, "voronoiGraph should have 3 faces");
265292
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 7, "voronoiGraph should have 7 edges");
266-
verifyVoronoiTopology(ck, voronoi);
293+
verifyVoronoiTopology(ck, voronoi, "ColinearPoints3");
267294
}
268295

269296
// 3d single edge graph
@@ -281,7 +308,7 @@ describe("Voronoi", () => {
281308
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
282309
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 3, "voronoiGraph should have 3 faces");
283310
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 7, "voronoiGraph should have 7 edges");
284-
verifyVoronoiTopology(ck, voronoi);
311+
verifyVoronoiTopology(ck, voronoi, "ColinearPoints4");
285312
}
286313

287314
dx += 9;
@@ -300,7 +327,7 @@ describe("Voronoi", () => {
300327
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
301328
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 4, "voronoiGraph should have 4 faces");
302329
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 10, "voronoiGraph should have 10 edges");
303-
verifyVoronoiTopology(ck, voronoi);
330+
verifyVoronoiTopology(ck, voronoi, "ColinearPoints5");
304331
}
305332
dx += 11;
306333
points = [[-1, -1], [1, 1], [4, 4]];
@@ -318,7 +345,7 @@ describe("Voronoi", () => {
318345
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
319346
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 4, "voronoiGraph should have 4 faces");
320347
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 10, "voronoiGraph should have 10 edges");
321-
verifyVoronoiTopology(ck, voronoi);
348+
verifyVoronoiTopology(ck, voronoi, "ColinearPoints6");
322349
}
323350

324351
dx += 9;
@@ -339,7 +366,7 @@ describe("Voronoi", () => {
339366
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
340367
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 5, "voronoiGraph should have 5 faces");
341368
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 13, "voronoiGraph should have 13 edges");
342-
verifyVoronoiTopology(ck, voronoi);
369+
verifyVoronoiTopology(ck, voronoi, "ColinearPoints7");
343370
}
344371

345372
GeometryCoreTestIO.saveGeometry(allGeometry, "Voronoi", "ColinearPoints");
@@ -372,7 +399,7 @@ describe("Voronoi", () => {
372399
visualizeGraphEdges(allGeometry, voronoiGraph);
373400
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 4, "voronoiGraph should have 4 faces");
374401
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 10, "voronoiGraph should have 10 edges");
375-
verifyVoronoiTopology(ck, voronoi);
402+
verifyVoronoiTopology(ck, voronoi, "GraphWith1Triangle0");
376403
}
377404

378405
const dy = 8;
@@ -399,7 +426,7 @@ describe("Voronoi", () => {
399426
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
400427
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 4, "voronoiGraph from points should have 4 faces");
401428
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 10, "voronoiGraph from points should have 10 edges");
402-
verifyVoronoiTopology(ck, voronoi);
429+
verifyVoronoiTopology(ck, voronoi, "GraphWith1Triangle1");
403430
}
404431
}
405432

@@ -416,7 +443,7 @@ describe("Voronoi", () => {
416443
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
417444
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 4, "voronoiGraph for 3d should have 4 faces");
418445
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 10, "voronoiGraph for 3d should have 10 edges");
419-
verifyVoronoiTopology(ck, voronoi);
446+
verifyVoronoiTopology(ck, voronoi, "GraphWith1Triangle2");
420447
}
421448
}
422449

@@ -433,7 +460,7 @@ describe("Voronoi", () => {
433460
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
434461
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 4, "voronoiGraph from points should have 4 faces");
435462
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 10, "voronoiGraph from points should have 10 edges");
436-
verifyVoronoiTopology(ck, voronoi);
463+
verifyVoronoiTopology(ck, voronoi, "GraphWith1Triangle3");
437464
}
438465
}
439466

@@ -475,7 +502,7 @@ describe("Voronoi", () => {
475502
visualizeGraphEdges(allGeometry, voronoiGraph);
476503
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 5, "voronoiGraph should have 5 faces");
477504
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 13, "voronoiGraph should have 13 edges");
478-
verifyVoronoiTopology(ck, voronoi);
505+
verifyVoronoiTopology(ck, voronoi, "GraphWith2Triangles0");
479506
}
480507

481508
const dy = 11;
@@ -502,7 +529,7 @@ describe("Voronoi", () => {
502529
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
503530
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 5, "voronoiGraph should have 5 faces");
504531
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 13, "voronoiGraph should have 13 edges");
505-
verifyVoronoiTopology(ck, voronoi);
532+
verifyVoronoiTopology(ck, voronoi, "GraphWith2Triangles1");
506533
}
507534
}
508535

@@ -518,7 +545,7 @@ describe("Voronoi", () => {
518545
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
519546
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 5, "voronoiGraph should have 5 faces");
520547
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 12, "voronoiGraph should have 12 edges");
521-
verifyVoronoiTopology(ck, voronoi);
548+
verifyVoronoiTopology(ck, voronoi, "GraphWith2Triangles2");
522549
}
523550
}
524551

@@ -535,7 +562,7 @@ describe("Voronoi", () => {
535562
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
536563
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 5, "voronoiGraph for 3d should have 5 faces");
537564
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 12, "voronoiGraph for 3d should have 12 edges");
538-
verifyVoronoiTopology(ck, voronoi);
565+
verifyVoronoiTopology(ck, voronoi, "GraphWith2Triangles3");
539566
}
540567
}
541568

@@ -552,7 +579,7 @@ describe("Voronoi", () => {
552579
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
553580
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 5, "voronoiGraph from points should have 5 faces");
554581
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 13, "voronoiGraph from points should have 13 edges");
555-
verifyVoronoiTopology(ck, voronoi);
582+
verifyVoronoiTopology(ck, voronoi, "GraphWith2Triangles4");
556583
}
557584
}
558585

@@ -569,7 +596,7 @@ describe("Voronoi", () => {
569596
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
570597
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 5, "voronoiGraph from points should have 5 faces");
571598
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 13, "voronoiGraph from points should have 13 edges");
572-
verifyVoronoiTopology(ck, voronoi);
599+
verifyVoronoiTopology(ck, voronoi, "GraphWith2Triangles5");
573600
}
574601
}
575602

@@ -595,7 +622,7 @@ describe("Voronoi", () => {
595622
visualizeGraphEdges(allGeometry, voronoiGraph);
596623
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 6, "voronoiGraph should have 6 faces");
597624
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 16, "voronoiGraph should have 16 edges");
598-
verifyVoronoiTopology(ck, voronoi);
625+
verifyVoronoiTopology(ck, voronoi, "GraphWith3Triangles0");
599626
}
600627
}
601628

@@ -612,7 +639,7 @@ describe("Voronoi", () => {
612639
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
613640
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 6, "voronoiGraph for 3d should have 6 faces");
614641
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 16, "voronoiGraph for 3d should have 16 edges");
615-
verifyVoronoiTopology(ck, voronoi);
642+
verifyVoronoiTopology(ck, voronoi, "GraphWith3Triangles1");
616643
}
617644
}
618645

@@ -629,7 +656,7 @@ describe("Voronoi", () => {
629656
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
630657
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 6, "voronoiGraph should have 6 faces");
631658
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 16, "voronoiGraph should have 16 edges");
632-
verifyVoronoiTopology(ck, voronoi);
659+
verifyVoronoiTopology(ck, voronoi, "GraphWith3Triangles2");
633660
}
634661
}
635662

@@ -655,7 +682,7 @@ describe("Voronoi", () => {
655682
visualizeGraphEdges(allGeometry, voronoiGraph);
656683
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 6, "voronoiGraph should have 6 faces");
657684
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 16, "voronoiGraph should have 16 edges");
658-
verifyVoronoiTopology(ck, voronoi);
685+
verifyVoronoiTopology(ck, voronoi, "GraphWith4Triangles0");
659686
}
660687
}
661688

@@ -672,7 +699,7 @@ describe("Voronoi", () => {
672699
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
673700
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 6, "voronoiGraph for 3d should have 6 faces");
674701
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 16, "voronoiGraph for 3d should have 16 edges");
675-
verifyVoronoiTopology(ck, voronoi);
702+
verifyVoronoiTopology(ck, voronoi, "GraphWith4Triangles1");
676703
}
677704
}
678705

@@ -689,7 +716,7 @@ describe("Voronoi", () => {
689716
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
690717
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 6, "voronoiGraph should have 6 faces");
691718
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 16, "voronoiGraph should have 16 edges");
692-
verifyVoronoiTopology(ck, voronoi);
719+
verifyVoronoiTopology(ck, voronoi, "GraphWith4Triangles2");
693720
}
694721
}
695722

@@ -715,7 +742,7 @@ describe("Voronoi", () => {
715742
visualizeGraphEdges(allGeometry, voronoiGraph);
716743
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 11, "voronoiGraph should have 11 faces");
717744
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 31, "voronoiGraph should have 31 edges");
718-
verifyVoronoiTopology(ck, voronoi);
745+
verifyVoronoiTopology(ck, voronoi, "GraphWithManyTriangles0");
719746
}
720747
}
721748

@@ -735,7 +762,7 @@ describe("Voronoi", () => {
735762
visualizeGraphEdges(allGeometry, voronoiGraph, dx);
736763
ck.testExactNumber(voronoiGraph.collectFaceLoops().length, 11, "voronoiGraph for 3d should have 11 faces");
737764
ck.testExactNumber(voronoiGraph.allHalfEdges.length / 2, 31, "voronoiGraph for 3d should have 31 edges");
738-
verifyVoronoiTopology(ck, voronoi);
765+
verifyVoronoiTopology(ck, voronoi, "GraphWithManyTriangles1");
739766
}
740767
}
741768

@@ -926,7 +953,7 @@ describe("Voronoi", () => {
926953
const graph = PolyfaceQuery.convertToHalfEdgeGraph(mesh);
927954
const testPoints: Point3d[] = [];
928955
for (let i = 0; i < 100; i++) // sample some interior points
929-
testPoints.push(Point3d.create(getRandomNumberScaled(side, 1/side), getRandomNumberScaled(side, 1/side)));
956+
testPoints.push(Point3d.create(getRandomNumberScaled(side, 1 / side), getRandomNumberScaled(side, 1 / side)));
930957
testPoints.push(Point3d.create(-1, -1)); // and one exterior point
931958
GeometryCoreTestIO.createAndCaptureXYCircle(allGeometry, testPoints, 0.1);
932959
const containingFaces = HalfEdgeGraphSearch.findContainingFaceXY(graph, testPoints) as (HalfEdge | undefined)[] | undefined;

0 commit comments

Comments
 (0)