@itwin/core-geometry 4.1.0-dev.70 → 4.1.0-dev.71

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 (96) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/lib/cjs/clipping/AlternatingConvexClipTree.d.ts +15 -17
  3. package/lib/cjs/clipping/AlternatingConvexClipTree.d.ts.map +1 -1
  4. package/lib/cjs/clipping/AlternatingConvexClipTree.js +24 -20
  5. package/lib/cjs/clipping/AlternatingConvexClipTree.js.map +1 -1
  6. package/lib/cjs/clipping/BooleanClipFactory.d.ts +28 -28
  7. package/lib/cjs/clipping/BooleanClipFactory.d.ts.map +1 -1
  8. package/lib/cjs/clipping/BooleanClipFactory.js +28 -28
  9. package/lib/cjs/clipping/BooleanClipFactory.js.map +1 -1
  10. package/lib/cjs/clipping/BooleanClipNode.d.ts +11 -11
  11. package/lib/cjs/clipping/BooleanClipNode.d.ts.map +1 -1
  12. package/lib/cjs/clipping/BooleanClipNode.js +11 -11
  13. package/lib/cjs/clipping/BooleanClipNode.js.map +1 -1
  14. package/lib/cjs/clipping/ClipPlane.d.ts +73 -76
  15. package/lib/cjs/clipping/ClipPlane.d.ts.map +1 -1
  16. package/lib/cjs/clipping/ClipPlane.js +105 -86
  17. package/lib/cjs/clipping/ClipPlane.js.map +1 -1
  18. package/lib/cjs/clipping/ClipPrimitive.d.ts +78 -47
  19. package/lib/cjs/clipping/ClipPrimitive.d.ts.map +1 -1
  20. package/lib/cjs/clipping/ClipPrimitive.js +110 -54
  21. package/lib/cjs/clipping/ClipPrimitive.js.map +1 -1
  22. package/lib/cjs/clipping/ClipUtils.d.ts +54 -44
  23. package/lib/cjs/clipping/ClipUtils.d.ts.map +1 -1
  24. package/lib/cjs/clipping/ClipUtils.js +33 -29
  25. package/lib/cjs/clipping/ClipUtils.js.map +1 -1
  26. package/lib/cjs/clipping/ClipVector.d.ts +39 -25
  27. package/lib/cjs/clipping/ClipVector.d.ts.map +1 -1
  28. package/lib/cjs/clipping/ClipVector.js +35 -23
  29. package/lib/cjs/clipping/ClipVector.js.map +1 -1
  30. package/lib/cjs/clipping/ConvexClipPlaneSet.d.ts +61 -38
  31. package/lib/cjs/clipping/ConvexClipPlaneSet.d.ts.map +1 -1
  32. package/lib/cjs/clipping/ConvexClipPlaneSet.js +64 -41
  33. package/lib/cjs/clipping/ConvexClipPlaneSet.js.map +1 -1
  34. package/lib/cjs/clipping/UnionOfConvexClipPlaneSets.d.ts +49 -30
  35. package/lib/cjs/clipping/UnionOfConvexClipPlaneSets.d.ts.map +1 -1
  36. package/lib/cjs/clipping/UnionOfConvexClipPlaneSets.js +50 -30
  37. package/lib/cjs/clipping/UnionOfConvexClipPlaneSets.js.map +1 -1
  38. package/lib/cjs/clipping/internalContexts/LineStringOffsetClipperContext.d.ts +2 -2
  39. package/lib/cjs/clipping/internalContexts/LineStringOffsetClipperContext.d.ts.map +1 -1
  40. package/lib/cjs/clipping/internalContexts/LineStringOffsetClipperContext.js +2 -2
  41. package/lib/cjs/clipping/internalContexts/LineStringOffsetClipperContext.js.map +1 -1
  42. package/lib/cjs/curve/CurvePrimitive.d.ts +4 -2
  43. package/lib/cjs/curve/CurvePrimitive.d.ts.map +1 -1
  44. package/lib/cjs/curve/CurvePrimitive.js.map +1 -1
  45. package/lib/cjs/curve/LineSegment3d.d.ts.map +1 -1
  46. package/lib/cjs/curve/LineSegment3d.js.map +1 -1
  47. package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
  48. package/lib/cjs/curve/LineString3d.js.map +1 -1
  49. package/lib/esm/clipping/AlternatingConvexClipTree.d.ts +15 -17
  50. package/lib/esm/clipping/AlternatingConvexClipTree.d.ts.map +1 -1
  51. package/lib/esm/clipping/AlternatingConvexClipTree.js +24 -20
  52. package/lib/esm/clipping/AlternatingConvexClipTree.js.map +1 -1
  53. package/lib/esm/clipping/BooleanClipFactory.d.ts +28 -28
  54. package/lib/esm/clipping/BooleanClipFactory.d.ts.map +1 -1
  55. package/lib/esm/clipping/BooleanClipFactory.js +28 -28
  56. package/lib/esm/clipping/BooleanClipFactory.js.map +1 -1
  57. package/lib/esm/clipping/BooleanClipNode.d.ts +11 -11
  58. package/lib/esm/clipping/BooleanClipNode.d.ts.map +1 -1
  59. package/lib/esm/clipping/BooleanClipNode.js +11 -11
  60. package/lib/esm/clipping/BooleanClipNode.js.map +1 -1
  61. package/lib/esm/clipping/ClipPlane.d.ts +73 -76
  62. package/lib/esm/clipping/ClipPlane.d.ts.map +1 -1
  63. package/lib/esm/clipping/ClipPlane.js +105 -86
  64. package/lib/esm/clipping/ClipPlane.js.map +1 -1
  65. package/lib/esm/clipping/ClipPrimitive.d.ts +78 -47
  66. package/lib/esm/clipping/ClipPrimitive.d.ts.map +1 -1
  67. package/lib/esm/clipping/ClipPrimitive.js +110 -54
  68. package/lib/esm/clipping/ClipPrimitive.js.map +1 -1
  69. package/lib/esm/clipping/ClipUtils.d.ts +54 -44
  70. package/lib/esm/clipping/ClipUtils.d.ts.map +1 -1
  71. package/lib/esm/clipping/ClipUtils.js +33 -29
  72. package/lib/esm/clipping/ClipUtils.js.map +1 -1
  73. package/lib/esm/clipping/ClipVector.d.ts +39 -25
  74. package/lib/esm/clipping/ClipVector.d.ts.map +1 -1
  75. package/lib/esm/clipping/ClipVector.js +35 -23
  76. package/lib/esm/clipping/ClipVector.js.map +1 -1
  77. package/lib/esm/clipping/ConvexClipPlaneSet.d.ts +61 -38
  78. package/lib/esm/clipping/ConvexClipPlaneSet.d.ts.map +1 -1
  79. package/lib/esm/clipping/ConvexClipPlaneSet.js +64 -41
  80. package/lib/esm/clipping/ConvexClipPlaneSet.js.map +1 -1
  81. package/lib/esm/clipping/UnionOfConvexClipPlaneSets.d.ts +49 -30
  82. package/lib/esm/clipping/UnionOfConvexClipPlaneSets.d.ts.map +1 -1
  83. package/lib/esm/clipping/UnionOfConvexClipPlaneSets.js +50 -30
  84. package/lib/esm/clipping/UnionOfConvexClipPlaneSets.js.map +1 -1
  85. package/lib/esm/clipping/internalContexts/LineStringOffsetClipperContext.d.ts +2 -2
  86. package/lib/esm/clipping/internalContexts/LineStringOffsetClipperContext.d.ts.map +1 -1
  87. package/lib/esm/clipping/internalContexts/LineStringOffsetClipperContext.js +2 -2
  88. package/lib/esm/clipping/internalContexts/LineStringOffsetClipperContext.js.map +1 -1
  89. package/lib/esm/curve/CurvePrimitive.d.ts +4 -2
  90. package/lib/esm/curve/CurvePrimitive.d.ts.map +1 -1
  91. package/lib/esm/curve/CurvePrimitive.js.map +1 -1
  92. package/lib/esm/curve/LineSegment3d.d.ts.map +1 -1
  93. package/lib/esm/curve/LineSegment3d.js.map +1 -1
  94. package/lib/esm/curve/LineString3d.d.ts.map +1 -1
  95. package/lib/esm/curve/LineString3d.js.map +1 -1
  96. package/package.json +3 -3
@@ -24,44 +24,47 @@ const ClipVector_1 = require("./ClipVector");
24
24
  const ConvexClipPlaneSet_1 = require("./ConvexClipPlaneSet");
25
25
  const LineStringOffsetClipperContext_1 = require("./internalContexts/LineStringOffsetClipperContext");
26
26
  const UnionOfConvexClipPlaneSets_1 = require("./UnionOfConvexClipPlaneSets");
27
- /** Enumerated type for describing where geometry lies with respect to clipping planes.
27
+ /**
28
+ * Enumerated type for describing where geometry lies with respect to clipping planes.
28
29
  * @public
29
30
  */
30
31
  var ClipPlaneContainment;
31
32
  (function (ClipPlaneContainment) {
32
- /** All points inside */
33
+ /** All points inside. */
33
34
  ClipPlaneContainment[ClipPlaneContainment["StronglyInside"] = 1] = "StronglyInside";
34
35
  /** Inside/outside state unknown. */
35
36
  ClipPlaneContainment[ClipPlaneContainment["Ambiguous"] = 2] = "Ambiguous";
36
- /** All points outside */
37
+ /** All points outside. */
37
38
  ClipPlaneContainment[ClipPlaneContainment["StronglyOutside"] = 3] = "StronglyOutside";
38
39
  })(ClipPlaneContainment = exports.ClipPlaneContainment || (exports.ClipPlaneContainment = {}));
39
40
  /**
40
- * Enumeration of ways to handle an intermediate fragment from a clipping step
41
+ * Enumeration of ways to handle an intermediate fragment from a clipping step.
41
42
  * @public
42
43
  */
43
44
  var ClipStepAction;
44
45
  (function (ClipStepAction) {
45
- /** Pass fragments directly to final accepted "in" state */
46
+ /** Pass fragments directly to final accepted "in" state. */
46
47
  ClipStepAction[ClipStepAction["acceptIn"] = 1] = "acceptIn";
47
- /** Pass fragments directly to final accepted "out" state */
48
+ /** Pass fragments directly to final accepted "out" state. */
48
49
  ClipStepAction[ClipStepAction["acceptOut"] = -1] = "acceptOut";
49
- /** forward fragments to subsequent steps. */
50
+ /** Forward fragments to subsequent steps. */
50
51
  ClipStepAction[ClipStepAction["passToNextStep"] = 0] = "passToNextStep";
51
52
  })(ClipStepAction = exports.ClipStepAction || (exports.ClipStepAction = {}));
52
- /** Enumerated type for describing what must yet be done to clip a piece of geometry.
53
+ /**
54
+ * Enumerated type for describing what must yet be done to clip a piece of geometry.
53
55
  * @public
54
56
  */
55
57
  var ClipStatus;
56
58
  (function (ClipStatus) {
57
- /** some geometry may cross the clip boundaries */
59
+ /** Some geometry may cross the clip boundaries */
58
60
  ClipStatus[ClipStatus["ClipRequired"] = 0] = "ClipRequired";
59
- /** geometry is clearly outside */
61
+ /** Geometry is clearly outside */
60
62
  ClipStatus[ClipStatus["TrivialReject"] = 1] = "TrivialReject";
61
- /** geometry is clearly inside */
63
+ /** Geometry is clearly inside */
62
64
  ClipStatus[ClipStatus["TrivialAccept"] = 2] = "TrivialAccept";
63
65
  })(ClipStatus = exports.ClipStatus || (exports.ClipStatus = {}));
64
- /** Class whose various static methods are functions for clipping geometry
66
+ /**
67
+ * Class whose various static methods are functions for clipping geometry
65
68
  * @public
66
69
  */
