@itwin/core-geometry 3.3.0-dev.9 → 3.4.0-dev.10
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 +43 -1
- package/lib/cjs/bspline/BSplineCurve.js +3 -3
- package/lib/cjs/bspline/BSplineCurve.js.map +1 -1
- package/lib/cjs/bspline/BezierCurve3dH.d.ts +2 -1
- package/lib/cjs/bspline/BezierCurve3dH.d.ts.map +1 -1
- package/lib/cjs/bspline/BezierCurve3dH.js +10 -1
- package/lib/cjs/bspline/BezierCurve3dH.js.map +1 -1
- package/lib/cjs/curve/Arc3d.d.ts +13 -2
- package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
- package/lib/cjs/curve/Arc3d.js +21 -3
- package/lib/cjs/curve/Arc3d.js.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +36 -2
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js +158 -7
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/cjs/curve/CurveCollection.d.ts +2 -0
- package/lib/cjs/curve/CurveCollection.d.ts.map +1 -1
- package/lib/cjs/curve/CurveCollection.js +8 -0
- package/lib/cjs/curve/CurveCollection.js.map +1 -1
- package/lib/cjs/curve/CurvePrimitive.d.ts +23 -0
- package/lib/cjs/curve/CurvePrimitive.d.ts.map +1 -1
- package/lib/cjs/curve/CurvePrimitive.js +65 -0
- package/lib/cjs/curve/CurvePrimitive.js.map +1 -1
- package/lib/cjs/curve/LineSegment3d.d.ts +5 -0
- package/lib/cjs/curve/LineSegment3d.d.ts.map +1 -1
- package/lib/cjs/curve/LineSegment3d.js +21 -0
- package/lib/cjs/curve/LineSegment3d.js.map +1 -1
- package/lib/cjs/curve/LineString3d.d.ts +2 -0
- package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
- package/lib/cjs/curve/LineString3d.js +28 -0
- package/lib/cjs/curve/LineString3d.js.map +1 -1
- package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts +2 -5
- package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/DirectSpiral3d.js +6 -8
- package/lib/cjs/curve/spiral/DirectSpiral3d.js.map +1 -1
- package/lib/cjs/curve/spiral/IntegratedSpiral3d.d.ts +0 -3
- package/lib/cjs/curve/spiral/IntegratedSpiral3d.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/IntegratedSpiral3d.js +0 -4
- package/lib/cjs/curve/spiral/IntegratedSpiral3d.js.map +1 -1
- package/lib/cjs/curve/spiral/TransitionSpiral3d.d.ts +7 -0
- package/lib/cjs/curve/spiral/TransitionSpiral3d.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/TransitionSpiral3d.js +17 -0
- package/lib/cjs/curve/spiral/TransitionSpiral3d.js.map +1 -1
- package/lib/cjs/geometry3d/GrowableBlockedArray.d.ts +32 -3
- package/lib/cjs/geometry3d/GrowableBlockedArray.d.ts.map +1 -1
- package/lib/cjs/geometry3d/GrowableBlockedArray.js +63 -14
- package/lib/cjs/geometry3d/GrowableBlockedArray.js.map +1 -1
- package/lib/cjs/geometry3d/GrowableFloat64Array.d.ts +24 -8
- package/lib/cjs/geometry3d/GrowableFloat64Array.d.ts.map +1 -1
- package/lib/cjs/geometry3d/GrowableFloat64Array.js +72 -54
- package/lib/cjs/geometry3d/GrowableFloat64Array.js.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYArray.d.ts +51 -26
- package/lib/cjs/geometry3d/GrowableXYArray.d.ts.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYArray.js +136 -116
- package/lib/cjs/geometry3d/GrowableXYArray.js.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYZArray.d.ts +35 -21
- package/lib/cjs/geometry3d/GrowableXYZArray.d.ts.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYZArray.js +124 -137
- package/lib/cjs/geometry3d/GrowableXYZArray.js.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.js +2 -3
- package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/cjs/geometry3d/PolygonOps.d.ts +8 -2
- package/lib/cjs/geometry3d/PolygonOps.d.ts.map +1 -1
- package/lib/cjs/geometry3d/PolygonOps.js +40 -3
- package/lib/cjs/geometry3d/PolygonOps.js.map +1 -1
- package/lib/cjs/geometry3d/Range.d.ts +12 -0
- package/lib/cjs/geometry3d/Range.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Range.js +32 -0
- package/lib/cjs/geometry3d/Range.js.map +1 -1
- package/lib/cjs/geometry3d/Ray3d.js +1 -1
- package/lib/cjs/geometry3d/Ray3d.js.map +1 -1
- package/lib/cjs/geometry3d/Transform.d.ts +1 -1
- package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Transform.js +1 -1
- package/lib/cjs/geometry3d/Transform.js.map +1 -1
- package/lib/cjs/geometry3d/XYZProps.d.ts +10 -3
- package/lib/cjs/geometry3d/XYZProps.d.ts.map +1 -1
- package/lib/cjs/geometry3d/XYZProps.js +21 -0
- package/lib/cjs/geometry3d/XYZProps.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceBuilder.d.ts +1 -1
- package/lib/cjs/polyface/PolyfaceBuilder.js +2 -2
- package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceClip.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceClip.js +1 -1
- package/lib/cjs/polyface/PolyfaceClip.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceQuery.d.ts +4 -2
- package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceQuery.js +10 -6
- package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
- package/lib/cjs/serialization/GeometrySamples.d.ts +2 -0
- package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
- package/lib/cjs/serialization/GeometrySamples.js +20 -0
- package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
- package/lib/cjs/topology/Merging.js +3 -3
- package/lib/cjs/topology/Merging.js.map +1 -1
- package/lib/cjs/topology/Triangulation.d.ts +1 -3
- package/lib/cjs/topology/Triangulation.d.ts.map +1 -1
- package/lib/cjs/topology/Triangulation.js +31 -21
- package/lib/cjs/topology/Triangulation.js.map +1 -1
- package/lib/esm/bspline/BSplineCurve.js +3 -3
- package/lib/esm/bspline/BSplineCurve.js.map +1 -1
- package/lib/esm/bspline/BezierCurve3dH.d.ts +2 -1
- package/lib/esm/bspline/BezierCurve3dH.d.ts.map +1 -1
- package/lib/esm/bspline/BezierCurve3dH.js +10 -1
- package/lib/esm/bspline/BezierCurve3dH.js.map +1 -1
- package/lib/esm/curve/Arc3d.d.ts +13 -2
- package/lib/esm/curve/Arc3d.d.ts.map +1 -1
- package/lib/esm/curve/Arc3d.js +22 -4
- package/lib/esm/curve/Arc3d.js.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +36 -2
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.js +158 -7
- package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/esm/curve/CurveCollection.d.ts +2 -0
- package/lib/esm/curve/CurveCollection.d.ts.map +1 -1
- package/lib/esm/curve/CurveCollection.js +8 -0
- package/lib/esm/curve/CurveCollection.js.map +1 -1
- package/lib/esm/curve/CurvePrimitive.d.ts +23 -0
- package/lib/esm/curve/CurvePrimitive.d.ts.map +1 -1
- package/lib/esm/curve/CurvePrimitive.js +65 -0
- package/lib/esm/curve/CurvePrimitive.js.map +1 -1
- package/lib/esm/curve/LineSegment3d.d.ts +5 -0
- package/lib/esm/curve/LineSegment3d.d.ts.map +1 -1
- package/lib/esm/curve/LineSegment3d.js +21 -0
- package/lib/esm/curve/LineSegment3d.js.map +1 -1
- package/lib/esm/curve/LineString3d.d.ts +2 -0
- package/lib/esm/curve/LineString3d.d.ts.map +1 -1
- package/lib/esm/curve/LineString3d.js +28 -0
- package/lib/esm/curve/LineString3d.js.map +1 -1
- package/lib/esm/curve/spiral/DirectSpiral3d.d.ts +2 -5
- package/lib/esm/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
- package/lib/esm/curve/spiral/DirectSpiral3d.js +6 -8
- package/lib/esm/curve/spiral/DirectSpiral3d.js.map +1 -1
- package/lib/esm/curve/spiral/IntegratedSpiral3d.d.ts +0 -3
- package/lib/esm/curve/spiral/IntegratedSpiral3d.d.ts.map +1 -1
- package/lib/esm/curve/spiral/IntegratedSpiral3d.js +0 -4
- package/lib/esm/curve/spiral/IntegratedSpiral3d.js.map +1 -1
- package/lib/esm/curve/spiral/TransitionSpiral3d.d.ts +7 -0
- package/lib/esm/curve/spiral/TransitionSpiral3d.d.ts.map +1 -1
- package/lib/esm/curve/spiral/TransitionSpiral3d.js +17 -0
- package/lib/esm/curve/spiral/TransitionSpiral3d.js.map +1 -1
- package/lib/esm/geometry3d/GrowableBlockedArray.d.ts +32 -3
- package/lib/esm/geometry3d/GrowableBlockedArray.d.ts.map +1 -1
- package/lib/esm/geometry3d/GrowableBlockedArray.js +63 -14
- package/lib/esm/geometry3d/GrowableBlockedArray.js.map +1 -1
- package/lib/esm/geometry3d/GrowableFloat64Array.d.ts +24 -8
- package/lib/esm/geometry3d/GrowableFloat64Array.d.ts.map +1 -1
- package/lib/esm/geometry3d/GrowableFloat64Array.js +72 -54
- package/lib/esm/geometry3d/GrowableFloat64Array.js.map +1 -1
- package/lib/esm/geometry3d/GrowableXYArray.d.ts +51 -26
- package/lib/esm/geometry3d/GrowableXYArray.d.ts.map +1 -1
- package/lib/esm/geometry3d/GrowableXYArray.js +136 -116
- package/lib/esm/geometry3d/GrowableXYArray.js.map +1 -1
- package/lib/esm/geometry3d/GrowableXYZArray.d.ts +35 -21
- package/lib/esm/geometry3d/GrowableXYZArray.d.ts.map +1 -1
- package/lib/esm/geometry3d/GrowableXYZArray.js +124 -137
- package/lib/esm/geometry3d/GrowableXYZArray.js.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.d.ts +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.js +2 -3
- package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/esm/geometry3d/PolygonOps.d.ts +8 -2
- package/lib/esm/geometry3d/PolygonOps.d.ts.map +1 -1
- package/lib/esm/geometry3d/PolygonOps.js +40 -3
- package/lib/esm/geometry3d/PolygonOps.js.map +1 -1
- package/lib/esm/geometry3d/Range.d.ts +12 -0
- package/lib/esm/geometry3d/Range.d.ts.map +1 -1
- package/lib/esm/geometry3d/Range.js +32 -0
- package/lib/esm/geometry3d/Range.js.map +1 -1
- package/lib/esm/geometry3d/Ray3d.js +1 -1
- package/lib/esm/geometry3d/Ray3d.js.map +1 -1
- package/lib/esm/geometry3d/Transform.d.ts +1 -1
- package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
- package/lib/esm/geometry3d/Transform.js +1 -1
- package/lib/esm/geometry3d/Transform.js.map +1 -1
- package/lib/esm/geometry3d/XYZProps.d.ts +10 -3
- package/lib/esm/geometry3d/XYZProps.d.ts.map +1 -1
- package/lib/esm/geometry3d/XYZProps.js +20 -1
- package/lib/esm/geometry3d/XYZProps.js.map +1 -1
- package/lib/esm/polyface/PolyfaceBuilder.d.ts +1 -1
- package/lib/esm/polyface/PolyfaceBuilder.js +2 -2
- package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
- package/lib/esm/polyface/PolyfaceClip.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceClip.js +1 -1
- package/lib/esm/polyface/PolyfaceClip.js.map +1 -1
- package/lib/esm/polyface/PolyfaceQuery.d.ts +4 -2
- package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceQuery.js +10 -6
- package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
- package/lib/esm/serialization/GeometrySamples.d.ts +2 -0
- package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
- package/lib/esm/serialization/GeometrySamples.js +20 -0
- package/lib/esm/serialization/GeometrySamples.js.map +1 -1
- package/lib/esm/topology/Merging.js +3 -3
- package/lib/esm/topology/Merging.js.map +1 -1
- package/lib/esm/topology/Triangulation.d.ts +1 -3
- package/lib/esm/topology/Triangulation.d.ts.map +1 -1
- package/lib/esm/topology/Triangulation.js +31 -21
- package/lib/esm/topology/Triangulation.js.map +1 -1
- package/package.json +7 -7
|
@@ -11,6 +11,7 @@ import { Transform } from "../../geometry3d/Transform";
|
|
|
11
11
|
import { Geometry } from "../../Geometry";
|
|
12
12
|
import { CurveOffsetXYHandler } from "../internalContexts/CurveOffsetXYHandler";
|
|
13
13
|
import { OffsetOptions } from "../internalContexts/PolygonOffsetContext";
|
|
14
|
+
import { Range3d } from "../../geometry3d/Range";
|
|
14
15
|
/**
|
|
15
16
|
* TransitionSpiral3d is a base class for multiple variants of spirals.
|
|
16
17
|
* * The menagerie of spiral types have 2 broad categories:
|
|
@@ -131,5 +132,21 @@ export class TransitionSpiral3d extends CurvePrimitive {
|
|
|
131
132
|
this.emitStrokableParts(handler, options.strokeOptions);
|
|
132
133
|
return handler.claimResult();
|
|
133
134
|
}
|
|
135
|
+
/** extend the range by the strokes of the spiral */
|
|
136
|
+
extendRange(rangeToExtend, transform) {
|
|
137
|
+
const myRange = this.rangeBetweenFractions(0.0, 1.0, transform);
|
|
138
|
+
rangeToExtend.extendRange(myRange);
|
|
139
|
+
}
|
|
140
|
+
/** return the range of spiral between fractions of the activeStrokes.
|
|
141
|
+
* * Use activeStrokes point count times interval factor for initial evaluation count, but do at least 5
|
|
142
|
+
*/
|
|
143
|
+
rangeBetweenFractions(fractionA, fractionB, transform) {
|
|
144
|
+
const strokes = this.activeStrokes;
|
|
145
|
+
if (undefined === strokes)
|
|
146
|
+
return Range3d.createNull();
|
|
147
|
+
let count = Math.ceil(strokes.numPoints() * Math.abs(fractionB - fractionA));
|
|
148
|
+
count = Geometry.clamp(5, count, 30);
|
|
149
|
+
return this.rangeBetweenFractionsByCount(fractionA, fractionB, count, transform, 0.5);
|
|
150
|
+
}
|
|
134
151
|
}
|
|
135
152
|
//# sourceMappingURL=TransitionSpiral3d.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransitionSpiral3d.js","sourceRoot":"","sources":["../../../../src/curve/spiral/TransitionSpiral3d.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAkCzE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,cAAc;IAmB7D,YAAsB,UAA8B,EAAE,YAAuB,EAAE,sBAA6C,EAAE,gBAA6D;QACzL,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC;QACjE,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC,CAAC,CAAC,sBAAsB,CA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AAM,OAAO,GAAG,IAAI,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC3E,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QACxD,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Curve\r\n */\r\n\r\nimport { CurvePrimitive } from \"../CurvePrimitive\";\r\nimport { Matrix3d } from \"../../geometry3d/Matrix3d\";\r\nimport { Segment1d } from \"../../geometry3d/Segment1d\";\r\nimport { Transform } from \"../../geometry3d/Transform\";\r\nimport { TransitionConditionalProperties } from \"./TransitionConditionalProperties\";\r\nimport { Geometry } from \"../../Geometry\";\r\nimport { LineString3d } from \"../LineString3d\";\r\nimport { CurveOffsetXYHandler } from \"../internalContexts/CurveOffsetXYHandler\";\r\nimport { OffsetOptions } from \"../internalContexts/PolygonOffsetContext\";\r\n/**\r\n * This is the set of valid type names for \"integrated\" spirals\r\n * * Behavior is expressed by a `NormalizedTransition` snap function.\r\n * * The snap function varies smoothly from f(0)=0 to f(1)=1\r\n * * The various snap functions are:\r\n * * clothoid: linear\r\n * * biquadratic: 2 quadratics pieced together, joining with 1st derivative continuity at f(0.) = 0.5, with zero slope f'(0)=0 and f'(1)= 0\r\n * * bloss: A single cubic with zero slope at 0 and 1\r\n * * cosine: half of a cosine wave, centered around 0.5\r\n * * sine: full period of a sine wave added to the line f(u)=u\r\n * *\r\n * @public\r\n */\r\nexport type IntegratedSpiralTypeName = \"clothoid\" | \"bloss\" | \"biquadratic\" | \"cosine\" | \"sine\";\r\n\r\n/**\r\n * This is the set of valid type names for \"direct\" spirals.\r\n * \"Direct\" spirals can evaluate fractionToPoint by direct equations, i.e. not requiring the numeric integrations in \"Integrated\" spiral types.\r\n * @public\r\n */\r\nexport type DirectSpiralTypeName =\r\n \"JapaneseCubic\" // 1 term from each of the X,Y clothoid series expansions: y = x^3 / (6RL)\r\n | \"Arema\" // 2 terms from each of the X,Y clothoid series expansions. Identical to ChineseCubic!\r\n | \"ChineseCubic\" // Identical to Arema!\r\n | \"HalfCosine\" // high continuity cosine variation from quadratic.\r\n | \"AustralianRailCorp\" // cubic with high accuracy distance series\r\n | \"WesternAustralian\" // simple cubic -- 2 terms of x series, 1 term of y series.\r\n | \"Czech\" // simple cubic with two term distance approximation\r\n | \"MXCubicAlongArc\" // x obtained from fractional distance via 2-terms from series, y = x^3/ (6RL)\r\n | \"Polish\"\r\n | \"Italian\"\r\n ;\r\n\r\n/**\r\n * TransitionSpiral3d is a base class for multiple variants of spirals.\r\n * * The menagerie of spiral types have 2 broad categories:\r\n * * IntegratedSpiral3d -- a spiral whose direct function for curvature versus distance must be integrated to determine x,y\r\n * * The IntegratedSpiral3d types are enumerated in `IntegratedSpiralTypes`\r\n * * DirectSpiral3d -- a spiral implemented with direct calculation of x,y from fractional position along the spiral.\r\n * * The direct spiral types are enumerated in the `DirectSpiralType`\r\n * * The method set for CurvePrimitive support includes a `handleTransitionSpiral(g: TransitionSpiral3d)` which receives all the spiral types.\r\n * * The spiral class may impose expectations that its inflection is at the origin, with tangent along the x axis.\r\n * * This is generally necessary for direct spirals.\r\n * * This is not necessary for integrated spirals.\r\n * @public\r\n */\r\nexport abstract class TransitionSpiral3d extends CurvePrimitive {\r\n /** string name of spiral type */\r\n protected _spiralType: string;\r\n /** Original defining properties. */\r\n protected _designProperties: TransitionConditionalProperties | undefined;\r\n\r\n /** Fractional interval for the \"active\" part of a containing spiral.\r\n * (The radius, angle, and length conditions define a complete spiral, and some portion of it is \"active\")\r\n */\r\n protected _activeFractionInterval: Segment1d;\r\n /** Return (reference to) the active portion of the reference spiral. */\r\n public get activeFractionInterval(): Segment1d { return this._activeFractionInterval; }\r\n /** strokes in the active portion */\r\n public abstract get activeStrokes(): LineString3d;\r\n /** Placement transform */\r\n protected _localToWorld: Transform;\r\n /** (reference to) placement transform. */\r\n public get localToWorld(): Transform { return this._localToWorld; }\r\n\r\n protected constructor(spiralType: string | undefined, localToWorld: Transform, activeFractionInterval: Segment1d | undefined, designProperties: TransitionConditionalProperties | undefined) {\r\n super();\r\n this._spiralType = spiralType ? spiralType : \"unknownSpiralType\";\r\n this._designProperties = designProperties;\r\n this._localToWorld = localToWorld;\r\n this._activeFractionInterval = activeFractionInterval ? activeFractionInterval : Segment1d.create(0, 1);\r\n }\r\n\r\n public get spiralType(): string { return this._spiralType; }\r\n /** Return 1/r with convention that if true zero is given as radius it represents infinite radius (0 curvature, straight line) */\r\n public static radiusToCurvature(radius: number): number { return (radius === 0.0) ? 0.0 : 1.0 / radius; }\r\n\r\n /** Return 1/k with convention that if near-zero is given as curvature, its infinite radius is returned as 0 */\r\n public static curvatureToRadius(curvature: number): number {\r\n if (Math.abs(curvature) < Geometry.smallAngleRadians)\r\n return 0.0;\r\n return 1.0 / curvature;\r\n }\r\n\r\n /** Return a deep clone. */\r\n public abstract override clone(): TransitionSpiral3d;\r\n\r\n /** Recompute strokes */\r\n public abstract refreshComputedProperties(): void;\r\n\r\n /** Return (if possible) a spiral which is a portion of this curve. */\r\n public override clonePartialCurve(fractionA: number, fractionB: number): TransitionSpiral3d {\r\n const spiralB = this.clone();\r\n const globalFractionA = this._activeFractionInterval.fractionToPoint(fractionA);\r\n const globalFractionB = this._activeFractionInterval.fractionToPoint(fractionB);\r\n spiralB._activeFractionInterval.set(globalFractionA, globalFractionB);\r\n spiralB.refreshComputedProperties();\r\n return spiralB;\r\n }\r\n\r\n /** Clone with a transform applied */\r\n public override cloneTransformed(transform: Transform): TransitionSpiral3d {\r\n const result = this.clone();\r\n result.tryTransformInPlace(transform); // ok, we're confident it will always work.\r\n return result;\r\n }\r\n\r\n /** Return the average of the start and end curvatures. */\r\n public static averageCurvature(radiusLimits: Segment1d): number {\r\n return 0.5 * (TransitionSpiral3d.radiusToCurvature(radiusLimits.x0) + TransitionSpiral3d.radiusToCurvature(radiusLimits.x1));\r\n }\r\n /**\r\n * Given two radii (or zeros for 0 curvature) return the average curvature\r\n * @param r0 start radius, or 0 for line\r\n * @param r1 end radius, or 0 for line\r\n */\r\n public static averageCurvatureR0R1(r0: number, r1: number): number {\r\n return 0.5 * (TransitionSpiral3d.radiusToCurvature(r0) + TransitionSpiral3d.radiusToCurvature(r1));\r\n }\r\n /**\r\n * Given two radii (or zeros for 0 curvature) return the average curvature\r\n * @param r0 start radius, or 0 for line\r\n * @param r1 end radius, or 0 for line\r\n */\r\n public static interpolateCurvatureR0R1(r0: number, fraction: number, r1: number): number {\r\n return Geometry.interpolate(TransitionSpiral3d.radiusToCurvature(r0), fraction, TransitionSpiral3d.radiusToCurvature(r1));\r\n }\r\n\r\n /** Return the arc length of a transition spiral with given sweep and radius pair. */\r\n public static radiusRadiusSweepRadiansToArcLength(radius0: number, radius1: number, sweepRadians: number): number {\r\n return Math.abs(sweepRadians / TransitionSpiral3d.averageCurvatureR0R1(radius0, radius1));\r\n }\r\n\r\n /** Return the turn angle for spiral of given length between two radii */\r\n public static radiusRadiusLengthToSweepRadians(radius0: number, radius1: number, arcLength: number): number {\r\n return TransitionSpiral3d.averageCurvatureR0R1(radius0, radius1) * arcLength;\r\n }\r\n\r\n /** Return the end radius for spiral of given start radius, length, and turn angle. */\r\n public static radius0LengthSweepRadiansToRadius1(radius0: number, arcLength: number, sweepRadians: number) {\r\n return TransitionSpiral3d.curvatureToRadius((2.0 * sweepRadians / arcLength) - TransitionSpiral3d.radiusToCurvature(radius0));\r\n }\r\n /** Return the start radius for spiral of given end radius, length, and turn angle. */\r\n public static radius1LengthSweepRadiansToRadius0(radius1: number, arcLength: number, sweepRadians: number) {\r\n return TransitionSpiral3d.curvatureToRadius((2.0 * sweepRadians / arcLength) - TransitionSpiral3d.radiusToCurvature(radius1));\r\n }\r\n /** Return the original defining properties (if any) saved by the constructor. */\r\n public get designProperties(): TransitionConditionalProperties | undefined { return this._designProperties; }\r\n /**\r\n * * If transformA is rigid with uniform scale, apply the rigid part of transformA to the localToWorld transform and return the scale and rigid separation.\r\n * * If not rigid, do nothing and return undefined.\r\n * * Also apply the scale factor to the designProperties.\r\n * @param transformA\r\n */\r\n protected applyRigidPartOfTransform(transformA: Transform): { rigidAxes: Matrix3d, scale: number } | undefined {\r\n const rigidData = transformA.matrix.factorRigidWithSignedScale();\r\n if (rigidData !== undefined) {\r\n // [sQ a][R b] = [sQ*R sQb+a]\r\n // but we save it as [Q*R sQb+a] with spiral data scaled by s.\r\n const transformC0 = transformA.multiplyTransformTransform(this.localToWorld);\r\n // BUT pull the scale part out of the matrix ...\r\n const matrixC = rigidData.rigidAxes.multiplyMatrixMatrix(this.localToWorld.matrix);\r\n this._localToWorld = Transform.createOriginAndMatrix(transformC0.origin, matrixC);\r\n if (this.designProperties)\r\n this.designProperties.applyScaleFactor(rigidData.scale);\r\n\r\n return rigidData;\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Construct an offset of the instance curve as viewed in the xy-plane (ignoring z).\r\n * * No attempt is made to join the offsets of smaller constituent primitives. To construct a fully joined offset\r\n * for an aggregate instance (e.g., LineString3d, CurveChainWithDistanceIndex), use RegionOps.constructCurveXYOffset() instead.\r\n * @param offsetDistanceOrOptions offset distance (positive to left of the instance curve), or options object\r\n */\r\n public override constructOffsetXY(offsetDistanceOrOptions: number | OffsetOptions): CurvePrimitive | CurvePrimitive[] | undefined {\r\n const options = OffsetOptions.create(offsetDistanceOrOptions);\r\n const handler = new CurveOffsetXYHandler(this, options.leftOffsetDistance);\r\n this.emitStrokableParts(handler, options.strokeOptions);\r\n return handler.claimResult();\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"TransitionSpiral3d.js","sourceRoot":"","sources":["../../../../src/curve/spiral/TransitionSpiral3d.ts"],"names":[],"mappings":"AAAA;;;+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,CAAC,SAAiB,EAAE,SAAiB,EAAE,SAAqB;QAChG,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC;QACnC,IAAI,SAAS,KAAK,OAAO;YACvB,OAAO,OAAO,CAAC,UAAU,EAAG,CAAC;QAC/B,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,CAAE,OAAO,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,GAAG,CAAE,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC;QAC/E,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,4BAA4B,CAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;IACzF,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Curve\r\n */\r\n\r\nimport { CurvePrimitive } from \"../CurvePrimitive\";\r\nimport { Matrix3d } from \"../../geometry3d/Matrix3d\";\r\nimport { Segment1d } from \"../../geometry3d/Segment1d\";\r\nimport { Transform } from \"../../geometry3d/Transform\";\r\nimport { TransitionConditionalProperties } from \"./TransitionConditionalProperties\";\r\nimport { Geometry } from \"../../Geometry\";\r\nimport { LineString3d } from \"../LineString3d\";\r\nimport { CurveOffsetXYHandler } from \"../internalContexts/CurveOffsetXYHandler\";\r\nimport { OffsetOptions } from \"../internalContexts/PolygonOffsetContext\";\r\nimport { Range3d } from \"../../geometry3d/Range\";\r\n/**\r\n * This is the set of valid type names for \"integrated\" spirals\r\n * * Behavior is expressed by a `NormalizedTransition` snap function.\r\n * * The snap function varies smoothly from f(0)=0 to f(1)=1\r\n * * The various snap functions are:\r\n * * clothoid: linear\r\n * * biquadratic: 2 quadratics pieced together, joining with 1st derivative continuity at f(0.) = 0.5, with zero slope f'(0)=0 and f'(1)= 0\r\n * * bloss: A single cubic with zero slope at 0 and 1\r\n * * cosine: half of a cosine wave, centered around 0.5\r\n * * sine: full period of a sine wave added to the line f(u)=u\r\n * *\r\n * @public\r\n */\r\nexport type IntegratedSpiralTypeName = \"clothoid\" | \"bloss\" | \"biquadratic\" | \"cosine\" | \"sine\";\r\n\r\n/**\r\n * This is the set of valid type names for \"direct\" spirals.\r\n * \"Direct\" spirals can evaluate fractionToPoint by direct equations, i.e. not requiring the numeric integrations in \"Integrated\" spiral types.\r\n * @public\r\n */\r\nexport type DirectSpiralTypeName =\r\n \"JapaneseCubic\" // 1 term from each of the X,Y clothoid series expansions: y = x^3 / (6RL)\r\n | \"Arema\" // 2 terms from each of the X,Y clothoid series expansions. Identical to ChineseCubic!\r\n | \"ChineseCubic\" // Identical to Arema!\r\n | \"HalfCosine\" // high continuity cosine variation from quadratic.\r\n | \"AustralianRailCorp\" // cubic with high accuracy distance series\r\n | \"WesternAustralian\" // simple cubic -- 2 terms of x series, 1 term of y series.\r\n | \"Czech\" // simple cubic with two term distance approximation\r\n | \"MXCubicAlongArc\" // x obtained from fractional distance via 2-terms from series, y = x^3/ (6RL)\r\n | \"Polish\"\r\n | \"Italian\"\r\n ;\r\n\r\n/**\r\n * TransitionSpiral3d is a base class for multiple variants of spirals.\r\n * * The menagerie of spiral types have 2 broad categories:\r\n * * IntegratedSpiral3d -- a spiral whose direct function for curvature versus distance must be integrated to determine x,y\r\n * * The IntegratedSpiral3d types are enumerated in `IntegratedSpiralTypes`\r\n * * DirectSpiral3d -- a spiral implemented with direct calculation of x,y from fractional position along the spiral.\r\n * * The direct spiral types are enumerated in the `DirectSpiralType`\r\n * * The method set for CurvePrimitive support includes a `handleTransitionSpiral(g: TransitionSpiral3d)` which receives all the spiral types.\r\n * * The spiral class may impose expectations that its inflection is at the origin, with tangent along the x axis.\r\n * * This is generally necessary for direct spirals.\r\n * * This is not necessary for integrated spirals.\r\n * @public\r\n */\r\nexport abstract class TransitionSpiral3d extends CurvePrimitive {\r\n /** string name of spiral type */\r\n protected _spiralType: string;\r\n /** Original defining properties. */\r\n protected _designProperties: TransitionConditionalProperties | undefined;\r\n\r\n /** Fractional interval for the \"active\" part of a containing spiral.\r\n * (The radius, angle, and length conditions define a complete spiral, and some portion of it is \"active\")\r\n */\r\n protected _activeFractionInterval: Segment1d;\r\n /** Return (reference to) the active portion of the reference spiral. */\r\n public get activeFractionInterval(): Segment1d { return this._activeFractionInterval; }\r\n /** strokes in the active portion */\r\n public abstract get activeStrokes(): LineString3d;\r\n /** Placement transform */\r\n protected _localToWorld: Transform;\r\n /** (reference to) placement transform. */\r\n public get localToWorld(): Transform { return this._localToWorld; }\r\n\r\n protected constructor(spiralType: string | undefined, localToWorld: Transform, activeFractionInterval: Segment1d | undefined, designProperties: TransitionConditionalProperties | undefined) {\r\n super();\r\n this._spiralType = spiralType ? spiralType : \"unknownSpiralType\";\r\n this._designProperties = designProperties;\r\n this._localToWorld = localToWorld;\r\n this._activeFractionInterval = activeFractionInterval ? activeFractionInterval : Segment1d.create(0, 1);\r\n }\r\n\r\n public get spiralType(): string { return this._spiralType; }\r\n /** Return 1/r with convention that if true zero is given as radius it represents infinite radius (0 curvature, straight line) */\r\n public static radiusToCurvature(radius: number): number { return (radius === 0.0) ? 0.0 : 1.0 / radius; }\r\n\r\n /** Return 1/k with convention that if near-zero is given as curvature, its infinite radius is returned as 0 */\r\n public static curvatureToRadius(curvature: number): number {\r\n if (Math.abs(curvature) < Geometry.smallAngleRadians)\r\n return 0.0;\r\n return 1.0 / curvature;\r\n }\r\n\r\n /** Return a deep clone. */\r\n public abstract override clone(): TransitionSpiral3d;\r\n\r\n /** Recompute strokes */\r\n public abstract refreshComputedProperties(): void;\r\n\r\n /** Return (if possible) a spiral which is a portion of this curve. */\r\n public override clonePartialCurve(fractionA: number, fractionB: number): TransitionSpiral3d {\r\n const spiralB = this.clone();\r\n const globalFractionA = this._activeFractionInterval.fractionToPoint(fractionA);\r\n const globalFractionB = this._activeFractionInterval.fractionToPoint(fractionB);\r\n spiralB._activeFractionInterval.set(globalFractionA, globalFractionB);\r\n spiralB.refreshComputedProperties();\r\n return spiralB;\r\n }\r\n\r\n /** Clone with a transform applied */\r\n public override cloneTransformed(transform: Transform): TransitionSpiral3d {\r\n const result = this.clone();\r\n result.tryTransformInPlace(transform); // ok, we're confident it will always work.\r\n return result;\r\n }\r\n\r\n /** Return the average of the start and end curvatures. */\r\n public static averageCurvature(radiusLimits: Segment1d): number {\r\n return 0.5 * (TransitionSpiral3d.radiusToCurvature(radiusLimits.x0) + TransitionSpiral3d.radiusToCurvature(radiusLimits.x1));\r\n }\r\n /**\r\n * Given two radii (or zeros for 0 curvature) return the average curvature\r\n * @param r0 start radius, or 0 for line\r\n * @param r1 end radius, or 0 for line\r\n */\r\n public static averageCurvatureR0R1(r0: number, r1: number): number {\r\n return 0.5 * (TransitionSpiral3d.radiusToCurvature(r0) + TransitionSpiral3d.radiusToCurvature(r1));\r\n }\r\n /**\r\n * Given two radii (or zeros for 0 curvature) return the average curvature\r\n * @param r0 start radius, or 0 for line\r\n * @param r1 end radius, or 0 for line\r\n */\r\n public static interpolateCurvatureR0R1(r0: number, fraction: number, r1: number): number {\r\n return Geometry.interpolate(TransitionSpiral3d.radiusToCurvature(r0), fraction, TransitionSpiral3d.radiusToCurvature(r1));\r\n }\r\n\r\n /** Return the arc length of a transition spiral with given sweep and radius pair. */\r\n public static radiusRadiusSweepRadiansToArcLength(radius0: number, radius1: number, sweepRadians: number): number {\r\n return Math.abs(sweepRadians / TransitionSpiral3d.averageCurvatureR0R1(radius0, radius1));\r\n }\r\n\r\n /** Return the turn angle for spiral of given length between two radii */\r\n public static radiusRadiusLengthToSweepRadians(radius0: number, radius1: number, arcLength: number): number {\r\n return TransitionSpiral3d.averageCurvatureR0R1(radius0, radius1) * arcLength;\r\n }\r\n\r\n /** Return the end radius for spiral of given start radius, length, and turn angle. */\r\n public static radius0LengthSweepRadiansToRadius1(radius0: number, arcLength: number, sweepRadians: number) {\r\n return TransitionSpiral3d.curvatureToRadius((2.0 * sweepRadians / arcLength) - TransitionSpiral3d.radiusToCurvature(radius0));\r\n }\r\n /** Return the start radius for spiral of given end radius, length, and turn angle. */\r\n public static radius1LengthSweepRadiansToRadius0(radius1: number, arcLength: number, sweepRadians: number) {\r\n return TransitionSpiral3d.curvatureToRadius((2.0 * sweepRadians / arcLength) - TransitionSpiral3d.radiusToCurvature(radius1));\r\n }\r\n /** Return the original defining properties (if any) saved by the constructor. */\r\n public get designProperties(): TransitionConditionalProperties | undefined { return this._designProperties; }\r\n /**\r\n * * If transformA is rigid with uniform scale, apply the rigid part of transformA to the localToWorld transform and return the scale and rigid separation.\r\n * * If not rigid, do nothing and return undefined.\r\n * * Also apply the scale factor to the designProperties.\r\n * @param transformA\r\n */\r\n protected applyRigidPartOfTransform(transformA: Transform): { rigidAxes: Matrix3d, scale: number } | undefined {\r\n const rigidData = transformA.matrix.factorRigidWithSignedScale();\r\n if (rigidData !== undefined) {\r\n // [sQ a][R b] = [sQ*R sQb+a]\r\n // but we save it as [Q*R sQb+a] with spiral data scaled by s.\r\n const transformC0 = transformA.multiplyTransformTransform(this.localToWorld);\r\n // BUT pull the scale part out of the matrix ...\r\n const matrixC = rigidData.rigidAxes.multiplyMatrixMatrix(this.localToWorld.matrix);\r\n this._localToWorld = Transform.createOriginAndMatrix(transformC0.origin, matrixC);\r\n if (this.designProperties)\r\n this.designProperties.applyScaleFactor(rigidData.scale);\r\n\r\n return rigidData;\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Construct an offset of the instance curve as viewed in the xy-plane (ignoring z).\r\n * * No attempt is made to join the offsets of smaller constituent primitives. To construct a fully joined offset\r\n * for an aggregate instance (e.g., LineString3d, CurveChainWithDistanceIndex), use RegionOps.constructCurveXYOffset() instead.\r\n * @param offsetDistanceOrOptions offset distance (positive to left of the instance curve), or options object\r\n */\r\n public override constructOffsetXY(offsetDistanceOrOptions: number | OffsetOptions): CurvePrimitive | CurvePrimitive[] | undefined {\r\n const options = OffsetOptions.create(offsetDistanceOrOptions);\r\n const handler = new CurveOffsetXYHandler(this, options.leftOffsetDistance);\r\n this.emitStrokableParts(handler, options.strokeOptions);\r\n return handler.claimResult();\r\n }\r\n /** extend the range by the strokes of the spiral */\r\n public override extendRange(rangeToExtend: Range3d, transform?: Transform): void {\r\n const myRange = this.rangeBetweenFractions (0.0, 1.0, transform);\r\n rangeToExtend.extendRange (myRange);\r\n }\r\n\r\n /** return the range of spiral between fractions of the activeStrokes.\r\n * * Use activeStrokes point count times interval factor for initial evaluation count, but do at least 5\r\n */\r\n public override rangeBetweenFractions(fractionA: number, fractionB: number, transform?: Transform): Range3d {\r\n const strokes = this.activeStrokes;\r\n if (undefined === strokes)\r\n return Range3d.createNull ();\r\n let count = Math.ceil (strokes.numPoints() * Math.abs (fractionB - fractionA));\r\n count = Geometry.clamp (5, count, 30);\r\n return this.rangeBetweenFractionsByCount (fractionA, fractionB, count, transform, 0.5);\r\n }\r\n}\r\n"]}
|
|
@@ -16,13 +16,42 @@ export declare class GrowableBlockedArray {
|
|
|
16
16
|
* * If viewing the array as a two dimensional array, this is the row size.
|
|
17
17
|
*/
|
|
18
18
|
protected _blockSize: number;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* multiplier used by ensureBlockCapacity to expand requested reallocation size
|
|
21
|
+
*/
|
|
22
|
+
protected _growthFactor: number;
|
|
23
|
+
/**
|
|
24
|
+
* Construct an array whose contents are in blocked (row-major) order, possibly with extra capacity.
|
|
25
|
+
* * Total capacity is `this._data.length`
|
|
26
|
+
* * Actual in-use count is `this._inUse * this._blockSize`
|
|
27
|
+
* @param blockSize number of entries in each block, i.e., row size
|
|
28
|
+
* @param initialBlocks initial capacity in blocks (default 8)
|
|
29
|
+
* @param growthFactor used by ensureBlockCapacity to expand requested reallocation size (default 1.5)
|
|
30
|
+
*/
|
|
31
|
+
constructor(blockSize: number, initialBlocks?: number, growthFactor?: number);
|
|
32
|
+
/** Copy data from source array. Does not reallocate or change active block count.
|
|
33
|
+
* @param source array to copy from
|
|
34
|
+
* @param sourceCount copy the first sourceCount blocks; all blocks if undefined
|
|
35
|
+
* @param destOffset copy to instance array starting at this block index; zero if undefined
|
|
36
|
+
* @return count and offset of blocks copied
|
|
37
|
+
*/
|
|
38
|
+
protected copyData(source: Float64Array | number[], sourceCount?: number, destOffset?: number): {
|
|
39
|
+
count: number;
|
|
40
|
+
offset: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Make a copy of the (active) blocks in this array.
|
|
44
|
+
* (The clone does NOT get excess capacity)
|
|
45
|
+
*/
|
|
46
|
+
clone(): GrowableBlockedArray;
|
|
47
|
+
/** computed property: length (in blocks, not doubles) */
|
|
48
|
+
get length(): number;
|
|
20
49
|
/** computed property: length (in blocks, not doubles) */
|
|
21
50
|
get numBlocks(): number;
|
|
22
51
|
/** property: number of data values per block */
|
|
23
52
|
get numPerBlock(): number;
|
|
24
53
|
/**
|
|
25
|
-
* Return a single value indexed within a block
|
|
54
|
+
* Return a single value indexed within a block. Indices are unchecked.
|
|
26
55
|
* @param blockIndex index of block to read
|
|
27
56
|
* @param indexInBlock offset within the block
|
|
28
57
|
*/
|
|
@@ -32,7 +61,7 @@ export declare class GrowableBlockedArray {
|
|
|
32
61
|
/** Return the capacity in blocks (not doubles) */
|
|
33
62
|
blockCapacity(): number;
|
|
34
63
|
/** ensure capacity (in blocks, not doubles) */
|
|
35
|
-
ensureBlockCapacity(blockCapacity: number): void;
|
|
64
|
+
ensureBlockCapacity(blockCapacity: number, applyGrowthFactor?: boolean): void;
|
|
36
65
|
/** Add a new block of data.
|
|
37
66
|
* * If newData has fewer than numPerBlock entries, the remaining part of the new block is zeros.
|
|
38
67
|
* * If newData has more entries, only the first numPerBlock are taken.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GrowableBlockedArray.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/GrowableBlockedArray.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;GAIG;AACH,qBAAa,oBAAoB;IAC/B,+CAA+C;IAC/C,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC;IAC9B,6CAA6C;IAC7C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"GrowableBlockedArray.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/GrowableBlockedArray.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;GAIG;AACH,qBAAa,oBAAoB;IAC/B,+CAA+C;IAC/C,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC;IAC9B,6CAA6C;IAC7C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC;IAEhC;;;;;;;OAOG;gBACgB,SAAS,EAAE,MAAM,EAAE,aAAa,GAAE,MAAU,EAAE,YAAY,CAAC,EAAE,MAAM;IAOtF;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC;IA2B/H;;;OAGG;IACI,KAAK,IAAI,oBAAoB;IAOpC,yDAAyD;IACzD,IAAW,MAAM,IAAI,MAAM,CAAwB;IACnD,yDAAyD;IACzD,IAAW,SAAS,IAAI,MAAM,CAAwB;IACtD,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|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Construct an array whose contents are in blocked (row-major) order, possibly with extra capacity.
|
|
16
|
+
* * Total capacity is `this._data.length`
|
|
17
|
+
* * Actual in-use count is `this._inUse * this._blockSize`
|
|
18
|
+
* @param blockSize number of entries in each block, i.e., row size
|
|
19
|
+
* @param initialBlocks initial capacity in blocks (default 8)
|
|
20
|
+
* @param growthFactor used by ensureBlockCapacity to expand requested reallocation size (default 1.5)
|
|
21
|
+
*/
|
|
22
|
+
constructor(blockSize, initialBlocks = 8, growthFactor) {
|
|
19
23
|
this._data = new Float64Array(initialBlocks * blockSize);
|
|
20
24
|
this._inUse = 0;
|
|
21
|
-
this._blockSize = blockSize;
|
|
25
|
+
this._blockSize = blockSize > 0 ? blockSize : 1;
|
|
26
|
+
this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;
|
|
27
|
+
}
|
|
28
|
+
/** Copy data from source array. Does not reallocate or change active block count.
|
|
29
|
+
* @param source array to copy from
|
|
30
|
+
* @param sourceCount copy the first sourceCount blocks; all blocks if undefined
|
|
31
|
+
* @param destOffset copy to instance array starting at this block index; zero if undefined
|
|
32
|
+
* @return count and offset of blocks copied
|
|
33
|
+
*/
|
|
34
|
+
copyData(source, sourceCount, destOffset) {
|
|
35
|
+
// validate inputs and convert from blocks to entries
|
|
36
|
+
let myOffset = (undefined !== destOffset) ? destOffset * this.numPerBlock : 0;
|
|
37
|
+
if (myOffset < 0)
|
|
38
|
+
myOffset = 0;
|
|
39
|
+
if (myOffset >= this._data.length)
|
|
40
|
+
return { count: 0, offset: 0 };
|
|
41
|
+
let myCount = (undefined !== sourceCount) ? sourceCount * this.numPerBlock : source.length;
|
|
42
|
+
if (myCount > 0) {
|
|
43
|
+
if (myCount > source.length)
|
|
44
|
+
myCount = source.length;
|
|
45
|
+
if (myOffset + myCount > this._data.length)
|
|
46
|
+
myCount = this._data.length - myOffset;
|
|
47
|
+
if (myCount % this.numPerBlock !== 0)
|
|
48
|
+
myCount -= myCount % this.numPerBlock;
|
|
49
|
+
}
|
|
50
|
+
if (myCount <= 0)
|
|
51
|
+
return { count: 0, offset: 0 };
|
|
52
|
+
if (myCount === source.length)
|
|
53
|
+
this._data.set(source, myOffset);
|
|
54
|
+
else if (source instanceof Float64Array)
|
|
55
|
+
this._data.set(source.subarray(0, myCount), myOffset);
|
|
56
|
+
else
|
|
57
|
+
this._data.set(source.slice(0, myCount), myOffset);
|
|
58
|
+
return { count: myCount / this.numPerBlock, offset: myOffset / this.numPerBlock };
|
|
22
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Make a copy of the (active) blocks in this array.
|
|
62
|
+
* (The clone does NOT get excess capacity)
|
|
63
|
+
*/
|
|
64
|
+
clone() {
|
|
65
|
+
const newBlocks = new GrowableBlockedArray(this.numPerBlock, this.numBlocks, this._growthFactor);
|
|
66
|
+
newBlocks.copyData(this._data, this.numBlocks);
|
|
67
|
+
newBlocks._inUse = this.numBlocks;
|
|
68
|
+
return newBlocks;
|
|
69
|
+
}
|
|
70
|
+
/** computed property: length (in blocks, not doubles) */
|
|
71
|
+
get length() { return this._inUse; }
|
|
23
72
|
/** computed property: length (in blocks, not doubles) */
|
|
24
73
|
get numBlocks() { return this._inUse; }
|
|
25
74
|
/** property: number of data values per block */
|
|
26
75
|
get numPerBlock() { return this._blockSize; }
|
|
27
76
|
/**
|
|
28
|
-
* Return a single value indexed within a block
|
|
77
|
+
* Return a single value indexed within a block. Indices are unchecked.
|
|
29
78
|
* @param blockIndex index of block to read
|
|
30
79
|
* @param indexInBlock offset within the block
|
|
31
80
|
*/
|
|
@@ -39,13 +88,13 @@ export class GrowableBlockedArray {
|
|
|
39
88
|
return this._data.length / this._blockSize;
|
|
40
89
|
}
|
|
41
90
|
/** ensure capacity (in blocks, not doubles) */
|
|
42
|
-
ensureBlockCapacity(blockCapacity) {
|
|
91
|
+
ensureBlockCapacity(blockCapacity, applyGrowthFactor = true) {
|
|
43
92
|
if (blockCapacity > this.blockCapacity()) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.
|
|
93
|
+
if (applyGrowthFactor)
|
|
94
|
+
blockCapacity *= this._growthFactor;
|
|
95
|
+
const prevData = this._data;
|
|
96
|
+
this._data = new Float64Array(blockCapacity * this._blockSize);
|
|
97
|
+
this.copyData(prevData, this._inUse);
|
|
49
98
|
}
|
|
50
99
|
}
|
|
51
100
|
/** Add a new block of data.
|
|
@@ -70,7 +119,7 @@ export class GrowableBlockedArray {
|
|
|
70
119
|
newBlockIndex() {
|
|
71
120
|
const index = this._blockSize * this._inUse;
|
|
72
121
|
if ((index + 1) > this._data.length)
|
|
73
|
-
this.ensureBlockCapacity(1 +
|
|
122
|
+
this.ensureBlockCapacity(1 + this._inUse);
|
|
74
123
|
this._inUse++;
|
|
75
124
|
for (let i = index; i < index + this._blockSize; i++)
|
|
76
125
|
this._data[i] = 0.0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GrowableBlockedArray.js","sourceRoot":"","sources":["../../../src/geometry3d/GrowableBlockedArray.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAS/B,YAAmB,SAAiB,EAAE,gBAAwB,CAAC;QAC7D;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IACD,yDAAyD;IACzD,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACtD,gDAAgD;IAChD,IAAW,WAAW,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5D;;;;OAIG;IACI,cAAc,CAAC,UAAkB,E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uB,CAAC,WAAW,CAAC,CAAC;QACnD,IAAI,EAAE,GAAG,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QACnD,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;YACxC,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5B,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;SACb;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;IAED,2HAA2H;IACpH,wBAAwB,CAAC,WAAmB,EAAE,WAAmB,EAAE,MAAc,EAAE,IAAY;QACpG,IAAI,EAAE,GAAG,GAAG,CAAC;QACb,MAAM,EAAE,GAAG,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QACrD,MAAM,EAAE,GAAG,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QACrD,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;YAClC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YAChC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;SACb;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ArraysAndInterfaces\r\n */\r\n\r\nimport { BlockComparisonFunction } from \"./GrowableFloat64Array\";\r\n\r\n/**\r\n * Array of contiguous doubles, indexed by block number and index within block.\r\n * * This is essentially a rectangular matrix (two dimensional array), with each block being a row of the matrix.\r\n * @public\r\n */\r\nexport class GrowableBlockedArray {\r\n /** underlying contiguous, oversized buffer. */\r\n protected _data: Float64Array;\r\n /** Number of blocks (matrix rows) in use. */\r\n protected _inUse: number;\r\n /** number of numbers per block in the array.\r\n * * If viewing the array as a two dimensional array, this is the row size.\r\n */\r\n protected _blockSize: number; // positive integer !!!\r\n public constructor(blockSize: number, initialBlocks: number = 8) {\r\n /** array contents in blocked (row-major) order, possibly with extra capacity\r\n * Total capacity is `this._data.length`\r\n * Actual in-use count is `this._inUse * this._blockSize`\r\n */\r\n this._data = new Float64Array(initialBlocks * blockSize);\r\n this._inUse = 0;\r\n this._blockSize = blockSize;\r\n }\r\n /** computed property: length (in blocks, not doubles) */\r\n public get numBlocks(): number { return this._inUse; }\r\n /** property: number of data values per block */\r\n public get numPerBlock(): number { return this._blockSize; }\r\n /**\r\n * Return a single value indexed within a block\r\n * @param blockIndex index of block to read\r\n * @param indexInBlock offset within the block\r\n */\r\n public getWithinBlock(blockIndex: number, indexWithinBlock: number): number {\r\n return this._data[blockIndex * this._blockSize + indexWithinBlock];\r\n }\r\n /** clear the block count to zero, but maintain the allocated memory */\r\n public clear() { this._inUse = 0; }\r\n /** Return the capacity in blocks (not doubles) */\r\n public blockCapacity() {\r\n return this._data.length / this._blockSize;\r\n }\r\n /** ensure capacity (in blocks, not doubles) */\r\n public ensureBlockCapacity(blockCapacity: number) {\r\n if (blockCapacity > this.blockCapacity()) {\r\n const newData = new Float64Array(blockCapacity * this._blockSize);\r\n for (let i = 0; i < this._data.length; i++) {\r\n newData[i] = this._data[i];\r\n }\r\n this._data = newData;\r\n }\r\n }\r\n /** Add a new block of data.\r\n * * If newData has fewer than numPerBlock entries, the remaining part of the new block is zeros.\r\n * * If newData has more entries, only the first numPerBlock are taken.\r\n */\r\n public addBlock(newData: number[]) {\r\n const k0 = this.newBlockIndex();\r\n let numValue = newData.length;\r\n if (numValue > this._blockSize)\r\n numValue = this._blockSize;\r\n for (let i = 0; i < numValue; i++)\r\n this._data[k0 + i] = newData[i];\r\n }\r\n /**\r\n * Return the starting index of a block of (zero-initialized) doubles at the end.\r\n *\r\n * * this.data is reallocated if needed to include the new block.\r\n * * The inUse count is incremented to include the new block.\r\n * * The returned block is an index to the Float64Array (not a block index)\r\n */\r\n protected newBlockIndex(): number {\r\n const index = this._blockSize * this._inUse;\r\n if ((index + 1) > this._data.length)\r\n this.ensureBlockCapacity(1 + 2 * this._inUse);\r\n this._inUse++;\r\n for (let i = index; i < index + this._blockSize; i++)\r\n this._data[i] = 0.0;\r\n return index;\r\n }\r\n /** reduce the block count by one. */\r\n public popBlock() {\r\n if (this._inUse > 0)\r\n this._inUse--;\r\n }\r\n /** convert a block index to the simple index to the underlying Float64Array. */\r\n protected blockIndexToDoubleIndex(blockIndex: number) { return this._blockSize * blockIndex; }\r\n /** Access a single double at offset within a block, with index checking and return undefined if indexing is invalid. */\r\n public checkedComponent(blockIndex: number, componentIndex: number): number | undefined {\r\n if (blockIndex >= this._inUse || blockIndex < 0 || componentIndex < 0 || componentIndex >= this._blockSize)\r\n return undefined;\r\n return this._data[this._blockSize * blockIndex + componentIndex];\r\n }\r\n /** Access a single double at offset within a block. This has no index checking. */\r\n public component(blockIndex: number, componentIndex: number): number {\r\n return this._data[this._blockSize * blockIndex + componentIndex];\r\n }\r\n /** compare two blocks in simple lexical order.\r\n * @param data data array\r\n * @param blockSize number of items to compare\r\n * @param ia raw index (not block index) of first block\r\n * @param ib raw index (not block index) of second block\r\n */\r\n public static compareLexicalBlock(data: Float64Array, blockSize: number, ia: number, ib: number): number {\r\n let ax = 0;\r\n let bx = 0;\r\n for (let i = 0; i < blockSize; i++) {\r\n ax = data[ia + i];\r\n bx = data[ib + i];\r\n if (ax > bx) return 1;\r\n if (ax < bx) return -1;\r\n }\r\n return ia - ib; // so original order is maintained among duplicates !!!!\r\n }\r\n /** Return an array of block indices sorted per compareLexicalBlock function */\r\n public sortIndicesLexical(compareBlocks: BlockComparisonFunction = GrowableBlockedArray.compareLexicalBlock): Uint32Array {\r\n const n = this._inUse;\r\n // let numCompare = 0;\r\n const result = new Uint32Array(n);\r\n const data = this._data;\r\n const blockSize = this._blockSize;\r\n for (let i = 0; i < n; i++)result[i] = i;\r\n result.sort(\r\n (blockIndexA: number, blockIndexB: number) => {\r\n // numCompare++;\r\n return compareBlocks(data, blockSize, blockIndexA * blockSize, blockIndexB * blockSize);\r\n });\r\n // console.log (n, numCompare);\r\n return result;\r\n }\r\n /** Return the distance (hypotenuse=sqrt(summed squares)) between indicated blocks */\r\n public distanceBetweenBlocks(blockIndexA: number, blockIndexB: number): number {\r\n let dd = 0.0;\r\n let iA = this.blockIndexToDoubleIndex(blockIndexA);\r\n let iB = this.blockIndexToDoubleIndex(blockIndexB);\r\n let a = 0;\r\n const data = this._data;\r\n for (let i = 0; i < this._blockSize; i++) {\r\n a = data[iA++] - data[iB++];\r\n dd += a * a;\r\n }\r\n return Math.sqrt(dd);\r\n }\r\n\r\n /** Return the distance (hypotenuse=sqrt(summed squares)) between block entries `iBegin <= i < iEnd` of indicated blocks */\r\n public distanceBetweenSubBlocks(blockIndexA: number, blockIndexB: number, iBegin: number, iEnd: number): number {\r\n let dd = 0.0;\r\n const iA = this.blockIndexToDoubleIndex(blockIndexA);\r\n const iB = this.blockIndexToDoubleIndex(blockIndexB);\r\n let a = 0;\r\n const data = this._data;\r\n for (let i = iBegin; i < iEnd; i++) {\r\n a = data[iA + i] - data[iB + i];\r\n dd += a * a;\r\n }\r\n return Math.sqrt(dd);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"GrowableBlockedArray.js","sourceRoot":"","sources":["../../../src/geometry3d/GrowableBlockedArray.ts"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ACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ArraysAndInterfaces\r\n */\r\n\r\nimport { BlockComparisonFunction } from \"./GrowableFloat64Array\";\r\n\r\n/**\r\n * Array of contiguous doubles, indexed by block number and index within block.\r\n * * This is essentially a rectangular matrix (two dimensional array), with each block being a row of the matrix.\r\n * @public\r\n */\r\nexport class GrowableBlockedArray {\r\n /** underlying contiguous, oversized buffer. */\r\n protected _data: Float64Array;\r\n /** Number of blocks (matrix rows) in use. */\r\n protected _inUse: number;\r\n /** number of numbers per block in the array.\r\n * * If viewing the array as a two dimensional array, this is the row size.\r\n */\r\n protected _blockSize: number; // positive integer !!!\r\n /**\r\n * multiplier used by ensureBlockCapacity to expand requested reallocation size\r\n */\r\n protected _growthFactor: number;\r\n\r\n /**\r\n * Construct an array whose contents are in blocked (row-major) order, possibly with extra capacity.\r\n * * Total capacity is `this._data.length`\r\n * * Actual in-use count is `this._inUse * this._blockSize`\r\n * @param blockSize number of entries in each block, i.e., row size\r\n * @param initialBlocks initial capacity in blocks (default 8)\r\n * @param growthFactor used by ensureBlockCapacity to expand requested reallocation size (default 1.5)\r\n */\r\n public constructor(blockSize: number, initialBlocks: number = 8, growthFactor?: number) {\r\n this._data = new Float64Array(initialBlocks * blockSize);\r\n this._inUse = 0;\r\n this._blockSize = blockSize > 0 ? blockSize : 1;\r\n this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;\r\n }\r\n\r\n /** Copy data from source array. Does not reallocate or change active block count.\r\n * @param source array to copy from\r\n * @param sourceCount copy the first sourceCount blocks; all blocks if undefined\r\n * @param destOffset copy to instance array starting at this block index; zero if undefined\r\n * @return count and offset of blocks copied\r\n */\r\n protected copyData(source: Float64Array | number[], sourceCount?: number, destOffset?: number): {count: number, offset: number} {\r\n // validate inputs and convert from blocks to entries\r\n let myOffset = (undefined !== destOffset) ? destOffset * this.numPerBlock : 0;\r\n if (myOffset < 0)\r\n myOffset = 0;\r\n if (myOffset >= this._data.length)\r\n return {count: 0, offset: 0};\r\n let myCount = (undefined !== sourceCount) ? sourceCount * this.numPerBlock : source.length;\r\n if (myCount > 0) {\r\n if (myCount > source.length)\r\n myCount = source.length;\r\n if (myOffset + myCount > this._data.length)\r\n myCount = this._data.length - myOffset;\r\n if (myCount % this.numPerBlock !== 0)\r\n myCount -= myCount % this.numPerBlock;\r\n }\r\n if (myCount <= 0)\r\n return {count: 0, offset: 0};\r\n if (myCount === source.length)\r\n this._data.set(source, myOffset);\r\n else if (source instanceof Float64Array)\r\n this._data.set(source.subarray(0, myCount), myOffset);\r\n else\r\n this._data.set(source.slice(0, myCount), myOffset);\r\n return {count: myCount / this.numPerBlock, offset: myOffset / this.numPerBlock};\r\n }\r\n\r\n /**\r\n * Make a copy of the (active) blocks in this array.\r\n * (The clone does NOT get excess capacity)\r\n */\r\n public clone(): GrowableBlockedArray {\r\n const newBlocks = new GrowableBlockedArray(this.numPerBlock, this.numBlocks, this._growthFactor);\r\n newBlocks.copyData(this._data, this.numBlocks);\r\n newBlocks._inUse = this.numBlocks;\r\n return newBlocks;\r\n }\r\n\r\n /** computed property: length (in blocks, not doubles) */\r\n public get length(): number { return this._inUse; }\r\n /** computed property: length (in blocks, not doubles) */\r\n public get numBlocks(): number { return this._inUse; }\r\n /** property: number of data values per block */\r\n public get numPerBlock(): number { return this._blockSize; }\r\n /**\r\n * Return a single value indexed within a block. Indices are unchecked.\r\n * @param blockIndex index of block to read\r\n * @param indexInBlock offset within the block\r\n */\r\n public getWithinBlock(blockIndex: number, indexWithinBlock: number): number {\r\n return this._data[blockIndex * this._blockSize + indexWithinBlock];\r\n }\r\n /** clear the block count to zero, but maintain the allocated memory */\r\n public clear() { this._inUse = 0; }\r\n /** Return the capacity in blocks (not doubles) */\r\n public blockCapacity() {\r\n return this._data.length / this._blockSize;\r\n }\r\n /** ensure capacity (in blocks, not doubles) */\r\n public ensureBlockCapacity(blockCapacity: number, applyGrowthFactor: boolean = true) {\r\n if (blockCapacity > this.blockCapacity()) {\r\n if (applyGrowthFactor)\r\n blockCapacity *= this._growthFactor;\r\n const prevData = this._data;\r\n this._data = new Float64Array(blockCapacity * this._blockSize);\r\n this.copyData(prevData, this._inUse);\r\n }\r\n }\r\n /** Add a new block of data.\r\n * * If newData has fewer than numPerBlock entries, the remaining part of the new block is zeros.\r\n * * If newData has more entries, only the first numPerBlock are taken.\r\n */\r\n public addBlock(newData: number[]) {\r\n const k0 = this.newBlockIndex();\r\n let numValue = newData.length;\r\n if (numValue > this._blockSize)\r\n numValue = this._blockSize;\r\n for (let i = 0; i < numValue; i++)\r\n this._data[k0 + i] = newData[i];\r\n }\r\n /**\r\n * Return the starting index of a block of (zero-initialized) doubles at the end.\r\n *\r\n * * this.data is reallocated if needed to include the new block.\r\n * * The inUse count is incremented to include the new block.\r\n * * The returned block is an index to the Float64Array (not a block index)\r\n */\r\n protected newBlockIndex(): number {\r\n const index = this._blockSize * this._inUse;\r\n if ((index + 1) > this._data.length)\r\n this.ensureBlockCapacity(1 + this._inUse);\r\n this._inUse++;\r\n for (let i = index; i < index + this._blockSize; i++)\r\n this._data[i] = 0.0;\r\n return index;\r\n }\r\n /** reduce the block count by one. */\r\n public popBlock() {\r\n if (this._inUse > 0)\r\n this._inUse--;\r\n }\r\n /** convert a block index to the simple index to the underlying Float64Array. */\r\n protected blockIndexToDoubleIndex(blockIndex: number) { return this._blockSize * blockIndex; }\r\n /** Access a single double at offset within a block, with index checking and return undefined if indexing is invalid. */\r\n public checkedComponent(blockIndex: number, componentIndex: number): number | undefined {\r\n if (blockIndex >= this._inUse || blockIndex < 0 || componentIndex < 0 || componentIndex >= this._blockSize)\r\n return undefined;\r\n return this._data[this._blockSize * blockIndex + componentIndex];\r\n }\r\n /** Access a single double at offset within a block. This has no index checking. */\r\n public component(blockIndex: number, componentIndex: number): number {\r\n return this._data[this._blockSize * blockIndex + componentIndex];\r\n }\r\n /** compare two blocks in simple lexical order.\r\n * @param data data array\r\n * @param blockSize number of items to compare\r\n * @param ia raw index (not block index) of first block\r\n * @param ib raw index (not block index) of second block\r\n */\r\n public static compareLexicalBlock(data: Float64Array, blockSize: number, ia: number, ib: number): number {\r\n let ax = 0;\r\n let bx = 0;\r\n for (let i = 0; i < blockSize; i++) {\r\n ax = data[ia + i];\r\n bx = data[ib + i];\r\n if (ax > bx) return 1;\r\n if (ax < bx) return -1;\r\n }\r\n return ia - ib; // so original order is maintained among duplicates !!!!\r\n }\r\n /** Return an array of block indices sorted per compareLexicalBlock function */\r\n public sortIndicesLexical(compareBlocks: BlockComparisonFunction = GrowableBlockedArray.compareLexicalBlock): Uint32Array {\r\n const n = this._inUse;\r\n // let numCompare = 0;\r\n const result = new Uint32Array(n);\r\n const data = this._data;\r\n const blockSize = this._blockSize;\r\n for (let i = 0; i < n; i++)result[i] = i;\r\n result.sort(\r\n (blockIndexA: number, blockIndexB: number) => {\r\n // numCompare++;\r\n return compareBlocks(data, blockSize, blockIndexA * blockSize, blockIndexB * blockSize);\r\n });\r\n // console.log (n, numCompare);\r\n return result;\r\n }\r\n /** Return the distance (hypotenuse=sqrt(summed squares)) between indicated blocks */\r\n public distanceBetweenBlocks(blockIndexA: number, blockIndexB: number): number {\r\n let dd = 0.0;\r\n let iA = this.blockIndexToDoubleIndex(blockIndexA);\r\n let iB = this.blockIndexToDoubleIndex(blockIndexB);\r\n let a = 0;\r\n const data = this._data;\r\n for (let i = 0; i < this._blockSize; i++) {\r\n a = data[iA++] - data[iB++];\r\n dd += a * a;\r\n }\r\n return Math.sqrt(dd);\r\n }\r\n\r\n /** Return the distance (hypotenuse=sqrt(summed squares)) between block entries `iBegin <= i < iEnd` of indicated blocks */\r\n public distanceBetweenSubBlocks(blockIndexA: number, blockIndexB: number, iBegin: number, iEnd: number): number {\r\n let dd = 0.0;\r\n const iA = this.blockIndexToDoubleIndex(blockIndexA);\r\n const iB = this.blockIndexToDoubleIndex(blockIndexB);\r\n let a = 0;\r\n const data = this._data;\r\n for (let i = iBegin; i < iEnd; i++) {\r\n a = data[iA + i] - data[iB + i];\r\n dd += a * a;\r\n }\r\n return Math.sqrt(dd);\r\n }\r\n}\r\n"]}
|
|
@@ -23,7 +23,22 @@ export declare type BlockComparisonFunction = (data: Float64Array, blockSize: nu
|
|
|
23
23
|
export declare class GrowableFloat64Array {
|
|
24
24
|
private _data;
|
|
25
25
|
private _inUse;
|
|
26
|
-
|
|
26
|
+
private _growthFactor;
|
|
27
|
+
/** Construct a GrowableFloat64Array.
|
|
28
|
+
* @param initialCapacity initial capacity (default 8)
|
|
29
|
+
* @param growthFactor used by ensureCapacity to expand requested reallocation size (default 1.5)
|
|
30
|
+
*/
|
|
31
|
+
constructor(initialCapacity?: number, growthFactor?: number);
|
|
32
|
+
/** Copy data from source array. Does not reallocate or change active entry count.
|
|
33
|
+
* @param source array to copy from
|
|
34
|
+
* @param sourceCount copy the first sourceCount entries; all entries if undefined
|
|
35
|
+
* @param destOffset copy to instance array starting at this index; zero if undefined
|
|
36
|
+
* @return count and offset of entries copied
|
|
37
|
+
*/
|
|
38
|
+
protected copyData(source: Float64Array | number[], sourceCount?: number, destOffset?: number): {
|
|
39
|
+
count: number;
|
|
40
|
+
offset: number;
|
|
41
|
+
};
|
|
27
42
|
/**
|
|
28
43
|
* Create a GrowableFloat64Array with given contents.
|
|
29
44
|
* @param contents data to copy into the array
|
|
@@ -74,7 +89,7 @@ export declare class GrowableFloat64Array {
|
|
|
74
89
|
* @param data array of values to push
|
|
75
90
|
*/
|
|
76
91
|
pushArray(data: Float64Array | number[]): void;
|
|
77
|
-
/** Push
|
|
92
|
+
/** Push `numToCopy` consecutive values starting at `copyFromIndex`. */
|
|
78
93
|
pushBlockCopy(copyFromIndex: number, numToCopy: number): void;
|
|
79
94
|
/** Clear the array to 0 length. The underlying memory remains allocated for reuse. */
|
|
80
95
|
clear(): void;
|
|
@@ -84,14 +99,15 @@ export declare class GrowableFloat64Array {
|
|
|
84
99
|
*/
|
|
85
100
|
capacity(): number;
|
|
86
101
|
/**
|
|
87
|
-
* * If the capacity (Float64Array length) is less than or equal to the requested newCapacity, do nothing
|
|
88
|
-
* * If the requested newCapacity is larger than the existing capacity, reallocate
|
|
89
|
-
* @param newCapacity
|
|
102
|
+
* * If the capacity (Float64Array length) is less than or equal to the requested newCapacity, do nothing.
|
|
103
|
+
* * If the requested newCapacity is larger than the existing capacity, reallocate to larger capacity, and copy existing values.
|
|
104
|
+
* @param newCapacity size of new array
|
|
105
|
+
* @param applyGrowthFactor whether to apply the growth factor to newCapacity when reallocating
|
|
90
106
|
*/
|
|
91
|
-
ensureCapacity(newCapacity: number): void;
|
|
107
|
+
ensureCapacity(newCapacity: number, applyGrowthFactor?: boolean): void;
|
|
92
108
|
/**
|
|
93
|
-
* * If newLength is less than current
|
|
94
|
-
* * If newLength is greater,
|
|
109
|
+
* * If newLength is less than current length, just reset current length to newLength, effectively trimming active entries but preserving original capacity.
|
|
110
|
+
* * If newLength is greater than current length, reallocate to (exactly) newLength, copy existing entries, and pad with padValue up to newLength.
|
|
95
111
|
* @param newLength new data count
|
|
96
112
|
* @param padValue value to use for padding if the length increases.
|
|
97
113
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GrowableFloat64Array.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/GrowableFloat64Array.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;GAGG;AACH,oBAAY,4BAA4B,GAAG,oBAAoB,GAAG,SAAS,CAAC;AAC5E;;;GAGG;AACH,oBAAY,uBAAuB,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC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;;OAIG;IACI,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAGhC;;;;OAIG;IACI,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAMhC;;;OAGG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM;IAK1B;;;OAGG;IACI,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,EAAE;IAK9C,uEAAuE;IAChE,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAO7D,uFAAuF;IAChF,KAAK;IAGZ;;;OAGG;IACI,QAAQ;IAGf;;;;;OAKG;IACI,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,iBAAiB,GAAE,OAAc;IAS5E;;;;;OAKG;IACI,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU;IASrD;;;;OAIG;IACI,GAAG;IAOV,4CAA4C;IACrC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAG9C,sDAAsD;IAC/C,KAAK;IAGZ,oDAAoD;IAC7C,IAAI;IAGX,2BAA2B;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAI5C;;;;OAIG;IACI,IAAI,CAAC,aAAa,GAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,MAAqC;IAapF;;;;;OAKG;IACI,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAa9C;;;OAGG;IACI,0BAA0B,CAAC,SAAS,GAAE,MAAY;CAmB1D"}
|
|
@@ -12,20 +12,53 @@
|
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
14
|
export class GrowableFloat64Array {
|
|
15
|
-
|
|
15
|
+
/** Construct a GrowableFloat64Array.
|
|
16
|
+
* @param initialCapacity initial capacity (default 8)
|
|
17
|
+
* @param growthFactor used by ensureCapacity to expand requested reallocation size (default 1.5)
|
|
18
|
+
*/
|
|
19
|
+
constructor(initialCapacity = 8, growthFactor) {
|
|
16
20
|
this._data = new Float64Array(initialCapacity);
|
|
17
21
|
this._inUse = 0;
|
|
22
|
+
this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;
|
|
23
|
+
}
|
|
24
|
+
/** Copy data from source array. Does not reallocate or change active entry count.
|
|
25
|
+
* @param source array to copy from
|
|
26
|
+
* @param sourceCount copy the first sourceCount entries; all entries if undefined
|
|
27
|
+
* @param destOffset copy to instance array starting at this index; zero if undefined
|
|
28
|
+
* @return count and offset of entries copied
|
|
29
|
+
*/
|
|
30
|
+
copyData(source, sourceCount, destOffset) {
|
|
31
|
+
let myOffset = destOffset !== null && destOffset !== void 0 ? destOffset : 0;
|
|
32
|
+
if (myOffset < 0)
|
|
33
|
+
myOffset = 0;
|
|
34
|
+
if (myOffset >= this._data.length)
|
|
35
|
+
return { count: 0, offset: 0 };
|
|
36
|
+
let myCount = sourceCount !== null && sourceCount !== void 0 ? sourceCount : source.length;
|
|
37
|
+
if (myCount > 0) {
|
|
38
|
+
if (myCount > source.length)
|
|
39
|
+
myCount = source.length;
|
|
40
|
+
if (myOffset + myCount > this._data.length)
|
|
41
|
+
myCount = this._data.length - myOffset;
|
|
42
|
+
}
|
|
43
|
+
if (myCount <= 0)
|
|
44
|
+
return { count: 0, offset: 0 };
|
|
45
|
+
if (myCount === source.length)
|
|
46
|
+
this._data.set(source, myOffset);
|
|
47
|
+
else if (source instanceof Float64Array)
|
|
48
|
+
this._data.set(source.subarray(0, myCount), myOffset);
|
|
49
|
+
else
|
|
50
|
+
this._data.set(source.slice(0, myCount), myOffset);
|
|
51
|
+
return { count: myCount, offset: myOffset };
|
|
18
52
|
}
|
|
19
53
|
/**
|
|
20
54
|
* Create a GrowableFloat64Array with given contents.
|
|
21
55
|
* @param contents data to copy into the array
|
|
22
56
|
*/
|
|
23
57
|
static create(contents) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return result;
|
|
58
|
+
const out = new GrowableFloat64Array(contents.length);
|
|
59
|
+
out.copyData(contents);
|
|
60
|
+
out._inUse = contents.length;
|
|
61
|
+
return out;
|
|
29
62
|
}
|
|
30
63
|
/** sort-compatible comparison.
|
|
31
64
|
* * Returns `(a-b)` which is
|
|
@@ -41,11 +74,9 @@ export class GrowableFloat64Array {
|
|
|
41
74
|
* * optionally trimmed capacity to the active length or replicate the capacity and unused space.
|
|
42
75
|
*/
|
|
43
76
|
clone(maintainExcessCapacity = false) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < n; i++)
|
|
48
|
-
out.push(data[i]);
|
|
77
|
+
const out = new GrowableFloat64Array(maintainExcessCapacity ? this.capacity() : this._inUse);
|
|
78
|
+
out.copyData(this._data, this._inUse);
|
|
79
|
+
out._inUse = this._inUse;
|
|
49
80
|
return out;
|
|
50
81
|
}
|
|
51
82
|
/**
|
|
@@ -86,41 +117,30 @@ export class GrowableFloat64Array {
|
|
|
86
117
|
* @param toPush value to append to the active array.
|
|
87
118
|
*/
|
|
88
119
|
push(toPush) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// Make new array (double size), copy values, then push toPush
|
|
95
|
-
const newData = new Float64Array(4 + this._inUse * 2);
|
|
96
|
-
for (let i = 0; i < this._inUse; i++) {
|
|
97
|
-
newData[i] = this._data[i];
|
|
98
|
-
}
|
|
99
|
-
this._data = newData;
|
|
100
|
-
this._data[this._inUse] = toPush;
|
|
101
|
-
this._inUse++;
|
|
102
|
-
}
|
|
120
|
+
this.ensureCapacity(this._inUse + 1);
|
|
121
|
+
this._data[this._inUse] = toPush;
|
|
122
|
+
this._inUse++;
|
|
103
123
|
}
|
|
104
124
|
/**
|
|
105
125
|
* Push each value from an array.
|
|
106
126
|
* @param data array of values to push
|
|
107
127
|
*/
|
|
108
128
|
pushArray(data) {
|
|
109
|
-
|
|
110
|
-
|
|
129
|
+
this.ensureCapacity(this._inUse + data.length);
|
|
130
|
+
this.copyData(data, data.length, this._inUse);
|
|
131
|
+
this._inUse += data.length;
|
|
111
132
|
}
|
|
112
|
-
/** Push
|
|
133
|
+
/** Push `numToCopy` consecutive values starting at `copyFromIndex`. */
|
|
113
134
|
pushBlockCopy(copyFromIndex, numToCopy) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
135
|
+
if (copyFromIndex >= 0 && copyFromIndex < this._inUse && numToCopy > 0 && copyFromIndex + numToCopy <= this._inUse) {
|
|
136
|
+
this.ensureCapacity(this._inUse + numToCopy);
|
|
137
|
+
this._data.copyWithin(this._inUse, copyFromIndex, copyFromIndex + numToCopy);
|
|
138
|
+
this._inUse += numToCopy;
|
|
139
|
+
}
|
|
119
140
|
}
|
|
120
141
|
/** Clear the array to 0 length. The underlying memory remains allocated for reuse. */
|
|
121
142
|
clear() {
|
|
122
|
-
|
|
123
|
-
this.pop();
|
|
143
|
+
this._inUse = 0;
|
|
124
144
|
}
|
|
125
145
|
/**
|
|
126
146
|
* Returns the number of entries in the supporting Float64Array buffer.
|
|
@@ -130,36 +150,34 @@ export class GrowableFloat64Array {
|
|
|
130
150
|
return this._data.length;
|
|
131
151
|
}
|
|
132
152
|
/**
|
|
133
|
-
* * If the capacity (Float64Array length) is less than or equal to the requested newCapacity, do nothing
|
|
134
|
-
* * If the requested newCapacity is larger than the existing capacity, reallocate
|
|
135
|
-
* @param newCapacity
|
|
153
|
+
* * If the capacity (Float64Array length) is less than or equal to the requested newCapacity, do nothing.
|
|
154
|
+
* * If the requested newCapacity is larger than the existing capacity, reallocate to larger capacity, and copy existing values.
|
|
155
|
+
* @param newCapacity size of new array
|
|
156
|
+
* @param applyGrowthFactor whether to apply the growth factor to newCapacity when reallocating
|
|
136
157
|
*/
|
|
137
|
-
ensureCapacity(newCapacity) {
|
|
158
|
+
ensureCapacity(newCapacity, applyGrowthFactor = true) {
|
|
138
159
|
if (newCapacity > this.capacity()) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.
|
|
160
|
+
if (applyGrowthFactor)
|
|
161
|
+
newCapacity *= this._growthFactor;
|
|
162
|
+
const prevData = this._data;
|
|
163
|
+
this._data = new Float64Array(newCapacity);
|
|
164
|
+
this.copyData(prevData, this._inUse);
|
|
144
165
|
}
|
|
145
166
|
}
|
|
146
167
|
/**
|
|
147
|
-
* * If newLength is less than current
|
|
148
|
-
* * If newLength is greater,
|
|
168
|
+
* * If newLength is less than current length, just reset current length to newLength, effectively trimming active entries but preserving original capacity.
|
|
169
|
+
* * If newLength is greater than current length, reallocate to (exactly) newLength, copy existing entries, and pad with padValue up to newLength.
|
|
149
170
|
* @param newLength new data count
|
|
150
171
|
* @param padValue value to use for padding if the length increases.
|
|
151
172
|
*/
|
|
152
173
|
resize(newLength, padValue = 0) {
|
|
153
|
-
|
|
154
|
-
|
|
174
|
+
if (newLength >= 0 && newLength < this._inUse)
|
|
175
|
+
this._inUse = newLength;
|
|
176
|
+
else if (newLength > this._inUse) {
|
|
177
|
+
this.ensureCapacity(newLength, false);
|
|
178
|
+
this._data.fill(padValue, this._inUse);
|
|
155
179
|
this._inUse = newLength;
|
|
156
|
-
return;
|
|
157
180
|
}
|
|
158
|
-
const oldLength = this._inUse;
|
|
159
|
-
this.ensureCapacity(newLength);
|
|
160
|
-
for (let i = oldLength; i < newLength; i++)
|
|
161
|
-
this._data[i] = padValue;
|
|
162
|
-
this._inUse = newLength;
|
|
163
181
|
}
|
|
164
182
|
/**
|
|
165
183
|
* * Reduce the length by one.
|