@itwin/core-geometry 5.9.0-dev.15 → 5.9.0-dev.17

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 (37) hide show
  1. package/lib/cjs/curve/Loop.d.ts.map +1 -1
  2. package/lib/cjs/curve/Loop.js +3 -1
  3. package/lib/cjs/curve/Loop.js.map +1 -1
  4. package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.js.map +1 -1
  5. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +21 -27
  6. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
  7. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js +97 -152
  8. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
  9. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts +15 -14
  10. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
  11. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +144 -163
  12. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
  13. package/lib/cjs/geometry3d/PointHelpers.d.ts.map +1 -1
  14. package/lib/cjs/geometry3d/PointHelpers.js +6 -7
  15. package/lib/cjs/geometry3d/PointHelpers.js.map +1 -1
  16. package/lib/cjs/numerics/Newton.d.ts +10 -2
  17. package/lib/cjs/numerics/Newton.d.ts.map +1 -1
  18. package/lib/cjs/numerics/Newton.js.map +1 -1
  19. package/lib/esm/curve/Loop.d.ts.map +1 -1
  20. package/lib/esm/curve/Loop.js +3 -1
  21. package/lib/esm/curve/Loop.js.map +1 -1
  22. package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.js.map +1 -1
  23. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +21 -27
  24. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
  25. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js +98 -153
  26. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
  27. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts +15 -14
  28. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
  29. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +144 -163
  30. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
  31. package/lib/esm/geometry3d/PointHelpers.d.ts.map +1 -1
  32. package/lib/esm/geometry3d/PointHelpers.js +6 -7
  33. package/lib/esm/geometry3d/PointHelpers.js.map +1 -1
  34. package/lib/esm/numerics/Newton.d.ts +10 -2
  35. package/lib/esm/numerics/Newton.d.ts.map +1 -1
  36. package/lib/esm/numerics/Newton.js.map +1 -1
  37. package/package.json +3 -3
@@ -6,7 +6,7 @@
6
6
  * @module Curve
7
7
  */
8
8
  import { assert, DuplicatePolicy, SortedArray } from "@itwin/core-bentley";
9
- import { BSplineCurve3d, BSplineCurve3dBase } from "../../bspline/BSplineCurve";
9
+ import { BSplineCurve3dBase } from "../../bspline/BSplineCurve";
10
10
  import { Geometry } from "../../Geometry";
11
11
  import { RecurseToCurvesGeometryHandler } from "../../geometry3d/GeometryHandler";
12
12
  import { GrowableFloat64Array } from "../../geometry3d/GrowableFloat64Array";
@@ -431,32 +431,6 @@ export class CurveCurveCloseApproachXY extends RecurseToCurvesGeometryHandler {
431
431
  // 2) perpendicular line between 2 arcs (includes intersections)
432
432
  this.allPerpendicularsArcArcBounded(cpA, cpB, reversed);
433
433
  }
434
- /** Low level dispatch of arc with (beziers of) a bspline curve */
435
- dispatchArcBsplineCurve3d(cpA, cpB, reversed) {
436
- const ls = LineString3d.create();
437
- cpB.emitStrokes(ls);
438
- this.computeArcLineString(cpA, ls, reversed);
439
- }
440
- /** Low level dispatch of (beziers of) a bspline curve with (beziers of) a bspline curve */
441
- dispatchBSplineCurve3dBSplineCurve3d(bcurveA, bcurveB, reversed) {
442
- const lsA = LineString3d.create();
443
- bcurveA.emitStrokes(lsA);
444
- const lsB = LineString3d.create();
445
- bcurveB.emitStrokes(lsB);
446
- this.computeLineStringLineString(lsA, lsB, reversed);
447
- }
448
- /** Low level dispatch of linestring with (beziers of) a bspline curve */
449
- dispatchLineStringBSplineCurve(lsA, curveB, reversed) {
450
- const lsB = LineString3d.create();
451
- curveB.emitStrokes(lsB);
452
- this.computeLineStringLineString(lsA, lsB, reversed);
453
- }
454
- /** Low level dispatch of segment with (beziers of) a bspline curve */
455
- dispatchSegmentBsplineCurve(segA, curveB, reversed) {
456
- const lsB = LineString3d.create();
457
- curveB.emitStrokes(lsB);
458
- this.computeSegmentLineString(segA, lsB, reversed);
459
- }
460
434
  /** Detail computation for segment approaching linestring. */