67
70
  class ClipUtilities {
@@ -99,7 +102,7 @@ class ClipUtilities {
99
102
  return false;
100
103
  }
101
104
  /**
102
- * Announce triples of (low, high, cp) for each entry in intervals
105
+ * Announce triples of (low, high, cp) for each entry in intervals.
103
106
  * @param intervals source array
104
107
  * @param cp CurvePrimitive for announcement
105
108
  * @param announce function to receive data
@@ -112,7 +115,8 @@ class ClipUtilities {
112
115
  }
113
116
  return intervals.length > 0;
114
117
  }
115
- /** Find portions of the curve that are within the clipper.
118
+ /**
119
+ * Find portions of the curve that are within the clipper.
116
120
  * Collect them into an array of curve primitives.
117
121
  */
118
122
  static collectClippedCurves(curve, clipper) {
@@ -150,7 +154,8 @@ class ClipUtilities {
150
154
  }
151
155
  return output;
152
156
  }
153
- /** Given an array of points, test for trivial containment conditions.
157
+ /**
158
+ * Given an array of points, test for trivial containment conditions.
154
159
  * * ClipStatus.TrivialAccept if all points are in any one of the convexSet's.
155
160
  * * ClipStatus.ClipRequired if (in any single convexSet) there were points on both sides of any single plane.
156
161
  * * ClipStatus.TrivialReject if neither of those occurred.
@@ -240,8 +245,9 @@ class ClipUtilities {
240
245
  }
241
246
  }
242
247
  /**
243
- * Return a (possibly empty) array of geometry (Loops !!) which are facets of the intersection of the convex set intersecting a range.
244
- * * return zero length array for (a) null range or (b) no intersections
248
+ * Return a (possibly empty) array of geometry (Loops !!) which are facets of the intersection of the convex set
249
+ * intersecting a range.
250
+ * * Return zero length array for (a) null range or (b) no intersections
245
251
  * @param allClippers convex or union clipper
246
252
  * @param range range to intersect
247
253
  * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.
@@ -411,7 +417,8 @@ class ClipUtilities {
411
417
  }
412
418
  return false;
413
419
  }
414
- /** Test for intersection of two ranges in different local coordinates.
420
+ /**
421
+ * Test for intersection of two ranges in different local coordinates.
415
422
  * * Useful for clash detection of elements in iModels, using their stored (tight) local ranges and placement transforms.
416
423
  * @param range0 range in local coordinates of first geometry
417
424
  * @param local0ToWorld placement transform for first geometry
@@ -456,8 +463,8 @@ class ClipUtilities {
456
463
  * * If there are more than baseCount+1 fragments:
457
464
  * * drop them all to the cache
458
465
  * * push a copy of the singleton.
459
- * * The use case for this is that a multi-step clipper (e.g. UnionOfConvexClipPlaneSets) may produce many fragments, and then be able to determine
460
- * that they really are the original pre-clip polygon unchanged.
466
+ * * The use case for this is that a multi-step clipper (e.g. UnionOfConvexClipPlaneSets) may produce many fragments,
467
+ * and then be able to determine that they really are the original pre-clip polygon unchanged.
461
468
  * * The baseCount+1 case is the case where the entire original singleton is still a singleton and can be left alone.
462
469
  * * Calling this replacer shuffles the original back into the fragment array, and drops the fragments.
463
470
  * * This determination is solely within the logic of the caller.
@@ -490,8 +497,7 @@ class ClipUtilities {
490
497
  }
491
498
  return LineStringOffsetClipperContext_1.LineStringOffsetClipperContext.createClipBetweenOffsets(points, leftOffset, rightOffset, z0, z1);
492
499
  }
493
- /** if data.length >= minLength threshold, push it to destination; if smaller drop it back to the cache.
494
- */
500
+ /** If data.length >= minLength threshold, push it to destination; if smaller drop it back to the cache. */
495
501
  static captureOrDrop(data, minLength, destination, cache) {
496
502
  if (data.length >= minLength)
497
503
  destination.push(data);
@@ -688,8 +694,8 @@ class ClipUtilities {
688
694
  const oldOutsideCount = acceptedOut ? acceptedOut.length : 0;
689
695
  let shard;
690
696
  // At each convex set, carryForwardA is all the fragments that have been outside all previous convex sets.
691
- // Clip each such fragment to the current set, sending the outside parts to carryForwardB, which will got to the next clipper
692
- // The final surviving carryForward really is out.
697
+ // Clip each such fragment to the current set, sending the outside parts to carryForwardB, which will got to
698
+ // the next clipper. The final surviving carryForward really is out.
693
699
  for (const c of clippers) {
694
700
  if (c.appendPolygonClip) {
695
701
  while (undefined !== (shard = candidates.pop())) {
@@ -713,9 +719,7 @@ class ClipUtilities {
713
719
  if (acceptedIn?.length === oldInsideCount)
714
720
  ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedOut, oldOutsideCount, xyz, arrayCache);
715
721
  }
716
- /**
717
- * Pass polygon `xyz` through a sequence of PolygonClip steps with "parity" rules
718
- */
722
+ /** Pass polygon `xyz` through a sequence of PolygonClip steps with "parity" rules */
719
723
  static doPolygonClipParitySequence(xyz, clippers, acceptedIn, acceptedOut, arrayCache) {
720
724
  if (arrayCache === undefined)
721
725
  arrayCache = new ReusableObjectCache_1.GrowableXYZArrayCache();
@@ -764,9 +768,9 @@ class ClipUtilities {
764
768
  moveFragments(candidatesOut, acceptedOut, arrayCache);
765
769
  }
766
770
  }
767
- /** For each plane of clipper, construct a UnionOfConvexClipPlaneSets for an outer (infinite) convex volume that
771
+ /**
772
+ * For each plane of clipper, construct a UnionOfConvexClipPlaneSets for an outer (infinite) convex volume that
768
773
  * abuts the outer volume of the neighbor faces.
769
- *
770
774
  */
771
775
  static createComplementaryClips(clipper) {
772
776
  const planes = clipper.planes;
@@ -1 +1 @@
1
- {"version":3,"file":"ClipUtils.js","sourceRoot":"","sources":["../../../src/clipping/ClipUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,wDAAqD;AAGrD,wDAAqD;AACrD,wCAAqC;AACrC,0CAAuC;AAEvC,qEAAkE;AAGlE,2EAAwE;AACxE,mEAAkE;AAClE,+CAAuD;AACvD,2EAA0E;AAG1E,iEAA8D;AAC9D,2CAAwC;AACxC,mDAAgD;AAChD,6CAA0C;AAC1C,6DAA0D;AAC1D,sGAAmG;AACnG,6EAA0E;AAE1E;;GAEG;AACH,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC9B,wBAAwB;IACxB,mFAAkB,CAAA;IAClB,oCAAoC;IACpC,yEAAa,CAAA;IACb,yBAAyB;IACzB,qFAAmB,CAAA;AACrB,CAAC,EAPW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAO/B;AACD;;;GAGG;AACH,IAAY,cAOT;AAPH,WAAY,cAAc;IACxB,2DAA2D;IAC3D,2DAAY,CAAA;IACZ,4DAA4D;IAC5D,8DAAc,CAAA;IAChB,6CAA6C;IAC3C,uEAAkB,CAAA;AAClB,CAAC,EAPS,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAOvB;AAEH;;GAEG;AACH,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,kDAAkD;IAClD,2DAAY,CAAA;IACZ,kCAAkC;IAClC,6DAAa,CAAA;IACb,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MAAM,CAAC,CAAC;yBAC5C;qBACF;iBACF;aACF;SACF;QACD,OAAO,uDAA0B,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAClE,CAAC;;AA7vBc,yCAA2B,GAAG,yBAAO,CAAC,MAAM,EAAE,CAAC;AANnD,sCAAa;AAqwB1B,SAAS,aAAa,CACpB,SAA6B,EAC7B,WAA2C,EAC3C,UAAiC;IACjC,IAAI,WAAW,KAAK,SAAS;QAC3B,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;SAClC;QACH,KAAK,MAAM,CAAC,IAAI,SAAS;YACvB,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvB;IACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AACvB,CAAC;AACD;;;;;;;;;GASG;AACH,SAAS,mBAAmB,CAC1B,MAAsB,EACtB,SAA6B,EAC7B,UAA0C,EAC1C,WAA2C,EAC3C,cAA8C,EAC9C,UAAiC;IACjC,IAAI,WAAW,CAAC;IAChB,IAAI,MAAM,KAAK,cAAc,CAAC,QAAQ;QACpC,WAAW,GAAG,UAAU,CAAC;SACtB,IAAI,MAAM,KAAK,cAAc,CAAC,SAAS;QAC1C,WAAW,GAAG,WAAW,CAAC;SACvB,IAAI,MAAM,KAAK,cAAc,CAAC,cAAc;QAC/C,WAAW,GAAG,cAAc,CAAC;IACjC,4EAA4E;IAC1E,IAAI,WAAW,KAAK,SAAS;QAC3B,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;SAClC;QACH,KAAK,MAAM,CAAC,IAAI,SAAS;YACvB,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvB;IACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AACvB,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\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\nimport { Arc3d } from \"../curve/Arc3d\";\r\nimport { CurveFactory } from \"../curve/CurveFactory\";\r\nimport { AnnounceNumberNumber, AnnounceNumberNumberCurvePrimitive, CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { GeometryQuery } from \"../curve/GeometryQuery\";\r\nimport { LineString3d } from \"../curve/LineString3d\";\r\nimport { Loop } from \"../curve/Loop\";\r\nimport { Geometry } from \"../Geometry\";\r\nimport { GrowableFloat64Array } from \"../geometry3d/GrowableFloat64Array\";\r\nimport { GrowableXYZArray } from \"../geometry3d/GrowableXYZArray\";\r\nimport { IndexedXYZCollection } from \"../geometry3d/IndexedXYZCollection\";\r\nimport { Plane3dByOriginAndUnitNormal } from \"../geometry3d/Plane3dByOriginAndUnitNormal\";\r\nimport { Point3dArrayCarrier } from \"../geometry3d/Point3dArrayCarrier\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Range1d, Range3d } from \"../geometry3d/Range\";\r\nimport { GrowableXYZArrayCache } from \"../geometry3d/ReusableObjectCache\";\r\nimport { Transform } from \"../geometry3d/Transform\";\r\nimport { XAndY } from \"../geometry3d/XYZProps\";\r\nimport { PolyfaceBuilder } from \"../polyface/PolyfaceBuilder\";\r\nimport { ClipPlane } from \"./ClipPlane\";\r\nimport { ClipPrimitive } from \"./ClipPrimitive\";\r\nimport { ClipVector } from \"./ClipVector\";\r\nimport { ConvexClipPlaneSet } from \"./ConvexClipPlaneSet\";\r\nimport { LineStringOffsetClipperContext } from \"./internalContexts/LineStringOffsetClipperContext\";\r\nimport { UnionOfConvexClipPlaneSets } from \"./UnionOfConvexClipPlaneSets\";\r\n\r\n/** Enumerated type for describing where geometry lies with respect to clipping planes.\r\n * @public\r\n */\r\nexport enum ClipPlaneContainment {\r\n /** All points inside */\r\n StronglyInside = 1,\r\n /** Inside/outside state unknown. */\r\n Ambiguous = 2,\r\n /** All points outside */\r\n StronglyOutside = 3,\r\n}\r\n/**\r\n * Enumeration of ways to handle an intermediate fragment from a clipping step\r\n * @public\r\n */\r\nexport enum ClipStepAction {\r\n /** Pass fragments directly to final accepted \"in\" state */\r\n acceptIn = 1,\r\n /** Pass fragments directly to final accepted \"out\" state */\r\n acceptOut = -1,\r\n/** forward fragments to subsequent steps. */\r\n passToNextStep = 0\r\n }\r\n\r\n/** Enumerated type for describing what must yet be done to clip a piece of geometry.\r\n * @public\r\n */\r\nexport enum ClipStatus {\r\n /** some geometry may cross the clip boundaries */\r\n ClipRequired,\r\n /** geometry is clearly outside */\r\n TrivialReject,\r\n /** geometry is clearly inside */\r\n TrivialAccept,\r\n}\r\n\r\n/** An object containing clipping planes that can be used to clip geometry.\r\n * @public\r\n */\r\nexport interface Clipper {\r\n /** test if `point` is on or inside the Clipper's volume. */\r\n isPointOnOrInside(point: Point3d, tolerance?: number): boolean;\r\n /** Find the parts of the line segment (if any) that is within the convex clip volume.\r\n * * The input fractional interval from fraction0 to fraction1 (increasing!!) is the active part to consider.\r\n * * To clip to the usual bounded line segment, start with fractions (0,1).\r\n * If the clip volume is unbounded, the line interval may also be unbounded.\r\n * * An unbounded line portion will have fraction coordinates positive or negative Number.MAX_VALUE.\r\n * @param f0 fraction that is the initial lower fraction of the active interval. (e.g. 0.0 for bounded segment)\r\n * @param f1 fraction that is the initial upper fraction of the active interval. (e.g. 1.0 for bounded segment)\r\n * @param pointA segment start (fraction 0)\r\n * @param pointB segment end (fraction 1)\r\n * @param announce function to be called to announce a fraction interval that is within the convex clip volume.\r\n * @returns true if a segment was announced, false if entirely outside.\r\n */\r\n announceClippedSegmentIntervals(f0: number, f1: number, pointA: Point3d, pointB: Point3d, announce?: AnnounceNumberNumber): boolean;\r\n /** Find the portion (or portions) of the arc (if any) that are within the convex clip volume.\r\n * * The input fractional interval from fraction0 to fraction1 (increasing!!) is the active part to consider.\r\n * @param announce function to be called to announce a fraction interval that is within the convex clip volume.\r\n * @returns true if one or more arcs portions were announced, false if entirely outside.\r\n */\r\n announceClippedArcIntervals(arc: Arc3d, announce?: AnnounceNumberNumberCurvePrimitive): boolean;\r\n/** Optional polygon clip method.\r\n * * This is expected to be implemented by planar clip structures.\r\n * * This is unimplemented for curve clippers (e.g. sphere) for which polygon clip result has\r\n * curved edges.\r\n */\r\n appendPolygonClip?: AppendPolygonClipFunction;\r\n}\r\n /**\r\n * Signature of method to execute polygon clip, distributing fragments of xyz among insideFragments and outsideFragments\r\n * @param xyz input polygon. This is not changed.\r\n * @param insideFragments Array to receive \"inside\" fragments. Each fragment is a GrowableXYZArray grabbed from the cache. This is NOT cleared.\r\n * @param outsideFragments Array to receive \"outside\" fragments. Each fragment is a GrowableXYZArray grabbed from the cache. This is NOT cleared.\r\n * @param arrayCache cache for reusable GrowableXYZArray.\r\n */\r\n type AppendPolygonClipFunction = (\r\n xyz: GrowableXYZArray,\r\n insideFragments: GrowableXYZArray[],\r\n outsideFragments: GrowableXYZArray[],\r\n arrayCache: GrowableXYZArrayCache) => void;\r\n\r\n/**\r\n * Interface for clipping polygons.\r\n * Supported by:\r\n * * AlternatingCCTreeNode\r\n * * ConvexClipPlaneSet\r\n * @public\r\n */\r\nexport interface PolygonClipper {\r\n appendPolygonClip: AppendPolygonClipFunction;\r\n}\r\n/** Class whose various static methods are functions for clipping geometry\r\n * @public\r\n */\r\nexport class ClipUtilities {\r\n // on-demand scratch objects for method implementations. If you use one, make sure it isn't already being used in scope.\r\n private static _workTransform?: Transform;\r\n private static _workRange?: Range3d;\r\n private static _workClipper?: ConvexClipPlaneSet;\r\n\r\n private static _selectIntervals01TestPoint = Point3d.create();\r\n /**\r\n * * Augment the unsortedFractionsArray with 0 and 1\r\n * * sort\r\n * * test the midpoint of each interval with `clipper.isPointOnOrInside`\r\n * * pass accepted intervals to `announce(f0,f1,curve)`\r\n */\r\n public static selectIntervals01(curve: CurvePrimitive, unsortedFractions: GrowableFloat64Array, clipper: Clipper, announce?: AnnounceNumberNumberCurvePrimitive): boolean {\r\n unsortedFractions.push(0);\r\n unsortedFractions.push(1);\r\n unsortedFractions.sort();\r\n let f0 = unsortedFractions.atUncheckedIndex(0);\r\n let f1;\r\n let fMid;\r\n const testPoint = ClipUtilities._selectIntervals01TestPoint;\r\n const n = unsortedFractions.length;\r\n for (let i = 1; i < n; i++) {\r\n f1 = unsortedFractions.atUncheckedIndex(i);\r\n if (f1 > f0 + Geometry.smallFraction) {\r\n fMid = 0.5 * (f0 + f1);\r\n if (fMid >= 0.0 && fMid <= 1.0) {\r\n curve.fractionToPoint(fMid, testPoint);\r\n if (clipper.isPointOnOrInside(testPoint)) {\r\n if (announce)\r\n announce(f0, f1, curve);\r\n else\r\n return true;\r\n }\r\n }\r\n f0 = f1;\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Announce triples of (low, high, cp) for each entry in intervals\r\n * @param intervals source array\r\n * @param cp CurvePrimitive for announcement\r\n * @param announce function to receive data\r\n */\r\n public static announceNNC(intervals: Range1d[], cp: CurvePrimitive, announce?: AnnounceNumberNumberCurvePrimitive): boolean {\r\n if (announce) {\r\n for (const ab of intervals) {\r\n announce(ab.low, ab.high, cp);\r\n }\r\n }\r\n return intervals.length > 0;\r\n }\r\n\r\n /** Find portions of the curve that are within the clipper.\r\n * Collect them into an array of curve primitives.\r\n */\r\n public static collectClippedCurves(curve: CurvePrimitive, clipper: Clipper): CurvePrimitive[] {\r\n const result: CurvePrimitive[] = [];\r\n curve.announceClipIntervals(clipper,\r\n (fraction0: number, fraction1: number, curveA: CurvePrimitive) => {\r\n if (fraction1 !== fraction0) {\r\n const partialCurve = curveA.clonePartialCurve(fraction0, fraction1);\r\n if (partialCurve)\r\n result.push(partialCurve);\r\n }\r\n });\r\n return result;\r\n }\r\n\r\n /**\r\n * Clip a polygon down to regions defined by each shape of a ClipShape.\r\n * @return An multidimensional array of points, where each array is the boundary of part of the remaining polygon.\r\n */\r\n public static clipPolygonToClipShape(polygon: Point3d[], clipShape: ClipPrimitive): Point3d[][] {\r\n const outputA = this.clipPolygonToClipShapeReturnGrowableXYZArrays(polygon, clipShape);\r\n const output = [];\r\n for (const g of outputA)\r\n output.push(g.getPoint3dArray());\r\n return output;\r\n }\r\n\r\n /**\r\n * Clip a polygon down to regions defined by each shape of a ClipShape.\r\n * @return An multidimensional array of points, where each array is the boundary of part of the remaining polygon.\r\n */\r\n public static clipPolygonToClipShapeReturnGrowableXYZArrays(polygon: Point3d[], clipShape: ClipPrimitive): GrowableXYZArray[] {\r\n const output: GrowableXYZArray[] = [];\r\n const clipper = clipShape.fetchClipPlanesRef();\r\n // NEEDS WORK -- what if it is a mask !!!!\r\n if (clipper) {\r\n clipper.polygonClip(polygon, output);\r\n }\r\n return output;\r\n }\r\n\r\n /** Given an array of points, test for trivial containment conditions.\r\n * * ClipStatus.TrivialAccept if all points are in any one of the convexSet's.\r\n * * ClipStatus.ClipRequired if (in any single convexSet) there were points on both sides of any single plane.\r\n * * ClipStatus.TrivialReject if neither of those occurred.\r\n */\r\n public static pointSetSingleClipStatus(points: GrowableXYZArray, planeSet: UnionOfConvexClipPlaneSets, tolerance: number): ClipStatus {\r\n if (planeSet.convexSets.length === 0)\r\n return ClipStatus.TrivialAccept;\r\n\r\n for (const convexSet of planeSet.convexSets) {\r\n let allOutsideSinglePlane = false, anyOutside = false;\r\n\r\n for (const plane of convexSet.planes) {\r\n let numInside = 0, numOutside = 0;\r\n const planeDistance = plane.distance - tolerance;\r\n\r\n const currPt = Point3d.create();\r\n const currVec = Vector3d.create();\r\n for (let i = 0; i < points.length; i++) {\r\n points.getPoint3dAtUncheckedPointIndex(i, currPt);\r\n currVec.setFrom(currPt);\r\n currVec.dotProduct(plane.inwardNormalRef) > planeDistance ? numInside++ : numOutside++;\r\n }\r\n\r\n anyOutside = (numOutside !== 0) ? true : anyOutside;\r\n if (numInside === 0) {\r\n allOutsideSinglePlane = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!anyOutside) // totally inside this set - no clip required\r\n return ClipStatus.TrivialAccept;\r\n if (!allOutsideSinglePlane)\r\n return ClipStatus.ClipRequired;\r\n }\r\n return ClipStatus.TrivialReject;\r\n }\r\n\r\n /**\r\n * Emit point loops for intersection of a convex set with a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static announceLoopsOfConvexClipPlaneSetIntersectRange(convexSet: ConvexClipPlaneSet | ClipPlane, range: Range3d, loopFunction: (loopPoints: GrowableXYZArray) => void,\r\n includeConvexSetFaces: boolean = true, includeRangeFaces: boolean = true, ignoreInvisiblePlanes = false) {\r\n const work = new GrowableXYZArray();\r\n if (includeConvexSetFaces) {\r\n // Clip convexSet planes to the range and to the rest of the convexSet . .\r\n if (convexSet instanceof ConvexClipPlaneSet) {\r\n for (const plane of convexSet.planes) {\r\n if (ignoreInvisiblePlanes && plane.invisible)\r\n continue;\r\n const pointsClippedToRange = plane.intersectRange(range, true);\r\n const finalPoints = new GrowableXYZArray();\r\n if (pointsClippedToRange) {\r\n convexSet.polygonClip(pointsClippedToRange, finalPoints, work, plane);\r\n if (finalPoints.length > 0)\r\n loopFunction(finalPoints);\r\n }\r\n }\r\n } else { // `convexSet` is just one plane ...\r\n if (ignoreInvisiblePlanes && convexSet.invisible) {\r\n // skip it !\r\n } else {\r\n const pointsClippedToRange = convexSet.intersectRange(range, true);\r\n if (pointsClippedToRange)\r\n loopFunction(pointsClippedToRange);\r\n }\r\n }\r\n }\r\n\r\n if (includeRangeFaces) {\r\n // clip range faces to the convex set . . .\r\n const corners = range.corners();\r\n for (let i = 0; i < 6; i++) {\r\n const indices = Range3d.faceCornerIndices(i);\r\n const finalPoints = new GrowableXYZArray();\r\n const lineString = LineString3d.createIndexedPoints(corners, indices);\r\n if (convexSet instanceof ConvexClipPlaneSet) {\r\n convexSet.polygonClip(lineString.packedPoints, finalPoints, work);\r\n if (finalPoints.length > 0)\r\n loopFunction(finalPoints);\r\n } else {\r\n convexSet.clipConvexPolygonInPlace(lineString.packedPoints, work);\r\n if (lineString.packedPoints.length > 0)\r\n loopFunction(lineString.packedPoints);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Return a (possibly empty) array of geometry (Loops !!) which are facets of the intersection of the convex set intersecting a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param allClippers convex or union clipper\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static loopsOfConvexClipPlaneIntersectionWithRange(allClippers: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPlane, range: Range3d,\r\n includeConvexSetFaces: boolean = true, includeRangeFaces: boolean = true, ignoreInvisiblePlanes = false): GeometryQuery[] {\r\n const result: GeometryQuery[] = [];\r\n if (allClippers instanceof UnionOfConvexClipPlaneSets) {\r\n for (const clipper of allClippers.convexSets) {\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(clipper, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.push(Loop.createPolygon(points));\r\n },\r\n includeConvexSetFaces, includeRangeFaces, ignoreInvisiblePlanes);\r\n }\r\n } else if (allClippers instanceof ConvexClipPlaneSet || allClippers instanceof ClipPlane) {\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(allClippers, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.push(Loop.createPolygon(points));\r\n },\r\n includeConvexSetFaces, includeRangeFaces, ignoreInvisiblePlanes);\r\n }\r\n return result;\r\n }\r\n /**\r\n * Return the (possibly null) range of the intersection of the convex set with a range.\r\n * * The convex set is permitted to be unbounded (e.g. a single plane). The range parameter provides bounds.\r\n * @param convexSet convex set for intersection.\r\n * @param range range to intersect\r\n */\r\n public static rangeOfConvexClipPlaneSetIntersectionWithRange(convexSet: ConvexClipPlaneSet, range: Range3d): Range3d {\r\n const result = Range3d.createNull();\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(convexSet, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.extendArray(points);\r\n },\r\n true, true, false);\r\n return result;\r\n }\r\n /**\r\n * Return the range of various types of clippers\r\n * * `ConvexClipPlaneSet` -- dispatch to `rangeOfConvexClipPlaneSetIntersectionWithRange`\r\n * * `UnionOfConvexClipPlaneSet` -- union of ranges of member `ConvexClipPlaneSet`\r\n * * `ClipPrimitive` -- access its `UnionOfConvexClipPlaneSet`.\r\n * * `ClipVector` -- intersection of the ranges of its `ClipPrimitive`.\r\n * * `undefined` -- entire input range.\r\n * * If `observeInvisibleFlag` is false, the \"invisible\" properties are ignored, and this effectively returns the range of the edge work of the members\r\n * * If `observeInvisibleFlag` is true, the \"invisible\" properties are observed, and \"invisible\" parts do not restrict the range.\r\n * @param clipper\r\n * @param range non-null range.\r\n * @param observeInvisibleFlag indicates how \"invisible\" bit is applied for ClipPrimitive.\r\n */\r\n public static rangeOfClipperIntersectionWithRange(clipper: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPrimitive | ClipVector | undefined, range: Range3d, observeInvisibleFlag: boolean = true): Range3d {\r\n if (clipper === undefined)\r\n return range.clone();\r\n if (clipper instanceof ConvexClipPlaneSet)\r\n return this.rangeOfConvexClipPlaneSetIntersectionWithRange(clipper, range);\r\n if (clipper instanceof UnionOfConvexClipPlaneSets) {\r\n const rangeUnion = Range3d.createNull();\r\n for (const c of clipper.convexSets) {\r\n const rangeC = this.rangeOfConvexClipPlaneSetIntersectionWithRange(c, range);\r\n rangeUnion.extendRange(rangeC);\r\n }\r\n return rangeUnion;\r\n }\r\n if (clipper instanceof ClipPrimitive) {\r\n if (observeInvisibleFlag && clipper.invisible)\r\n return range.clone();\r\n return this.rangeOfClipperIntersectionWithRange(clipper.fetchClipPlanesRef(), range);\r\n }\r\n if (clipper instanceof ClipVector) {\r\n const rangeIntersection = range.clone();\r\n for (const c of clipper.clips) {\r\n if (observeInvisibleFlag && c.invisible) {\r\n // trivial range tests do not expose the effects. Assume the hole allows everything.\r\n } else {\r\n const rangeC = this.rangeOfClipperIntersectionWithRange(c, range, observeInvisibleFlag);\r\n rangeIntersection.intersect(rangeC, rangeIntersection);\r\n }\r\n }\r\n return rangeIntersection;\r\n\r\n }\r\n return range.clone();\r\n }\r\n /**\r\n * Test if various types of clippers have any intersection with a range.\r\n * * This follows the same logic as `rangeOfClipperIntersectionWithRange` but attempts to exit at earliest point of confirmed intersection\r\n * * `ConvexClipPlaneSet` -- dispatch to `doesConvexClipPlaneSetIntersectRange`\r\n * * `UnionOfConvexClipPlaneSet` -- union of ranges of member `ConvexClipPlaneSet`\r\n * * `ClipPrimitive` -- access its `UnionOfConvexClipPlaneSet`.\r\n * * `ClipVector` -- intersection of the ranges of its `ClipPrimitive`.\r\n * * `undefined` -- entire input range.\r\n * * If `observeInvisibleFlag` is false, the \"invisible\" properties are ignored, and holes do not affect the result.\r\n * * If `observeInvisibleFlag` is true, the \"invisible\" properties are observed, and may affect the result.\r\n * @param clipper\r\n * @param range non-null range.\r\n * @param observeInvisibleFlag indicates how \"invisible\" bit is applied for ClipPrimitive.\r\n */\r\n public static doesClipperIntersectRange(clipper: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPrimitive | ClipVector | undefined, range: Range3d, observeInvisibleFlag: boolean = true): boolean {\r\n if (clipper === undefined)\r\n return true;\r\n\r\n if (clipper instanceof ConvexClipPlaneSet)\r\n return this.doesConvexClipPlaneSetIntersectRange(clipper, range);\r\n\r\n if (clipper instanceof UnionOfConvexClipPlaneSets) {\r\n for (const c of clipper.convexSets) {\r\n if (this.doesConvexClipPlaneSetIntersectRange(c, range))\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n if (clipper instanceof ClipPrimitive) {\r\n if (observeInvisibleFlag && clipper.invisible) // um is there an easy way to detect range-completely-inside?\r\n return true;\r\n return this.doesClipperIntersectRange(clipper.fetchClipPlanesRef(), range);\r\n }\r\n\r\n if (clipper instanceof ClipVector) {\r\n const rangeIntersection = range.clone();\r\n for (const c of clipper.clips) {\r\n if (observeInvisibleFlag && c.invisible) {\r\n // trivial range tests do not expose the effects. Assume the hole allows everything.\r\n } else {\r\n const rangeC = this.rangeOfClipperIntersectionWithRange(c, range, observeInvisibleFlag);\r\n rangeIntersection.intersect(rangeC, rangeIntersection);\r\n }\r\n }\r\n return !rangeIntersection.isNull;\r\n }\r\n /** If the case statement above is complete for the variant inputs, this is unreachable .. */\r\n return false;\r\n }\r\n /**\r\n * Emit point loops for intersection of a convex set with a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static doesConvexClipPlaneSetIntersectRange(convexSet: ConvexClipPlaneSet, range: Range3d,\r\n includeConvexSetFaces: boolean = true, includeRangeFaces: boolean = true, ignoreInvisiblePlanes = false): boolean {\r\n const work = new GrowableXYZArray();\r\n if (includeConvexSetFaces) {\r\n // Clip convexSet planes to the range and to the rest of the convexSet . .\r\n for (const plane of convexSet.planes) {\r\n if (ignoreInvisiblePlanes && plane.invisible)\r\n continue;\r\n const pointsClippedToRange = plane.intersectRange(range, true);\r\n if (pointsClippedToRange) {\r\n const finalPoints = new GrowableXYZArray();\r\n convexSet.polygonClip(pointsClippedToRange, finalPoints, work, plane);\r\n if (finalPoints.length > 0)\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n if (includeRangeFaces) {\r\n // clip range faces to the convex set . . .\r\n const corners = range.corners();\r\n for (let i = 0; i < 6; i++) {\r\n const indices = Range3d.faceCornerIndices(i);\r\n const finalPoints = new GrowableXYZArray();\r\n const lineString = LineString3d.createIndexedPoints(corners, indices);\r\n convexSet.polygonClip(lineString.packedPoints, finalPoints, work);\r\n if (finalPoints.length > 0)\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /** Test for intersection of two ranges in different local coordinates.\r\n * * Useful for clash detection of elements in iModels, using their stored (tight) local ranges and placement transforms.\r\n * @param range0 range in local coordinates of first geometry\r\n * @param local0ToWorld placement transform for first geometry\r\n * @param range1 range in local coordinates of second geometry\r\n * @param local1ToWorld placement transform for second geometry. Assumed to be invertible.\r\n * @param range1Margin optional signed local distance to expand/contract the second range before intersection. Positive expands.\r\n * @return whether the local ranges are adjacent or intersect. Also returns false if local1ToWorld is singular.\r\n */\r\n public static doLocalRangesIntersect(range0: Range3d, local0ToWorld: Transform, range1: Range3d, local1ToWorld: Transform, range1Margin?: number): boolean {\r\n const worldToLocal1 = ClipUtilities._workTransform = local1ToWorld.inverse(ClipUtilities._workTransform);\r\n if (!worldToLocal1)\r\n return false;\r\n let myRange1 = range1;\r\n if (range1Margin) {\r\n myRange1 = ClipUtilities._workRange = range1.clone(ClipUtilities._workRange);\r\n myRange1.expandInPlace(range1Margin);\r\n }\r\n // convert range0 into a clipper in local1 coordinates, then intersect with range1\r\n const local0ToLocal1 = worldToLocal1.multiplyTransformTransform(local0ToWorld, worldToLocal1);\r\n const builder = PolyfaceBuilder.create();\r\n builder.addTransformedRangeMesh(local0ToLocal1, range0);\r\n const mesh0 = builder.claimPolyface();\r\n const clipper = ClipUtilities._workClipper = ConvexClipPlaneSet.createConvexPolyface(mesh0, ClipUtilities._workClipper).clipper;\r\n return ClipUtilities.doesClipperIntersectRange(clipper, myRange1);\r\n }\r\n\r\n /**\r\n * Test if `obj` is a `Clipper` object.\r\n * * This is implemented by testing for each of the methods in the `Clipper` interface.\r\n */\r\n public static isClipper(obj: any): boolean {\r\n if (obj) {\r\n if (obj.isPointOnOrInside\r\n && obj.announceClippedSegmentIntervals\r\n && obj.announceClippedArcIntervals)\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Specialized logic for replacing clip fragments by an equivalent singleton.\r\n * * If there are baseCount + 1 or fewer fragments, do nothing.\r\n * * If there are more than baseCount+1 fragments:\r\n * * drop them all to the cache\r\n * * push a copy of the singleton.\r\n * * The use case for this is that a multi-step clipper (e.g. UnionOfConvexClipPlaneSets) may produce many fragments, and then be able to determine\r\n * that they really are the original pre-clip polygon unchanged.\r\n * * The baseCount+1 case is the case where the entire original singleton is still a singleton and can be left alone.\r\n * * Calling this replacer shuffles the original back into the fragment array, and drops the fragments.\r\n * * This determination is solely within the logic of the caller.\r\n * @param shards array of fragments\r\n * @param baseCount original count\r\n * @param singleton single array which may be a replacement for multiple fragments\r\n * @param cache cache for array management\r\n */\r\n public static restoreSingletonInPlaceOfMultipleShards(fragments: GrowableXYZArray[] | undefined, baseCount: number, singleton: GrowableXYZArray, arrayCache: GrowableXYZArrayCache) {\r\n if (fragments && fragments.length > baseCount + 1) {\r\n while (fragments.length > baseCount) {\r\n const f = fragments.pop();\r\n arrayCache.dropToCache(f);\r\n }\r\n fragments.push(arrayCache.grabAndFill(singleton));\r\n }\r\n }\r\n\r\n /**\r\n * Create a UnionOfConvexClipPlaneSets for a volume defined by a path and offsets.\r\n * @param points points along the path.\r\n * @param positiveOffsetLeft offset to left. 0 is clip on the path.\r\n * @param positiveOffsetRight offset to the right. 0 is clip on the path.\r\n * @param z0 z for lower clipping plane. If undefined, unbounded in positive z\r\n * @param z1 z for upper clipping plane. If undefined, unbounded in negative z.\r\n * @alpha\r\n */\r\n public static createXYOffsetClipFromLineString(points: Point3d[] | IndexedXYZCollection,\r\n leftOffset: number, rightOffset: number, z0: number, z1: number): UnionOfConvexClipPlaneSets {\r\n if (Array.isArray(points)) {\r\n return LineStringOffsetClipperContext.createClipBetweenOffsets(\r\n new Point3dArrayCarrier(points), leftOffset, rightOffset, z0, z1);\r\n }\r\n return LineStringOffsetClipperContext.createClipBetweenOffsets(points, leftOffset, rightOffset, z0, z1);\r\n }\r\n /** if data.length >= minLength threshold, push it to destination; if smaller drop it back to the cache.\r\n */\r\n public static captureOrDrop(data: GrowableXYZArray, minLength: number, destination: GrowableXYZArray[], cache: GrowableXYZArrayCache) {\r\n if (data.length >= minLength)\r\n destination.push(data);\r\n else\r\n cache.dropToCache(data);\r\n }\r\n /**\r\n * Find the portion of a line within a half-plane clip.\r\n * * The half-plane clip is to the left of the line from clipA to clipB.\r\n * * The original clipped segment has fractions 0 and 1 at respective segment points.\r\n * * Caller initializes the interval\r\n * * This method reduces the interval size.\r\n * * See clipSegmentToCCWTriangleXY for typical use.\r\n * @param linePointA First point of clip line\r\n * @param linePointB Second point of clip line\r\n * @param segmentPoint0 First point of clipped segment\r\n * @param segmentPoint1 Second point of clipped segment\r\n * @param interval Live interval.\r\n * @param absoluteTolerance absolute tolerance for both cross product values to indicate \"on\" the line\r\n */\r\n public static clipSegmentToLLeftOfLineXY(linePointA: XAndY, linePointB: XAndY, segmentPoint0: XAndY, segmentPoint1: XAndY, interval: Range1d,\r\n absoluteTolerance: number = 1.0e-14) {\r\n const ux = linePointB.x - linePointA.x;\r\n const uy = linePointB.y - linePointA.y;\r\n // negative is in positive is out ...\r\n const h0 = -(ux * (segmentPoint0.y - linePointA.y) - uy * (segmentPoint0.x - linePointA.x));\r\n const h1 = -(ux * (segmentPoint1.y - linePointA.y) - uy * (segmentPoint1.x - linePointA.x));\r\n if (h0 < absoluteTolerance && h1 < absoluteTolerance) {\r\n // The entire segment is in .....\r\n return;\r\n }\r\n if (h0 * h1 > 0.0) {\r\n if (h0 > 0.0)\r\n interval.setNull();\r\n } else if (h0 * h1 < 0.0) {\r\n // strict crossing with safe fraction . . .\r\n const fraction = -h0 / (h1 - h0);\r\n if (h0 < 0.0) {\r\n return interval.intersectRangeXXInPlace(0.0, fraction);\r\n } else {\r\n return interval.intersectRangeXXInPlace(fraction, 1.0);\r\n }\r\n } else {\r\n // There is an exact hit at one end, possibly non-zero at the other ... the sign of either determines which side is in play\r\n // A zero and a zero or negative is entirely in, which does not alter the prior clip.\r\n if (h0 > 0.0) {\r\n interval.intersectRangeXXInPlace(1.0, 1.0);\r\n } else if (h1 > 0.0) {\r\n interval.intersectRangeXXInPlace(0.0, 0.0);\r\n }\r\n }\r\n }\r\n /**\r\n * Clip an interval of a line segment to a triangle.\r\n * * Triangle is assumed CCW\r\n * @param pointA point of triangle.\r\n * @param pointB point of triangle.\r\n * @param pointC point of triangle.\r\n * @param segment0 start of segment\r\n * @param segment1 end of segment\r\n * @param interval Pre-initialized interval of live part of segment\r\n * @param absoluteTolerance absolute tolerance for begin \"on a line\"\r\n */\r\n public static clipSegmentToCCWTriangleXY(pointA: XAndY, pointB: XAndY, pointC: XAndY, segment0: XAndY, segment1: XAndY, interval: Range1d,\r\n absoluteTolerance: number = 1.0e-14) {\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointA, pointB, segment0, segment1, interval, absoluteTolerance);\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointB, pointC, segment0, segment1, interval, absoluteTolerance);\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointC, pointA, segment0, segment1, interval, absoluteTolerance);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Find the portion of a line within a half-plane clip.\r\n * * The half-plane clip is to the left of the line from clipA to clipB.\r\n * * The original clipped segment has fractions 0 and 1 at respective segment points.\r\n * * Caller initializes the interval\r\n * * This method reduces the interval size.\r\n * * See clipSegmentToCCWTriangleXY for typical use.\r\n * @param linePointA First point of clip line\r\n * @param linePointB Second point of clip line\r\n * @param segmentPoint0 First point of clipped segment\r\n * @param segmentPoint1 Second point of clipped segment\r\n * @param interval Live interval.\r\n * @param absoluteTolerance absolute tolerance for both cross product values to indicate \"on\" the line\r\n */\r\n public static clipSegmentBelowPlaneXY(plane: Plane3dByOriginAndUnitNormal, segmentPoint0: XAndY, segmentPoint1: XAndY, interval: Range1d,\r\n absoluteTolerance: number = 1.0e-14) {\r\n // negative is in positive is out ...\r\n const h0 = plane.altitudeXY(segmentPoint0.x, segmentPoint0.y);\r\n const h1 = plane.altitudeXY(segmentPoint1.x, segmentPoint1.y);\r\n if (h0 < absoluteTolerance && h1 < absoluteTolerance) {\r\n // The entire segment is in ..... the interval is unaffected.\r\n return;\r\n }\r\n if (h0 * h1 > 0.0) {\r\n if (h0 > 0.0)\r\n interval.setNull();\r\n } else if (h0 * h1 < 0.0) {\r\n // strict crossing with safe fraction . . .\r\n const fraction = -h0 / (h1 - h0);\r\n if (h0 < 0.0) {\r\n return interval.intersectRangeXXInPlace(0.0, fraction);\r\n } else {\r\n return interval.intersectRangeXXInPlace(fraction, 1.0);\r\n }\r\n } else {\r\n // There is an exact hit at one end, possibly non-zero at the other ... the sign of either determines which side is in play\r\n // A zero and a zero or negative is entirely in, which does not alter the prior clip.\r\n if (h0 > 0.0) {\r\n interval.intersectRangeXXInPlace(1.0, 1.0);\r\n } else if (h1 > 0.0) {\r\n interval.intersectRangeXXInPlace(0.0, 0.0);\r\n }\r\n }\r\n }\r\n /**\r\n * Clip an interval of a line segment to an array of planes\r\n * * plane normals assumed OUTWARD\r\n * * planeAltitude is typically a tolerance a tolerance distance.\r\n * * positive altitude makes tha plane move in the direction of the unit normal.\r\n * @param planes array of planes\r\n * @param segment0 start of segment\r\n * @param segment1 end of segment\r\n * @param interval Pre-initialized interval of live part of segment\r\n * @param absoluteTolerance absolute tolerance for begin \"on a line\"\r\n */\r\n public static clipSegmentBelowPlanesXY(planes: Plane3dByOriginAndUnitNormal[], segment0: XAndY, segment1: XAndY, interval: Range1d,\r\n signedAltitude: number = 1.0e-14) {\r\n const numPlanes = planes.length;\r\n for (let i = 0; (!interval.isNull) && i < numPlanes; i++) {\r\n this.clipSegmentBelowPlaneXY(planes[i], segment0, segment1, interval, signedAltitude);\r\n }\r\n }\r\n /**\r\n * Pass line segments from a polyline to the clipper. Resolve the fractional clips to simple points for announcement.\r\n * @param clipper clipper to call\r\n * @param points polyline whose segments are passed to the clipper\r\n * @param announce caller's handler for simple point pairs.\r\n */\r\n public static announcePolylineClip(clipper: Clipper, points: Point3d[], announce: (point0: Point3d, point1: Point3d) => void) {\r\n for (let i = 0; i + 1 < points.length; i++) {\r\n clipper.announceClippedSegmentIntervals(0, 1, points[i], points[i + 1],\r\n (f0: number, f1: number) => {\r\n announce(points[i].interpolate(f0, points[i + 1]), points[i].interpolate(f1, points[i + 1]));\r\n });\r\n }\r\n }\r\n /**\r\n * Pass line segments from a polyline to the clipper. Sum the lengths of the clipped pieces. Return the sum.\r\n * @param clipper clipper to call\r\n * @param points polyline whose segments are passed to the clipper\r\n */\r\n public static sumPolylineClipLength(clipper: Clipper, points: Point3d[]) {\r\n let s = 0;\r\n for (let i = 0; i + 1 < points.length; i++) {\r\n const a = points[i].distance(points[i + 1]);\r\n clipper.announceClippedSegmentIntervals(0, 1, points[i], points[i + 1],\r\n (f0: number, f1: number) => { s += Math.abs(f1 - f0) * a; });\r\n }\r\n return s;\r\n }\r\n /**\r\n * Pass polygon `xyz` through a sequence of PolygonClip steps.\r\n * * At the outset, `xyz` is the (only) entry in a set of candidates.\r\n * * For each clipper, each candidate is presented for appendPolygon to inside and outside parts.\r\n * * Each (in,out) result is distributed among (acceptedIn, acceptedOut, candidates) according to\r\n * (inAction, outAction)\r\n * * At the end, all remaining candidates are distributed among (acceptedIn, acceptedOut, finalUnknown)\r\n * according to finalAction\r\n * * Any clipper that does not have an appendPolygonClip method is skipped.\r\n * @param xyz\r\n * @param clippers\r\n * @param acceptedIn\r\n * @param acceptedOut\r\n * @param finalCandidates\r\n * @param inAction\r\n * @param outAction\r\n * @param finalCandidateAction\r\n */\r\n public static doPolygonClipSequence(\r\n xyz: GrowableXYZArray,\r\n clippers: Clipper[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n finalCandidates: GrowableXYZArray[] | undefined,\r\n inAction: ClipStepAction,\r\n outAction: ClipStepAction,\r\n finalFragmentAction: ClipStepAction,\r\n arrayCache: GrowableXYZArrayCache | undefined,\r\n ) {\r\n if (arrayCache === undefined)\r\n arrayCache = new GrowableXYZArrayCache();\r\n let candidates = [arrayCache.grabAndFill(xyz)];\r\n let nextCandidates: GrowableXYZArray[] = [];\r\n const intermediateIn: GrowableXYZArray[] = [];\r\n const intermediateOut: GrowableXYZArray[] = [];\r\n const oldInsideCount = acceptedIn ? acceptedIn.length : 0;\r\n const oldOutsideCount = acceptedOut ? acceptedOut.length : 0;\r\n let shard;\r\n // At each convex set, carryForwardA is all the fragments that have been outside all previous convex sets.\r\n // Clip each such fragment to the current set, sending the outside parts to carryForwardB, which will got to the next clipper\r\n // The final surviving carryForward really is out.\r\n for (const c of clippers) {\r\n if (c.appendPolygonClip) {\r\n while (undefined !== (shard = candidates.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(inAction, intermediateIn, acceptedIn, acceptedOut, nextCandidates, arrayCache);\r\n distributeFragments(outAction, intermediateOut, acceptedIn, acceptedOut, nextCandidates, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // candidates is empty !!\r\n const temp = candidates; candidates = nextCandidates; nextCandidates = temp;\r\n }\r\n }\r\n distributeFragments(finalFragmentAction, candidates, acceptedIn, acceptedOut, finalCandidates, arrayCache);\r\n // Note: The following assumes that there were no residual candidates ... need to track if that happened?\r\n // If nothing was out, the inside fragments can be replaced by the original.\r\n if (acceptedOut?.length === oldOutsideCount)\r\n ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedIn, oldInsideCount, xyz, arrayCache);\r\n // If nothing was in, the outside fragments can be replaced by the original.\r\n if (acceptedIn?.length === oldInsideCount)\r\n ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedOut, oldOutsideCount, xyz, arrayCache);\r\n }\r\n /**\r\n * Pass polygon `xyz` through a sequence of PolygonClip steps with \"parity\" rules\r\n */\r\n public static doPolygonClipParitySequence(\r\n xyz: GrowableXYZArray,\r\n clippers: Clipper[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache | undefined,\r\n ) {\r\n if (arrayCache === undefined)\r\n arrayCache = new GrowableXYZArrayCache();\r\n let candidatesOut = [arrayCache.grabAndFill(xyz)];\r\n let candidatesIn: GrowableXYZArray[] = [];\r\n let nextCandidatesIn: GrowableXYZArray[] = [];\r\n let nextCandidatesOut: GrowableXYZArray[] = [];\r\n const intermediateIn: GrowableXYZArray[] = [];\r\n const intermediateOut: GrowableXYZArray[] = [];\r\n let shard;\r\n // at each step ..\r\n // candidatesIn and candidatesOut are evolved in and out\r\n // nextCandidatesIn and nextCandidatesOut are EMPTY\r\n for (const c of clippers) {\r\n if (c.appendPolygonClip) {\r\n // (IN,OUT) parts of IN parts distribute to (OUT,IN)\r\n while (undefined !== (shard = candidatesIn.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(ClipStepAction.acceptOut, intermediateIn, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n distributeFragments(ClipStepAction.acceptIn, intermediateOut, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // (IN,OUT) parts of IN parts distribute to (OUT,IN)\r\n while (undefined !== (shard = candidatesOut.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(ClipStepAction.acceptIn, intermediateIn, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n distributeFragments(ClipStepAction.acceptOut, intermediateOut, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // reload each candidate step\r\n const tempA = candidatesIn; candidatesIn = nextCandidatesIn; nextCandidatesIn = tempA;\r\n const tempB = candidatesOut; candidatesOut = nextCandidatesOut; nextCandidatesOut = tempB;\r\n }\r\n }\r\n // candidatesIn and candidatesOut are final ....\r\n if (candidatesOut.length === 0)\r\n acceptedIn?.push(arrayCache.grabAndFill(xyz));\r\n else if (candidatesOut.length === 0)\r\n acceptedOut?.push(arrayCache.grabAndFill(xyz));\r\n else {\r\n moveFragments(candidatesIn, acceptedIn, arrayCache);\r\n moveFragments(candidatesOut, acceptedOut, arrayCache);\r\n }\r\n }\r\n /** For each plane of clipper, construct a UnionOfConvexClipPlaneSets for an outer (infinite) convex volume that\r\n * abuts the outer volume of the neighbor faces.\r\n *\r\n */\r\n public static createComplementaryClips(clipper: ConvexClipPlaneSet): UnionOfConvexClipPlaneSets {\r\n const planes = clipper.planes;\r\n const interval = Range1d.createNull();\r\n const n = planes.length;\r\n const newClippers: ConvexClipPlaneSet[] = [];\r\n for (const p of planes){\r\n const outerSet = ConvexClipPlaneSet.createEmpty();\r\n outerSet.addPlaneToConvexSet(p.cloneNegated());\r\n newClippers.push(outerSet);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n const ray = CurveFactory.planePlaneIntersectionRay(planes[i], planes[j]);\r\n if (ray) {\r\n if (clipper.hasIntersectionWithRay(ray, interval)) {\r\n // the normal-to-normal vector is bisector (or close to bisector?)\r\n const newNormal = planes[j].inwardNormalRef.minus(planes[i].inwardNormalRef);\r\n const plane1 = ClipPlane.createNormalAndPoint(newNormal, ray.origin);\r\n if (plane1) {\r\n const plane2 = plane1.cloneNegated();\r\n newClippers[i].addPlaneToConvexSet(plane1);\r\n newClippers[j].addPlaneToConvexSet(plane2);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return UnionOfConvexClipPlaneSets.createConvexSets(newClippers);\r\n }\r\n}\r\nfunction moveFragments(\r\n fragments: GrowableXYZArray[],\r\n destination: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache) {\r\n if (destination === undefined)\r\n arrayCache.dropAllToCache(fragments);\r\n else {\r\n for (const f of fragments)\r\n destination.push(f);\r\n }\r\n fragments.length = 0;\r\n}\r\n/**\r\n * Distribute fragments among acceptedIn, acceptedOut, and passToNextStep as directed by action.\r\n * * If the indicated destination is unknown, drop the fragments to the arrayCache.\r\n * @param action destination selector\r\n * @param fragments fragments to be distributed\r\n * @param acceptedIn destination for \"in\"\r\n * @param acceptedOut destination for \"out\"\r\n * @param passToNextStep destination for fragments to be passed to a later step\r\n * @param arrayCache destination for un-distributed fragments.\r\n */\r\nfunction distributeFragments(\r\n action: ClipStepAction,\r\n fragments: GrowableXYZArray[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n passToNextStep: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache) {\r\n let destination;\r\n if (action === ClipStepAction.acceptIn)\r\n destination = acceptedIn;\r\n else if (action === ClipStepAction.acceptOut)\r\n destination = acceptedOut;\r\n else if (action === ClipStepAction.passToNextStep)\r\n destination = passToNextStep;\r\n// remark: if action is other than the enum values, destination is undefined\r\n if (destination === undefined)\r\n arrayCache.dropAllToCache(fragments);\r\n else {\r\n for (const f of fragments)\r\n destination.push(f);\r\n }\r\n fragments.length = 0;\r\n}\r\n"]}
1
+ {"version":3,"file":"ClipUtils.js","sourceRoot":"","sources":["../../../src/clipping/ClipUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,wDAAqD;AAGrD,wDAAqD;AACrD,wCAAqC;AACrC,0CAAuC;AAEvC,qEAAkE;AAGlE,2EAAwE;AACxE,mEAAkE;AAClE,+CAAuD;AACvD,2EAA0E;AAG1E,iEAA8D;AAC9D,2CAAwC;AACxC,mDAAgD;AAChD,6CAA0C;AAC1C,6DAA0D;AAC1D,sGAAmG;AACnG,6EAA0E;AAE1E;;;GAGG;AACH,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC9B,yBAAyB;IACzB,mFAAkB,CAAA;IAClB,oCAAoC;IACpC,yEAAa,CAAA;IACb,0BAA0B;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c,CAAC,cAAc;QAC/C,WAAW,GAAG,cAAc,CAAC;IAC/B,4EAA4E;IAC5E,IAAI,WAAW,KAAK,SAAS;QAC3B,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;SAClC;QACH,KAAK,MAAM,CAAC,IAAI,SAAS;YACvB,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvB;IACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AACvB,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\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\nimport { Arc3d } from \"../curve/Arc3d\";\r\nimport { CurveFactory } from \"../curve/CurveFactory\";\r\nimport { AnnounceNumberNumber, AnnounceNumberNumberCurvePrimitive, CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { GeometryQuery } from \"../curve/GeometryQuery\";\r\nimport { LineString3d } from \"../curve/LineString3d\";\r\nimport { Loop } from \"../curve/Loop\";\r\nimport { Geometry } from \"../Geometry\";\r\nimport { GrowableFloat64Array } from \"../geometry3d/GrowableFloat64Array\";\r\nimport { GrowableXYZArray } from \"../geometry3d/GrowableXYZArray\";\r\nimport { IndexedXYZCollection } from \"../geometry3d/IndexedXYZCollection\";\r\nimport { Plane3dByOriginAndUnitNormal } from \"../geometry3d/Plane3dByOriginAndUnitNormal\";\r\nimport { Point3dArrayCarrier } from \"../geometry3d/Point3dArrayCarrier\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Range1d, Range3d } from \"../geometry3d/Range\";\r\nimport { GrowableXYZArrayCache } from \"../geometry3d/ReusableObjectCache\";\r\nimport { Transform } from \"../geometry3d/Transform\";\r\nimport { XAndY } from \"../geometry3d/XYZProps\";\r\nimport { PolyfaceBuilder } from \"../polyface/PolyfaceBuilder\";\r\nimport { ClipPlane } from \"./ClipPlane\";\r\nimport { ClipPrimitive } from \"./ClipPrimitive\";\r\nimport { ClipVector } from \"./ClipVector\";\r\nimport { ConvexClipPlaneSet } from \"./ConvexClipPlaneSet\";\r\nimport { LineStringOffsetClipperContext } from \"./internalContexts/LineStringOffsetClipperContext\";\r\nimport { UnionOfConvexClipPlaneSets } from \"./UnionOfConvexClipPlaneSets\";\r\n\r\n/**\r\n * Enumerated type for describing where geometry lies with respect to clipping planes.\r\n * @public\r\n */\r\nexport enum ClipPlaneContainment {\r\n /** All points inside. */\r\n StronglyInside = 1,\r\n /** Inside/outside state unknown. */\r\n Ambiguous = 2,\r\n /** All points outside. */\r\n StronglyOutside = 3,\r\n}\r\n/**\r\n * Enumeration of ways to handle an intermediate fragment from a clipping step.\r\n * @public\r\n */\r\nexport enum ClipStepAction {\r\n /** Pass fragments directly to final accepted \"in\" state. */\r\n acceptIn = 1,\r\n /** Pass fragments directly to final accepted \"out\" state. */\r\n acceptOut = -1,\r\n /** Forward fragments to subsequent steps. */\r\n passToNextStep = 0,\r\n}\r\n\r\n/**\r\n * Enumerated type for describing what must yet be done to clip a piece of geometry.\r\n * @public\r\n */\r\nexport enum ClipStatus {\r\n /** Some geometry may cross the clip boundaries */\r\n ClipRequired,\r\n /** Geometry is clearly outside */\r\n TrivialReject,\r\n /** Geometry is clearly inside */\r\n TrivialAccept,\r\n}\r\n\r\n/**\r\n * An object containing clipping planes that can be used to clip geometry.\r\n * @public\r\n */\r\nexport interface Clipper {\r\n /** Test if `point` is on or inside the Clipper's volume. */\r\n isPointOnOrInside(point: Point3d, tolerance?: number): boolean;\r\n /**\r\n * Find the parts of the line segment (if any) that is within the convex clip volume.\r\n * * The line segment is defined by `pointA` and `pointB`.\r\n * * The input fractional interval from `fraction0` to `fraction1` (increasing) is the active part to consider.\r\n * * To clip to the usual bounded line segment, start with fractions (0,1).\r\n * If the clip volume is unbounded, the line interval may also be unbounded.\r\n * * An unbounded line portion will have fraction coordinates positive or negative `Number.MAX_VALUE`.\r\n * @param f0 fraction that is the initial lower fraction of the active interval (e.g., 0.0 for bounded segment).\r\n * @param f1 fraction that is the initial upper fraction of the active interval (e.g., 1.0 for bounded segment).\r\n * @param pointA segment start (fraction 0)\r\n * @param pointB segment end (fraction 1)\r\n * @param announce function to be called to announce a fraction interval that is within the convex clip volume.\r\n * @returns true if a segment was announced, false if entirely outside.\r\n */\r\n announceClippedSegmentIntervals(\r\n f0: number, f1: number, pointA: Point3d, pointB: Point3d, announce?: AnnounceNumberNumber\r\n ): boolean;\r\n /**\r\n * Find the portion (or portions) of the arc (if any) that are within the convex clip volume.\r\n * @param arc the arc to be clipped.\r\n * @param announce function to be called to announce a fraction intervals that are within the convex clip volume.\r\n * @returns true if one or more arcs portions were announced, false if entirely outside.\r\n */\r\n announceClippedArcIntervals(arc: Arc3d, announce?: AnnounceNumberNumberCurvePrimitive): boolean;\r\n /**\r\n * Optional polygon clip method.\r\n * * This is expected to be implemented by planar clip structures.\r\n * * This is unimplemented for curve clippers (e.g. sphere) for which polygon clip result has curved edges.\r\n */\r\n appendPolygonClip?: AppendPolygonClipFunction;\r\n}\r\n/**\r\n * Signature of method to execute polygon clip, distributing fragments of xyz among insideFragments and outsideFragments\r\n * @param xyz input polygon. This is not changed.\r\n * @param insideFragments Array to receive \"inside\" fragments. Each fragment is a GrowableXYZArray grabbed from\r\n * the cache. This is NOT cleared.\r\n * @param outsideFragments Array to receive \"outside\" fragments. Each fragment is a GrowableXYZArray grabbed from\r\n * the cache. This is NOT cleared.\r\n * @param arrayCache cache for reusable GrowableXYZArray.\r\n */\r\ntype AppendPolygonClipFunction = (\r\n xyz: GrowableXYZArray,\r\n insideFragments: GrowableXYZArray[],\r\n outsideFragments: GrowableXYZArray[],\r\n arrayCache: GrowableXYZArrayCache\r\n) => void;\r\n\r\n/**\r\n * Interface for clipping polygons.\r\n * Supported by:\r\n * * AlternatingCCTreeNode\r\n * * ConvexClipPlaneSet\r\n * @public\r\n */\r\nexport interface PolygonClipper {\r\n appendPolygonClip: AppendPolygonClipFunction;\r\n}\r\n/**\r\n * Class whose various static methods are functions for clipping geometry\r\n * @public\r\n */\r\nexport class ClipUtilities {\r\n // on-demand scratch objects for method implementations. If you use one, make sure it isn't already being used in scope.\r\n private static _workTransform?: Transform;\r\n private static _workRange?: Range3d;\r\n private static _workClipper?: ConvexClipPlaneSet;\r\n\r\n private static _selectIntervals01TestPoint = Point3d.create();\r\n /**\r\n * * Augment the unsortedFractionsArray with 0 and 1\r\n * * sort\r\n * * test the midpoint of each interval with `clipper.isPointOnOrInside`\r\n * * pass accepted intervals to `announce(f0,f1,curve)`\r\n */\r\n public static selectIntervals01(\r\n curve: CurvePrimitive, unsortedFractions: GrowableFloat64Array, clipper: Clipper, announce?: AnnounceNumberNumberCurvePrimitive,\r\n ): boolean {\r\n unsortedFractions.push(0);\r\n unsortedFractions.push(1);\r\n unsortedFractions.sort();\r\n let f0 = unsortedFractions.atUncheckedIndex(0);\r\n let f1;\r\n let fMid;\r\n const testPoint = ClipUtilities._selectIntervals01TestPoint;\r\n const n = unsortedFractions.length;\r\n for (let i = 1; i < n; i++) {\r\n f1 = unsortedFractions.atUncheckedIndex(i);\r\n if (f1 > f0 + Geometry.smallFraction) {\r\n fMid = 0.5 * (f0 + f1);\r\n if (fMid >= 0.0 && fMid <= 1.0) {\r\n curve.fractionToPoint(fMid, testPoint);\r\n if (clipper.isPointOnOrInside(testPoint)) {\r\n if (announce)\r\n announce(f0, f1, curve);\r\n else\r\n return true;\r\n }\r\n }\r\n f0 = f1;\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Announce triples of (low, high, cp) for each entry in intervals.\r\n * @param intervals source array\r\n * @param cp CurvePrimitive for announcement\r\n * @param announce function to receive data\r\n */\r\n public static announceNNC(\r\n intervals: Range1d[], cp: CurvePrimitive, announce?: AnnounceNumberNumberCurvePrimitive,\r\n ): boolean {\r\n if (announce) {\r\n for (const ab of intervals) {\r\n announce(ab.low, ab.high, cp);\r\n }\r\n }\r\n return intervals.length > 0;\r\n }\r\n /**\r\n * Find portions of the curve that are within the clipper.\r\n * Collect them into an array of curve primitives.\r\n */\r\n public static collectClippedCurves(curve: CurvePrimitive, clipper: Clipper): CurvePrimitive[] {\r\n const result: CurvePrimitive[] = [];\r\n curve.announceClipIntervals(\r\n clipper,\r\n (fraction0: number, fraction1: number, curveA: CurvePrimitive) => {\r\n if (fraction1 !== fraction0) {\r\n const partialCurve = curveA.clonePartialCurve(fraction0, fraction1);\r\n if (partialCurve)\r\n result.push(partialCurve);\r\n }\r\n },\r\n );\r\n return result;\r\n }\r\n /**\r\n * Clip a polygon down to regions defined by each shape of a ClipShape.\r\n * @return An multidimensional array of points, where each array is the boundary of part of the remaining polygon.\r\n */\r\n public static clipPolygonToClipShape(polygon: Point3d[], clipShape: ClipPrimitive): Point3d[][] {\r\n const outputA = this.clipPolygonToClipShapeReturnGrowableXYZArrays(polygon, clipShape);\r\n const output = [];\r\n for (const g of outputA)\r\n output.push(g.getPoint3dArray());\r\n return output;\r\n }\r\n /**\r\n * Clip a polygon down to regions defined by each shape of a ClipShape.\r\n * @return An multidimensional array of points, where each array is the boundary of part of the remaining polygon.\r\n */\r\n public static clipPolygonToClipShapeReturnGrowableXYZArrays(\r\n polygon: Point3d[], clipShape: ClipPrimitive,\r\n ): GrowableXYZArray[] {\r\n const output: GrowableXYZArray[] = [];\r\n const clipper = clipShape.fetchClipPlanesRef();\r\n // NEEDS WORK -- what if it is a mask !!!!\r\n if (clipper) {\r\n clipper.polygonClip(polygon, output);\r\n }\r\n return output;\r\n }\r\n /**\r\n * Given an array of points, test for trivial containment conditions.\r\n * * ClipStatus.TrivialAccept if all points are in any one of the convexSet's.\r\n * * ClipStatus.ClipRequired if (in any single convexSet) there were points on both sides of any single plane.\r\n * * ClipStatus.TrivialReject if neither of those occurred.\r\n */\r\n public static pointSetSingleClipStatus(\r\n points: GrowableXYZArray, planeSet: UnionOfConvexClipPlaneSets, tolerance: number,\r\n ): ClipStatus {\r\n if (planeSet.convexSets.length === 0)\r\n return ClipStatus.TrivialAccept;\r\n\r\n for (const convexSet of planeSet.convexSets) {\r\n let allOutsideSinglePlane = false, anyOutside = false;\r\n\r\n for (const plane of convexSet.planes) {\r\n let numInside = 0, numOutside = 0;\r\n const planeDistance = plane.distance - tolerance;\r\n\r\n const currPt = Point3d.create();\r\n const currVec = Vector3d.create();\r\n for (let i = 0; i < points.length; i++) {\r\n points.getPoint3dAtUncheckedPointIndex(i, currPt);\r\n currVec.setFrom(currPt);\r\n currVec.dotProduct(plane.inwardNormalRef) > planeDistance ? numInside++ : numOutside++;\r\n }\r\n\r\n anyOutside = (numOutside !== 0) ? true : anyOutside;\r\n if (numInside === 0) {\r\n allOutsideSinglePlane = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!anyOutside) // totally inside this set - no clip required\r\n return ClipStatus.TrivialAccept;\r\n if (!allOutsideSinglePlane)\r\n return ClipStatus.ClipRequired;\r\n }\r\n return ClipStatus.TrivialReject;\r\n }\r\n /**\r\n * Emit point loops for intersection of a convex set with a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static announceLoopsOfConvexClipPlaneSetIntersectRange(\r\n convexSet: ConvexClipPlaneSet | ClipPlane,\r\n range: Range3d,\r\n loopFunction: (loopPoints: GrowableXYZArray) => void,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): void {\r\n const work = new GrowableXYZArray();\r\n if (includeConvexSetFaces) {\r\n // Clip convexSet planes to the range and to the rest of the convexSet . .\r\n if (convexSet instanceof ConvexClipPlaneSet) {\r\n for (const plane of convexSet.planes) {\r\n if (ignoreInvisiblePlanes && plane.invisible)\r\n continue;\r\n const pointsClippedToRange = plane.intersectRange(range, true);\r\n const finalPoints = new GrowableXYZArray();\r\n if (pointsClippedToRange) {\r\n convexSet.polygonClip(pointsClippedToRange, finalPoints, work, plane);\r\n if (finalPoints.length > 0)\r\n loopFunction(finalPoints);\r\n }\r\n }\r\n } else { // `convexSet` is just one plane ...\r\n if (ignoreInvisiblePlanes && convexSet.invisible) {\r\n // skip it !\r\n } else {\r\n const pointsClippedToRange = convexSet.intersectRange(range, true);\r\n if (pointsClippedToRange)\r\n loopFunction(pointsClippedToRange);\r\n }\r\n }\r\n }\r\n\r\n if (includeRangeFaces) {\r\n // clip range faces to the convex set . . .\r\n const corners = range.corners();\r\n for (let i = 0; i < 6; i++) {\r\n const indices = Range3d.faceCornerIndices(i);\r\n const finalPoints = new GrowableXYZArray();\r\n const lineString = LineString3d.createIndexedPoints(corners, indices);\r\n if (convexSet instanceof ConvexClipPlaneSet) {\r\n convexSet.polygonClip(lineString.packedPoints, finalPoints, work);\r\n if (finalPoints.length > 0)\r\n loopFunction(finalPoints);\r\n } else {\r\n convexSet.clipConvexPolygonInPlace(lineString.packedPoints, work);\r\n if (lineString.packedPoints.length > 0)\r\n loopFunction(lineString.packedPoints);\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * Return a (possibly empty) array of geometry (Loops !!) which are facets of the intersection of the convex set\r\n * intersecting a range.\r\n * * Return zero length array for (a) null range or (b) no intersections\r\n * @param allClippers convex or union clipper\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static loopsOfConvexClipPlaneIntersectionWithRange(\r\n allClippers: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPlane,\r\n range: Range3d,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): GeometryQuery[] {\r\n const result: GeometryQuery[] = [];\r\n if (allClippers instanceof UnionOfConvexClipPlaneSets) {\r\n for (const clipper of allClippers.convexSets) {\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(clipper, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.push(Loop.createPolygon(points));\r\n },\r\n includeConvexSetFaces, includeRangeFaces, ignoreInvisiblePlanes);\r\n }\r\n } else if (allClippers instanceof ConvexClipPlaneSet || allClippers instanceof ClipPlane) {\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(allClippers, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.push(Loop.createPolygon(points));\r\n },\r\n includeConvexSetFaces, includeRangeFaces, ignoreInvisiblePlanes);\r\n }\r\n return result;\r\n }\r\n /**\r\n * Return the (possibly null) range of the intersection of the convex set with a range.\r\n * * The convex set is permitted to be unbounded (e.g. a single plane). The range parameter provides bounds.\r\n * @param convexSet convex set for intersection.\r\n * @param range range to intersect\r\n */\r\n public static rangeOfConvexClipPlaneSetIntersectionWithRange(convexSet: ConvexClipPlaneSet, range: Range3d): Range3d {\r\n const result = Range3d.createNull();\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(convexSet, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.extendArray(points);\r\n },\r\n true, true, false);\r\n return result;\r\n }\r\n /**\r\n * Return the range of various types of clippers\r\n * * `ConvexClipPlaneSet` -- dispatch to `rangeOfConvexClipPlaneSetIntersectionWithRange`\r\n * * `UnionOfConvexClipPlaneSet` -- union of ranges of member `ConvexClipPlaneSet`\r\n * * `ClipPrimitive` -- access its `UnionOfConvexClipPlaneSet`.\r\n * * `ClipVector` -- intersection of the ranges of its `ClipPrimitive`.\r\n * * `undefined` -- entire input range.\r\n * * If `observeInvisibleFlag` is false, the \"invisible\" properties are ignored, and this effectively returns the range of the edge work of the members\r\n * * If `observeInvisibleFlag` is true, the \"invisible\" properties are observed, and \"invisible\" parts do not restrict the range.\r\n * @param clipper\r\n * @param range non-null range.\r\n * @param observeInvisibleFlag indicates how \"invisible\" bit is applied for ClipPrimitive.\r\n */\r\n public static rangeOfClipperIntersectionWithRange(\r\n clipper: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPrimitive | ClipVector | undefined,\r\n range: Range3d,\r\n observeInvisibleFlag: boolean = true,\r\n ): Range3d {\r\n if (clipper === undefined)\r\n return range.clone();\r\n if (clipper instanceof ConvexClipPlaneSet)\r\n return this.rangeOfConvexClipPlaneSetIntersectionWithRange(clipper, range);\r\n if (clipper instanceof UnionOfConvexClipPlaneSets) {\r\n const rangeUnion = Range3d.createNull();\r\n for (const c of clipper.convexSets) {\r\n const rangeC = this.rangeOfConvexClipPlaneSetIntersectionWithRange(c, range);\r\n rangeUnion.extendRange(rangeC);\r\n }\r\n return rangeUnion;\r\n }\r\n if (clipper instanceof ClipPrimitive) {\r\n if (observeInvisibleFlag && clipper.invisible)\r\n return range.clone();\r\n return this.rangeOfClipperIntersectionWithRange(clipper.fetchClipPlanesRef(), range);\r\n }\r\n if (clipper instanceof ClipVector) {\r\n const rangeIntersection = range.clone();\r\n for (const c of clipper.clips) {\r\n if (observeInvisibleFlag && c.invisible) {\r\n // trivial range tests do not expose the effects. Assume the hole allows everything.\r\n } else {\r\n const rangeC = this.rangeOfClipperIntersectionWithRange(c, range, observeInvisibleFlag);\r\n rangeIntersection.intersect(rangeC, rangeIntersection);\r\n }\r\n }\r\n return rangeIntersection;\r\n\r\n }\r\n return range.clone();\r\n }\r\n /**\r\n * Test if various types of clippers have any intersection with a range.\r\n * * This follows the same logic as `rangeOfClipperIntersectionWithRange` but attempts to exit at earliest point of confirmed intersection\r\n * * `ConvexClipPlaneSet` -- dispatch to `doesConvexClipPlaneSetIntersectRange`\r\n * * `UnionOfConvexClipPlaneSet` -- union of ranges of member `ConvexClipPlaneSet`\r\n * * `ClipPrimitive` -- access its `UnionOfConvexClipPlaneSet`.\r\n * * `ClipVector` -- intersection of the ranges of its `ClipPrimitive`.\r\n * * `undefined` -- entire input range.\r\n * * If `observeInvisibleFlag` is false, the \"invisible\" properties are ignored, and holes do not affect the result.\r\n * * If `observeInvisibleFlag` is true, the \"invisible\" properties are observed, and may affect the result.\r\n * @param clipper\r\n * @param range non-null range.\r\n * @param observeInvisibleFlag indicates how \"invisible\" bit is applied for ClipPrimitive.\r\n */\r\n public static doesClipperIntersectRange(\r\n clipper: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPrimitive | ClipVector | undefined,\r\n range: Range3d,\r\n observeInvisibleFlag: boolean = true,\r\n ): boolean {\r\n if (clipper === undefined)\r\n return true;\r\n\r\n if (clipper instanceof ConvexClipPlaneSet)\r\n return this.doesConvexClipPlaneSetIntersectRange(clipper, range);\r\n\r\n if (clipper instanceof UnionOfConvexClipPlaneSets) {\r\n for (const c of clipper.convexSets) {\r\n if (this.doesConvexClipPlaneSetIntersectRange(c, range))\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n if (clipper instanceof ClipPrimitive) {\r\n if (observeInvisibleFlag && clipper.invisible) // um is there an easy way to detect range-completely-inside?\r\n return true;\r\n return this.doesClipperIntersectRange(clipper.fetchClipPlanesRef(), range);\r\n }\r\n\r\n if (clipper instanceof ClipVector) {\r\n const rangeIntersection = range.clone();\r\n for (const c of clipper.clips) {\r\n if (observeInvisibleFlag && c.invisible) {\r\n // trivial range tests do not expose the effects. Assume the hole allows everything.\r\n } else {\r\n const rangeC = this.rangeOfClipperIntersectionWithRange(c, range, observeInvisibleFlag);\r\n rangeIntersection.intersect(rangeC, rangeIntersection);\r\n }\r\n }\r\n return !rangeIntersection.isNull;\r\n }\r\n /** If the case statement above is complete for the variant inputs, this is unreachable .. */\r\n return false;\r\n }\r\n /**\r\n * Emit point loops for intersection of a convex set with a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static doesConvexClipPlaneSetIntersectRange(\r\n convexSet: ConvexClipPlaneSet,\r\n range: Range3d,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): boolean {\r\n const work = new GrowableXYZArray();\r\n if (includeConvexSetFaces) {\r\n // Clip convexSet planes to the range and to the rest of the convexSet . .\r\n for (const plane of convexSet.planes) {\r\n if (ignoreInvisiblePlanes && plane.invisible)\r\n continue;\r\n const pointsClippedToRange = plane.intersectRange(range, true);\r\n if (pointsClippedToRange) {\r\n const finalPoints = new GrowableXYZArray();\r\n convexSet.polygonClip(pointsClippedToRange, finalPoints, work, plane);\r\n if (finalPoints.length > 0)\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n if (includeRangeFaces) {\r\n // clip range faces to the convex set . . .\r\n const corners = range.corners();\r\n for (let i = 0; i < 6; i++) {\r\n const indices = Range3d.faceCornerIndices(i);\r\n const finalPoints = new GrowableXYZArray();\r\n const lineString = LineString3d.createIndexedPoints(corners, indices);\r\n convexSet.polygonClip(lineString.packedPoints, finalPoints, work);\r\n if (finalPoints.length > 0)\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Test for intersection of two ranges in different local coordinates.\r\n * * Useful for clash detection of elements in iModels, using their stored (tight) local ranges and placement transforms.\r\n * @param range0 range in local coordinates of first geometry\r\n * @param local0ToWorld placement transform for first geometry\r\n * @param range1 range in local coordinates of second geometry\r\n * @param local1ToWorld placement transform for second geometry. Assumed to be invertible.\r\n * @param range1Margin optional signed local distance to expand/contract the second range before intersection. Positive expands.\r\n * @return whether the local ranges are adjacent or intersect. Also returns false if local1ToWorld is singular.\r\n */\r\n public static doLocalRangesIntersect(\r\n range0: Range3d, local0ToWorld: Transform, range1: Range3d, local1ToWorld: Transform, range1Margin?: number,\r\n ): boolean {\r\n const worldToLocal1 = ClipUtilities._workTransform = local1ToWorld.inverse(ClipUtilities._workTransform);\r\n if (!worldToLocal1)\r\n return false;\r\n let myRange1 = range1;\r\n if (range1Margin) {\r\n myRange1 = ClipUtilities._workRange = range1.clone(ClipUtilities._workRange);\r\n myRange1.expandInPlace(range1Margin);\r\n }\r\n // convert range0 into a clipper in local1 coordinates, then intersect with range1\r\n const local0ToLocal1 = worldToLocal1.multiplyTransformTransform(local0ToWorld, worldToLocal1);\r\n const builder = PolyfaceBuilder.create();\r\n builder.addTransformedRangeMesh(local0ToLocal1, range0);\r\n const mesh0 = builder.claimPolyface();\r\n const clipper = ClipUtilities._workClipper = ConvexClipPlaneSet.createConvexPolyface(mesh0, ClipUtilities._workClipper).clipper;\r\n return ClipUtilities.doesClipperIntersectRange(clipper, myRange1);\r\n }\r\n /**\r\n * Test if `obj` is a `Clipper` object.\r\n * * This is implemented by testing for each of the methods in the `Clipper` interface.\r\n */\r\n public static isClipper(obj: any): boolean {\r\n if (obj) {\r\n if (obj.isPointOnOrInside\r\n && obj.announceClippedSegmentIntervals\r\n && obj.announceClippedArcIntervals)\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Specialized logic for replacing clip fragments by an equivalent singleton.\r\n * * If there are baseCount + 1 or fewer fragments, do nothing.\r\n * * If there are more than baseCount+1 fragments:\r\n * * drop them all to the cache\r\n * * push a copy of the singleton.\r\n * * The use case for this is that a multi-step clipper (e.g. UnionOfConvexClipPlaneSets) may produce many fragments,\r\n * and then be able to determine that they really are the original pre-clip polygon unchanged.\r\n * * The baseCount+1 case is the case where the entire original singleton is still a singleton and can be left alone.\r\n * * Calling this replacer shuffles the original back into the fragment array, and drops the fragments.\r\n * * This determination is solely within the logic of the caller.\r\n * @param shards array of fragments\r\n * @param baseCount original count\r\n * @param singleton single array which may be a replacement for multiple fragments\r\n * @param cache cache for array management\r\n */\r\n public static restoreSingletonInPlaceOfMultipleShards(\r\n fragments: GrowableXYZArray[] | undefined, baseCount: number, singleton: GrowableXYZArray, arrayCache: GrowableXYZArrayCache,\r\n ): void {\r\n if (fragments && fragments.length > baseCount + 1) {\r\n while (fragments.length > baseCount) {\r\n const f = fragments.pop();\r\n arrayCache.dropToCache(f);\r\n }\r\n fragments.push(arrayCache.grabAndFill(singleton));\r\n }\r\n }\r\n /**\r\n * Create a UnionOfConvexClipPlaneSets for a volume defined by a path and offsets.\r\n * @param points points along the path.\r\n * @param positiveOffsetLeft offset to left. 0 is clip on the path.\r\n * @param positiveOffsetRight offset to the right. 0 is clip on the path.\r\n * @param z0 z for lower clipping plane. If undefined, unbounded in positive z\r\n * @param z1 z for upper clipping plane. If undefined, unbounded in negative z.\r\n * @alpha\r\n */\r\n public static createXYOffsetClipFromLineString(\r\n points: Point3d[] | IndexedXYZCollection, leftOffset: number, rightOffset: number, z0: number, z1: number,\r\n ): UnionOfConvexClipPlaneSets {\r\n if (Array.isArray(points)) {\r\n return LineStringOffsetClipperContext.createClipBetweenOffsets(\r\n new Point3dArrayCarrier(points), leftOffset, rightOffset, z0, z1);\r\n }\r\n return LineStringOffsetClipperContext.createClipBetweenOffsets(points, leftOffset, rightOffset, z0, z1);\r\n }\r\n /** If data.length >= minLength threshold, push it to destination; if smaller drop it back to the cache. */\r\n public static captureOrDrop(\r\n data: GrowableXYZArray, minLength: number, destination: GrowableXYZArray[], cache: GrowableXYZArrayCache,\r\n ): void {\r\n if (data.length >= minLength)\r\n destination.push(data);\r\n else\r\n cache.dropToCache(data);\r\n }\r\n /**\r\n * Find the portion of a line within a half-plane clip.\r\n * * The half-plane clip is to the left of the line from clipA to clipB.\r\n * * The original clipped segment has fractions 0 and 1 at respective segment points.\r\n * * Caller initializes the interval\r\n * * This method reduces the interval size.\r\n * * See clipSegmentToCCWTriangleXY for typical use.\r\n * @param linePointA First point of clip line\r\n * @param linePointB Second point of clip line\r\n * @param segmentPoint0 First point of clipped segment\r\n * @param segmentPoint1 Second point of clipped segment\r\n * @param interval Live interval.\r\n * @param absoluteTolerance absolute tolerance for both cross product values to indicate \"on\" the line\r\n */\r\n public static clipSegmentToLLeftOfLineXY(\r\n linePointA: XAndY, linePointB: XAndY, segmentPoint0: XAndY, segmentPoint1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n const ux = linePointB.x - linePointA.x;\r\n const uy = linePointB.y - linePointA.y;\r\n // negative is in positive is out ...\r\n const h0 = -(ux * (segmentPoint0.y - linePointA.y) - uy * (segmentPoint0.x - linePointA.x));\r\n const h1 = -(ux * (segmentPoint1.y - linePointA.y) - uy * (segmentPoint1.x - linePointA.x));\r\n if (h0 < absoluteTolerance && h1 < absoluteTolerance) {\r\n // The entire segment is in .....\r\n return;\r\n }\r\n if (h0 * h1 > 0.0) {\r\n if (h0 > 0.0)\r\n interval.setNull();\r\n } else if (h0 * h1 < 0.0) {\r\n // strict crossing with safe fraction . . .\r\n const fraction = -h0 / (h1 - h0);\r\n if (h0 < 0.0) {\r\n return interval.intersectRangeXXInPlace(0.0, fraction);\r\n } else {\r\n return interval.intersectRangeXXInPlace(fraction, 1.0);\r\n }\r\n } else {\r\n // There is an exact hit at one end, possibly non-zero at the other ... the sign of either determines which side is in play\r\n // A zero and a zero or negative is entirely in, which does not alter the prior clip.\r\n if (h0 > 0.0) {\r\n interval.intersectRangeXXInPlace(1.0, 1.0);\r\n } else if (h1 > 0.0) {\r\n interval.intersectRangeXXInPlace(0.0, 0.0);\r\n }\r\n }\r\n }\r\n /**\r\n * Clip an interval of a line segment to a triangle.\r\n * * Triangle is assumed CCW\r\n * @param pointA point of triangle.\r\n * @param pointB point of triangle.\r\n * @param pointC point of triangle.\r\n * @param segment0 start of segment\r\n * @param segment1 end of segment\r\n * @param interval Pre-initialized interval of live part of segment\r\n * @param absoluteTolerance absolute tolerance for begin \"on a line\"\r\n */\r\n public static clipSegmentToCCWTriangleXY(\r\n pointA: XAndY, pointB: XAndY, pointC: XAndY, segment0: XAndY, segment1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointA, pointB, segment0, segment1, interval, absoluteTolerance);\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointB, pointC, segment0, segment1, interval, absoluteTolerance);\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointC, pointA, segment0, segment1, interval, absoluteTolerance);\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * Find the portion of a line within a half-plane clip.\r\n * * The half-plane clip is to the left of the line from clipA to clipB.\r\n * * The original clipped segment has fractions 0 and 1 at respective segment points.\r\n * * Caller initializes the interval\r\n * * This method reduces the interval size.\r\n * * See clipSegmentToCCWTriangleXY for typical use.\r\n * @param linePointA First point of clip line\r\n * @param linePointB Second point of clip line\r\n * @param segmentPoint0 First point of clipped segment\r\n * @param segmentPoint1 Second point of clipped segment\r\n * @param interval Live interval.\r\n * @param absoluteTolerance absolute tolerance for both cross product values to indicate \"on\" the line\r\n */\r\n public static clipSegmentBelowPlaneXY(\r\n plane: Plane3dByOriginAndUnitNormal, segmentPoint0: XAndY, segmentPoint1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n // negative is in positive is out ...\r\n const h0 = plane.altitudeXY(segmentPoint0.x, segmentPoint0.y);\r\n const h1 = plane.altitudeXY(segmentPoint1.x, segmentPoint1.y);\r\n if (h0 < absoluteTolerance && h1 < absoluteTolerance) {\r\n // The entire segment is in ..... the interval is unaffected.\r\n return;\r\n }\r\n if (h0 * h1 > 0.0) {\r\n if (h0 > 0.0)\r\n interval.setNull();\r\n } else if (h0 * h1 < 0.0) {\r\n // strict crossing with safe fraction . . .\r\n const fraction = -h0 / (h1 - h0);\r\n if (h0 < 0.0) {\r\n return interval.intersectRangeXXInPlace(0.0, fraction);\r\n } else {\r\n return interval.intersectRangeXXInPlace(fraction, 1.0);\r\n }\r\n } else {\r\n // There is an exact hit at one end, possibly non-zero at the other ... the sign of either determines which side is in play\r\n // A zero and a zero or negative is entirely in, which does not alter the prior clip.\r\n if (h0 > 0.0) {\r\n interval.intersectRangeXXInPlace(1.0, 1.0);\r\n } else if (h1 > 0.0) {\r\n interval.intersectRangeXXInPlace(0.0, 0.0);\r\n }\r\n }\r\n }\r\n /**\r\n * Clip an interval of a line segment to an array of planes\r\n * * plane normals assumed OUTWARD\r\n * * planeAltitude is typically a tolerance a tolerance distance.\r\n * * positive altitude makes tha plane move in the direction of the unit normal.\r\n * @param planes array of planes\r\n * @param segment0 start of segment\r\n * @param segment1 end of segment\r\n * @param interval Pre-initialized interval of live part of segment\r\n * @param absoluteTolerance absolute tolerance for begin \"on a line\"\r\n */\r\n public static clipSegmentBelowPlanesXY(\r\n planes: Plane3dByOriginAndUnitNormal[], segment0: XAndY, segment1: XAndY, interval: Range1d, signedAltitude: number = 1.0e-14,\r\n ): void {\r\n const numPlanes = planes.length;\r\n for (let i = 0; (!interval.isNull) && i < numPlanes; i++) {\r\n this.clipSegmentBelowPlaneXY(planes[i], segment0, segment1, interval, signedAltitude);\r\n }\r\n }\r\n /**\r\n * Pass line segments from a polyline to the clipper. Resolve the fractional clips to simple points for announcement.\r\n * @param clipper clipper to call\r\n * @param points polyline whose segments are passed to the clipper\r\n * @param announce caller's handler for simple point pairs.\r\n */\r\n public static announcePolylineClip(\r\n clipper: Clipper, points: Point3d[], announce: (point0: Point3d, point1: Point3d) => void,\r\n ): void {\r\n for (let i = 0; i + 1 < points.length; i++) {\r\n clipper.announceClippedSegmentIntervals(0, 1, points[i], points[i + 1],\r\n (f0: number, f1: number) => {\r\n announce(points[i].interpolate(f0, points[i + 1]), points[i].interpolate(f1, points[i + 1]));\r\n });\r\n }\r\n }\r\n /**\r\n * Pass line segments from a polyline to the clipper. Sum the lengths of the clipped pieces. Return the sum.\r\n * @param clipper clipper to call\r\n * @param points polyline whose segments are passed to the clipper\r\n */\r\n public static sumPolylineClipLength(clipper: Clipper, points: Point3d[]): number {\r\n let s = 0;\r\n for (let i = 0; i + 1 < points.length; i++) {\r\n const a = points[i].distance(points[i + 1]);\r\n clipper.announceClippedSegmentIntervals(0, 1, points[i], points[i + 1],\r\n (f0: number, f1: number) => { s += Math.abs(f1 - f0) * a; });\r\n }\r\n return s;\r\n }\r\n /**\r\n * Pass polygon `xyz` through a sequence of PolygonClip steps.\r\n * * At the outset, `xyz` is the (only) entry in a set of candidates.\r\n * * For each clipper, each candidate is presented for appendPolygon to inside and outside parts.\r\n * * Each (in,out) result is distributed among (acceptedIn, acceptedOut, candidates) according to\r\n * (inAction, outAction)\r\n * * At the end, all remaining candidates are distributed among (acceptedIn, acceptedOut, finalUnknown)\r\n * according to finalAction\r\n * * Any clipper that does not have an appendPolygonClip method is skipped.\r\n * @param xyz\r\n * @param clippers\r\n * @param acceptedIn\r\n * @param acceptedOut\r\n * @param finalCandidates\r\n * @param inAction\r\n * @param outAction\r\n * @param finalCandidateAction\r\n */\r\n public static doPolygonClipSequence(\r\n xyz: GrowableXYZArray,\r\n clippers: Clipper[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n finalCandidates: GrowableXYZArray[] | undefined,\r\n inAction: ClipStepAction,\r\n outAction: ClipStepAction,\r\n finalFragmentAction: ClipStepAction,\r\n arrayCache: GrowableXYZArrayCache | undefined,\r\n ) {\r\n if (arrayCache === undefined)\r\n arrayCache = new GrowableXYZArrayCache();\r\n let candidates = [arrayCache.grabAndFill(xyz)];\r\n let nextCandidates: GrowableXYZArray[] = [];\r\n const intermediateIn: GrowableXYZArray[] = [];\r\n const intermediateOut: GrowableXYZArray[] = [];\r\n const oldInsideCount = acceptedIn ? acceptedIn.length : 0;\r\n const oldOutsideCount = acceptedOut ? acceptedOut.length : 0;\r\n let shard;\r\n // At each convex set, carryForwardA is all the fragments that have been outside all previous convex sets.\r\n // Clip each such fragment to the current set, sending the outside parts to carryForwardB, which will got to\r\n // the next clipper. The final surviving carryForward really is out.\r\n for (const c of clippers) {\r\n if (c.appendPolygonClip) {\r\n while (undefined !== (shard = candidates.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(inAction, intermediateIn, acceptedIn, acceptedOut, nextCandidates, arrayCache);\r\n distributeFragments(outAction, intermediateOut, acceptedIn, acceptedOut, nextCandidates, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // candidates is empty !!\r\n const temp = candidates; candidates = nextCandidates; nextCandidates = temp;\r\n }\r\n }\r\n distributeFragments(finalFragmentAction, candidates, acceptedIn, acceptedOut, finalCandidates, arrayCache);\r\n // Note: The following assumes that there were no residual candidates ... need to track if that happened?\r\n // If nothing was out, the inside fragments can be replaced by the original.\r\n if (acceptedOut?.length === oldOutsideCount)\r\n ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedIn, oldInsideCount, xyz, arrayCache);\r\n // If nothing was in, the outside fragments can be replaced by the original.\r\n if (acceptedIn?.length === oldInsideCount)\r\n ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedOut, oldOutsideCount, xyz, arrayCache);\r\n }\r\n /** Pass polygon `xyz` through a sequence of PolygonClip steps with \"parity\" rules */\r\n public static doPolygonClipParitySequence(\r\n xyz: GrowableXYZArray,\r\n clippers: Clipper[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache | undefined,\r\n ) {\r\n if (arrayCache === undefined)\r\n arrayCache = new GrowableXYZArrayCache();\r\n let candidatesOut = [arrayCache.grabAndFill(xyz)];\r\n let candidatesIn: GrowableXYZArray[] = [];\r\n let nextCandidatesIn: GrowableXYZArray[] = [];\r\n let nextCandidatesOut: GrowableXYZArray[] = [];\r\n const intermediateIn: GrowableXYZArray[] = [];\r\n const intermediateOut: GrowableXYZArray[] = [];\r\n let shard;\r\n // at each step ..\r\n // candidatesIn and candidatesOut are evolved in and out\r\n // nextCandidatesIn and nextCandidatesOut are EMPTY\r\n for (const c of clippers) {\r\n if (c.appendPolygonClip) {\r\n // (IN,OUT) parts of IN parts distribute to (OUT,IN)\r\n while (undefined !== (shard = candidatesIn.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(ClipStepAction.acceptOut, intermediateIn, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n distributeFragments(ClipStepAction.acceptIn, intermediateOut, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // (IN,OUT) parts of IN parts distribute to (OUT,IN)\r\n while (undefined !== (shard = candidatesOut.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(ClipStepAction.acceptIn, intermediateIn, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n distributeFragments(ClipStepAction.acceptOut, intermediateOut, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // reload each candidate step\r\n const tempA = candidatesIn; candidatesIn = nextCandidatesIn; nextCandidatesIn = tempA;\r\n const tempB = candidatesOut; candidatesOut = nextCandidatesOut; nextCandidatesOut = tempB;\r\n }\r\n }\r\n // candidatesIn and candidatesOut are final ....\r\n if (candidatesOut.length === 0)\r\n acceptedIn?.push(arrayCache.grabAndFill(xyz));\r\n else if (candidatesOut.length === 0)\r\n acceptedOut?.push(arrayCache.grabAndFill(xyz));\r\n else {\r\n moveFragments(candidatesIn, acceptedIn, arrayCache);\r\n moveFragments(candidatesOut, acceptedOut, arrayCache);\r\n }\r\n }\r\n /**\r\n * For each plane of clipper, construct a UnionOfConvexClipPlaneSets for an outer (infinite) convex volume that\r\n * abuts the outer volume of the neighbor faces.\r\n */\r\n public static createComplementaryClips(clipper: ConvexClipPlaneSet): UnionOfConvexClipPlaneSets {\r\n const planes = clipper.planes;\r\n const interval = Range1d.createNull();\r\n const n = planes.length;\r\n const newClippers: ConvexClipPlaneSet[] = [];\r\n for (const p of planes) {\r\n const outerSet = ConvexClipPlaneSet.createEmpty();\r\n outerSet.addPlaneToConvexSet(p.cloneNegated());\r\n newClippers.push(outerSet);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n const ray = CurveFactory.planePlaneIntersectionRay(planes[i], planes[j]);\r\n if (ray) {\r\n if (clipper.hasIntersectionWithRay(ray, interval)) {\r\n // the normal-to-normal vector is bisector (or close to bisector?)\r\n const newNormal = planes[j].inwardNormalRef.minus(planes[i].inwardNormalRef);\r\n const plane1 = ClipPlane.createNormalAndPoint(newNormal, ray.origin);\r\n if (plane1) {\r\n const plane2 = plane1.cloneNegated();\r\n newClippers[i].addPlaneToConvexSet(plane1);\r\n newClippers[j].addPlaneToConvexSet(plane2);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return UnionOfConvexClipPlaneSets.createConvexSets(newClippers);\r\n }\r\n}\r\nfunction moveFragments(\r\n fragments: GrowableXYZArray[],\r\n destination: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache,\r\n) {\r\n if (destination === undefined)\r\n arrayCache.dropAllToCache(fragments);\r\n else {\r\n for (const f of fragments)\r\n destination.push(f);\r\n }\r\n fragments.length = 0;\r\n}\r\n/**\r\n * Distribute fragments among acceptedIn, acceptedOut, and passToNextStep as directed by action.\r\n * * If the indicated destination is unknown, drop the fragments to the arrayCache.\r\n * @param action destination selector\r\n * @param fragments fragments to be distributed\r\n * @param acceptedIn destination for \"in\"\r\n * @param acceptedOut destination for \"out\"\r\n * @param passToNextStep destination for fragments to be passed to a later step\r\n * @param arrayCache destination for un-distributed fragments.\r\n */\r\nfunction distributeFragments(\r\n action: ClipStepAction,\r\n fragments: GrowableXYZArray[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n passToNextStep: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache,\r\n) {\r\n let destination;\r\n if (action === ClipStepAction.acceptIn)\r\n destination = acceptedIn;\r\n else if (action === ClipStepAction.acceptOut)\r\n destination = acceptedOut;\r\n else if (action === ClipStepAction.passToNextStep)\r\n destination = passToNextStep;\r\n // remark: if action is other than the enum values, destination is undefined\r\n if (destination === undefined)\r\n arrayCache.dropAllToCache(fragments);\r\n else {\r\n for (const f of fragments)\r\n destination.push(f);\r\n }\r\n fragments.length = 0;\r\n}\r\n"]}