@itwin/core-geometry 4.0.0-dev.98 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/lib/cjs/Geometry.d.ts.map +1 -1
  3. package/lib/cjs/Geometry.js +8 -5
  4. package/lib/cjs/Geometry.js.map +1 -1
  5. package/lib/cjs/curve/CurveCurveIntersectXY.d.ts.map +1 -1
  6. package/lib/cjs/curve/CurveCurveIntersectXY.js +3 -3
  7. package/lib/cjs/curve/CurveCurveIntersectXY.js.map +1 -1
  8. package/lib/cjs/curve/CurveLocationDetail.d.ts +1 -1
  9. package/lib/cjs/curve/CurveLocationDetail.js +1 -1
  10. package/lib/cjs/curve/CurveLocationDetail.js.map +1 -1
  11. package/lib/cjs/curve/Query/PlanarSubdivision.d.ts +3 -2
  12. package/lib/cjs/curve/Query/PlanarSubdivision.d.ts.map +1 -1
  13. package/lib/cjs/curve/Query/PlanarSubdivision.js +57 -43
  14. package/lib/cjs/curve/Query/PlanarSubdivision.js.map +1 -1
  15. package/lib/cjs/curve/RegionOps.d.ts +7 -5
  16. package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
  17. package/lib/cjs/curve/RegionOps.js +17 -16
  18. package/lib/cjs/curve/RegionOps.js.map +1 -1
  19. package/lib/cjs/curve/RegionOpsClassificationSweeps.js +1 -1
  20. package/lib/cjs/curve/RegionOpsClassificationSweeps.js.map +1 -1
  21. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts +9 -9
  22. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  23. package/lib/cjs/geometry3d/CoincidentGeometryOps.js +82 -56
  24. package/lib/cjs/geometry3d/CoincidentGeometryOps.js.map +1 -1
  25. package/lib/cjs/geometry3d/Matrix3d.js +1 -1
  26. package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
  27. package/lib/cjs/topology/Merging.d.ts +1 -0
  28. package/lib/cjs/topology/Merging.d.ts.map +1 -1
  29. package/lib/cjs/topology/Merging.js +1 -0
  30. package/lib/cjs/topology/Merging.js.map +1 -1
  31. package/lib/esm/Geometry.d.ts.map +1 -1
  32. package/lib/esm/Geometry.js +8 -5
  33. package/lib/esm/Geometry.js.map +1 -1
  34. package/lib/esm/curve/CurveCurveIntersectXY.d.ts.map +1 -1
  35. package/lib/esm/curve/CurveCurveIntersectXY.js +3 -3
  36. package/lib/esm/curve/CurveCurveIntersectXY.js.map +1 -1
  37. package/lib/esm/curve/CurveLocationDetail.d.ts +1 -1
  38. package/lib/esm/curve/CurveLocationDetail.js +1 -1
  39. package/lib/esm/curve/CurveLocationDetail.js.map +1 -1
  40. package/lib/esm/curve/Query/PlanarSubdivision.d.ts +3 -2
  41. package/lib/esm/curve/Query/PlanarSubdivision.d.ts.map +1 -1
  42. package/lib/esm/curve/Query/PlanarSubdivision.js +58 -44
  43. package/lib/esm/curve/Query/PlanarSubdivision.js.map +1 -1
  44. package/lib/esm/curve/RegionOps.d.ts +7 -5
  45. package/lib/esm/curve/RegionOps.d.ts.map +1 -1
  46. package/lib/esm/curve/RegionOps.js +17 -16
  47. package/lib/esm/curve/RegionOps.js.map +1 -1
  48. package/lib/esm/curve/RegionOpsClassificationSweeps.js +1 -1
  49. package/lib/esm/curve/RegionOpsClassificationSweeps.js.map +1 -1
  50. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts +9 -9
  51. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  52. package/lib/esm/geometry3d/CoincidentGeometryOps.js +82 -56
  53. package/lib/esm/geometry3d/CoincidentGeometryOps.js.map +1 -1
  54. package/lib/esm/geometry3d/Matrix3d.js +1 -1
  55. package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
  56. package/lib/esm/topology/Merging.d.ts +1 -0
  57. package/lib/esm/topology/Merging.d.ts.map +1 -1
  58. package/lib/esm/topology/Merging.js +1 -0
  59. package/lib/esm/topology/Merging.js.map +1 -1
  60. package/package.json +3 -3
@@ -6,7 +6,10 @@ import { Geometry } from "../../Geometry";
6
6
  import { HalfEdgeGraph } from "../../topology/Graph";
7
7
  import { HalfEdgeGraphSearch } from "../../topology/HalfEdgeGraphSearch";
8
8
  import { HalfEdgeGraphMerge } from "../../topology/Merging";
9
- import { CurveLocationDetail } from "../CurveLocationDetail";
9
+ import { Arc3d } from "../Arc3d";
10
+ import { CurveLocationDetail, CurveLocationDetailPair } from "../CurveLocationDetail";
11
+ import { LineSegment3d } from "../LineSegment3d";
12
+ import { LineString3d } from "../LineString3d";
10
13
  import { Loop, LoopCurveLoopCurve } from "../Loop";
11
14
  import { RegionOps } from "../RegionOps";
12
15
  /** @packageDocumentation
@@ -15,7 +18,7 @@ import { RegionOps } from "../RegionOps";
15
18
  class MapCurvePrimitiveToCurveLocationDetailPairArray {
16
19
  constructor() {
17
20
  this.primitiveToPair = new Map();
18
- // index assigned to this primitive for this calculation.
21
+ // index assigned to this primitive (for debugging)
19
22
  this.primitiveToIndex = new Map();
20
23
  this._numIndexedPrimitives = 0;
21
24
  }
@@ -47,52 +50,61 @@ class MapCurvePrimitiveToCurveLocationDetailPairArray {
47
50
  if (primitiveB)
48
51
  this.insertPrimitiveToPair(primitiveB, pair);
49
52
  }
53
+ /** Split closed missing primitives in half and add new intersection pairs */
54
+ splitAndAppendMissingClosedPrimitives(primitives, tolerance = Geometry.smallMetricDistance) {
55
+ for (const p of primitives) {
56
+ let closedCurveSplitCandidate = false;
57
+ if (p instanceof Arc3d)
58
+ closedCurveSplitCandidate = p.sweep.isFullCircle;
59
+ else if (!(p instanceof LineSegment3d) && !(p instanceof LineString3d))
60
+ closedCurveSplitCandidate = p.startPoint().isAlmostEqualXY(p.endPoint(), tolerance);
61
+ if (closedCurveSplitCandidate && !this.primitiveToPair.has(p)) {
62
+ const p0 = p.clonePartialCurve(0.0, 0.5);
63
+ const p1 = p.clonePartialCurve(0.5, 1.0);
64
+ if (p0 && p1) {
65
+ this.insertPair(CurveLocationDetailPair.createCapture(CurveLocationDetail.createCurveEvaluatedFraction(p0, 0.0), CurveLocationDetail.createCurveEvaluatedFraction(p1, 1.0)));
66
+ this.insertPair(CurveLocationDetailPair.createCapture(CurveLocationDetail.createCurveEvaluatedFraction(p0, 1.0), CurveLocationDetail.createCurveEvaluatedFraction(p1, 0.0)));
67
+ }
68
+ }
69
+ }
70
+ }
50
71
  }