461
435
  computeSegmentLineString(segA, lsB, reversed) {
462
436
  const numB = lsB.numPoints();
@@ -612,6 +586,91 @@ export class CurveCurveCloseApproachXY extends RecurseToCurvesGeometryHandler {
612
586
  });
613
587
  saveResults.forEach((pair) => this._results.insert(pair));
614
588
  }
589
+ /** Specifies whether the curve needs to be stroked for close approach computation. */
590
+ needsStroking(curve) {
591
+ return curve instanceof BSplineCurve3dBase || curve instanceof TransitionSpiral3d;
592
+ }
593
+ /**
594
+ * Process seeds for xy close approach between one curve and another curve to be stroked.
595
+ * * Refine each result via Newton iteration. If it doesn't converge, remove it.
596
+ * @param seeds the initial seed results to refine.
597
+ * @param curveA curve to find its XY close approach with curveB.
598
+ * @param curveB the other curve to be stroked.
599
+ * @param reversed whether `curveB` data is in `detailA` of each recorded pair, and `curveA` data in `detailB`.
600
+ */
601
+ refineStrokedResultsByNewton(seeds, curveA, curveB, reversed = false) {
602
+ const xyMatchingFunction = new CurveCurveCloseApproachXYRRtoRRD(curveA, curveB);
603
+ const newtonSearcher = new Newton2dUnboundedWithDerivative(xyMatchingFunction, 50, this._newtonTolerance); // seen: 47
604
+ for (const seed of seeds) {
605
+ const detailA = reversed ? seed.detailB : seed.detailA;
606
+ const detailB = reversed ? seed.detailA : seed.detailB;
607
+ assert(detailB.curve instanceof LineString3d, "Caller has discretized the curve");
608
+ newtonSearcher.setUV(detailA.fraction, detailB.fraction); // use the linestring fraction as initial curveB fraction (ASSUME it's close enough)
609
+ if (newtonSearcher.runIterations()) {
610
+ const fractionA = newtonSearcher.getU();
611
+ const fractionB = newtonSearcher.getV();
612
+ if (this.acceptFraction(fractionA) && this.acceptFraction(fractionB))
613
+ this.testAndRecordPointPair(curveA, fractionA, undefined, curveB, fractionB, undefined, reversed);
614
+ } // ignore failure to converge
615
+ }
616
+ }
617
+ /**
618
+ * Append stroke points and return the line string.
619
+ * * This is a convenient wrapper for [[CurvePrimitive.emitStrokes]] but the analogous instance method cannot be added
620
+ * to that class due to the ensuing recursion with subclass [[LineString3d]].
621
+ * @param options options for stroking the instance curve.
622
+ * @param result object to receive appended stroke points; if omitted, a new object is created, populated, and returned.
623
+ */
624
+ strokeCurve(curve, options, result) {
625
+ const ls = result ? result : LineString3d.create();
626
+ curve.emitStrokes(ls, options);
627
+ return ls;
628
+ }
629
+ /** Find and return the close approaches between curveA and the discretization of curveB. */
630
+ computeDiscreteCloseApproachResults(curveA, lsB, reversed) {
631
+ const maxDist = this.maxDistanceToAccept;
632
+ const saveResults = this.grabPairedResults(); // save current results
633
+ const geomB = this._geometryB;
634
+ this.maxDistanceToAccept = maxDist ? maxDist * 1.2 : undefined; // HEURISTIC: allow slack for Newton seeds
635
+ this.resetGeometry(curveA);
636
+ this.handleLineString3d(lsB); // populate empty results with discrete solutions
637
+ if (!reversed) {
638
+ // handleLineString3d put lsB data into detailA, so if we aren't reversing, we need to swap
639
+ for (const result of this._results)
640
+ result.swapDetails();
641
+ }
642
+ this.resetGeometry(geomB);
643
+ this.maxDistanceToAccept = maxDist;
644
+ const discreteResults = this._results.extractArray();
645
+ saveResults.forEach((pair) => this._results.insert(pair)); // restore current results
646
+ return discreteResults;
647
+ }
648
+ /**
649
+ * Compute the XY close approach of a curve and another curve to be stroked.
650
+ * @param curveA curve to find its XY close approach with curveB.
651
+ * @param curveB the other curve to be stroked.
652
+ * @param reversed whether `curveB` data will be recorded in `detailA` of each result, and `curveA` data in `detailB`.
653
+ */
654
+ dispatchCurveStrokedCurve(curveA, curveB, reversed) {
655
+ // explicit search for intersections (Newton converges too slowly on DirectSpiral3d tangent intersections)
656
+ const intersections = CurveCurve.intersectionXYPairs(curveA, false, curveB, false, this._xyTolerance);
657
+ for (const intersection of intersections)
658
+ this.testAndRecordPair(intersection, reversed);
659
+ // append seeds computed by solving the discretized spiral close approach problem, then refine the seeds via Newton
660
+ let cpA = curveA;
661
+ if (this.needsStroking(curveA))
662
+ cpA = this.strokeCurve(curveA);
663
+ const cpB = this.strokeCurve(curveB);
664
+ const seeds = this.computeDiscreteCloseApproachResults(cpA, cpB, reversed);
665
+ this.refineStrokedResultsByNewton(seeds, curveA, curveB, reversed);
666
+ if (curveA instanceof LineString3d) { // explicitly test corners (where Newton converges too slowly)
667
+ const fStep = Geometry.safeDivideFraction(1.0, curveA.numEdges(), 0);
668
+ const v0 = CurveCurveCloseApproachXY._workPointBB0;
669
+ for (let i = 1; i < curveA.numEdges(); ++i)
670
+ this.testAndRecordProjection(curveA, i * fStep, curveA.pointAtUnchecked(i, v0), curveB, reversed);
671
+ }
672
+ this.testAndRecordEndPointApproaches(curveA, curveB, reversed);
673
+ }
615
674
  /** Double dispatch handler for strongly typed segment. */
