@itwin/core-geometry 4.4.0-dev.8 → 4.5.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/lib/cjs/Geometry.d.ts +17 -0
- package/lib/cjs/Geometry.d.ts.map +1 -1
- package/lib/cjs/Geometry.js +14 -0
- package/lib/cjs/Geometry.js.map +1 -1
- package/lib/cjs/core-geometry.d.ts +3 -2
- package/lib/cjs/core-geometry.d.ts.map +1 -1
- package/lib/cjs/core-geometry.js +3 -2
- package/lib/cjs/core-geometry.js.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +2 -2
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js +3 -3
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/cjs/curve/CurveExtendMode.d.ts +7 -6
- package/lib/cjs/curve/CurveExtendMode.d.ts.map +1 -1
- package/lib/cjs/curve/CurveExtendMode.js +7 -6
- package/lib/cjs/curve/CurveExtendMode.js.map +1 -1
- package/lib/cjs/curve/CurveLocationDetail.d.ts.map +1 -1
- package/lib/cjs/curve/CurveLocationDetail.js +23 -18
- package/lib/cjs/curve/CurveLocationDetail.js.map +1 -1
- package/lib/cjs/curve/LineSegment3d.d.ts +14 -4
- package/lib/cjs/curve/LineSegment3d.d.ts.map +1 -1
- package/lib/cjs/curve/LineSegment3d.js +107 -2
- package/lib/cjs/curve/LineSegment3d.js.map +1 -1
- package/lib/cjs/curve/LineString3d.d.ts +41 -8
- package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
- package/lib/cjs/curve/LineString3d.js +53 -15
- package/lib/cjs/curve/LineString3d.js.map +1 -1
- package/lib/cjs/curve/Loop.js +1 -1
- package/lib/cjs/curve/Loop.js.map +1 -1
- package/lib/cjs/curve/Query/PlanarSubdivision.d.ts +2 -2
- package/lib/cjs/curve/Query/PlanarSubdivision.js +2 -2
- package/lib/cjs/curve/Query/PlanarSubdivision.js.map +1 -1
- package/lib/cjs/curve/RegionOps.d.ts +1 -2
- package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
- package/lib/cjs/curve/RegionOps.js.map +1 -1
- package/lib/cjs/curve/RegionOpsClassificationSweeps.d.ts +5 -8
- package/lib/cjs/curve/RegionOpsClassificationSweeps.d.ts.map +1 -1
- package/lib/cjs/curve/RegionOpsClassificationSweeps.js +12 -12
- package/lib/cjs/curve/RegionOpsClassificationSweeps.js.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYArray.d.ts +2 -2
- package/lib/cjs/geometry3d/GrowableXYArray.d.ts.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYArray.js +1 -1
- package/lib/cjs/geometry3d/GrowableXYArray.js.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYZArray.d.ts +2 -3
- package/lib/cjs/geometry3d/GrowableXYZArray.d.ts.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYZArray.js +1 -1
- package/lib/cjs/geometry3d/GrowableXYZArray.js.map +1 -1
- package/lib/cjs/geometry3d/IndexedXYZCollection.d.ts +18 -1
- package/lib/cjs/geometry3d/IndexedXYZCollection.d.ts.map +1 -1
- package/lib/cjs/geometry3d/IndexedXYZCollection.js +13 -0
- package/lib/cjs/geometry3d/IndexedXYZCollection.js.map +1 -1
- package/lib/cjs/geometry3d/PointHelpers.d.ts +1 -2
- package/lib/cjs/geometry3d/PointHelpers.d.ts.map +1 -1
- package/lib/cjs/geometry3d/PointHelpers.js.map +1 -1
- package/lib/cjs/geometry3d/PointStreaming.d.ts +1 -1
- package/lib/cjs/geometry3d/PointStreaming.d.ts.map +1 -1
- package/lib/cjs/geometry3d/PointStreaming.js +3 -1
- package/lib/cjs/geometry3d/PointStreaming.js.map +1 -1
- package/lib/cjs/geometry3d/PolygonOps.d.ts +68 -1
- package/lib/cjs/geometry3d/PolygonOps.d.ts.map +1 -1
- package/lib/cjs/geometry3d/PolygonOps.js +152 -4
- package/lib/cjs/geometry3d/PolygonOps.js.map +1 -1
- package/lib/cjs/geometry3d/PolylineOps.d.ts +23 -1
- package/lib/cjs/geometry3d/PolylineOps.d.ts.map +1 -1
- package/lib/cjs/geometry3d/PolylineOps.js +73 -1
- package/lib/cjs/geometry3d/PolylineOps.js.map +1 -1
- package/lib/cjs/geometry3d/Range.d.ts +1 -1
- package/lib/cjs/geometry3d/Range.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Range.js.map +1 -1
- package/lib/cjs/geometry3d/Transform.js +1 -1
- package/lib/cjs/geometry3d/Transform.js.map +1 -1
- package/lib/cjs/geometry3d/YawPitchRollAngles.d.ts +7 -5
- package/lib/cjs/geometry3d/YawPitchRollAngles.d.ts.map +1 -1
- package/lib/cjs/geometry3d/YawPitchRollAngles.js +8 -6
- package/lib/cjs/geometry3d/YawPitchRollAngles.js.map +1 -1
- package/lib/cjs/numerics/Polynomials.d.ts +13 -1
- package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
- package/lib/cjs/numerics/Polynomials.js +13 -1
- package/lib/cjs/numerics/Polynomials.js.map +1 -1
- package/lib/cjs/polyface/FacetLocationDetail.d.ts +28 -5
- package/lib/cjs/polyface/FacetLocationDetail.d.ts.map +1 -1
- package/lib/cjs/polyface/FacetLocationDetail.js +50 -15
- package/lib/cjs/polyface/FacetLocationDetail.js.map +1 -1
- package/lib/cjs/polyface/Polyface.d.ts +1 -1
- package/lib/cjs/polyface/Polyface.d.ts.map +1 -1
- package/lib/cjs/polyface/Polyface.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceQuery.d.ts +7 -3
- package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceQuery.js +23 -0
- package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
- package/lib/cjs/polyface/RangeTree/LineString3dRangeTreeContext.d.ts +52 -0
- package/lib/cjs/polyface/RangeTree/LineString3dRangeTreeContext.d.ts.map +1 -0
- package/lib/cjs/polyface/RangeTree/LineString3dRangeTreeContext.js +78 -0
- package/lib/cjs/polyface/RangeTree/LineString3dRangeTreeContext.js.map +1 -0
- package/lib/cjs/polyface/RangeTree/MinimumValueTester.d.ts +60 -0
- package/lib/cjs/polyface/RangeTree/MinimumValueTester.d.ts.map +1 -0
- package/lib/cjs/polyface/RangeTree/MinimumValueTester.js +96 -0
- package/lib/cjs/polyface/RangeTree/MinimumValueTester.js.map +1 -0
- package/lib/cjs/polyface/RangeTree/Point3dArrayRangeTreeContext.d.ts +57 -0
- package/lib/cjs/polyface/RangeTree/Point3dArrayRangeTreeContext.d.ts.map +1 -0
- package/lib/cjs/polyface/RangeTree/Point3dArrayRangeTreeContext.js +73 -0
- package/lib/cjs/polyface/RangeTree/Point3dArrayRangeTreeContext.js.map +1 -0
- package/lib/cjs/polyface/RangeTree/PolyfaceRangeTreeContext.d.ts +57 -0
- package/lib/cjs/polyface/RangeTree/PolyfaceRangeTreeContext.d.ts.map +1 -0
- package/lib/cjs/polyface/RangeTree/PolyfaceRangeTreeContext.js +84 -0
- package/lib/cjs/polyface/RangeTree/PolyfaceRangeTreeContext.js.map +1 -0
- package/lib/cjs/polyface/RangeTree/RangeTreeNode.d.ts +274 -0
- package/lib/cjs/polyface/RangeTree/RangeTreeNode.d.ts.map +1 -0
- package/lib/cjs/polyface/RangeTree/RangeTreeNode.js +505 -0
- package/lib/cjs/polyface/RangeTree/RangeTreeNode.js.map +1 -0
- package/lib/cjs/polyface/RangeTree/RangeTreeSearchHandlers.d.ts +204 -0
- package/lib/cjs/polyface/RangeTree/RangeTreeSearchHandlers.d.ts.map +1 -0
- package/lib/cjs/polyface/RangeTree/RangeTreeSearchHandlers.js +383 -0
- package/lib/cjs/polyface/RangeTree/RangeTreeSearchHandlers.js.map +1 -0
- package/lib/cjs/serialization/GeometrySamples.d.ts +36 -3
- package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
- package/lib/cjs/serialization/GeometrySamples.js +93 -4
- package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
- package/lib/cjs/solid/LinearSweep.d.ts +1 -1
- package/lib/cjs/solid/LinearSweep.js +1 -1
- package/lib/cjs/solid/LinearSweep.js.map +1 -1
- package/lib/cjs/solid/SweepContour.d.ts +2 -2
- package/lib/cjs/solid/SweepContour.d.ts.map +1 -1
- package/lib/cjs/solid/SweepContour.js.map +1 -1
- package/lib/cjs/topology/Graph.d.ts +5 -6
- package/lib/cjs/topology/Graph.d.ts.map +1 -1
- package/lib/cjs/topology/Graph.js +7 -6
- package/lib/cjs/topology/Graph.js.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts +4 -4
- package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.js +5 -5
- package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.js.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphSearch.d.ts +108 -71
- package/lib/cjs/topology/HalfEdgeGraphSearch.d.ts.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphSearch.js +223 -109
- package/lib/cjs/topology/HalfEdgeGraphSearch.js.map +1 -1
- package/lib/cjs/topology/Merging.d.ts +1 -1
- package/lib/cjs/topology/Merging.d.ts.map +1 -1
- package/lib/cjs/topology/Merging.js.map +1 -1
- package/lib/cjs/topology/SignedDataSummary.d.ts +13 -13
- package/lib/cjs/topology/SignedDataSummary.d.ts.map +1 -1
- package/lib/cjs/topology/SignedDataSummary.js +3 -3
- package/lib/cjs/topology/SignedDataSummary.js.map +1 -1
- package/lib/cjs/topology/Triangulation.d.ts +1 -12
- package/lib/cjs/topology/Triangulation.d.ts.map +1 -1
- package/lib/cjs/topology/Triangulation.js.map +1 -1
- package/lib/cjs/topology/XYParitySearchContext.d.ts +27 -21
- package/lib/cjs/topology/XYParitySearchContext.d.ts.map +1 -1
- package/lib/cjs/topology/XYParitySearchContext.js +73 -71
- package/lib/cjs/topology/XYParitySearchContext.js.map +1 -1
- package/lib/esm/Geometry.d.ts +17 -0
- package/lib/esm/Geometry.d.ts.map +1 -1
- package/lib/esm/Geometry.js +14 -0
- package/lib/esm/Geometry.js.map +1 -1
- package/lib/esm/core-geometry.d.ts +3 -2
- package/lib/esm/core-geometry.d.ts.map +1 -1
- package/lib/esm/core-geometry.js +3 -2
- package/lib/esm/core-geometry.js.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +2 -2
- package/lib/esm/curve/CurveChainWithDistanceIndex.js +3 -3
- package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/esm/curve/CurveExtendMode.d.ts +7 -6
- package/lib/esm/curve/CurveExtendMode.d.ts.map +1 -1
- package/lib/esm/curve/CurveExtendMode.js +7 -6
- package/lib/esm/curve/CurveExtendMode.js.map +1 -1
- package/lib/esm/curve/CurveLocationDetail.d.ts.map +1 -1
- package/lib/esm/curve/CurveLocationDetail.js +23 -18
- package/lib/esm/curve/CurveLocationDetail.js.map +1 -1
- package/lib/esm/curve/LineSegment3d.d.ts +14 -4
- package/lib/esm/curve/LineSegment3d.d.ts.map +1 -1
- package/lib/esm/curve/LineSegment3d.js +108 -3
- package/lib/esm/curve/LineSegment3d.js.map +1 -1
- package/lib/esm/curve/LineString3d.d.ts +41 -8
- package/lib/esm/curve/LineString3d.d.ts.map +1 -1
- package/lib/esm/curve/LineString3d.js +53 -15
- package/lib/esm/curve/LineString3d.js.map +1 -1
- package/lib/esm/curve/Loop.js +1 -1
- package/lib/esm/curve/Loop.js.map +1 -1
- package/lib/esm/curve/Query/PlanarSubdivision.d.ts +2 -2
- package/lib/esm/curve/Query/PlanarSubdivision.js +2 -2
- package/lib/esm/curve/Query/PlanarSubdivision.js.map +1 -1
- package/lib/esm/curve/RegionOps.d.ts +1 -2
- package/lib/esm/curve/RegionOps.d.ts.map +1 -1
- package/lib/esm/curve/RegionOps.js +1 -1
- package/lib/esm/curve/RegionOps.js.map +1 -1
- package/lib/esm/curve/RegionOpsClassificationSweeps.d.ts +5 -8
- package/lib/esm/curve/RegionOpsClassificationSweeps.d.ts.map +1 -1
- package/lib/esm/curve/RegionOpsClassificationSweeps.js +12 -12
- package/lib/esm/curve/RegionOpsClassificationSweeps.js.map +1 -1
- package/lib/esm/geometry3d/GrowableXYArray.d.ts +2 -2
- package/lib/esm/geometry3d/GrowableXYArray.d.ts.map +1 -1
- package/lib/esm/geometry3d/GrowableXYArray.js +1 -1
- package/lib/esm/geometry3d/GrowableXYArray.js.map +1 -1
- package/lib/esm/geometry3d/GrowableXYZArray.d.ts +2 -3
- package/lib/esm/geometry3d/GrowableXYZArray.d.ts.map +1 -1
- package/lib/esm/geometry3d/GrowableXYZArray.js +1 -1
- package/lib/esm/geometry3d/GrowableXYZArray.js.map +1 -1
- package/lib/esm/geometry3d/IndexedXYZCollection.d.ts +18 -1
- package/lib/esm/geometry3d/IndexedXYZCollection.d.ts.map +1 -1
- package/lib/esm/geometry3d/IndexedXYZCollection.js +13 -0
- package/lib/esm/geometry3d/IndexedXYZCollection.js.map +1 -1
- package/lib/esm/geometry3d/PointHelpers.d.ts +1 -2
- package/lib/esm/geometry3d/PointHelpers.d.ts.map +1 -1
- package/lib/esm/geometry3d/PointHelpers.js.map +1 -1
- package/lib/esm/geometry3d/PointStreaming.d.ts +1 -1
- package/lib/esm/geometry3d/PointStreaming.d.ts.map +1 -1
- package/lib/esm/geometry3d/PointStreaming.js +3 -1
- package/lib/esm/geometry3d/PointStreaming.js.map +1 -1
- package/lib/esm/geometry3d/PolygonOps.d.ts +68 -1
- package/lib/esm/geometry3d/PolygonOps.d.ts.map +1 -1
- package/lib/esm/geometry3d/PolygonOps.js +150 -3
- package/lib/esm/geometry3d/PolygonOps.js.map +1 -1
- package/lib/esm/geometry3d/PolylineOps.d.ts +23 -1
- package/lib/esm/geometry3d/PolylineOps.d.ts.map +1 -1
- package/lib/esm/geometry3d/PolylineOps.js +73 -1
- package/lib/esm/geometry3d/PolylineOps.js.map +1 -1
- package/lib/esm/geometry3d/Range.d.ts +1 -1
- package/lib/esm/geometry3d/Range.d.ts.map +1 -1
- package/lib/esm/geometry3d/Range.js.map +1 -1
- package/lib/esm/geometry3d/Transform.js +1 -1
- package/lib/esm/geometry3d/Transform.js.map +1 -1
- package/lib/esm/geometry3d/YawPitchRollAngles.d.ts +7 -5
- package/lib/esm/geometry3d/YawPitchRollAngles.d.ts.map +1 -1
- package/lib/esm/geometry3d/YawPitchRollAngles.js +8 -6
- package/lib/esm/geometry3d/YawPitchRollAngles.js.map +1 -1
- package/lib/esm/numerics/Polynomials.d.ts +13 -1
- package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
- package/lib/esm/numerics/Polynomials.js +13 -1
- package/lib/esm/numerics/Polynomials.js.map +1 -1
- package/lib/esm/polyface/FacetLocationDetail.d.ts +28 -5
- package/lib/esm/polyface/FacetLocationDetail.d.ts.map +1 -1
- package/lib/esm/polyface/FacetLocationDetail.js +48 -14
- package/lib/esm/polyface/FacetLocationDetail.js.map +1 -1
- package/lib/esm/polyface/Polyface.d.ts +1 -1
- package/lib/esm/polyface/Polyface.d.ts.map +1 -1
- package/lib/esm/polyface/Polyface.js.map +1 -1
- package/lib/esm/polyface/PolyfaceQuery.d.ts +7 -3
- package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceQuery.js +23 -0
- package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
- package/lib/esm/polyface/RangeTree/LineString3dRangeTreeContext.d.ts +52 -0
- package/lib/esm/polyface/RangeTree/LineString3dRangeTreeContext.d.ts.map +1 -0
- package/lib/esm/polyface/RangeTree/LineString3dRangeTreeContext.js +74 -0
- package/lib/esm/polyface/RangeTree/LineString3dRangeTreeContext.js.map +1 -0
- package/lib/esm/polyface/RangeTree/MinimumValueTester.d.ts +60 -0
- package/lib/esm/polyface/RangeTree/MinimumValueTester.d.ts.map +1 -0
- package/lib/esm/polyface/RangeTree/MinimumValueTester.js +92 -0
- package/lib/esm/polyface/RangeTree/MinimumValueTester.js.map +1 -0
- package/lib/esm/polyface/RangeTree/Point3dArrayRangeTreeContext.d.ts +57 -0
- package/lib/esm/polyface/RangeTree/Point3dArrayRangeTreeContext.d.ts.map +1 -0
- package/lib/esm/polyface/RangeTree/Point3dArrayRangeTreeContext.js +69 -0
- package/lib/esm/polyface/RangeTree/Point3dArrayRangeTreeContext.js.map +1 -0
- package/lib/esm/polyface/RangeTree/PolyfaceRangeTreeContext.d.ts +57 -0
- package/lib/esm/polyface/RangeTree/PolyfaceRangeTreeContext.d.ts.map +1 -0
- package/lib/esm/polyface/RangeTree/PolyfaceRangeTreeContext.js +80 -0
- package/lib/esm/polyface/RangeTree/PolyfaceRangeTreeContext.js.map +1 -0
- package/lib/esm/polyface/RangeTree/RangeTreeNode.d.ts +274 -0
- package/lib/esm/polyface/RangeTree/RangeTreeNode.d.ts.map +1 -0
- package/lib/esm/polyface/RangeTree/RangeTreeNode.js +497 -0
- package/lib/esm/polyface/RangeTree/RangeTreeNode.js.map +1 -0
- package/lib/esm/polyface/RangeTree/RangeTreeSearchHandlers.d.ts +204 -0
- package/lib/esm/polyface/RangeTree/RangeTreeSearchHandlers.d.ts.map +1 -0
- package/lib/esm/polyface/RangeTree/RangeTreeSearchHandlers.js +374 -0
- package/lib/esm/polyface/RangeTree/RangeTreeSearchHandlers.js.map +1 -0
- package/lib/esm/serialization/GeometrySamples.d.ts +36 -3
- package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
- package/lib/esm/serialization/GeometrySamples.js +93 -4
- package/lib/esm/serialization/GeometrySamples.js.map +1 -1
- package/lib/esm/solid/LinearSweep.d.ts +1 -1
- package/lib/esm/solid/LinearSweep.js +1 -1
- package/lib/esm/solid/LinearSweep.js.map +1 -1
- package/lib/esm/solid/SweepContour.d.ts +2 -2
- package/lib/esm/solid/SweepContour.d.ts.map +1 -1
- package/lib/esm/solid/SweepContour.js.map +1 -1
- package/lib/esm/topology/Graph.d.ts +5 -6
- package/lib/esm/topology/Graph.d.ts.map +1 -1
- package/lib/esm/topology/Graph.js +7 -6
- package/lib/esm/topology/Graph.js.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts +4 -4
- package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.js +5 -5
- package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.js.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphSearch.d.ts +108 -71
- package/lib/esm/topology/HalfEdgeGraphSearch.d.ts.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphSearch.js +223 -109
- package/lib/esm/topology/HalfEdgeGraphSearch.js.map +1 -1
- package/lib/esm/topology/Merging.d.ts +1 -1
- package/lib/esm/topology/Merging.d.ts.map +1 -1
- package/lib/esm/topology/Merging.js.map +1 -1
- package/lib/esm/topology/SignedDataSummary.d.ts +13 -13
- package/lib/esm/topology/SignedDataSummary.d.ts.map +1 -1
- package/lib/esm/topology/SignedDataSummary.js +3 -3
- package/lib/esm/topology/SignedDataSummary.js.map +1 -1
- package/lib/esm/topology/Triangulation.d.ts +1 -12
- package/lib/esm/topology/Triangulation.d.ts.map +1 -1
- package/lib/esm/topology/Triangulation.js.map +1 -1
- package/lib/esm/topology/XYParitySearchContext.d.ts +27 -21
- package/lib/esm/topology/XYParitySearchContext.d.ts.map +1 -1
- package/lib/esm/topology/XYParitySearchContext.js +73 -71
- package/lib/esm/topology/XYParitySearchContext.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module RangeSearch
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.RangeTreeOps = exports.RangeTreeNode = exports.TwoTreeDistanceMinimizationSearchHandler = exports.TwoTreeSearchHandler = exports.SingleTreeSearchHandler = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const Range_1 = require("../../geometry3d/Range");
|
|
13
|
+
/**
|
|
14
|
+
* Map an (unchecked) integer to a parameterized type T, where the data argument can be either:
|
|
15
|
+
* * an array of type T
|
|
16
|
+
* * a function which takes an index and returns type T
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
function evaluateIndexToType(data, index) {
|
|
20
|
+
if (Array.isArray(data))
|
|
21
|
+
return data[index];
|
|
22
|
+
return data(index);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get data by index from a source that may be undefined, an array of item of type T, or a singleton of the item type.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
function getByIndex(index, data) {
|
|
29
|
+
if (data !== undefined) {
|
|
30
|
+
if (Array.isArray(data)) {
|
|
31
|
+
if (index < data.length)
|
|
32
|
+
return data[index];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Return the number of items in an object that can be undefined, an array of item of type T, or a singleton of the item type.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
function getFlexDataCount(data) {
|
|
45
|
+
if (data !== undefined) {
|
|
46
|
+
if (Array.isArray(data)) {
|
|
47
|
+
return data.length;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Abstract class for handler objects called during traversal of a single range tree.
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
class SingleTreeSearchHandler {
|
|
60
|
+
/**
|
|
61
|
+
* Query to see if the active search has been aborted.
|
|
62
|
+
* * Default implementation returns false so query runs to completion.
|
|
63
|
+
* * Search processes check this after range tests and child processing.
|
|
64
|
+
*/
|
|
65
|
+
// eslint-disable-next-line @itwin/prefer-get
|
|
66
|
+
isAborted() { return false; }
|
|
67
|
+
}
|
|
68
|
+
exports.SingleTreeSearchHandler = SingleTreeSearchHandler;
|
|
69
|
+
/**
|
|
70
|
+
* Abstract class for handler objects called during traversal of two range trees.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
class TwoTreeSearchHandler {
|
|
74
|
+
/**
|
|
75
|
+
* Query to see if the active search has been aborted.
|
|
76
|
+
* * Default implementation returns false so query runs to completion.
|
|
77
|
+
* * Search processes check this after range tests and child processing.
|
|
78
|
+
*/
|
|
79
|
+
// eslint-disable-next-line @itwin/prefer-get
|
|
80
|
+
isAborted() { return false; }
|
|
81
|
+
}
|
|
82
|
+
exports.TwoTreeSearchHandler = TwoTreeSearchHandler;
|
|
83
|
+
/**
|
|
84
|
+
* This class refines the TwoTreeSearchHandler with an implementation of `isRangePairActive` appropriate for computing the minimum distance between trees.
|
|
85
|
+
* * The concrete class must implement `getCurrentDistance()` method to provide the best-so-far distance.
|
|
86
|
+
* * The implementation of `isRangePairActive` returns true if the distance between ranges is less than or equal to the `getCurrentDistance()` value.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
class TwoTreeDistanceMinimizationSearchHandler extends TwoTreeSearchHandler {
|
|
90
|
+
/**
|
|
91
|
+
* Method called to decide whether to process subtrees and immediate child appData items from a left tree node and right tree node.
|
|
92
|
+
* @param leftRange range from a node in the left tree
|
|
93
|
+
* @param rightRange range from a node in the right tree.
|
|
94
|
+
* @returns true if the smallest distance from leftRange to rightRange is less than or equal to getCurrentDistance()
|
|
95
|
+
*/
|
|
96
|
+
isRangePairActive(leftRange, rightRange) {
|
|
97
|
+
const currentDistance = this.getCurrentDistance();
|
|
98
|
+
const distanceBetweenRanges = leftRange.distanceToRange(rightRange);
|
|
99
|
+
if (distanceBetweenRanges <= currentDistance) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.TwoTreeDistanceMinimizationSearchHandler = TwoTreeDistanceMinimizationSearchHandler;
|
|
106
|
+
let numNodeCreated = 0;
|
|
107
|
+
/**
|
|
108
|
+
* * TREE STRUCTURE
|
|
109
|
+
* * A RangeTreeNode is part of a range tree.
|
|
110
|
+
* * TREE is used here in a strictly _structural_ sense, which has no broad promises about data members.
|
|
111
|
+
* * Each RangeNode points to 0, 1 or many children.
|
|
112
|
+
* * Each child has (but does not point back to) a single parent.
|
|
113
|
+
* * The overall tree has a single root.
|
|
114
|
+
* * Each node is effectively the root of the tree of its children.
|
|
115
|
+
* * NON-TREE DATA MEMBERS
|
|
116
|
+
* * Data members in each node (in addition to children) are
|
|
117
|
+
* * _range = the union of ranges below in the heap
|
|
118
|
+
* * _appData = application data associated with the node.
|
|
119
|
+
* * Construction methods may place multiple _appData items in each node.
|
|
120
|
+
* * In common use, only the leaves will have _appData. However, the class definitions allow _appData at all nodes, and search algorithms must include them.
|
|
121
|
+
* * CONSTRUCTION
|
|
122
|
+
* * The RangeTreeNode.createByIndexSplits method constructs the tree with simple right-left splits within an array of input items.
|
|
123
|
+
* * The appData is placed entirely in the leaves.
|
|
124
|
+
* * caller can specify:
|
|
125
|
+
* * the number of _appData items per leaf
|
|
126
|
+
* * the number of children per node within the tree.
|
|
127
|
+
* * "deep" trees (2 children per node and one appData per leaf) may have (compared to shallow trees with many children per node and many appData per leaf)
|
|
128
|
+
* * faster search because lower nodes have smaller ranges that will be skipped by search algorithms.
|
|
129
|
+
* * larger memory use because of more nodes
|
|
130
|
+
* * For future construction methods:
|
|
131
|
+
* * _appData "above the leaves" may allow nodes below to have smaller ranges, but add complexity to search.
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
class RangeTreeNode {
|
|
135
|
+
/**
|
|
136
|
+
* CONSTRUCTOR
|
|
137
|
+
* CAPTURE (not copy)
|
|
138
|
+
* * range = range for search algorithms
|
|
139
|
+
* * appData = application data relevant to this node.
|
|
140
|
+
* * children = child node reference(s).
|
|
141
|
+
*/
|
|
142
|
+
constructor(range, appData, children) {
|
|
143
|
+
this._range = range;
|
|
144
|
+
this._appData = appData;
|
|
145
|
+
this._children = children;
|
|
146
|
+
this._id = numNodeCreated++;
|
|
147
|
+
// const childIds: number[] = [];
|
|
148
|
+
// if (Array.isArray(this._children))
|
|
149
|
+
// for (const c of this._children) childIds.push(c._id);
|
|
150
|
+
// else if (this._children instanceof RangeTreeNode)
|
|
151
|
+
// childIds.push(this._children._id);
|
|
152
|
+
// const numAppData = getFlexDataCount(appData);
|
|
153
|
+
// console.log({ id: this._id, childIds, numAppData });
|
|
154
|
+
}
|
|
155
|
+
/** Simplest public create: capture the range, appData, and children. */
|
|
156
|
+
static createCapture(range, appData, children) {
|
|
157
|
+
return new RangeTreeNode(range, appData, children);
|
|
158
|
+
}
|
|
159
|
+
/** copy (not capture) from given data into the range in this RangeEntry */
|
|
160
|
+
setRange(data) {
|
|
161
|
+
this._range.setFrom(data);
|
|
162
|
+
}
|
|
163
|
+
/** return (a copy of) the range in this RangeEntry */
|
|
164
|
+
getRange(data) {
|
|
165
|
+
return this._range.clone(data);
|
|
166
|
+
}
|
|
167
|
+
/** return (a reference to) the range in this RangeEntry */
|
|
168
|
+
getRangeRef() {
|
|
169
|
+
return this._range;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Access a child by index.
|
|
173
|
+
* * If the child data is an array, this dereferences the array.
|
|
174
|
+
* * If the child data is a singleton, treat it as index 0.
|
|
175
|
+
* * return undefined if there are no children.
|
|
176
|
+
* @param index index of item to access.
|
|
177
|
+
*/
|
|
178
|
+
getChildByIndex(index) {
|
|
179
|
+
return getByIndex(index, this._children);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* * Access an appData by index.
|
|
183
|
+
* * If the appData data is an array, this dereferences the array.
|
|
184
|
+
* * If the appData data is a singleton, treat it as if it is at index 0 in an array
|
|
185
|
+
* * return undefined if there are no appData or for any index out of range.
|
|
186
|
+
* @param index index of item to access.
|
|
187
|
+
*/
|
|
188
|
+
getAppDataByIndex(index) {
|
|
189
|
+
return getByIndex(index, this._appData);
|
|
190
|
+
}
|
|
191
|
+
/** Access the children or child (does not clone). */
|
|
192
|
+
getAllChildren() {
|
|
193
|
+
return this._children;
|
|
194
|
+
}
|
|
195
|
+
/** Access the appData array or singleton (does not clone). */
|
|
196
|
+
getAllAppData() {
|
|
197
|
+
return this._appData;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Count the direct children in this node of the tree.
|
|
201
|
+
* * This is not recursive. For a recursive count, use `RangeTreeOps.getRecursiveNodeCount`.
|
|
202
|
+
*/
|
|
203
|
+
getNumChildren() {
|
|
204
|
+
return getFlexDataCount(this._children);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Count the appData items in this node of the tree.
|
|
208
|
+
* * This is not recursive. For a recursive count, use `RangeTreeOps.getRecursiveAppDataCount`.
|
|
209
|
+
*/
|
|
210
|
+
getNumAppData() {
|
|
211
|
+
return getFlexDataCount(this._appData);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Depth-first tree iteration, calling `announceNode` on each node.
|
|
215
|
+
* @param announceNode callback that returns true to recurse into children
|
|
216
|
+
*/
|
|
217
|
+
recurseIntoTree(announceNode) {
|
|
218
|
+
const doChildren = announceNode(this);
|
|
219
|
+
if (doChildren) {
|
|
220
|
+
if (Array.isArray(this._children)) {
|
|
221
|
+
for (const child of this._children)
|
|
222
|
+
child.recurseIntoTree(announceNode);
|
|
223
|
+
}
|
|
224
|
+
else if (this._children !== undefined) {
|
|
225
|
+
this._children.recurseIntoTree(announceNode);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Depth-first tree iteration via handler.
|
|
231
|
+
* * if handler decides the instance range is active, process appData, then recurse on children
|
|
232
|
+
* * if handler decides to abort after processing an appData, skip processing rest of appData and children
|
|
233
|
+
*/
|
|
234
|
+
searchTopDown(handler) {
|
|
235
|
+
if (handler.isRangeActive(this._range)) {
|
|
236
|
+
let itemToProcess;
|
|
237
|
+
for (let i = 0; undefined !== (itemToProcess = this.getAppDataByIndex(i)); i++) {
|
|
238
|
+
// console.log(itemToProcess);
|
|
239
|
+
handler.processAppData(itemToProcess);
|
|
240
|
+
if (handler.isAborted())
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
let child;
|
|
244
|
+
for (let i = 0; undefined !== (child = this.getChildByIndex(i)); i++) {
|
|
245
|
+
child.searchTopDown(handler);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Apply the handler.processAppDataPair method to each pair of appData items from leftAppData and rightStack.
|
|
251
|
+
* @param leftAppData singleton or array with data "from left"
|
|
252
|
+
* @param rightStack stack of nodes to process from right path.
|
|
253
|
+
* @param reverseArgs true if the caller is exchanging the sense of left and right and this should be undone in the actual call to handler.processAppDataPair.
|
|
254
|
+
* @param handler search handler
|
|
255
|
+
*/
|
|
256
|
+
static processAppDataAndAppDataStack(leftAppData, rightStack, reverseArgs, handler) {
|
|
257
|
+
if (leftAppData !== undefined) {
|
|
258
|
+
let leftItem;
|
|
259
|
+
let rightItem;
|
|
260
|
+
// hmm.. we ASSUME that if the tip ranges passed, then all parent ranges would pass without further test.
|
|
261
|
+
for (let rangeIndex = rightStack.length; rangeIndex-- > 0;) {
|
|
262
|
+
const rightAppData = rightStack[rangeIndex]._appData;
|
|
263
|
+
for (let rightIndex = 0; undefined !== (rightItem = getByIndex(rightIndex, rightAppData)); rightIndex++) {
|
|
264
|
+
for (let leftIndex = 0; undefined !== (leftItem = getByIndex(leftIndex, leftAppData)); leftIndex++) {
|
|
265
|
+
if (!reverseArgs)
|
|
266
|
+
handler.processAppDataPair(leftItem, rightItem);
|
|
267
|
+
else
|
|
268
|
+
handler.processAppDataPair(rightItem, leftItem);
|
|
269
|
+
if (handler.isAborted())
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Apply the handler.processAppDataPair method to each pair of appData items from leftAppData and rightAppData.
|
|
278
|
+
* @param leftAppData singleton or array with data "from left"
|
|
279
|
+
* @param rightAppData singleton or array with data "from right"
|
|
280
|
+
* @param reverseArgs true if the caller is exchanging the sense of left and right and this should be undone in the actual call to handler.processAppDataPair.
|
|
281
|
+
* @param handler search handler
|
|
282
|
+
*/
|
|
283
|
+
static processAppDataAndAppData(leftAppData, rightAppData, reverseArgs, handler) {
|
|
284
|
+
if (leftAppData !== undefined && rightAppData !== undefined) {
|
|
285
|
+
let leftItem;
|
|
286
|
+
let rightItem;
|
|
287
|
+
for (let rightIndex = 0; undefined !== (rightItem = getByIndex(rightIndex, rightAppData)); rightIndex++) {
|
|
288
|
+
for (let leftIndex = 0; undefined !== (leftItem = getByIndex(leftIndex, leftAppData)); leftIndex++) {
|
|
289
|
+
if (!reverseArgs)
|
|
290
|
+
handler.processAppDataPair(leftItem, rightItem);
|
|
291
|
+
else
|
|
292
|
+
handler.processAppDataPair(rightItem, leftItem);
|
|
293
|
+
if (handler.isAborted())
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Push the tip node to stack(s).
|
|
301
|
+
* @param tip new node (to be pushed)
|
|
302
|
+
* @param fullPath complete path, which is always extended
|
|
303
|
+
* @param partialPath partial path, which is only extended if the tip has _appData.
|
|
304
|
+
*/
|
|
305
|
+
static pushPaths(tip, fullPath, partialPath) {
|
|
306
|
+
fullPath.push(tip);
|
|
307
|
+
if (tip._appData !== undefined) {
|
|
308
|
+
partialPath.push(tip);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Pop the tip node from stack(s).
|
|
313
|
+
* @param tip should match the fullPath tip.
|
|
314
|
+
* @param fullPath complete path, which is always popped
|
|
315
|
+
* @param partialPath partial path, which is only popped if the tip has _appData.
|
|
316
|
+
*/
|
|
317
|
+
static popPaths(tip, fullPath, partialPath) {
|
|
318
|
+
(0, core_bentley_1.assert)(fullPath[fullPath.length - 1] === tip);
|
|
319
|
+
fullPath.pop();
|
|
320
|
+
if (tip._appData !== undefined) {
|
|
321
|
+
partialPath.pop();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Process nodes from left and right trees of dual search.
|
|
326
|
+
* * The separate stacks for nodes that have appData is for efficiency.
|
|
327
|
+
* * If data is entirely in the leaves (or just in a few nodes), the stacks will all be empty (or very small) and no time will be wasted looking up the stacks for appData to process with the other tip.
|
|
328
|
+
* @param leftTip tip node being explored on left
|
|
329
|
+
* @param leftStack stack of prior left nodes
|
|
330
|
+
* @param leftStackWithAppData stack of prior left nodes which have appData.
|
|
331
|
+
* @param rightTip tip node being explored on right.
|
|
332
|
+
* @param rightStack stack of prior right nodes.
|
|
333
|
+
* @param rightStackWithAppData stack of prior right nodes which have appData.
|
|
334
|
+
* @param handler search handler
|
|
335
|
+
*/
|
|
336
|
+
static recursivePairSearch(leftTip, leftStack, leftStackWithAppData, rightTip, rightStack, rightStackWithAppData, handler) {
|
|
337
|
+
// console.log({ leftId: leftTip._id, rightId: rightTip._id });
|
|
338
|
+
const leftTipHasAppData = leftTip._appData !== undefined;
|
|
339
|
+
const rightTipHasAppData = rightTip._appData !== undefined;
|
|
340
|
+
let leftChild;
|
|
341
|
+
let rightChild;
|
|
342
|
+
// process immediate appData from each tip node with the entire prior path of the other side (each stack currently lacks the tip).
|
|
343
|
+
if (leftTipHasAppData && rightStackWithAppData.length > 0) {
|
|
344
|
+
this.processAppDataAndAppDataStack(leftTip._appData, rightStackWithAppData, false, handler);
|
|
345
|
+
}
|
|
346
|
+
if (leftStackWithAppData.length > 0 && rightTipHasAppData) {
|
|
347
|
+
this.processAppDataAndAppDataStack(rightTip._appData, leftStackWithAppData, true, handler);
|
|
348
|
+
}
|
|
349
|
+
if (handler.isRangePairActive(leftTip._range, rightTip._range)) {
|
|
350
|
+
this.processAppDataAndAppData(leftTip._appData, rightTip._appData, false, handler);
|
|
351
|
+
if (leftTip._children !== undefined && rightTip._children !== undefined) {
|
|
352
|
+
this.pushPaths(leftTip, leftStack, leftStackWithAppData);
|
|
353
|
+
this.pushPaths(rightTip, rightStack, rightStackWithAppData);
|
|
354
|
+
for (let leftIndex = 0; undefined !== (leftChild = getByIndex(leftIndex, leftTip._children)); leftIndex++) {
|
|
355
|
+
for (let rightIndex = 0; undefined !== (rightChild = getByIndex(rightIndex, rightTip._children)); rightIndex++) {
|
|
356
|
+
this.recursivePairSearch(leftChild, leftStack, leftStackWithAppData, rightChild, rightStack, rightStackWithAppData, handler);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
this.popPaths(leftTip, leftStack, leftStackWithAppData);
|
|
360
|
+
this.popPaths(rightTip, rightStack, rightStackWithAppData);
|
|
361
|
+
}
|
|
362
|
+
else if (leftTip._children !== undefined) {
|
|
363
|
+
this.leftRecursivePairSearch(leftTip, rightTip, rightStackWithAppData, false, handler);
|
|
364
|
+
}
|
|
365
|
+
else if (rightTip._children !== undefined) {
|
|
366
|
+
this.leftRecursivePairSearch(rightTip, leftTip, leftStackWithAppData, true, handler);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Recurse below the tip of leftTip, offering each level's appData to the appData of rightTip and rightStackWithAppData.
|
|
372
|
+
* @param leftTip tip node being explored on left. Its appData is not processed.
|
|
373
|
+
* @param rightTip tip node being explored on right. It has no children.
|
|
374
|
+
* @param rightStackWithAppData stack of prior right nodes which have appData.
|
|
375
|
+
* @param reverseArgs true if the caller is exchanging the sense of left and right
|
|
376
|
+
* @param handler search handler
|
|
377
|
+
*/
|
|
378
|
+
static leftRecursivePairSearch(leftTip, rightTip, rightStackWithAppData, reverseArgs, handler) {
|
|
379
|
+
(0, core_bentley_1.assert)(rightTip._children === undefined);
|
|
380
|
+
// The (possibly deep) left children appData needs to be offered to the right path (including tip)
|
|
381
|
+
// Note that there are no stack push/pop operations -- the right stack is already reaching to leaf level, so there are no range or appData nodes to add.
|
|
382
|
+
let leftChild;
|
|
383
|
+
for (let leftIndex = 0; undefined !== (leftChild = getByIndex(leftIndex, leftTip._children)); leftIndex++) {
|
|
384
|
+
if (handler.isRangePairActive(leftChild._range, rightTip._range)) {
|
|
385
|
+
this.processAppDataAndAppData(leftChild._appData, rightTip._appData, reverseArgs, handler);
|
|
386
|
+
this.processAppDataAndAppDataStack(leftChild._appData, rightStackWithAppData, reverseArgs, handler);
|
|
387
|
+
this.leftRecursivePairSearch(leftChild, rightTip, rightStackWithAppData, reverseArgs, handler);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Recursive search down two trees, with range tests and child processing under control of a handler.
|
|
393
|
+
* @param leftRoot root of left tree
|
|
394
|
+
* @param rightRoot root of right tree
|
|
395
|
+
* @param handler handler for range tests and child process
|
|
396
|
+
*/
|
|
397
|
+
static searchTwoTreesTopDown(leftRoot, rightRoot, handler) {
|
|
398
|
+
this.recursivePairSearch(leftRoot, [], [], rightRoot, [], [], handler);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
exports.RangeTreeNode = RangeTreeNode;
|
|
402
|
+
/**
|
|
403
|
+
* Utilities for various operations on RangeTree
|
|
404
|
+
* @internal
|
|
405
|
+
*/
|
|
406
|
+
class RangeTreeOps {
|
|
407
|
+
/** Count nodes in this tree. */
|
|
408
|
+
static getRecursiveNodeCount(root) {
|
|
409
|
+
let count = 0;
|
|
410
|
+
root.recurseIntoTree((_node) => { count++; return true; });
|
|
411
|
+
return count;
|
|
412
|
+
}
|
|
413
|
+
/** Count appData in this tree. */
|
|
414
|
+
static getRecursiveAppDataCount(root) {
|
|
415
|
+
let count = 0;
|
|
416
|
+
root.recurseIntoTree((node) => { count += node.getNumAppData(); return true; });
|
|
417
|
+
return count;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Create a leaf referencing appData items indexed index0<=index<index1 and with combined range of the same indices
|
|
421
|
+
* @param ranges access to ranges
|
|
422
|
+
* @param appData access to AppDataType items
|
|
423
|
+
* @param index0 first index for block of items
|
|
424
|
+
* @param index1 upper limit index for block of items.
|
|
425
|
+
* @param arrayLength one more than the largest range/appData index
|
|
426
|
+
* @returns newly created node.
|
|
427
|
+
*/
|
|
428
|
+
static createLeafInIndexRange(ranges, appData, index0, index1, arrayLength) {
|
|
429
|
+
const appDataBlock = [];
|
|
430
|
+
const range = Range_1.Range3d.createNull();
|
|
431
|
+
index1 = Math.min(index1, arrayLength);
|
|
432
|
+
// console.log({ case: "LEAF", index0, index1 });
|
|
433
|
+
for (let i = index0; i < index1; i++) {
|
|
434
|
+
appDataBlock.push(evaluateIndexToType(appData, i));
|
|
435
|
+
range.extendRange(evaluateIndexToType(ranges, i));
|
|
436
|
+
}
|
|
437
|
+
return RangeTreeNode.createCapture(range, appDataBlock, undefined);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Split the array entries appData[index0 <= i < index1] into blocks of at most maxChildPerNode * maxAppDataPerLeaf and assemble into a tree structure.
|
|
441
|
+
* @param ranges access to ranges
|
|
442
|
+
* @param appData access to AppDataType items
|
|
443
|
+
* @param index0 start index of the block to access
|
|
444
|
+
* @param index1 terminal index for the block (one after final)
|
|
445
|
+
* @param arrayLength one more than the largest range/appData index
|
|
446
|
+
* @param maxChildPerNode max number of child nodes in each interior node
|
|
447
|
+
* @param maxAppDataPerLeaf max number of appData items in each leaf.
|
|
448
|
+
* @returns
|
|
449
|
+
*/
|
|
450
|
+
static createRecursiveByIndexSplits(ranges, appData, index0, index1, arrayLength, maxChildPerNode, maxAppDataPerLeaf) {
|
|
451
|
+
if (index1 > arrayLength)
|
|
452
|
+
index1 = arrayLength;
|
|
453
|
+
const range = Range_1.Range3d.createNull();
|
|
454
|
+
const children = [];
|
|
455
|
+
const maxChildrenAppData = maxChildPerNode * maxAppDataPerLeaf;
|
|
456
|
+
// console.log({ name: "createRecursive", index0, index1, maxChildrenAppData });
|
|
457
|
+
if (index1 <= index0 + maxChildrenAppData) { // index range is small enough to hold the appData in leaf children
|
|
458
|
+
// console.log({ case: "LEAF GROUP", index0, index1 });
|
|
459
|
+
for (let indexA = index0 + maxAppDataPerLeaf; index0 < index1; index0 = indexA, indexA = Math.min(indexA + maxAppDataPerLeaf, index1)) {
|
|
460
|
+
const leaf = RangeTreeOps.createLeafInIndexRange(ranges, appData, index0, indexA, arrayLength);
|
|
461
|
+
if (leaf !== undefined) {
|
|
462
|
+
range.extendRange(leaf.getRangeRef());
|
|
463
|
+
children.push(leaf);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
else { // split the appData among interior and leaf children
|
|
468
|
+
// console.log({ case: "INTERIOR", index0, index1 });
|
|
469
|
+
const numPerGulp = Math.ceil((index1 - index0) / maxChildPerNode);
|
|
470
|
+
for (let indexA = index0 + numPerGulp; index0 < index1; index0 = indexA, indexA = Math.min(indexA + numPerGulp, index1)) {
|
|
471
|
+
const child = this.createRecursiveByIndexSplits(ranges, appData, index0, indexA, arrayLength, maxChildPerNode, maxAppDataPerLeaf);
|
|
472
|
+
if (child !== undefined) {
|
|
473
|
+
range.extendRange(child.getRangeRef());
|
|
474
|
+
children.push(child);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return (children.length > 0) ? RangeTreeNode.createCapture(range, undefined, children) : undefined;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Create a range tree by simple left-right split of given ranges.
|
|
482
|
+
* * Leaves carry the inputs in left-to-right order.
|
|
483
|
+
* * Each leaf range is labeled by its corresponding object(s) in the appData array.
|
|
484
|
+
* @param ranges access to ranges.
|
|
485
|
+
* @param appData access to AppDataType items (for leaves).
|
|
486
|
+
* @param arrayLength one more than the largest range/appData index
|
|
487
|
+
* @param maxChildrenPerNode max number of child nodes allowed for each interior node.
|
|
488
|
+
* @param maxAppDataPerLeaf max number of appData items allowed in each leaf.
|
|
489
|
+
* @returns the root of the new tree, or undefined if array lengths differ or are zero.
|
|
490
|
+
*/
|
|
491
|
+
static createByIndexSplits(ranges, appData, arrayLength, maxChildrenPerNode = 2, maxAppDataPerLeaf = 2) {
|
|
492
|
+
// console.log();
|
|
493
|
+
// const numData = getFlexDataCount(appData);
|
|
494
|
+
// console.log({ numData });
|
|
495
|
+
if (arrayLength <= 0
|
|
496
|
+
|| (Array.isArray(ranges) && ranges.length !== arrayLength)
|
|
497
|
+
|| (Array.isArray(appData) && appData.length !== arrayLength))
|
|
498
|
+
return undefined;
|
|
499
|
+
if (maxChildrenPerNode < 2)
|
|
500
|
+
maxChildrenPerNode = 2;
|
|
501
|
+
return RangeTreeOps.createRecursiveByIndexSplits(ranges, appData, 0, arrayLength, arrayLength, maxChildrenPerNode, maxAppDataPerLeaf);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
exports.RangeTreeOps = RangeTreeOps;
|
|
505
|
+
//# sourceMappingURL=RangeTreeNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RangeTreeNode.js","sourceRoot":"","sources":["../../../../src/polyface/RangeTree/RangeTreeNode.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,kDAAiD;AAejD;;;;;GAKG;AACH,SAAS,mBAAmB,CAAI,IAAoB,EAAE,KAAa;IACjE,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,IAAI,CAA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KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,CAAC;YAC7D,OAAO,SAAS,CAAC;QACnB,IAAI,kBAAkB,GAAG,CAAC;YACxB,kBAAkB,GAAG,CAAC,CAAC;QACzB,OAAO,YAAY,CAAC,4BAA4B,CAAc,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;IACrJ,CAAC;CACF;AAtHD,oCAsHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module RangeSearch\n */\n\nimport { assert } from \"@itwin/core-bentley\";\nimport { Range3d } from \"../../geometry3d/Range\";\n\n/** Type name FlexData is shorthand for a member or parameter which can be:\n * * undefined\n * * an array of values of type T\n * * a singleton of type T\n */\ntype FlexData<T> = undefined | T[] | T;\n/**\n * Type name IndexToType is shorthand for a member or parameter which can be:\n * * an array of values of type T\n * * a function from integers to type T.\n */\ntype IndexToType<T> = T[] | ((index: number) => T);\n\n/**\n * Map an (unchecked) integer to a parameterized type T, where the data argument can be either:\n * * an array of type T\n * * a function which takes an index and returns type T\n * @internal\n */\nfunction evaluateIndexToType<T>(data: IndexToType<T>, index: number): T {\n if (Array.isArray(data))\n return data[index];\n return data(index);\n}\n/**\n * Get data by index from a source that may be undefined, an array of item of type T, or a singleton of the item type.\n * @internal\n */\nfunction getByIndex<T>(index: number, data: FlexData<T>): T | undefined {\n if (data !== undefined) {\n if (Array.isArray(data)) {\n if (index < data.length)\n return data[index];\n } else {\n return data;\n }\n }\n return undefined;\n}\n/**\n * Return the number of items in an object that can be undefined, an array of item of type T, or a singleton of the item type.\n * @internal\n */\nfunction getFlexDataCount<T>(data: FlexData<T>): number {\n if (data !== undefined) {\n if (Array.isArray(data)) {\n return data.length;\n } else {\n return 1;\n }\n }\n return 0;\n}\n/**\n * Abstract class for handler objects called during traversal of a single range tree.\n * @internal\n */\nexport abstract class SingleTreeSearchHandler<AppDataType> {\n /** Return true if appData within the range should be offered to `processAppData`. */\n public abstract isRangeActive(range: Range3d): boolean;\n /**\n * Called for a (single) child referenced by a tree.\n * * This is only called when range checks on the path from root have been passed.\n * @param item child (of type AppDataType) in the tree.\n */\n public abstract processAppData(item: AppDataType): void;\n /**\n * Query to see if the active search has been aborted.\n * * Default implementation returns false so query runs to completion.\n * * Search processes check this after range tests and child processing.\n */\n // eslint-disable-next-line @itwin/prefer-get\n public isAborted(): boolean { return false; }\n}\n/**\n * Abstract class for handler objects called during traversal of two range trees.\n * @internal\n */\nexport abstract class TwoTreeSearchHandler<AppDataType> {\n /** Return true if appData within the ranges should be offered to `processAppDataPair`. */\n public abstract isRangePairActive(leftRange: Range3d, rightRange: Range3d): boolean;\n /**\n * Called with AppDataType items from left tree and right tree.\n * * This is only called when range tests have been passed.\n * @param leftItem\n * @param rightItem\n */\n public abstract processAppDataPair(leftItem: AppDataType, rightItem: AppDataType): void;\n /**\n * Query to see if the active search has been aborted.\n * * Default implementation returns false so query runs to completion.\n * * Search processes check this after range tests and child processing.\n */\n // eslint-disable-next-line @itwin/prefer-get\n public isAborted(): boolean { return false; }\n}\n/**\n * This class refines the TwoTreeSearchHandler with an implementation of `isRangePairActive` appropriate for computing the minimum distance between trees.\n * * The concrete class must implement `getCurrentDistance()` method to provide the best-so-far distance.\n * * The implementation of `isRangePairActive` returns true if the distance between ranges is less than or equal to the `getCurrentDistance()` value.\n * @internal\n */\nexport abstract class TwoTreeDistanceMinimizationSearchHandler<AppDataType> extends TwoTreeSearchHandler<AppDataType>{\n /**\n * Provides the allowable distance between ranges.\n * * Range pairs with more than this distance separation are rejected.\n * * The implementation may alter (probably reduce) the getCurrentDistance() value as the search progresses.\n */\n public abstract getCurrentDistance(): number;\n /**\n * Method called to decide whether to process subtrees and immediate child appData items from a left tree node and right tree node.\n * @param leftRange range from a node in the left tree\n * @param rightRange range from a node in the right tree.\n * @returns true if the smallest distance from leftRange to rightRange is less than or equal to getCurrentDistance()\n */\n public override isRangePairActive(leftRange: Range3d, rightRange: Range3d): boolean {\n const currentDistance = this.getCurrentDistance();\n const distanceBetweenRanges = leftRange.distanceToRange(rightRange);\n if (distanceBetweenRanges <= currentDistance) {\n return true;\n }\n return false;\n }\n}\nlet numNodeCreated = 0;\n/**\n * * TREE STRUCTURE\n * * A RangeTreeNode is part of a range tree.\n * * TREE is used here in a strictly _structural_ sense, which has no broad promises about data members.\n * * Each RangeNode points to 0, 1 or many children.\n * * Each child has (but does not point back to) a single parent.\n * * The overall tree has a single root.\n * * Each node is effectively the root of the tree of its children.\n * * NON-TREE DATA MEMBERS\n * * Data members in each node (in addition to children) are\n * * _range = the union of ranges below in the heap\n * * _appData = application data associated with the node.\n * * Construction methods may place multiple _appData items in each node.\n * * In common use, only the leaves will have _appData. However, the class definitions allow _appData at all nodes, and search algorithms must include them.\n * * CONSTRUCTION\n * * The RangeTreeNode.createByIndexSplits method constructs the tree with simple right-left splits within an array of input items.\n * * The appData is placed entirely in the leaves.\n * * caller can specify:\n * * the number of _appData items per leaf\n * * the number of children per node within the tree.\n * * \"deep\" trees (2 children per node and one appData per leaf) may have (compared to shallow trees with many children per node and many appData per leaf)\n * * faster search because lower nodes have smaller ranges that will be skipped by search algorithms.\n * * larger memory use because of more nodes\n * * For future construction methods:\n * * _appData \"above the leaves\" may allow nodes below to have smaller ranges, but add complexity to search.\n * @internal\n */\nexport class RangeTreeNode<AppDataType> {\n private _range: Range3d;\n private _appData: FlexData<AppDataType>;\n private _children: FlexData<RangeTreeNode<AppDataType>>;\n /** an id assigned sequentially as nodes are created. For debugging use only. */\n private _id: number;\n /**\n * CONSTRUCTOR\n * CAPTURE (not copy)\n * * range = range for search algorithms\n * * appData = application data relevant to this node.\n * * children = child node reference(s).\n */\n private constructor(range: Range3d, appData: FlexData<AppDataType>, children: FlexData<RangeTreeNode<AppDataType>>) {\n this._range = range;\n this._appData = appData;\n this._children = children;\n this._id = numNodeCreated++;\n // const childIds: number[] = [];\n // if (Array.isArray(this._children))\n // for (const c of this._children) childIds.push(c._id);\n // else if (this._children instanceof RangeTreeNode)\n // childIds.push(this._children._id);\n // const numAppData = getFlexDataCount(appData);\n // console.log({ id: this._id, childIds, numAppData });\n }\n /** Simplest public create: capture the range, appData, and children. */\n public static createCapture<AppDataType>(\n range: Range3d,\n appData: FlexData<AppDataType>,\n children: FlexData<RangeTreeNode<AppDataType>>): RangeTreeNode<AppDataType> {\n return new RangeTreeNode<AppDataType>(range, appData, children);\n }\n /** copy (not capture) from given data into the range in this RangeEntry */\n public setRange(data: Range3d) {\n this._range.setFrom(data);\n }\n /** return (a copy of) the range in this RangeEntry */\n public getRange(data?: Range3d): Range3d {\n return this._range.clone(data);\n }\n /** return (a reference to) the range in this RangeEntry */\n public getRangeRef(): Range3d {\n return this._range;\n }\n /**\n * Access a child by index.\n * * If the child data is an array, this dereferences the array.\n * * If the child data is a singleton, treat it as index 0.\n * * return undefined if there are no children.\n * @param index index of item to access.\n */\n public getChildByIndex(index: number): RangeTreeNode<AppDataType> | undefined {\n return getByIndex<RangeTreeNode<AppDataType>>(index, this._children);\n }\n /**\n * * Access an appData by index.\n * * If the appData data is an array, this dereferences the array.\n * * If the appData data is a singleton, treat it as if it is at index 0 in an array\n * * return undefined if there are no appData or for any index out of range.\n * @param index index of item to access.\n */\n public getAppDataByIndex(index: number): AppDataType | undefined {\n return getByIndex<AppDataType>(index, this._appData);\n }\n /** Access the children or child (does not clone). */\n public getAllChildren(): FlexData<RangeTreeNode<AppDataType>> {\n return this._children;\n }\n /** Access the appData array or singleton (does not clone). */\n public getAllAppData(): FlexData<AppDataType> {\n return this._appData;\n }\n /**\n * Count the direct children in this node of the tree.\n * * This is not recursive. For a recursive count, use `RangeTreeOps.getRecursiveNodeCount`.\n */\n public getNumChildren(): number {\n return getFlexDataCount(this._children);\n }\n /**\n * Count the appData items in this node of the tree.\n * * This is not recursive. For a recursive count, use `RangeTreeOps.getRecursiveAppDataCount`.\n */\n public getNumAppData(): number {\n return getFlexDataCount(this._appData);\n }\n /**\n * Depth-first tree iteration, calling `announceNode` on each node.\n * @param announceNode callback that returns true to recurse into children\n */\n public recurseIntoTree(announceNode: (node: RangeTreeNode<AppDataType>) => boolean) {\n const doChildren = announceNode(this);\n if (doChildren) {\n if (Array.isArray(this._children)) {\n for (const child of this._children)\n child.recurseIntoTree(announceNode);\n } else if (this._children !== undefined) {\n this._children.recurseIntoTree(announceNode);\n }\n }\n }\n /**\n * Depth-first tree iteration via handler.\n * * if handler decides the instance range is active, process appData, then recurse on children\n * * if handler decides to abort after processing an appData, skip processing rest of appData and children\n */\n public searchTopDown(handler: SingleTreeSearchHandler<AppDataType>) {\n if (handler.isRangeActive(this._range)) {\n let itemToProcess: AppDataType | undefined;\n for (let i = 0; undefined !== (itemToProcess = this.getAppDataByIndex(i)); i++) {\n // console.log(itemToProcess);\n handler.processAppData(itemToProcess);\n if (handler.isAborted())\n return;\n }\n let child: RangeTreeNode<AppDataType> | undefined;\n for (let i = 0; undefined !== (child = this.getChildByIndex(i)); i++) {\n child.searchTopDown(handler);\n }\n }\n }\n\n /**\n * Apply the handler.processAppDataPair method to each pair of appData items from leftAppData and rightStack.\n * @param leftAppData singleton or array with data \"from left\"\n * @param rightStack stack of nodes to process from right path.\n * @param reverseArgs true if the caller is exchanging the sense of left and right and this should be undone in the actual call to handler.processAppDataPair.\n * @param handler search handler\n */\n private static processAppDataAndAppDataStack<AppDataType>(\n leftAppData: FlexData<AppDataType>,\n rightStack: RangeTreeNode<AppDataType>[],\n reverseArgs: boolean,\n handler: TwoTreeSearchHandler<AppDataType>,\n ) {\n if (leftAppData !== undefined) {\n let leftItem: AppDataType | undefined;\n let rightItem: AppDataType | undefined;\n // hmm.. we ASSUME that if the tip ranges passed, then all parent ranges would pass without further test.\n for (let rangeIndex = rightStack.length; rangeIndex-- > 0;) {\n const rightAppData = rightStack[rangeIndex]._appData;\n for (let rightIndex = 0; undefined !== (rightItem = getByIndex<AppDataType>(rightIndex, rightAppData)); rightIndex++) {\n for (let leftIndex = 0; undefined !== (leftItem = getByIndex<AppDataType>(leftIndex, leftAppData)); leftIndex++) {\n if (!reverseArgs)\n handler.processAppDataPair(leftItem, rightItem);\n else\n handler.processAppDataPair(rightItem, leftItem);\n if (handler.isAborted())\n return;\n }\n }\n }\n }\n }\n\n /**\n * Apply the handler.processAppDataPair method to each pair of appData items from leftAppData and rightAppData.\n * @param leftAppData singleton or array with data \"from left\"\n * @param rightAppData singleton or array with data \"from right\"\n * @param reverseArgs true if the caller is exchanging the sense of left and right and this should be undone in the actual call to handler.processAppDataPair.\n * @param handler search handler\n */\n private static processAppDataAndAppData<AppDataType>(\n leftAppData: FlexData<AppDataType>,\n rightAppData: FlexData<AppDataType>,\n reverseArgs: boolean,\n handler: TwoTreeSearchHandler<AppDataType>,\n ) {\n if (leftAppData !== undefined && rightAppData !== undefined) {\n let leftItem: AppDataType | undefined;\n let rightItem: AppDataType | undefined;\n for (let rightIndex = 0; undefined !== (rightItem = getByIndex<AppDataType>(rightIndex, rightAppData)); rightIndex++) {\n for (let leftIndex = 0; undefined !== (leftItem = getByIndex<AppDataType>(leftIndex, leftAppData)); leftIndex++) {\n if (!reverseArgs)\n handler.processAppDataPair(leftItem, rightItem);\n else\n handler.processAppDataPair(rightItem, leftItem);\n if (handler.isAborted())\n return;\n }\n }\n }\n }\n /**\n * Push the tip node to stack(s).\n * @param tip new node (to be pushed)\n * @param fullPath complete path, which is always extended\n * @param partialPath partial path, which is only extended if the tip has _appData.\n */\n private static pushPaths<AppDataType>(\n tip: RangeTreeNode<AppDataType>,\n fullPath: RangeTreeNode<AppDataType>[],\n partialPath: RangeTreeNode<AppDataType>[],\n ) {\n fullPath.push(tip);\n if (tip._appData !== undefined) {\n partialPath.push(tip);\n }\n }\n /**\n * Pop the tip node from stack(s).\n * @param tip should match the fullPath tip.\n * @param fullPath complete path, which is always popped\n * @param partialPath partial path, which is only popped if the tip has _appData.\n */\n private static popPaths<AppDataType>(\n tip: RangeTreeNode<AppDataType>,\n fullPath: RangeTreeNode<AppDataType>[],\n partialPath: RangeTreeNode<AppDataType>[],\n ) {\n assert(fullPath[fullPath.length - 1] === tip);\n fullPath.pop();\n if (tip._appData !== undefined) {\n partialPath.pop();\n }\n }\n /**\n * Process nodes from left and right trees of dual search.\n * * The separate stacks for nodes that have appData is for efficiency.\n * * If data is entirely in the leaves (or just in a few nodes), the stacks will all be empty (or very small) and no time will be wasted looking up the stacks for appData to process with the other tip.\n * @param leftTip tip node being explored on left\n * @param leftStack stack of prior left nodes\n * @param leftStackWithAppData stack of prior left nodes which have appData.\n * @param rightTip tip node being explored on right.\n * @param rightStack stack of prior right nodes.\n * @param rightStackWithAppData stack of prior right nodes which have appData.\n * @param handler search handler\n */\n private static recursivePairSearch<AppDataType>(\n leftTip: RangeTreeNode<AppDataType>,\n leftStack: RangeTreeNode<AppDataType>[],\n leftStackWithAppData: RangeTreeNode<AppDataType>[],\n rightTip: RangeTreeNode<AppDataType>,\n rightStack: RangeTreeNode<AppDataType>[],\n rightStackWithAppData: RangeTreeNode<AppDataType>[],\n handler: TwoTreeSearchHandler<AppDataType>,\n ) {\n // console.log({ leftId: leftTip._id, rightId: rightTip._id });\n const leftTipHasAppData = leftTip._appData !== undefined;\n const rightTipHasAppData = rightTip._appData !== undefined;\n let leftChild: RangeTreeNode<AppDataType> | undefined;\n let rightChild: RangeTreeNode<AppDataType> | undefined;\n\n // process immediate appData from each tip node with the entire prior path of the other side (each stack currently lacks the tip).\n if (leftTipHasAppData && rightStackWithAppData.length > 0) {\n this.processAppDataAndAppDataStack<AppDataType>(leftTip._appData, rightStackWithAppData, false, handler);\n }\n if (leftStackWithAppData.length > 0 && rightTipHasAppData) {\n this.processAppDataAndAppDataStack<AppDataType>(rightTip._appData, leftStackWithAppData, true, handler);\n }\n\n if (handler.isRangePairActive(leftTip._range, rightTip._range)) {\n this.processAppDataAndAppData<AppDataType>(leftTip._appData, rightTip._appData, false, handler);\n\n if (leftTip._children !== undefined && rightTip._children !== undefined) {\n this.pushPaths<AppDataType>(leftTip, leftStack, leftStackWithAppData);\n this.pushPaths<AppDataType>(rightTip, rightStack, rightStackWithAppData);\n for (let leftIndex = 0; undefined !== (leftChild = getByIndex<RangeTreeNode<AppDataType>>(leftIndex, leftTip._children)); leftIndex++) {\n for (let rightIndex = 0; undefined !== (rightChild = getByIndex<RangeTreeNode<AppDataType>>(rightIndex, rightTip._children)); rightIndex++) {\n this.recursivePairSearch(\n leftChild, leftStack, leftStackWithAppData,\n rightChild, rightStack, rightStackWithAppData,\n handler);\n }\n }\n this.popPaths<AppDataType>(leftTip, leftStack, leftStackWithAppData);\n this.popPaths<AppDataType>(rightTip, rightStack, rightStackWithAppData);\n } else if (leftTip._children !== undefined) {\n this.leftRecursivePairSearch<AppDataType>(leftTip, rightTip, rightStackWithAppData, false, handler);\n } else if (rightTip._children !== undefined) {\n this.leftRecursivePairSearch<AppDataType>(rightTip, leftTip, leftStackWithAppData, true, handler);\n }\n }\n }\n /**\n * Recurse below the tip of leftTip, offering each level's appData to the appData of rightTip and rightStackWithAppData.\n * @param leftTip tip node being explored on left. Its appData is not processed.\n * @param rightTip tip node being explored on right. It has no children.\n * @param rightStackWithAppData stack of prior right nodes which have appData.\n * @param reverseArgs true if the caller is exchanging the sense of left and right\n * @param handler search handler\n */\n private static leftRecursivePairSearch<AppDataType>(\n leftTip: RangeTreeNode<AppDataType>,\n rightTip: RangeTreeNode<AppDataType>,\n rightStackWithAppData: RangeTreeNode<AppDataType>[],\n reverseArgs: boolean,\n handler: TwoTreeSearchHandler<AppDataType>,\n ) {\n assert(rightTip._children === undefined);\n // The (possibly deep) left children appData needs to be offered to the right path (including tip)\n // Note that there are no stack push/pop operations -- the right stack is already reaching to leaf level, so there are no range or appData nodes to add.\n let leftChild: RangeTreeNode<AppDataType> | undefined;\n for (let leftIndex = 0; undefined !== (leftChild = getByIndex<RangeTreeNode<AppDataType>>(leftIndex, leftTip._children)); leftIndex++) {\n if (handler.isRangePairActive(leftChild._range, rightTip._range)) {\n this.processAppDataAndAppData<AppDataType>(leftChild._appData, rightTip._appData, reverseArgs, handler);\n this.processAppDataAndAppDataStack<AppDataType>(leftChild._appData, rightStackWithAppData, reverseArgs, handler);\n this.leftRecursivePairSearch<AppDataType>(leftChild, rightTip, rightStackWithAppData, reverseArgs, handler);\n }\n }\n }\n /**\n * Recursive search down two trees, with range tests and child processing under control of a handler.\n * @param leftRoot root of left tree\n * @param rightRoot root of right tree\n * @param handler handler for range tests and child process\n */\n public static searchTwoTreesTopDown<AppDataType>(\n leftRoot: RangeTreeNode<AppDataType>,\n rightRoot: RangeTreeNode<AppDataType>,\n handler: TwoTreeSearchHandler<AppDataType>,\n ) {\n this.recursivePairSearch(leftRoot, [], [], rightRoot, [], [], handler);\n }\n}\n/**\n * Utilities for various operations on RangeTree\n * @internal\n */\nexport class RangeTreeOps {\n /** Count nodes in this tree. */\n public static getRecursiveNodeCount<AppDataType>(root: RangeTreeNode<AppDataType>): number {\n let count = 0;\n root.recurseIntoTree((_node: RangeTreeNode<AppDataType>): boolean => { count++; return true; });\n return count;\n }\n /** Count appData in this tree. */\n public static getRecursiveAppDataCount<AppDataType>(root: RangeTreeNode<AppDataType>): number {\n let count = 0;\n root.recurseIntoTree(\n (node: RangeTreeNode<AppDataType>): boolean => { count += node.getNumAppData(); return true; });\n return count;\n }\n /**\n * Create a leaf referencing appData items indexed index0<=index<index1 and with combined range of the same indices\n * @param ranges access to ranges\n * @param appData access to AppDataType items\n * @param index0 first index for block of items\n * @param index1 upper limit index for block of items.\n * @param arrayLength one more than the largest range/appData index\n * @returns newly created node.\n */\n private static createLeafInIndexRange<AppDataType>(\n ranges: IndexToType<Range3d>,\n appData: IndexToType<AppDataType>,\n index0: number,\n index1: number,\n arrayLength: number): RangeTreeNode<AppDataType> {\n const appDataBlock: AppDataType[] = [];\n const range = Range3d.createNull();\n index1 = Math.min(index1, arrayLength);\n // console.log({ case: \"LEAF\", index0, index1 });\n for (let i = index0; i < index1; i++) {\n appDataBlock.push(evaluateIndexToType(appData, i));\n range.extendRange(evaluateIndexToType(ranges, i));\n }\n return RangeTreeNode.createCapture(range, appDataBlock, undefined);\n }\n /**\n * Split the array entries appData[index0 <= i < index1] into blocks of at most maxChildPerNode * maxAppDataPerLeaf and assemble into a tree structure.\n * @param ranges access to ranges\n * @param appData access to AppDataType items\n * @param index0 start index of the block to access\n * @param index1 terminal index for the block (one after final)\n * @param arrayLength one more than the largest range/appData index\n * @param maxChildPerNode max number of child nodes in each interior node\n * @param maxAppDataPerLeaf max number of appData items in each leaf.\n * @returns\n */\n private static createRecursiveByIndexSplits<AppDataType>(\n ranges: IndexToType<Range3d>,\n appData: IndexToType<AppDataType>,\n index0: number,\n index1: number,\n arrayLength: number,\n maxChildPerNode: number,\n maxAppDataPerLeaf: number,\n ): RangeTreeNode<AppDataType> | undefined {\n if (index1 > arrayLength)\n index1 = arrayLength;\n\n const range = Range3d.createNull();\n const children: RangeTreeNode<AppDataType>[] = [];\n const maxChildrenAppData = maxChildPerNode * maxAppDataPerLeaf;\n // console.log({ name: \"createRecursive\", index0, index1, maxChildrenAppData });\n\n if (index1 <= index0 + maxChildrenAppData) { // index range is small enough to hold the appData in leaf children\n // console.log({ case: \"LEAF GROUP\", index0, index1 });\n for (let indexA = index0 + maxAppDataPerLeaf; index0 < index1; index0 = indexA, indexA = Math.min(indexA + maxAppDataPerLeaf, index1)) {\n const leaf = RangeTreeOps.createLeafInIndexRange(ranges, appData, index0, indexA, arrayLength);\n if (leaf !== undefined) {\n range.extendRange(leaf.getRangeRef());\n children.push(leaf);\n }\n }\n } else { // split the appData among interior and leaf children\n // console.log({ case: \"INTERIOR\", index0, index1 });\n const numPerGulp = Math.ceil((index1 - index0) / maxChildPerNode);\n for (let indexA = index0 + numPerGulp; index0 < index1; index0 = indexA, indexA = Math.min(indexA + numPerGulp, index1)) {\n const child = this.createRecursiveByIndexSplits(ranges, appData, index0, indexA, arrayLength, maxChildPerNode, maxAppDataPerLeaf);\n if (child !== undefined) {\n range.extendRange(child.getRangeRef());\n children.push(child);\n }\n }\n }\n return (children.length > 0) ? RangeTreeNode.createCapture(range, undefined, children) : undefined;\n }\n /**\n * Create a range tree by simple left-right split of given ranges.\n * * Leaves carry the inputs in left-to-right order.\n * * Each leaf range is labeled by its corresponding object(s) in the appData array.\n * @param ranges access to ranges.\n * @param appData access to AppDataType items (for leaves).\n * @param arrayLength one more than the largest range/appData index\n * @param maxChildrenPerNode max number of child nodes allowed for each interior node.\n * @param maxAppDataPerLeaf max number of appData items allowed in each leaf.\n * @returns the root of the new tree, or undefined if array lengths differ or are zero.\n */\n public static createByIndexSplits<AppDataType>(\n ranges: IndexToType<Range3d>,\n appData: IndexToType<AppDataType>,\n arrayLength: number,\n maxChildrenPerNode: number = 2,\n maxAppDataPerLeaf: number = 2,\n ): RangeTreeNode<AppDataType> | undefined {\n // console.log();\n // const numData = getFlexDataCount(appData);\n // console.log({ numData });\n if (arrayLength <= 0\n || (Array.isArray(ranges) && ranges.length !== arrayLength)\n || (Array.isArray(appData) && appData.length !== arrayLength))\n return undefined;\n if (maxChildrenPerNode < 2)\n maxChildrenPerNode = 2;\n return RangeTreeOps.createRecursiveByIndexSplits<AppDataType>(ranges, appData, 0, arrayLength, arrayLength, maxChildrenPerNode, maxAppDataPerLeaf);\n }\n}\n\n"]}
|