51
- /*
52
- function getDetailString(detail: CurveLocationDetail | undefined): string {
53
- if (!detail)
54
- return "{}";
55
- else return tagString("primitive", this.primitiveToIndex.get(detail.curve!)) + tagString("f0", detail.fraction) + tagString("f1", detail.fraction1);
56
- }
57
- }
58
- function tagString(name: string, value: number | undefined): string {
59
- if (value !== undefined)
60
- return "(" + name + " " + value + ")";
61
- return "";
62
- }
63
- */
64
72
  /**
65
73
  * @internal
66
74
  */
67
75
  export class PlanarSubdivision {
68
- /** Create a graph from an array of curves, and an array of the curves' precomputed intersections. */
69
- static assembleHalfEdgeGraph(primitives, allPairs) {
76
+ /** Create a graph from an array of curves, and an array of the curves' precomputed intersections. Z-coordinates are ignored. */
77
+ static assembleHalfEdgeGraph(primitives, allPairs, mergeTolerance = Geometry.smallMetricDistance) {
70
78
  const detailByPrimitive = new MapCurvePrimitiveToCurveLocationDetailPairArray(); // map from key CurvePrimitive to CurveLocationDetailPair.
71
- for (const p of primitives)
72
- detailByPrimitive.assignPrimitiveIndex(p);
73
- for (const pair of allPairs) {
79
+ for (const pair of allPairs)
74
80
  detailByPrimitive.insertPair(pair);
75
- }
81
+ if (primitives.length > detailByPrimitive.primitiveToPair.size)
82
+ detailByPrimitive.splitAndAppendMissingClosedPrimitives(primitives, mergeTolerance); // otherwise, these single-primitive loops are missing from the graph
76
83
  const graph = new HalfEdgeGraph();
77
84
  for (const entry of detailByPrimitive.primitiveToPair.entries()) {
78
85
  const p = entry[0];
79
- const details = entry[1];
86
+ // convert each interval intersection into two isolated intersections
87
+ const details = entry[1].reduce((accumulator, detailPair) => {
88
+ if (!detailPair.detailA.hasFraction1)
89
+ return [...accumulator, detailPair];
90
+ const detail = getDetailOnCurve(detailPair, p);
91
+ const detail0 = CurveLocationDetail.createCurveFractionPoint(p, detail.fraction, detail.point);
92
+ const detail1 = CurveLocationDetail.createCurveFractionPoint(p, detail.fraction1, detail.point1);
93
+ return [...accumulator, CurveLocationDetailPair.createCapture(detail0, detail0), CurveLocationDetailPair.createCapture(detail1, detail1)];
94
+ }, []);
95
+ // lexical sort on p intersection fraction
80
96
  details.sort((pairA, pairB) => {
81
97
  const fractionA = getFractionOnCurve(pairA, p);
82
98
  const fractionB = getFractionOnCurve(pairB, p);
83
- if (fractionA === undefined || fractionB === undefined)
84
- return -1000.0;
85
99
  return fractionA - fractionB;
86
100
  });
87
- let detail0 = getDetailOnCurve(details[0], p);
88
- this.addHalfEdge(graph, p, p.startPoint(), 0.0, detail0.point, detail0.fraction);
89
- for (let i = 1; i < details.length; i++) {
90
- // create (both sides of) a graph edge . . .
91
- const detail1 = getDetailOnCurve(details[i], p);
92
- this.addHalfEdge(graph, p, detail0.point, detail0.fraction, detail1.point, detail1.fraction);
93
- detail0 = detail1;
101
+ let last = { point: p.startPoint(), fraction: 0.0 };
102
+ for (const detailPair of details) {
103
+ const detail = getDetailOnCurve(detailPair, p);
104
+ const detailFraction = Geometry.restrictToInterval(detail.fraction, 0, 1); // truncate fraction, but don't snap point; clustering happens later
105
+ last = this.addHalfEdge(graph, p, last.point, last.fraction, detail.point, detailFraction, mergeTolerance);
94
106
  }
95
- this.addHalfEdge(graph, p, detail0.point, detail0.fraction, p.endPoint(), 1.0);
107
+ this.addHalfEdge(graph, p, last.point, last.fraction, p.endPoint(), 1.0, mergeTolerance);
96
108
  }
97
109
  HalfEdgeGraphMerge.clusterAndMergeXYTheta(graph, (he) => he.sortAngle);
98
110
  return graph;
@@ -106,19 +118,21 @@ export class PlanarSubdivision {
106
118
  * @param point0 start point
107
119
  * @param fraction1 end fraction
108
120
  * @param point1 end point
121
+ * @returns end point and fraction, or start point and fraction if no action
109
122
  */
110
- static addHalfEdge(graph, p, point0, fraction0, point1, fraction1) {
111
- if (!point0.isAlmostEqual(point1)) {
112
- const halfEdge = graph.createEdgeXYAndZ(point0, 0, point1, 0);
113
- const detail01 = CurveLocationDetail.createCurveEvaluatedFractionFraction(p, fraction0, fraction1);
114
- const mate = halfEdge.edgeMate;
115
- halfEdge.edgeTag = detail01;
116
- halfEdge.sortData = 1.0;
117
- mate.edgeTag = detail01;
118
- mate.sortData = -1.0;
119
- halfEdge.sortAngle = sortAngle(detail01.curve, detail01.fraction, false);
120
- mate.sortAngle = sortAngle(detail01.curve, detail01.fraction1, true);
121
- }
123
+ static addHalfEdge(graph, p, point0, fraction0, point1, fraction1, mergeTolerance = Geometry.smallMetricDistance) {
124
+ if (point0.isAlmostEqualXY(point1, mergeTolerance))
125
+ return { point: point0, fraction: fraction0 };
126
+ const halfEdge = graph.createEdgeXYAndZ(point0, 0, point1, 0);
127
+ const detail01 = CurveLocationDetail.createCurveEvaluatedFractionFraction(p, fraction0, fraction1);
128
+ const mate = halfEdge.edgeMate;
129
+ halfEdge.edgeTag = detail01;
130
+ halfEdge.sortData = 1.0;
131
+ mate.edgeTag = detail01;
132
+ mate.sortData = -1.0;
133
+ halfEdge.sortAngle = sortAngle(p, fraction0, false);
134
+ mate.sortAngle = sortAngle(p, fraction1, true);
135
+ return { point: point1, fraction: fraction1 };
122
136
  }
123
137
  /**
124
138
  * Based on computed (and toleranced) area, push the loop (pointer) onto the appropriate array of positive, negative, or sliver loops.
@@ -1 +1 @@
1
- {"version":3,"file":"PlanarSubdivision.js","sourceRoot":"","sources":["../../../../src/curve/Query/PlanarSubdivision.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAY,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC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CAAC;AAC9D,CAAC;AAED,SAAS,kBAAkB,CAAC,IAA6B,EAAE,KAAqB;IAC9E,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,OAAO,SAAS,CAAC;AACnB,CAAC;AACD,SAAS,gBAAgB,CAAC,IAA6B,EAAE,KAAqB;IAC5E,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { Geometry } from \"../../Geometry\";\r\nimport { Point3d } from \"../../geometry3d/Point3dVector3d\";\r\nimport { HalfEdge, HalfEdgeGraph } from \"../../topology/Graph\";\r\nimport { HalfEdgeGraphSearch } from \"../../topology/HalfEdgeGraphSearch\";\r\nimport { HalfEdgeGraphMerge } from \"../../topology/Merging\";\r\nimport { CurveLocationDetail, CurveLocationDetailPair } from \"../CurveLocationDetail\";\r\nimport { CurvePrimitive } from \"../CurvePrimitive\";\r\nimport { Loop, LoopCurveLoopCurve, SignedLoops } from \"../Loop\";\r\nimport { RegionOps } from \"../RegionOps\";\r\n\r\n/** @packageDocumentation\r\n * @module Curve\r\n */\r\n\r\nclass MapCurvePrimitiveToCurveLocationDetailPairArray {\r\n public primitiveToPair = new Map<CurvePrimitive, CurveLocationDetailPair[]>();\r\n // index assigned to this primitive for this calculation.\r\n public primitiveToIndex = new Map<CurvePrimitive, number>();\r\n private _numIndexedPrimitives: number = 0;\r\n public assignPrimitiveIndex(primitive: CurvePrimitive | undefined) {\r\n if (primitive !== undefined) {\r\n const index = this.primitiveToIndex.get(primitive);\r\n if (index === undefined) {\r\n this.primitiveToIndex.set(primitive, this._numIndexedPrimitives++);\r\n }\r\n }\r\n }\r\n public insertPrimitiveToPair(primitive: CurvePrimitive | undefined, pair: CurveLocationDetailPair) {\r\n if (primitive) {\r\n const priorPairs = this.primitiveToPair.get(primitive);\r\n this.assignPrimitiveIndex(primitive);\r\n if (!priorPairs) {\r\n this.primitiveToPair.set(primitive, [pair]);\r\n } else {\r\n priorPairs.push(pair);\r\n }\r\n }\r\n }\r\n public insertPair(pair: CurveLocationDetailPair) {\r\n const primitiveA = pair.detailA.curve;\r\n if (primitiveA)\r\n this.insertPrimitiveToPair(primitiveA, pair);\r\n const primitiveB = pair.detailB.curve;\r\n if (primitiveB)\r\n this.insertPrimitiveToPair(primitiveB, pair);\r\n }\r\n}\r\n/*\r\n function getDetailString(detail: CurveLocationDetail | undefined): string {\r\n if (!detail)\r\n return \"{}\";\r\n else return tagString(\"primitive\", this.primitiveToIndex.get(detail.curve!)) + tagString(\"f0\", detail.fraction) + tagString(\"f1\", detail.fraction1);\r\n }\r\n}\r\nfunction tagString(name: string, value: number | undefined): string {\r\n if (value !== undefined)\r\n return \"(\" + name + \" \" + value + \")\";\r\n return \"\";\r\n}\r\n*/\r\n/**\r\n * @internal\r\n */\r\nexport class PlanarSubdivision {\r\n /** Create a graph from an array of curves, and an array of the curves' precomputed intersections. */\r\n public static assembleHalfEdgeGraph(primitives: CurvePrimitive[], allPairs: CurveLocationDetailPair[]): HalfEdgeGraph {\r\n const detailByPrimitive = new MapCurvePrimitiveToCurveLocationDetailPairArray(); // map from key CurvePrimitive to CurveLocationDetailPair.\r\n for (const p of primitives)\r\n detailByPrimitive.assignPrimitiveIndex(p);\r\n for (const pair of allPairs) {\r\n detailByPrimitive.insertPair(pair);\r\n }\r\n const graph = new HalfEdgeGraph();\r\n for (const entry of detailByPrimitive.primitiveToPair.entries()) {\r\n const p = entry[0];\r\n const details = entry[1];\r\n details.sort((pairA: CurveLocationDetailPair, pairB: CurveLocationDetailPair) => {\r\n const fractionA = getFractionOnCurve(pairA, p);\r\n const fractionB = getFractionOnCurve(pairB, p);\r\n if (fractionA === undefined || fractionB === undefined)\r\n return -1000.0;\r\n return fractionA - fractionB;\r\n });\r\n let detail0 = getDetailOnCurve(details[0], p)!;\r\n this.addHalfEdge(graph, p, p.startPoint (), 0.0, detail0.point, detail0.fraction);\r\n for (let i = 1; i < details.length; i++) {\r\n // create (both sides of) a graph edge . . .\r\n const detail1 = getDetailOnCurve(details[i], p)!;\r\n this.addHalfEdge(graph, p, detail0.point, detail0.fraction, detail1.point, detail1.fraction);\r\n detail0 = detail1;\r\n }\r\n this.addHalfEdge(graph, p, detail0.point, detail0.fraction, p.endPoint(), 1.0);\r\n }\r\n HalfEdgeGraphMerge.clusterAndMergeXYTheta(graph, (he: HalfEdge) => he.sortAngle!);\r\n return graph;\r\n }\r\n /**\r\n * Create a pair of mated half edges referencing an interval of a primitive\r\n * * no action if start and end points are identical.\r\n * @param graph containing graph.\r\n * @param p the curve\r\n * @param fraction0 starting fraction\r\n * @param point0 start point\r\n * @param fraction1 end fraction\r\n * @param point1 end point\r\n */\r\n private static addHalfEdge(graph: HalfEdgeGraph, p: CurvePrimitive, point0: Point3d, fraction0: number, point1: Point3d, fraction1: number) {\r\n if (!point0.isAlmostEqual (point1)){\r\n const halfEdge = graph.createEdgeXYAndZ(point0, 0, point1, 0);\r\n const detail01 = CurveLocationDetail.createCurveEvaluatedFractionFraction(p, fraction0, fraction1);\r\n const mate = halfEdge.edgeMate;\r\n halfEdge.edgeTag = detail01;\r\n halfEdge.sortData = 1.0;\r\n mate.edgeTag = detail01;\r\n mate.sortData = -1.0;\r\n halfEdge.sortAngle = sortAngle(detail01.curve!, detail01.fraction, false);\r\n mate.sortAngle = sortAngle(detail01.curve!, detail01.fraction1!, true);\r\n }\r\n }\r\n /**\r\n * Based on computed (and toleranced) area, push the loop (pointer) onto the appropriate array of positive, negative, or sliver loops.\r\n * @param zeroAreaTolerance absolute area tolerance for sliver face detection\r\n * @param isSliverFace whether the loop is known a priori (e.g., via topology) to have zero area\r\n * @returns the area (forced to zero if within tolerance)\r\n */\r\n public static collectSignedLoop(loop: Loop, outLoops: SignedLoops, zeroAreaTolerance: number = 1.0e-10, isSliverFace?: boolean): number{\r\n let area = isSliverFace ? 0.0 : RegionOps.computeXYArea(loop);\r\n if (area === undefined)\r\n area = 0;\r\n if (Math.abs(area) < zeroAreaTolerance)\r\n area = 0.0;\r\n (loop as any).computedAreaInPlanarSubdivision = area;\r\n if (area > 0)\r\n outLoops.positiveAreaLoops.push(loop);\r\n else if (area < 0)\r\n outLoops.negativeAreaLoops.push(loop);\r\n else\r\n outLoops.slivers.push(loop);\r\n return area;\r\n }\r\n public static createLoopInFace(faceSeed: HalfEdge,\r\n announce?: (he: HalfEdge, curve: CurvePrimitive, loop: Loop) => void): Loop {\r\n let he = faceSeed;\r\n const loop = Loop.create();\r\n do {\r\n const detail = he.edgeTag as CurveLocationDetail;\r\n if (detail) {\r\n let curve;\r\n if (he.sortData! > 0)\r\n curve = detail.curve!.clonePartialCurve(detail.fraction, detail.fraction1!);\r\n else\r\n curve = detail.curve!.clonePartialCurve(detail.fraction1!, detail.fraction);\r\n if (curve) {\r\n if (announce !== undefined)\r\n announce(he, curve, loop);\r\n loop.tryAddChild(curve);\r\n }\r\n }\r\n he = he.faceSuccessor;\r\n } while (he !== faceSeed);\r\n return loop;\r\n }\r\n // Return true if there are only two edges in the face loop, and their start curvatures are the same.\r\n private static isNullFace(he: HalfEdge): boolean {\r\n const faceHasTwoEdges = (he.faceSuccessor.faceSuccessor === he);\r\n let faceIsBanana = false;\r\n if (faceHasTwoEdges) {\r\n const c0 = HalfEdgeGraphMerge.curvatureSortKey(he);\r\n const c1 = HalfEdgeGraphMerge.curvatureSortKey(he.faceSuccessor.edgeMate);\r\n if (!Geometry.isSameCoordinate(c0, c1)) // default tol!\r\n faceIsBanana = true; // heuristic: we could also check end curvatures, and/or higher derivatives...\r\n }\r\n return faceHasTwoEdges && !faceIsBanana;\r\n }\r\n // Look across edge mates (possibly several) for a nonnull mate face.\r\n private static nonNullEdgeMate(_graph: HalfEdgeGraph, e: HalfEdge): HalfEdge | undefined {\r\n if (this.isNullFace (e))\r\n return undefined;\r\n let e1 = e.edgeMate;\r\n while (this.isNullFace(e1)){\r\n e1 = e1.faceSuccessor.edgeMate;\r\n if (e1 === e)\r\n return undefined;\r\n }\r\n return e1;\r\n }\r\n public static collectSignedLoopSetsInHalfEdgeGraph(graph: HalfEdgeGraph, zeroAreaTolerance: number = 1.0e-10): SignedLoops[] {\r\n const q = HalfEdgeGraphSearch.collectConnectedComponentsWithExteriorParityMasks(graph, undefined);\r\n const result: SignedLoops[] = [];\r\n const edgeMap = new Map<HalfEdge, LoopCurveLoopCurve>();\r\n for (const faceSeeds of q) {\r\n const componentAreas: SignedLoops = { positiveAreaLoops: [], negativeAreaLoops: [], slivers: [] };\r\n const edges: LoopCurveLoopCurve[] = [];\r\n for (const faceSeed of faceSeeds) {\r\n const isNullFace = this.isNullFace(faceSeed);\r\n const loop = this.createLoopInFace(faceSeed, (he: HalfEdge, curveC: CurvePrimitive, loopC: Loop) => {\r\n if (!isNullFace) {\r\n const mate = this.nonNullEdgeMate(graph, he);\r\n if (mate !== undefined) {\r\n const e = edgeMap.get(mate);\r\n if (e === undefined) {\r\n // Record this as loopA,edgeA of a shared edge to be completed later from the other side of the edge\r\n const e1 = new LoopCurveLoopCurve(loopC, curveC, undefined, undefined);\r\n edgeMap.set(he, e1);\r\n } else if (e instanceof LoopCurveLoopCurve) {\r\n e.setB(loopC, curveC);\r\n edges.push(e);\r\n edgeMap.delete(mate);\r\n }\r\n }\r\n }\r\n });\r\n this.collectSignedLoop(loop, componentAreas, zeroAreaTolerance, isNullFace);\r\n }\r\n componentAreas.edges = edges;\r\n result.push(componentAreas);\r\n edgeMap.clear();\r\n }\r\n return result;\r\n }\r\n}\r\n\r\nfunction sortAngle(curve: CurvePrimitive, fraction: number, reverse: boolean): number {\r\n const ray = curve.fractionToPointAndDerivative(fraction);\r\n const s = reverse ? -1.0 : 1.0;\r\n return Math.atan2(s * ray.direction.y, s * ray.direction.x);\r\n}\r\n\r\nfunction getFractionOnCurve(pair: CurveLocationDetailPair, curve: CurvePrimitive): number | undefined {\r\n if (pair.detailA.curve === curve)\r\n return pair.detailA.fraction;\r\n if (pair.detailB.curve === curve)\r\n return pair.detailB.fraction;\r\n return undefined;\r\n}\r\nfunction getDetailOnCurve(pair: CurveLocationDetailPair, curve: CurvePrimitive): CurveLocationDetail | undefined {\r\n if (pair.detailA.curve === curve)\r\n return pair.detailA;\r\n if (pair.detailB.curve === curve)\r\n return pair.detailB;\r\n return undefined;\r\n}\r\n"]}
1
+ {"version":3,"file":"PlanarSubdivision.js","sourceRoot":"","sources":["../../../../src/curve/Query/PlanarSubdivision.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAY,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEtF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAe,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,SAAS,EAA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C;SACjB;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,SAAS,SAAS,CAAC,KAAqB,EAAE,QAAgB,EAAE,OAAgB;IAC1E,MAAM,GAAG,GAAG,KAAK,CAAC,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IACzD,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,kBAAkB,CAAC,IAA6B,EAAE,KAAqB;IAC9E,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,OAAO,SAAS,CAAC;AACnB,CAAC;AACD,SAAS,gBAAgB,CAAC,IAA6B,EAAE,KAAqB;IAC5E,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { Geometry } from \"../../Geometry\";\r\nimport { Point3d } from \"../../geometry3d/Point3dVector3d\";\r\nimport { HalfEdge, HalfEdgeGraph } from \"../../topology/Graph\";\r\nimport { HalfEdgeGraphSearch } from \"../../topology/HalfEdgeGraphSearch\";\r\nimport { HalfEdgeGraphMerge } from \"../../topology/Merging\";\r\nimport { Arc3d } from \"../Arc3d\";\r\nimport { CurveLocationDetail, CurveLocationDetailPair } from \"../CurveLocationDetail\";\r\nimport { CurvePrimitive } from \"../CurvePrimitive\";\r\nimport { LineSegment3d } from \"../LineSegment3d\";\r\nimport { LineString3d } from \"../LineString3d\";\r\nimport { Loop, LoopCurveLoopCurve, SignedLoops } from \"../Loop\";\r\nimport { RegionOps } from \"../RegionOps\";\r\n\r\n/** @packageDocumentation\r\n * @module Curve\r\n */\r\n\r\nclass MapCurvePrimitiveToCurveLocationDetailPairArray {\r\n public primitiveToPair = new Map<CurvePrimitive, CurveLocationDetailPair[]>();\r\n // index assigned to this primitive (for debugging)\r\n public primitiveToIndex = new Map<CurvePrimitive, number>();\r\n private _numIndexedPrimitives: number = 0;\r\n public assignPrimitiveIndex(primitive: CurvePrimitive | undefined) {\r\n if (primitive !== undefined) {\r\n const index = this.primitiveToIndex.get(primitive);\r\n if (index === undefined) {\r\n this.primitiveToIndex.set(primitive, this._numIndexedPrimitives++);\r\n }\r\n }\r\n }\r\n public insertPrimitiveToPair(primitive: CurvePrimitive | undefined, pair: CurveLocationDetailPair) {\r\n if (primitive) {\r\n const priorPairs = this.primitiveToPair.get(primitive);\r\n this.assignPrimitiveIndex(primitive);\r\n if (!priorPairs) {\r\n this.primitiveToPair.set(primitive, [pair]);\r\n } else {\r\n priorPairs.push(pair);\r\n }\r\n }\r\n }\r\n public insertPair(pair: CurveLocationDetailPair) {\r\n const primitiveA = pair.detailA.curve;\r\n if (primitiveA)\r\n this.insertPrimitiveToPair(primitiveA, pair);\r\n const primitiveB = pair.detailB.curve;\r\n if (primitiveB)\r\n this.insertPrimitiveToPair(primitiveB, pair);\r\n }\r\n /** Split closed missing primitives in half and add new intersection pairs */\r\n public splitAndAppendMissingClosedPrimitives(primitives: CurvePrimitive[], tolerance: number = Geometry.smallMetricDistance) {\r\n for (const p of primitives) {\r\n let closedCurveSplitCandidate = false;\r\n if (p instanceof Arc3d)\r\n closedCurveSplitCandidate = p.sweep.isFullCircle;\r\n else if (!(p instanceof LineSegment3d) && !(p instanceof LineString3d))\r\n closedCurveSplitCandidate = p.startPoint().isAlmostEqualXY(p.endPoint(), tolerance);\r\n if (closedCurveSplitCandidate && !this.primitiveToPair.has(p)) {\r\n const p0 = p.clonePartialCurve(0.0, 0.5);\r\n const p1 = p.clonePartialCurve(0.5, 1.0);\r\n if (p0 && p1) {\r\n this.insertPair(CurveLocationDetailPair.createCapture(CurveLocationDetail.createCurveEvaluatedFraction(p0, 0.0), CurveLocationDetail.createCurveEvaluatedFraction(p1, 1.0)));\r\n this.insertPair(CurveLocationDetailPair.createCapture(CurveLocationDetail.createCurveEvaluatedFraction(p0, 1.0), CurveLocationDetail.createCurveEvaluatedFraction(p1, 0.0)));\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class PlanarSubdivision {\r\n /** Create a graph from an array of curves, and an array of the curves' precomputed intersections. Z-coordinates are ignored. */\r\n public static assembleHalfEdgeGraph(primitives: CurvePrimitive[], allPairs: CurveLocationDetailPair[], mergeTolerance: number = Geometry.smallMetricDistance): HalfEdgeGraph {\r\n const detailByPrimitive = new MapCurvePrimitiveToCurveLocationDetailPairArray(); // map from key CurvePrimitive to CurveLocationDetailPair.\r\n for (const pair of allPairs)\r\n detailByPrimitive.insertPair(pair);\r\n if (primitives.length > detailByPrimitive.primitiveToPair.size)\r\n detailByPrimitive.splitAndAppendMissingClosedPrimitives(primitives, mergeTolerance); // otherwise, these single-primitive loops are missing from the graph\r\n const graph = new HalfEdgeGraph();\r\n for (const entry of detailByPrimitive.primitiveToPair.entries()) {\r\n const p = entry[0];\r\n // convert each interval intersection into two isolated intersections\r\n const details = entry[1].reduce((accumulator: CurveLocationDetailPair[], detailPair) => {\r\n if (!detailPair.detailA.hasFraction1)\r\n return [...accumulator, detailPair];\r\n const detail = getDetailOnCurve(detailPair, p)!;\r\n const detail0 = CurveLocationDetail.createCurveFractionPoint(p, detail.fraction, detail.point);\r\n const detail1 = CurveLocationDetail.createCurveFractionPoint(p, detail.fraction1!, detail.point1!);\r\n return [...accumulator, CurveLocationDetailPair.createCapture(detail0, detail0), CurveLocationDetailPair.createCapture(detail1, detail1)];\r\n }, []);\r\n // lexical sort on p intersection fraction\r\n details.sort((pairA: CurveLocationDetailPair, pairB: CurveLocationDetailPair) => {\r\n const fractionA = getFractionOnCurve(pairA, p)!;\r\n const fractionB = getFractionOnCurve(pairB, p)!;\r\n return fractionA - fractionB;\r\n });\r\n let last = {point: p.startPoint(), fraction: 0.0};\r\n for (const detailPair of details) {\r\n const detail = getDetailOnCurve(detailPair, p)!;\r\n const detailFraction = Geometry.restrictToInterval(detail.fraction, 0, 1); // truncate fraction, but don't snap point; clustering happens later\r\n last = this.addHalfEdge(graph, p, last.point, last.fraction, detail.point, detailFraction, mergeTolerance);\r\n }\r\n this.addHalfEdge(graph, p, last.point, last.fraction, p.endPoint(), 1.0, mergeTolerance);\r\n }\r\n HalfEdgeGraphMerge.clusterAndMergeXYTheta(graph, (he: HalfEdge) => he.sortAngle!);\r\n return graph;\r\n }\r\n /**\r\n * Create a pair of mated half edges referencing an interval of a primitive\r\n * * no action if start and end points are identical.\r\n * @param graph containing graph.\r\n * @param p the curve\r\n * @param fraction0 starting fraction\r\n * @param point0 start point\r\n * @param fraction1 end fraction\r\n * @param point1 end point\r\n * @returns end point and fraction, or start point and fraction if no action\r\n */\r\n private static addHalfEdge(graph: HalfEdgeGraph, p: CurvePrimitive, point0: Point3d, fraction0: number, point1: Point3d, fraction1: number, mergeTolerance: number = Geometry.smallMetricDistance): {point: Point3d, fraction: number} {\r\n if (point0.isAlmostEqualXY(point1, mergeTolerance))\r\n return {point: point0, fraction: fraction0};\r\n const halfEdge = graph.createEdgeXYAndZ(point0, 0, point1, 0);\r\n const detail01 = CurveLocationDetail.createCurveEvaluatedFractionFraction(p, fraction0, fraction1);\r\n const mate = halfEdge.edgeMate;\r\n halfEdge.edgeTag = detail01;\r\n halfEdge.sortData = 1.0;\r\n mate.edgeTag = detail01;\r\n mate.sortData = -1.0;\r\n halfEdge.sortAngle = sortAngle(p, fraction0, false);\r\n mate.sortAngle = sortAngle(p, fraction1, true);\r\n return {point: point1, fraction: fraction1};\r\n }\r\n /**\r\n * Based on computed (and toleranced) area, push the loop (pointer) onto the appropriate array of positive, negative, or sliver loops.\r\n * @param zeroAreaTolerance absolute area tolerance for sliver face detection\r\n * @param isSliverFace whether the loop is known a priori (e.g., via topology) to have zero area\r\n * @returns the area (forced to zero if within tolerance)\r\n */\r\n public static collectSignedLoop(loop: Loop, outLoops: SignedLoops, zeroAreaTolerance: number = 1.0e-10, isSliverFace?: boolean): number{\r\n let area = isSliverFace ? 0.0 : RegionOps.computeXYArea(loop);\r\n if (area === undefined)\r\n area = 0;\r\n if (Math.abs(area) < zeroAreaTolerance)\r\n area = 0.0;\r\n (loop as any).computedAreaInPlanarSubdivision = area;\r\n if (area > 0)\r\n outLoops.positiveAreaLoops.push(loop);\r\n else if (area < 0)\r\n outLoops.negativeAreaLoops.push(loop);\r\n else\r\n outLoops.slivers.push(loop);\r\n return area;\r\n }\r\n public static createLoopInFace(faceSeed: HalfEdge,\r\n announce?: (he: HalfEdge, curve: CurvePrimitive, loop: Loop) => void): Loop {\r\n let he = faceSeed;\r\n const loop = Loop.create();\r\n do {\r\n const detail = he.edgeTag as CurveLocationDetail;\r\n if (detail) {\r\n let curve;\r\n if (he.sortData! > 0)\r\n curve = detail.curve!.clonePartialCurve(detail.fraction, detail.fraction1!);\r\n else\r\n curve = detail.curve!.clonePartialCurve(detail.fraction1!, detail.fraction);\r\n if (curve) {\r\n if (announce !== undefined)\r\n announce(he, curve, loop);\r\n loop.tryAddChild(curve);\r\n }\r\n }\r\n he = he.faceSuccessor;\r\n } while (he !== faceSeed);\r\n return loop;\r\n }\r\n // Return true if there are only two edges in the face loop, and their start curvatures are the same.\r\n private static isNullFace(he: HalfEdge): boolean {\r\n const faceHasTwoEdges = (he.faceSuccessor.faceSuccessor === he);\r\n let faceIsBanana = false;\r\n if (faceHasTwoEdges) {\r\n const c0 = HalfEdgeGraphMerge.curvatureSortKey(he);\r\n const c1 = HalfEdgeGraphMerge.curvatureSortKey(he.faceSuccessor.edgeMate);\r\n if (!Geometry.isSameCoordinate(c0, c1)) // default tol!\r\n faceIsBanana = true; // heuristic: we could also check end curvatures, and/or higher derivatives...\r\n }\r\n return faceHasTwoEdges && !faceIsBanana;\r\n }\r\n // Look across edge mates (possibly several) for a nonnull mate face.\r\n private static nonNullEdgeMate(_graph: HalfEdgeGraph, e: HalfEdge): HalfEdge | undefined {\r\n if (this.isNullFace (e))\r\n return undefined;\r\n let e1 = e.edgeMate;\r\n while (this.isNullFace(e1)){\r\n e1 = e1.faceSuccessor.edgeMate;\r\n if (e1 === e)\r\n return undefined;\r\n }\r\n return e1;\r\n }\r\n public static collectSignedLoopSetsInHalfEdgeGraph(graph: HalfEdgeGraph, zeroAreaTolerance: number = 1.0e-10): SignedLoops[] {\r\n const q = HalfEdgeGraphSearch.collectConnectedComponentsWithExteriorParityMasks(graph, undefined);\r\n const result: SignedLoops[] = [];\r\n const edgeMap = new Map<HalfEdge, LoopCurveLoopCurve>();\r\n for (const faceSeeds of q) {\r\n const componentAreas: SignedLoops = { positiveAreaLoops: [], negativeAreaLoops: [], slivers: [] };\r\n const edges: LoopCurveLoopCurve[] = [];\r\n for (const faceSeed of faceSeeds) {\r\n const isNullFace = this.isNullFace(faceSeed);\r\n const loop = this.createLoopInFace(faceSeed, (he: HalfEdge, curveC: CurvePrimitive, loopC: Loop) => {\r\n if (!isNullFace) {\r\n const mate = this.nonNullEdgeMate(graph, he);\r\n if (mate !== undefined) {\r\n const e = edgeMap.get(mate);\r\n if (e === undefined) {\r\n // Record this as loopA,edgeA of a shared edge to be completed later from the other side of the edge\r\n const e1 = new LoopCurveLoopCurve(loopC, curveC, undefined, undefined);\r\n edgeMap.set(he, e1);\r\n } else if (e instanceof LoopCurveLoopCurve) {\r\n e.setB(loopC, curveC);\r\n edges.push(e);\r\n edgeMap.delete(mate);\r\n }\r\n }\r\n }\r\n });\r\n this.collectSignedLoop(loop, componentAreas, zeroAreaTolerance, isNullFace);\r\n }\r\n componentAreas.edges = edges;\r\n result.push(componentAreas);\r\n edgeMap.clear();\r\n }\r\n return result;\r\n }\r\n}\r\n\r\nfunction sortAngle(curve: CurvePrimitive, fraction: number, reverse: boolean): number {\r\n const ray = curve.fractionToPointAndDerivative(fraction);\r\n const s = reverse ? -1.0 : 1.0;\r\n return Math.atan2(s * ray.direction.y, s * ray.direction.x);\r\n}\r\n\r\nfunction getFractionOnCurve(pair: CurveLocationDetailPair, curve: CurvePrimitive): number | undefined {\r\n if (pair.detailA.curve === curve)\r\n return pair.detailA.fraction;\r\n if (pair.detailB.curve === curve)\r\n return pair.detailB.fraction;\r\n return undefined;\r\n}\r\nfunction getDetailOnCurve(pair: CurveLocationDetailPair, curve: CurvePrimitive): CurveLocationDetail | undefined {\r\n if (pair.detailA.curve === curve)\r\n return pair.detailA;\r\n if (pair.detailB.curve === curve)\r\n return pair.detailB;\r\n return undefined;\r\n}\r\n"]}
@@ -129,7 +129,7 @@ export declare class RegionOps {
129
129
  * @param loopsB second set of loops
130
130
  * @param operation indicates Union, Intersection, Parity, AMinusB, or BMinusA
131
131
  * @param mergeTolerance absolute distance tolerance for merging loops
132
- * @returns a region resulting from merging input loops and the boolean operation. May contain bridge edges connecting interior loops to exterior loops.
132
+ * @returns a region resulting from merging input loops and the boolean operation. May contain bridge edges added to connect interior loops to exterior loops.
133
133
  */
134
134
  static regionBooleanXY(loopsA: AnyRegion | AnyRegion[] | undefined, loopsB: AnyRegion | AnyRegion[] | undefined, operation: RegionBinaryOpType, mergeTolerance?: number): AnyRegion | undefined;
135
135
  /**
@@ -290,17 +290,19 @@ export declare class RegionOps {
290
290
  static sortOuterAndHoleLoopsXY(loops: Array<Loop | IndexedXYZCollection>): AnyRegion;
291
291
  /**
292
292
  * Find all areas bounded by the unstructured, possibly intersecting curves.
293
- * * This method performs no merging of nearly coincident edges and vertices, which can lead to unexpected results
294
- * given sufficiently imprecise input. Input geometry consisting of regions can be merged for better results by pre-processing with
295
- * [[regionBooleanXY]].
293
+ * * A common use case of this method is to assemble the bounding "exterior" loop (or loops) containing the input curves.
294
+ * * This method does not add bridge edges to connect outer loops to inner loops. Each disconnected loop, regardless
295
+ * of its containment, is returned as its own SignedLoops object. Pre-process with [[regionBooleanXY]] to add bridge edges so that
296
+ * [[constructAllXYRegionLoops]] will return outer and inner loops in the same SignedLoops object.
296
297
  * @param curvesAndRegions Any collection of curves. Each Loop/ParityRegion/UnionRegion contributes its curve primitives.
298
+ * @param tolerance optional distance tolerance for coincidence
297
299
  * @returns array of [[SignedLoops]], each entry of which describes the faces in a single connected component:
298
300
  * * `positiveAreaLoops` contains "interior" loops, _including holes in ParityRegion input_. These loops have positive area and counterclockwise orientation.
299
301
  * * `negativeAreaLoops` contains (probably just one) "exterior" loop which is ordered clockwise.
300
302
  * * `slivers` contains sliver loops that have zero area, such as appear between coincident curves.
301
303
  * * `edges` contains a [[LoopCurveLoopCurve]] object for each component edge, collecting both loops adjacent to the edge and a constituent curve in each.
302
304
  */
303
- static constructAllXYRegionLoops(curvesAndRegions: AnyCurve | AnyCurve[]): SignedLoops[];
305
+ static constructAllXYRegionLoops(curvesAndRegions: AnyCurve | AnyCurve[], tolerance?: number): SignedLoops[];
304
306
  /**
305
307
  * Collect all `CurvePrimitives` in loosely typed input.
306
308
  * * Always recurses into primitives within explicit collections (Path, Loop, ParityRegion, UnionRegion).
@@ -1 +1 @@
1
- {"version":3,"file":"RegionOps.d.ts","sourceRoot":"","sources":["../../../src/curve/RegionOps.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA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3F;;;;;;;;;;;;;OAaG;WACW,yBAAyB,CAAC,gBAAgB,EAAE,QAAQ,GAAG,QAAQ,EAAE,EAAE,SAAS,GAAE,MAAqC,GAAG,WAAW,EAAE;IASjJ;;;;;;;;OAQG;WACW,sBAAsB,CAAC,UAAU,EAAE,QAAQ,GAAG,QAAQ,EAAE,EAAE,cAAc,CAAC,EAAE,cAAc,EAAE,EACvG,0BAA0B,GAAE,OAAe,EAC3C,kBAAkB,GAAE,OAAe,GAAG,cAAc,EAAE;IAaxD;;;;OAIG;WACW,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE;IAe/E;;;;OAIG;WACW,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,SAAS,GAAG,OAAO;CAkB5E"}
@@ -17,27 +17,27 @@ import { Transform } from "../geometry3d/Transform";
17
17
  import { MomentData } from "../geometry4d/MomentData";
18
18
  import { PolyfaceBuilder } from "../polyface/PolyfaceBuilder";
19
19
  import { HalfEdgeMask } from "../topology/Graph";
20
+ import { HalfEdgeGraphSearch } from "../topology/HalfEdgeGraphSearch";
20
21
  import { Triangulator } from "../topology/Triangulation";
21
22
  import { ChainCollectorContext } from "./ChainCollectorContext";
22
23
  import { BagOfCurves, CurveChain, CurveCollection } from "./CurveCollection";
23
24
  import { CurveCurve } from "./CurveCurve";
24
25
  import { CurvePrimitive } from "./CurvePrimitive";
25
26
  import { CurveWireMomentsXYZ } from "./CurveWireMomentsXYZ";
27
+ import { GeometryQuery } from "./GeometryQuery";
28
+ import { OffsetHelpers } from "./internalContexts/MultiChainCollector";
26
29
  import { CurveChainWireOffsetContext, PolygonWireOffsetContext } from "./internalContexts/PolygonOffsetContext";
27
30
  import { LineString3d } from "./LineString3d";
28
31
  import { Loop } from "./Loop";
32
+ import { ParityRegion } from "./ParityRegion";
29
33
  import { Path } from "./Path";
30
34
  import { ConsolidateAdjacentCurvePrimitivesContext } from "./Query/ConsolidateAdjacentPrimitivesContext";
31
35
  import { CurveSplitContext } from "./Query/CurveSplitContext";
32
36
  import { PointInOnOutContext } from "./Query/InOutTests";
33
37
  import { PlanarSubdivision } from "./Query/PlanarSubdivision";
34
38
  import { RegionMomentsXY } from "./RegionMomentsXY";
35
- import { OffsetHelpers } from "./internalContexts/MultiChainCollector";
36
- import { GeometryQuery } from "./GeometryQuery";
37
39
  import { RegionBooleanContext, RegionGroupOpType, RegionOpsFaceToFaceSearch } from "./RegionOpsClassificationSweeps";
38
40
  import { UnionRegion } from "./UnionRegion";
39
- import { HalfEdgeGraphSearch } from "../topology/HalfEdgeGraphSearch";
40
- import { ParityRegion } from "./ParityRegion";
41
41
  /**
42
42
  * Enumeration of the binary operation types for a booleans among regions
43
43
  * @public
@@ -236,7 +236,7 @@ export class RegionOps {
236
236
  * @param loopsB second set of loops
237
237
  * @param operation indicates Union, Intersection, Parity, AMinusB, or BMinusA
238
238
  * @param mergeTolerance absolute distance tolerance for merging loops
239
- * @returns a region resulting from merging input loops and the boolean operation. May contain bridge edges connecting interior loops to exterior loops.
239
+ * @returns a region resulting from merging input loops and the boolean operation. May contain bridge edges added to connect interior loops to exterior loops.
240
240
  */
241
241
  static regionBooleanXY(loopsA, loopsB, operation, mergeTolerance = Geometry.smallMetricDistance) {
242
242
  const result = UnionRegion.create();
@@ -244,7 +244,7 @@ export class RegionOps {
244
244
  context.addMembers(loopsA, loopsB);
245
245
  context.annotateAndMergeCurvesInGraph(mergeTolerance);
246
246
  const range = context.groupA.range().union(context.groupB.range());
247
- const areaTol = this.computeXYAreaTolerance(range);
247
+ const areaTol = this.computeXYAreaTolerance(range, mergeTolerance);
248
248
  context.runClassificationSweep(operation, (_graph, face, faceType, area) => {
249
249
  // ignore danglers and null faces, but not 2-edge "banana" faces with nonzero area
250
250
  if (face.countEdgesAroundFace() < 2)
@@ -562,23 +562,24 @@ export class RegionOps {
562
562
  }
563
563
  /**
564
564
  * Find all areas bounded by the unstructured, possibly intersecting curves.
565
- * * This method performs no merging of nearly coincident edges and vertices, which can lead to unexpected results
566
- * given sufficiently imprecise input. Input geometry consisting of regions can be merged for better results by pre-processing with
567
- * [[regionBooleanXY]].
565
+ * * A common use case of this method is to assemble the bounding "exterior" loop (or loops) containing the input curves.
566
+ * * This method does not add bridge edges to connect outer loops to inner loops. Each disconnected loop, regardless
567
+ * of its containment, is returned as its own SignedLoops object. Pre-process with [[regionBooleanXY]] to add bridge edges so that
568
+ * [[constructAllXYRegionLoops]] will return outer and inner loops in the same SignedLoops object.
568
569
  * @param curvesAndRegions Any collection of curves. Each Loop/ParityRegion/UnionRegion contributes its curve primitives.
570
+ * @param tolerance optional distance tolerance for coincidence
569
571
  * @returns array of [[SignedLoops]], each entry of which describes the faces in a single connected component:
570
572
  * * `positiveAreaLoops` contains "interior" loops, _including holes in ParityRegion input_. These loops have positive area and counterclockwise orientation.
571
573
  * * `negativeAreaLoops` contains (probably just one) "exterior" loop which is ordered clockwise.
572
574
  * * `slivers` contains sliver loops that have zero area, such as appear between coincident curves.
573
575
  * * `edges` contains a [[LoopCurveLoopCurve]] object for each component edge, collecting both loops adjacent to the edge and a constituent curve in each.
574
576
  */
575
- static constructAllXYRegionLoops(curvesAndRegions) {
576
- const primitivesA = RegionOps.collectCurvePrimitives(curvesAndRegions, undefined, true);
577
- const primitivesB = this.expandLineStrings(primitivesA);
578
- const range = this.curveArrayRange(primitivesB);
579
- const areaTol = this.computeXYAreaTolerance(range);
580
- const intersections = CurveCurve.allIntersectionsAmongPrimitivesXY(primitivesB);
581
- const graph = PlanarSubdivision.assembleHalfEdgeGraph(primitivesB, intersections);
577
+ static constructAllXYRegionLoops(curvesAndRegions, tolerance = Geometry.smallMetricDistance) {
578
+ const primitives = RegionOps.collectCurvePrimitives(curvesAndRegions, undefined, true, true);
579
+ const range = this.curveArrayRange(primitives);
580
+ const areaTol = this.computeXYAreaTolerance(range, tolerance);
581
+ const intersections = CurveCurve.allIntersectionsAmongPrimitivesXY(primitives, tolerance);
582
+ const graph = PlanarSubdivision.assembleHalfEdgeGraph(primitives, intersections, tolerance);
582
583
  return PlanarSubdivision.collectSignedLoopSetsInHalfEdgeGraph(graph, areaTol);
583
584
  }
584
585
  /**