616
675
  handleLineSegment3d(segmentA) {
617
676
  if (this._geometryB instanceof LineSegment3d) {
@@ -624,11 +683,8 @@ export class CurveCurveCloseApproachXY extends RecurseToCurvesGeometryHandler {
624
683
  else if (this._geometryB instanceof Arc3d) {
625
684
  this.computeSegmentArc(segmentA, this._geometryB, false);
626
685
  }
627
- else if (this._geometryB instanceof BSplineCurve3d) {
628
- this.dispatchSegmentBsplineCurve(segmentA, this._geometryB, false);
629
- }
630
- else if (this._geometryB instanceof TransitionSpiral3d) {
631
- this.dispatchCurveSpiral(segmentA, this._geometryB, false);
686
+ else if (this.needsStroking(this._geometryB)) {
687
+ this.dispatchCurveStrokedCurve(segmentA, this._geometryB, false);
632
688
  }
633
689
  else if (this._geometryB instanceof CurveCollection) {
634
690
  this.dispatchCurveCollection(segmentA, this.handleLineSegment3d.bind(this));
@@ -649,11 +705,8 @@ export class CurveCurveCloseApproachXY extends RecurseToCurvesGeometryHandler {
649
705
  else if (this._geometryB instanceof Arc3d) {
650
706
  this.computeArcLineString(this._geometryB, lsA, true);
651
707
  }
652
- else if (this._geometryB instanceof BSplineCurve3d) {
653
- this.dispatchLineStringBSplineCurve(lsA, this._geometryB, false);
654
- }
655
- else if (this._geometryB instanceof TransitionSpiral3d) {
656
- this.dispatchCurveSpiral(lsA, this._geometryB, false);
708
+ else if (this.needsStroking(this._geometryB)) {
709
+ this.dispatchCurveStrokedCurve(lsA, this._geometryB, false);
657
710
  }
658
711
  else if (this._geometryB instanceof CurveCollection) {
659
712
  this.dispatchCurveCollection(lsA, this.handleLineString3d.bind(this));
@@ -674,11 +727,8 @@ export class CurveCurveCloseApproachXY extends RecurseToCurvesGeometryHandler {
674
727
  else if (this._geometryB instanceof Arc3d) {
675
728
  this.dispatchArcArc(arcA, this._geometryB, false);
676
729
  }
677
- else if (this._geometryB instanceof BSplineCurve3d) {
678
- this.dispatchArcBsplineCurve3d(arcA, this._geometryB, false);
679
- }
680
- else if (this._geometryB instanceof TransitionSpiral3d) {
681
- this.dispatchCurveSpiral(arcA, this._geometryB, false);
730
+ else if (this.needsStroking(this._geometryB)) {
731
+ this.dispatchCurveStrokedCurve(arcA, this._geometryB, false);
682
732
  }
683
733
  else if (this._geometryB instanceof CurveCollection) {
684
734
  this.dispatchCurveCollection(arcA, this.handleArc3d.bind(this));
@@ -690,117 +740,24 @@ export class CurveCurveCloseApproachXY extends RecurseToCurvesGeometryHandler {
690
740
  }
691
741
  /** Double dispatch handler for strongly typed bspline curve. */
692
742
  handleBSplineCurve3d(curveA) {
693
- if (this._geometryB instanceof LineSegment3d) {
694
- this.dispatchSegmentBsplineCurve(this._geometryB, curveA, true);
695
- }
696
- else if (this._geometryB instanceof LineString3d) {
697
- this.dispatchLineStringBSplineCurve(this._geometryB, curveA, true);
698
- }
699
- else if (this._geometryB instanceof Arc3d) {
700
- this.dispatchArcBsplineCurve3d(this._geometryB, curveA, true);
701
- }
702
- else if (this._geometryB instanceof BSplineCurve3dBase) {
703
- this.dispatchBSplineCurve3dBSplineCurve3d(curveA, this._geometryB, false);
743
+ if (this._geometryB instanceof CurveChainWithDistanceIndex) {
744
+ this.dispatchCurveChainWithDistanceIndex(curveA, this.handleBSplineCurve3d.bind(this));
704
745
  }
705
- else if (this._geometryB instanceof TransitionSpiral3d) {
706
- this.dispatchCurveSpiral(curveA, this._geometryB, false);
746
+ else if (this._geometryB instanceof CurvePrimitive) {
747
+ this.dispatchCurveStrokedCurve(this._geometryB, curveA, true);
707
748
  }
708
749
  else if (this._geometryB instanceof CurveCollection) {
709
750
  this.dispatchCurveCollection(curveA, this.handleBSplineCurve3d.bind(this));
710
751
  }
711
- else if (this._geometryB instanceof CurveChainWithDistanceIndex) {
712
- this.dispatchCurveChainWithDistanceIndex(curveA, this.handleBSplineCurve3d.bind(this));
713
- }
714
752
  return undefined;
715
753
  }
716
- /**
717
- * Process seeds for xy close approach between the curve and spiral.
718
- * * Refine each result via Newton iteration. If it doesn't converge, remove it.
719
- * @param seeds The initial seed results to refine.
720
- * @param curveA The other curve primitive. May also be a transition spiral.
721
- * @param spiralB The transition spiral.
722
- * @param reversed whether `spiralB` data is in `detailA` of each recorded pair, and `curveA` data in `detailB`.
723
- */
724
- refineSpiralResultsByNewton(seeds, curveA, spiralB, reversed = false) {
725
- const xyMatchingFunction = new CurveCurveCloseApproachXYRRtoRRD(curveA, spiralB);
726
- const newtonSearcher = new Newton2dUnboundedWithDerivative(xyMatchingFunction, 50, this._newtonTolerance); // seen: 47
727
- for (const seed of seeds) {
728
- const detailA = reversed ? seed.detailB : seed.detailA;
729
- const detailB = reversed ? seed.detailA : seed.detailB;
730
- assert(detailB.curve instanceof LineString3d, "Caller has discretized the spiral");
731
- newtonSearcher.setUV(detailA.fraction, detailB.fraction); // use linestring fraction as spiral param; it generally yields a closer point than fractional length!
732
- if (newtonSearcher.runIterations()) {
733
- const fractionA = newtonSearcher.getU();
734
- const fractionB = newtonSearcher.getV();
735
- if (this.acceptFraction(fractionA) && this.acceptFraction(fractionB))
736
- this.testAndRecordPointPair(curveA, fractionA, undefined, spiralB, fractionB, undefined, reversed);
737
- } // ignore failure to converge
738
- }
739
- }
740
- /**
741
- * Append stroke points and return the line string.
742
- * * This is a convenient wrapper for [[CurvePrimitive.emitStrokes]] but the analogous instance method cannot be added
743
- * to that class due to the ensuing recursion with subclass [[LineString3d]].
744
- * @param options options for stroking the instance curve.
745
- * @param result object to receive appended stroke points; if omitted, a new object is created, populated, and returned.
746
- */
747
- strokeCurve(curve, options, result) {
748
- const ls = result ? result : LineString3d.create();
749
- curve.emitStrokes(ls, options);
750
- return ls;
751
- }
752
- /** Find and return the close approaches between curveA and the discretization of curveB. */
753
- computeDiscreteCloseApproachResults(curveA, lsB, reversed) {
754
- const maxDist = this.maxDistanceToAccept;
755
- const saveResults = this.grabPairedResults(); // save current results
756
- const geomB = this._geometryB;
757
- this.maxDistanceToAccept = maxDist ? maxDist * 1.2 : undefined; // HEURISTIC: allow slack for Newton seeds
758
- this.resetGeometry(curveA);
759
- this.handleLineString3d(lsB); // populate empty results with discrete solutions
760
- if (!reversed) {
761
- // handleLineString3d put lsB data into detailA, so if we aren't reversing, we need to swap
762
- for (const result of this._results)
763
- result.swapDetails();
764
- }
765
- this.resetGeometry(geomB);
766
- this.maxDistanceToAccept = maxDist;
767
- const discreteResults = this._results.extractArray();
768
- saveResults.forEach((pair) => this._results.insert(pair)); // restore current results
769
- return discreteResults;
770
- }
771
- /**
772
- * Compute the XY close approach of a curve and a spiral.
773
- * @param curveA curve to find its close approach with spiralB. May also be a transition spiral.
774
- * @param spiralB transition spiral to find its close approach with curveA.
775
- * @param reversed whether `spiralB` data will be recorded in `detailA` of each result, and `curveA` data in `detailB`.
776
- */
777
- dispatchCurveSpiral(curveA, spiralB, reversed) {
778
- // explicit search for intersections (Newton converges too slowly on DirectSpiral3d tangent intersections)
779
- const intersections = CurveCurve.intersectionXYPairs(curveA, false, spiralB, false, this._xyTolerance);
780
- for (const intersection of intersections)
781
- this.testAndRecordPair(intersection, reversed);
782
- // append seeds computed by solving the discretized spiral close approach problem, then refine the seeds via Newton
783
- let cpA = curveA;
784
- if (curveA instanceof TransitionSpiral3d)
785
- cpA = this.strokeCurve(curveA);
786
- const cpB = this.strokeCurve(spiralB);
787
- const seeds = this.computeDiscreteCloseApproachResults(cpA, cpB, reversed);
788
- this.refineSpiralResultsByNewton(seeds, curveA, spiralB, reversed);
789
- if (curveA instanceof LineString3d) { // explicitly test corners (where Newton converges too slowly)
790
- const fStep = Geometry.safeDivideFraction(1.0, curveA.numEdges(), 0);
791
- const v0 = CurveCurveCloseApproachXY._workPointBB0;
792
- for (let i = 1; i < curveA.numEdges(); ++i)
793
- this.testAndRecordProjection(curveA, i * fStep, curveA.pointAtUnchecked(i, v0), spiralB, reversed);
794
- }
795
- this.testAndRecordEndPointApproaches(curveA, spiralB, reversed);
796
- }
797
754
  /** Double dispatch handler for strongly typed spiral curve. */
798
755
  handleTransitionSpiral(spiral) {
799
756
  if (this._geometryB instanceof CurveChainWithDistanceIndex) {
800
757
  this.dispatchCurveChainWithDistanceIndex(spiral, this.handleTransitionSpiral.bind(this));
801
758
  }
802
759
  else if (this._geometryB instanceof CurvePrimitive) {
803
- this.dispatchCurveSpiral(this._geometryB, spiral, true);
760
+ this.dispatchCurveStrokedCurve(this._geometryB, spiral, true);
804
761
  }
805
762
  else if (this._geometryB instanceof CurveCollection) {
806
763
  this.dispatchCurveCollection(spiral, this.handleTransitionSpiral.bind(this));
@@ -819,19 +776,7 @@ export class CurveCurveCloseApproachXY extends RecurseToCurvesGeometryHandler {
819
776
  }
820
777
  /** Double dispatch handler for strongly typed homogeneous bspline curve .. */
821
778
  handleBSplineCurve3dH(_curve) {
822
- /*
823
- //NEEDS WORK -- make "dispatch" methods tolerant of both 3d and 3dH.
824
- // "easy" if both present BezierCurve3dH span loaders
825
- if (this._geometryB instanceof LineSegment3d) {
826
- this.dispatchSegmentBsplineCurve(
827
- this._geometryB, this._extendB, this._geometryB.point0Ref, 0.0, this._geometryB.point1Ref, 1.0, this._extendB,
828
- curve, this._extendA, true);
829
- } else if (this._geometryB instanceof LineString3d) {
830
- this.dispatchLineStringBSplineCurve(this._geometryB, this._extendB, curve, this._extendA, true);
831
- } else if (this._geometryB instanceof Arc3d) {
832
- this.dispatchArcBsplineCurve3d(this._geometryB, this._extendB, curve, this._extendA, true);
833
- }
834
- */
779
+ // NEEDS WORK -- make "dispatch" methods tolerant of both 3d and 3dH
835
780
  return undefined;
836
781
  }
837
782
  }