@itwin/core-geometry 3.0.0-dev.152 → 3.0.0-dev.153

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.
@@ -1 +1 @@
1
- {"version":3,"file":"BezierCurve3dH.d.ts","sourceRoot":"","sources":["../../../src/bspline/BezierCurve3dH.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAY,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,eAAe;IACjD,gDAAgD;IACzC,mBAAmB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAC/C;;;OAGG;IACI,mBAAmB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO;IASzD;;;OAGG;IACI,0BAA0B,CAAC,MAAM,EAAE,QAAQ;IAGlD,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,SAAS,CAAQ;IACzB,2DAA2D;IACpD,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS;IAMvE;OACG;IACI,cAAc,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D,iFAAiF;IAC1E,yBAAyB,CAAC,OAAO,EAAE,eAAe,GAAG,GAAG;IAG/D;;;;;;;OAOG;IACI,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAM9F;;;;;;OAMG;IACI,qCAAqC,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO;IAmDvG;;;OAGG;IACI,WAAW,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,SAAS;CAgFjE"}
@@ -252,12 +252,16 @@ export class BezierCurve3dH extends BezierCurveBase {
252
252
  const workB = this._workCoffsB;
253
253
  const packedData = this._polygon.packedData;
254
254
  for (let i = 0; i < 3; i++) {
255
- // x representing loop pass: (w * spacePoint.x - curve.x(s) * 1.0) * (curveDelta.x(s) * curve.w(s) - curve.x(s) * curveDelta.w(s))
255
+ // x representing loop pass: (w * spacePoint.x - curve.x(s)) * (curveDelta.x(s) * curve.w(s) - curve.x(s) * curveDelta.w(s))
256
256
  // (and p.w is always 1)
257
+ for (let k = 0; k < workA.length; k++)
258
+ workA[k] = 0;
259
+ for (let k = 0; k < workB.length; k++)
260
+ workB[k] = 0;
257
261
  BezierPolynomialAlgebra.scaledComponentSum(workA, packedData, 4, orderA, 3, spacePoint.at(i), // w * spacePoint.x
258
262
  i, -1.0); // curve.x(s) * 1.0
259
- BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(workB, packedData, 4, orderA, 1.0, 3, 1.0, i);
260
- BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(workB, packedData, 4, orderA, -1.0, i, 1.0, 3);
263
+ BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(workB, packedData, 4, orderA, 1.0, 3, 0.0, i);
264
+ BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(workB, packedData, 4, orderA, -1.0, i, 0.0, 3);
261
265
  BezierPolynomialAlgebra.accumulateProduct(bezier.coffs, workA, workB);
262
266
  }
263
267
  roots = bezier.roots(0.0, true);
@@ -1 +1 @@
1
- {"version":3,"file":"BezierCurve3dH.js","sourceRoot":"","sources":["../../../src/bspline/BezierCurve3dH.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IA0DjD;;;OAGG;IACH,YAAoB,OAAqB;QACvC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IACvC,CAAC;IAjED,gDAAgD;IACzC,mBAAmB,CAAC,KAAU,IAAa,OAAO,KAAK,YAAY,cAAc,CAAC,CAAC,CAAC;IAC3F;;;OAGG;IACI,mBAAmB,CAAC,SAAoB;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAA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IAAI,CAAC,EAAE;oBAC7C,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBACrB,cAAc,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,qBAAqB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;oBAC1G,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;iBACzB;gBACD,uBAAuB,CAAC,gCAAgC,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC;gBACzG,uBAAuB,CAAC,gCAAgC,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC;gBAC1G,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;gBACtC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;oBAC7B,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;wBACrB,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;wBAC1C,aAAa,CAAC,sBAAsB,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;qBACnE;iBACF;aACF;SACF;IACH,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 Bspline\r\n */\r\n\r\nimport { CurveLocationDetail } from \"../curve/CurveLocationDetail\";\r\nimport { Geometry } from \"../Geometry\";\r\nimport { GeometryHandler } from \"../geometry3d/GeometryHandler\";\r\nimport { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Range3d } from \"../geometry3d/Range\";\r\nimport { Ray3d } from \"../geometry3d/Ray3d\";\r\nimport { Transform } from \"../geometry3d/Transform\";\r\nimport { Matrix4d } from \"../geometry4d/Matrix4d\";\r\nimport { Point4d } from \"../geometry4d/Point4d\";\r\nimport { BezierPolynomialAlgebra } from \"../numerics/BezierPolynomials\";\r\nimport { BezierCurveBase } from \"./BezierCurveBase\";\r\n\r\n/** 3d curve with homogeneous weights.\r\n * * A control point with weight w and cartesian (projected) coordinates x,y,z has the weight multiplied into the coordinates,\r\n * hence the control point as stored is (xw, yw, zw, w).\r\n * @public\r\n */\r\nexport class BezierCurve3dH extends BezierCurveBase {\r\n /** test if `other` is also a BezierCurve3dH. */\r\n public isSameGeometryClass(other: any): boolean { return other instanceof BezierCurve3dH; }\r\n /**\r\n * Apply (multiply by) an affine transform\r\n * @param transform\r\n */\r\n public tryTransformInPlace(transform: Transform): boolean {\r\n const data = this._workData0;\r\n for (let i = 0; i < this._polygon.order; i++) {\r\n this._polygon.getPolygonPoint(i, data);\r\n transform.multiplyXYZWToFloat64Array(data[0], data[1], data[2], data[3], data);\r\n this._polygon.setPolygonPoint(i, data);\r\n }\r\n return true;\r\n }\r\n /**\r\n * Apply (multiply by) a perspective transform\r\n * @param matrix\r\n */\r\n public tryMultiplyMatrix4dInPlace(matrix: Matrix4d) {\r\n matrix.multiplyBlockedFloat64ArrayInPlace(this._polygon.packedData);\r\n }\r\n private _workRay0: Ray3d;\r\n private _workRay1: Ray3d;\r\n /** Return a specific pole as a full `[x,y,z,x] Point4d` */\r\n public getPolePoint4d(i: number, result?: Point4d): Point4d | undefined {\r\n const data = this._polygon.getPolygonPoint(i, this._workData0);\r\n if (data)\r\n return Point4d.create(data[0], data[1], data[2], data[3], result);\r\n return undefined;\r\n }\r\n /** Return a specific pole normalized to weight 1\r\n */\r\n public getPolePoint3d(i: number, result?: Point3d): Point3d | undefined {\r\n const data = this._polygon.getPolygonPoint(i, this._workData0);\r\n if (data)\r\n return Point3d.createFromPackedXYZW(data, 0, result);\r\n return undefined;\r\n }\r\n /**\r\n * Returns true if all weights are within tolerance of 1.0\r\n */\r\n public isUnitWeight(tolerance?: number): boolean {\r\n if (tolerance === undefined)\r\n tolerance = Geometry.smallAngleRadians;\r\n const aLow = 1.0 - tolerance;\r\n const aHigh = 1.0 + tolerance;\r\n const data = this._polygon.packedData;\r\n const n = data.length;\r\n let a;\r\n for (let i = 3; i < n; i += 4) {\r\n a = data[i];\r\n if (a < aLow || a > aHigh)\r\n return false;\r\n }\r\n return true;\r\n }\r\n /**\r\n * Capture a polygon as the data for a new `BezierCurve3dH`\r\n * @param polygon complete packed data and order.\r\n */\r\n private constructor(polygon: Float64Array) {\r\n super(4, polygon);\r\n this._workRay0 = Ray3d.createXAxis();\r\n this._workRay1 = Ray3d.createXAxis();\r\n }\r\n /** Create a curve with given points.\r\n * * If input is `Point2d[]`, the points are promoted with `z=0` and `w=1`\r\n * * If input is `Point3d[]`, the points are promoted with w=1`\r\n *\r\n */\r\n public static create(data: Point3d[] | Point4d[] | Point2d[]): BezierCurve3dH | undefined {\r\n if (data.length < 1)\r\n return undefined;\r\n const polygon = new Float64Array(data.length * 4);\r\n if (data[0] instanceof Point3d) {\r\n let i = 0;\r\n for (const p of (data as Point3d[])) {\r\n polygon[i++] = p.x;\r\n polygon[i++] = p.y;\r\n polygon[i++] = p.z;\r\n polygon[i++] = 1.0;\r\n }\r\n return new BezierCurve3dH(polygon);\r\n } else if (data[0] instanceof Point4d) {\r\n let i = 0;\r\n for (const p of (data as Point4d[])) {\r\n polygon[i++] = p.x;\r\n polygon[i++] = p.y;\r\n polygon[i++] = p.z;\r\n polygon[i++] = p.w;\r\n }\r\n return new BezierCurve3dH(polygon);\r\n } else if (data[0] instanceof Point2d) {\r\n let i = 0;\r\n for (const p of (data as Point2d[])) {\r\n polygon[i++] = p.x;\r\n polygon[i++] = p.y;\r\n polygon[i++] = 0.0;\r\n polygon[i++] = 1.0;\r\n }\r\n return new BezierCurve3dH(polygon);\r\n }\r\n return undefined;\r\n }\r\n /** create a bezier curve of specified order, filled with zeros */\r\n public static createOrder(order: number): BezierCurve3dH {\r\n const polygonArray = new Float64Array(order * 4); // and we trust that this is all zeros !!!\r\n return new BezierCurve3dH(polygonArray);\r\n }\r\n /** Load order * 4 doubles from data[3 * spanIndex] as poles (with added weight) */\r\n public loadSpan3dPolesWithWeight(data: Float64Array, spanIndex: number, weight: number) {\r\n this._polygon.loadSpanPolesWithWeight(data, 3, spanIndex, weight);\r\n }\r\n /** Load order * 4 doubles from data[3 * spanIndex] as poles (with added weight) */\r\n public loadSpan4dPoles(data: Float64Array, spanIndex: number) {\r\n this._polygon.loadSpanPoles(data, spanIndex);\r\n }\r\n /** Clone the entire curve. */\r\n public clone(): BezierCurve3dH {\r\n return new BezierCurve3dH(this._polygon.clonePolygon());\r\n }\r\n /**\r\n * Return a curve after transform.\r\n */\r\n public cloneTransformed(transform: Transform): BezierCurve3dH {\r\n const curve1 = this.clone();\r\n curve1.tryTransformInPlace(transform);\r\n return curve1;\r\n }\r\n /** Return a (deweighted) point on the curve. If deweight fails, returns 000 */\r\n public fractionToPoint(fraction: number, result?: Point3d): Point3d {\r\n this._polygon.evaluate(fraction, this._workData0);\r\n result = Point3d.createFromPackedXYZW(this._workData0, 0, result);\r\n return result ? result : Point3d.createZero();\r\n }\r\n /** Return a (deweighted) point on the curve. If deweight fails, returns 000 */\r\n public fractionToPoint4d(fraction: number, result?: Point4d): Point4d {\r\n this._polygon.evaluate(fraction, this._workData0);\r\n return Point4d.createFromPackedXYZW(this._workData0, 0, result);\r\n }\r\n /** Return the cartesian point and derivative vector. */\r\n public fractionToPointAndDerivative(fraction: number, result?: Ray3d): Ray3d {\r\n this._polygon.evaluate(fraction, this._workData0);\r\n this._polygon.evaluateDerivative(fraction, this._workData1);\r\n result = Ray3d.createWeightedDerivative(this._workData0, this._workData1, result);\r\n if (result)\r\n return result;\r\n // Bad. Very Bad. Return origin and x axis. Should be undefined, but usual cartesian types do not allow that\r\n return Ray3d.createXAxis();\r\n }\r\n /** Construct a plane with\r\n * * origin at the fractional position along the arc\r\n * * x axis is the first derivative, i.e. tangent along the arc\r\n * * y axis is the second derivative, i.e. in the plane and on the center side of the tangent.\r\n * If the arc is circular, the second derivative is directly towards the center\r\n */\r\n public fractionToPointAnd2Derivatives(fraction: number, result?: Plane3dByOriginAndVectors): Plane3dByOriginAndVectors {\r\n const epsilon = 1.0e-8;\r\n const a = 1.0 / (2.0 * epsilon);\r\n if (!result)\r\n result = Plane3dByOriginAndVectors.createXYPlane();\r\n const ray = this.fractionToPointAndDerivative(fraction, this._workRay0);\r\n result.origin.setFrom(ray.origin);\r\n result.vectorU.setFrom(ray.direction);\r\n const ray0 = this.fractionToPointAndDerivative(fraction - epsilon, this._workRay0);\r\n const ray1 = this.fractionToPointAndDerivative(fraction + epsilon, this._workRay1);\r\n Vector3d.createAdd2Scaled(ray0.direction, -a, ray1.direction, a, result.vectorV);\r\n return result;\r\n }\r\n /** test for nearly equal control points */\r\n public override isAlmostEqual(other: any): boolean {\r\n if (other instanceof BezierCurve3dH) {\r\n return this._polygon.isAlmostEqual(other._polygon);\r\n }\r\n return false;\r\n }\r\n /** Second step of double dispatch: call `handler.handleBezierCurve3dH(this)` */\r\n public dispatchToGeometryHandler(handler: GeometryHandler): any {\r\n return handler.handleBezierCurve3dH(this);\r\n }\r\n /**\r\n * Form dot products of each pole with given coefficients. Return as entries in products array.\r\n * @param products array of (scalar) dot products\r\n * @param ax x coefficient\r\n * @param ay y coefficient\r\n * @param az z coefficient\r\n * @param aw w coefficient\r\n */\r\n public poleProductsXYZW(products: Float64Array, ax: number, ay: number, az: number, aw: number) {\r\n const n = this.numPoles;\r\n const data = this._polygon.packedData;\r\n for (let i = 0, k = 0; i < n; i++, k += 4)\r\n products[i] = ax * data[k] + ay * data[k + 1] + az * data[k + 2] + aw * data[k + 3];\r\n }\r\n /** Find the closest point within the bezier span, using true perpendicular test (but no endpoint test)\r\n * * If closer than previously recorded, update the CurveLocationDetail\r\n * * This assumes this bezier is saturated.\r\n * @param spacePoint point being projected\r\n * @param detail pre-allocated detail to record (evolving) closest point.\r\n * @returns true if an updated occurred, false if either (a) no perpendicular projections or (b) perpendiculars were not closer.\r\n */\r\n public updateClosestPointByTruePerpendicular(spacePoint: Point3d, detail: CurveLocationDetail): boolean {\r\n let numUpdates = 0;\r\n let roots: number[] | undefined;\r\n if (this.isUnitWeight()) {\r\n // unweighted !!!\r\n const productOrder = 2 * this.order - 2;\r\n this.allocateAndZeroBezierWorkData(productOrder, 0, 0);\r\n const bezier = this._workBezier!;\r\n // closestPoint condition is:\r\n // (spacePoint - curvePoint) DOT curveTangent = 0;\r\n // Each product (x,y,z) of the DOT is the product of two bezier polynomials\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(bezier.coffs, this._polygon.packedData, 4, this.order, 1.0, 0, -spacePoint.x, 0);\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(bezier.coffs, this._polygon.packedData, 4, this.order, 1.0, 1, -spacePoint.y, 1);\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(bezier.coffs, this._polygon.packedData, 4, this.order, 1.0, 2, -spacePoint.z, 2);\r\n roots = bezier.roots(0.0, true);\r\n } else {\r\n // This bezier has weights.\r\n // The pure cartesian closest point condition is\r\n // (spacePoint - X/w) DOT (X' w - w' X)/ w^2 = 0\r\n // ignoring denominator and using bezier coefficient differences for the derivative, making the numerator 0 is\r\n // (w * spacePoint - X) DOT ( DELTA X * w - DELTA w * X) = 0\r\n const orderA = this.order;\r\n const orderB = 2 * this.order - 2; // products of component and component difference.\r\n const productOrder = orderA + orderB - 1;\r\n this.allocateAndZeroBezierWorkData(productOrder, orderA, orderB);\r\n const bezier = this._workBezier!;\r\n const workA = this._workCoffsA!;\r\n const workB = this._workCoffsB!;\r\n const packedData = this._polygon.packedData;\r\n for (let i = 0; i < 3; i++) {\r\n // x representing loop pass: (w * spacePoint.x - curve.x(s) * 1.0) * (curveDelta.x(s) * curve.w(s) - curve.x(s) * curveDelta.w(s))\r\n // (and p.w is always 1)\r\n BezierPolynomialAlgebra.scaledComponentSum(workA, packedData, 4, orderA, 3, spacePoint.at(i), // w * spacePoint.x\r\n i, -1.0); // curve.x(s) * 1.0\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(workB, packedData, 4, orderA, 1.0, 3, 1.0, i);\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(workB, packedData, 4, orderA, -1.0, i, 1.0, 3);\r\n BezierPolynomialAlgebra.accumulateProduct(bezier.coffs, workA, workB);\r\n }\r\n roots = bezier.roots(0.0, true);\r\n }\r\n if (roots) {\r\n for (const fraction of roots) {\r\n const xyz = this.fractionToPoint(fraction);\r\n const a = xyz.distance(spacePoint);\r\n numUpdates += detail.updateIfCloserCurveFractionPointDistance(this, fraction, xyz, a) ? 1 : 0;\r\n }\r\n }\r\n return numUpdates > 0;\r\n }\r\n /** Extend `rangeToExtend`, using candidate extrema at\r\n * * both end points\r\n * * any internal extrema in x,y,z\r\n */\r\n public extendRange(rangeToExtend: Range3d, transform?: Transform) {\r\n const order = this.order;\r\n if (!transform) {\r\n this.allocateAndZeroBezierWorkData(order * 2 - 2, 0, 0);\r\n const bezier = this._workBezier!;\r\n const data = this._polygon.packedData;\r\n this.getPolePoint3d(0, this._workPoint0);\r\n rangeToExtend.extend(this._workPoint0);\r\n this.getPolePoint3d(order - 1, this._workPoint0);\r\n rangeToExtend.extend(this._workPoint0);\r\n // Example:\r\n // For x component ...\r\n // coefficients of (weighted x) are at axisIndex=0\r\n // deweighted polynomial is (x(s)/w(s))\r\n // its derivative (to be zeroed) is\r\n // (x'(s)*w(s) -x(s) * w'(s)) / w^2(s)\r\n // The coefficients of the derivatives are (degree times) differences of successive coffs.\r\n // Make the numerator zero to get extrema\r\n for (let axisIndex = 0; axisIndex < 3; axisIndex++) {\r\n bezier.zero();\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(\r\n bezier.coffs,\r\n data, 4, order,\r\n 1.0,\r\n axisIndex, 0.0,\r\n 3);\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(\r\n bezier.coffs,\r\n data, 4, order,\r\n -1.0,\r\n 3, 0.0,\r\n axisIndex);\r\n const roots = bezier.roots(0.0, true);\r\n if (roots) {\r\n for (const r of roots) {\r\n this.fractionToPoint(r, this._workPoint0);\r\n rangeToExtend.extend(this._workPoint0);\r\n }\r\n }\r\n }\r\n } else {\r\n this.allocateAndZeroBezierWorkData(order * 2 - 2, order, order);\r\n const componentCoffs = this._workCoffsA!; // to hold transformed copy of x,y,z in turn.\r\n const weightCoffs = this._workCoffsB!; // to hold weights\r\n const bezier = this._workBezier!;\r\n\r\n this.getPolePoint3d(0, this._workPoint0);\r\n rangeToExtend.extendTransformedPoint(transform, this._workPoint0);\r\n this.getPolePoint3d(order - 1, this._workPoint0);\r\n rangeToExtend.extendTransformedPoint(transform, this._workPoint0);\r\n\r\n const data = this._polygon.packedData; // Example:\r\n // For x component ...\r\n // coefficients of (weighted x) are at axisIndex=0\r\n // deweighted polynomial is (x(s)/w(s))\r\n // its derivative (to be zeroed) is\r\n // (x'(s)*w(s) -x(s) * w'(s)) / w^2(s)\r\n // The coefficients of the derivatives are (degree times) differences of successive coffs.\r\n // Make the numerator zero to get extrema\r\n // apply one row of the transform to get the transformed coff by itself\r\n let weight;\r\n for (let axisIndex = 0; axisIndex < 3; axisIndex++) {\r\n bezier.zero();\r\n for (let i = 0, k = 0; i < order; i++, k += 4) {\r\n weight = data[k + 3];\r\n componentCoffs[i] = transform.multiplyComponentXYZW(axisIndex, data[k], data[k + 1], data[k + 2], weight);\r\n weightCoffs[i] = weight;\r\n }\r\n BezierPolynomialAlgebra.accumulateProductWithDifferences(bezier.coffs, componentCoffs, weightCoffs, 1.0);\r\n BezierPolynomialAlgebra.accumulateProductWithDifferences(bezier.coffs, weightCoffs, componentCoffs, -1.0);\r\n const roots = bezier.roots(0.0, true);\r\n if (roots && roots.length > 0) {\r\n for (const r of roots) {\r\n this.fractionToPoint(r, this._workPoint0);\r\n rangeToExtend.extendTransformedPoint(transform, this._workPoint0);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"BezierCurve3dH.js","sourceRoot":"","sources":["../../../src/bspline/BezierCurve3dH.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IA0DjD;;;OAGG;IACH,YAAoB,OAAqB;QACvC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IACvC,CAAC;IAjED,gDAAgD;IACzC,mBAAmB,CAAC,KAAU,IAAa,OAAO,KAAK,YAAY,cAAc,CAAC,CAAC,C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AAI,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;wBAC1C,aAAa,CAAC,sBAAsB,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;qBACnE;iBACF;aACF;SACF;IACH,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 Bspline\r\n */\r\n\r\nimport { CurveLocationDetail } from \"../curve/CurveLocationDetail\";\r\nimport { Geometry } from \"../Geometry\";\r\nimport { GeometryHandler } from \"../geometry3d/GeometryHandler\";\r\nimport { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Range3d } from \"../geometry3d/Range\";\r\nimport { Ray3d } from \"../geometry3d/Ray3d\";\r\nimport { Transform } from \"../geometry3d/Transform\";\r\nimport { Matrix4d } from \"../geometry4d/Matrix4d\";\r\nimport { Point4d } from \"../geometry4d/Point4d\";\r\nimport { BezierPolynomialAlgebra } from \"../numerics/BezierPolynomials\";\r\nimport { BezierCurveBase } from \"./BezierCurveBase\";\r\n\r\n/** 3d curve with homogeneous weights.\r\n * * A control point with weight w and cartesian (projected) coordinates x,y,z has the weight multiplied into the coordinates,\r\n * hence the control point as stored is (xw, yw, zw, w).\r\n * @public\r\n */\r\nexport class BezierCurve3dH extends BezierCurveBase {\r\n /** test if `other` is also a BezierCurve3dH. */\r\n public isSameGeometryClass(other: any): boolean { return other instanceof BezierCurve3dH; }\r\n /**\r\n * Apply (multiply by) an affine transform\r\n * @param transform\r\n */\r\n public tryTransformInPlace(transform: Transform): boolean {\r\n const data = this._workData0;\r\n for (let i = 0; i < this._polygon.order; i++) {\r\n this._polygon.getPolygonPoint(i, data);\r\n transform.multiplyXYZWToFloat64Array(data[0], data[1], data[2], data[3], data);\r\n this._polygon.setPolygonPoint(i, data);\r\n }\r\n return true;\r\n }\r\n /**\r\n * Apply (multiply by) a perspective transform\r\n * @param matrix\r\n */\r\n public tryMultiplyMatrix4dInPlace(matrix: Matrix4d) {\r\n matrix.multiplyBlockedFloat64ArrayInPlace(this._polygon.packedData);\r\n }\r\n private _workRay0: Ray3d;\r\n private _workRay1: Ray3d;\r\n /** Return a specific pole as a full `[x,y,z,x] Point4d` */\r\n public getPolePoint4d(i: number, result?: Point4d): Point4d | undefined {\r\n const data = this._polygon.getPolygonPoint(i, this._workData0);\r\n if (data)\r\n return Point4d.create(data[0], data[1], data[2], data[3], result);\r\n return undefined;\r\n }\r\n /** Return a specific pole normalized to weight 1\r\n */\r\n public getPolePoint3d(i: number, result?: Point3d): Point3d | undefined {\r\n const data = this._polygon.getPolygonPoint(i, this._workData0);\r\n if (data)\r\n return Point3d.createFromPackedXYZW(data, 0, result);\r\n return undefined;\r\n }\r\n /**\r\n * Returns true if all weights are within tolerance of 1.0\r\n */\r\n public isUnitWeight(tolerance?: number): boolean {\r\n if (tolerance === undefined)\r\n tolerance = Geometry.smallAngleRadians;\r\n const aLow = 1.0 - tolerance;\r\n const aHigh = 1.0 + tolerance;\r\n const data = this._polygon.packedData;\r\n const n = data.length;\r\n let a;\r\n for (let i = 3; i < n; i += 4) {\r\n a = data[i];\r\n if (a < aLow || a > aHigh)\r\n return false;\r\n }\r\n return true;\r\n }\r\n /**\r\n * Capture a polygon as the data for a new `BezierCurve3dH`\r\n * @param polygon complete packed data and order.\r\n */\r\n private constructor(polygon: Float64Array) {\r\n super(4, polygon);\r\n this._workRay0 = Ray3d.createXAxis();\r\n this._workRay1 = Ray3d.createXAxis();\r\n }\r\n /** Create a curve with given points.\r\n * * If input is `Point2d[]`, the points are promoted with `z=0` and `w=1`\r\n * * If input is `Point3d[]`, the points are promoted with w=1`\r\n *\r\n */\r\n public static create(data: Point3d[] | Point4d[] | Point2d[]): BezierCurve3dH | undefined {\r\n if (data.length < 1)\r\n return undefined;\r\n const polygon = new Float64Array(data.length * 4);\r\n if (data[0] instanceof Point3d) {\r\n let i = 0;\r\n for (const p of (data as Point3d[])) {\r\n polygon[i++] = p.x;\r\n polygon[i++] = p.y;\r\n polygon[i++] = p.z;\r\n polygon[i++] = 1.0;\r\n }\r\n return new BezierCurve3dH(polygon);\r\n } else if (data[0] instanceof Point4d) {\r\n let i = 0;\r\n for (const p of (data as Point4d[])) {\r\n polygon[i++] = p.x;\r\n polygon[i++] = p.y;\r\n polygon[i++] = p.z;\r\n polygon[i++] = p.w;\r\n }\r\n return new BezierCurve3dH(polygon);\r\n } else if (data[0] instanceof Point2d) {\r\n let i = 0;\r\n for (const p of (data as Point2d[])) {\r\n polygon[i++] = p.x;\r\n polygon[i++] = p.y;\r\n polygon[i++] = 0.0;\r\n polygon[i++] = 1.0;\r\n }\r\n return new BezierCurve3dH(polygon);\r\n }\r\n return undefined;\r\n }\r\n /** create a bezier curve of specified order, filled with zeros */\r\n public static createOrder(order: number): BezierCurve3dH {\r\n const polygonArray = new Float64Array(order * 4); // and we trust that this is all zeros !!!\r\n return new BezierCurve3dH(polygonArray);\r\n }\r\n /** Load order * 4 doubles from data[3 * spanIndex] as poles (with added weight) */\r\n public loadSpan3dPolesWithWeight(data: Float64Array, spanIndex: number, weight: number) {\r\n this._polygon.loadSpanPolesWithWeight(data, 3, spanIndex, weight);\r\n }\r\n /** Load order * 4 doubles from data[3 * spanIndex] as poles (with added weight) */\r\n public loadSpan4dPoles(data: Float64Array, spanIndex: number) {\r\n this._polygon.loadSpanPoles(data, spanIndex);\r\n }\r\n /** Clone the entire curve. */\r\n public clone(): BezierCurve3dH {\r\n return new BezierCurve3dH(this._polygon.clonePolygon());\r\n }\r\n /**\r\n * Return a curve after transform.\r\n */\r\n public cloneTransformed(transform: Transform): BezierCurve3dH {\r\n const curve1 = this.clone();\r\n curve1.tryTransformInPlace(transform);\r\n return curve1;\r\n }\r\n /** Return a (deweighted) point on the curve. If deweight fails, returns 000 */\r\n public fractionToPoint(fraction: number, result?: Point3d): Point3d {\r\n this._polygon.evaluate(fraction, this._workData0);\r\n result = Point3d.createFromPackedXYZW(this._workData0, 0, result);\r\n return result ? result : Point3d.createZero();\r\n }\r\n /** Return a (deweighted) point on the curve. If deweight fails, returns 000 */\r\n public fractionToPoint4d(fraction: number, result?: Point4d): Point4d {\r\n this._polygon.evaluate(fraction, this._workData0);\r\n return Point4d.createFromPackedXYZW(this._workData0, 0, result);\r\n }\r\n /** Return the cartesian point and derivative vector. */\r\n public fractionToPointAndDerivative(fraction: number, result?: Ray3d): Ray3d {\r\n this._polygon.evaluate(fraction, this._workData0);\r\n this._polygon.evaluateDerivative(fraction, this._workData1);\r\n result = Ray3d.createWeightedDerivative(this._workData0, this._workData1, result);\r\n if (result)\r\n return result;\r\n // Bad. Very Bad. Return origin and x axis. Should be undefined, but usual cartesian types do not allow that\r\n return Ray3d.createXAxis();\r\n }\r\n /** Construct a plane with\r\n * * origin at the fractional position along the arc\r\n * * x axis is the first derivative, i.e. tangent along the arc\r\n * * y axis is the second derivative, i.e. in the plane and on the center side of the tangent.\r\n * If the arc is circular, the second derivative is directly towards the center\r\n */\r\n public fractionToPointAnd2Derivatives(fraction: number, result?: Plane3dByOriginAndVectors): Plane3dByOriginAndVectors {\r\n const epsilon = 1.0e-8;\r\n const a = 1.0 / (2.0 * epsilon);\r\n if (!result)\r\n result = Plane3dByOriginAndVectors.createXYPlane();\r\n const ray = this.fractionToPointAndDerivative(fraction, this._workRay0);\r\n result.origin.setFrom(ray.origin);\r\n result.vectorU.setFrom(ray.direction);\r\n const ray0 = this.fractionToPointAndDerivative(fraction - epsilon, this._workRay0);\r\n const ray1 = this.fractionToPointAndDerivative(fraction + epsilon, this._workRay1);\r\n Vector3d.createAdd2Scaled(ray0.direction, -a, ray1.direction, a, result.vectorV);\r\n return result;\r\n }\r\n /** test for nearly equal control points */\r\n public override isAlmostEqual(other: any): boolean {\r\n if (other instanceof BezierCurve3dH) {\r\n return this._polygon.isAlmostEqual(other._polygon);\r\n }\r\n return false;\r\n }\r\n /** Second step of double dispatch: call `handler.handleBezierCurve3dH(this)` */\r\n public dispatchToGeometryHandler(handler: GeometryHandler): any {\r\n return handler.handleBezierCurve3dH(this);\r\n }\r\n /**\r\n * Form dot products of each pole with given coefficients. Return as entries in products array.\r\n * @param products array of (scalar) dot products\r\n * @param ax x coefficient\r\n * @param ay y coefficient\r\n * @param az z coefficient\r\n * @param aw w coefficient\r\n */\r\n public poleProductsXYZW(products: Float64Array, ax: number, ay: number, az: number, aw: number) {\r\n const n = this.numPoles;\r\n const data = this._polygon.packedData;\r\n for (let i = 0, k = 0; i < n; i++, k += 4)\r\n products[i] = ax * data[k] + ay * data[k + 1] + az * data[k + 2] + aw * data[k + 3];\r\n }\r\n /** Find the closest point within the bezier span, using true perpendicular test (but no endpoint test)\r\n * * If closer than previously recorded, update the CurveLocationDetail\r\n * * This assumes this bezier is saturated.\r\n * @param spacePoint point being projected\r\n * @param detail pre-allocated detail to record (evolving) closest point.\r\n * @returns true if an updated occurred, false if either (a) no perpendicular projections or (b) perpendiculars were not closer.\r\n */\r\n public updateClosestPointByTruePerpendicular(spacePoint: Point3d, detail: CurveLocationDetail): boolean {\r\n let numUpdates = 0;\r\n let roots: number[] | undefined;\r\n if (this.isUnitWeight()) {\r\n // unweighted !!!\r\n const productOrder = 2 * this.order - 2;\r\n this.allocateAndZeroBezierWorkData(productOrder, 0, 0);\r\n const bezier = this._workBezier!;\r\n // closestPoint condition is:\r\n // (spacePoint - curvePoint) DOT curveTangent = 0;\r\n // Each product (x,y,z) of the DOT is the product of two bezier polynomials\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(bezier.coffs, this._polygon.packedData, 4, this.order, 1.0, 0, -spacePoint.x, 0);\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(bezier.coffs, this._polygon.packedData, 4, this.order, 1.0, 1, -spacePoint.y, 1);\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(bezier.coffs, this._polygon.packedData, 4, this.order, 1.0, 2, -spacePoint.z, 2);\r\n roots = bezier.roots(0.0, true);\r\n } else {\r\n // This bezier has weights.\r\n // The pure cartesian closest point condition is\r\n // (spacePoint - X/w) DOT (X' w - w' X)/ w^2 = 0\r\n // ignoring denominator and using bezier coefficient differences for the derivative, making the numerator 0 is\r\n // (w * spacePoint - X) DOT ( DELTA X * w - DELTA w * X) = 0\r\n const orderA = this.order;\r\n const orderB = 2 * this.order - 2; // products of component and component difference.\r\n const productOrder = orderA + orderB - 1;\r\n this.allocateAndZeroBezierWorkData(productOrder, orderA, orderB);\r\n const bezier = this._workBezier!;\r\n const workA = this._workCoffsA!;\r\n const workB = this._workCoffsB!;\r\n const packedData = this._polygon.packedData;\r\n for (let i = 0; i < 3; i++) {\r\n // x representing loop pass: (w * spacePoint.x - curve.x(s)) * (curveDelta.x(s) * curve.w(s) - curve.x(s) * curveDelta.w(s))\r\n // (and p.w is always 1)\r\n for (let k = 0; k < workA.length; k++)workA[k] = 0;\r\n for (let k = 0; k < workB.length; k++)workB[k] = 0;\r\n BezierPolynomialAlgebra.scaledComponentSum(workA, packedData, 4, orderA, 3, spacePoint.at(i), // w * spacePoint.x\r\n i, -1.0); // curve.x(s) * 1.0\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(workB, packedData, 4, orderA, 1.0, 3, 0.0, i);\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(workB, packedData, 4, orderA, -1.0, i, 0.0, 3);\r\n BezierPolynomialAlgebra.accumulateProduct(bezier.coffs, workA, workB);\r\n }\r\n roots = bezier.roots(0.0, true);\r\n }\r\n if (roots) {\r\n for (const fraction of roots) {\r\n const xyz = this.fractionToPoint(fraction);\r\n const a = xyz.distance(spacePoint);\r\n numUpdates += detail.updateIfCloserCurveFractionPointDistance(this, fraction, xyz, a) ? 1 : 0;\r\n }\r\n }\r\n return numUpdates > 0;\r\n }\r\n /** Extend `rangeToExtend`, using candidate extrema at\r\n * * both end points\r\n * * any internal extrema in x,y,z\r\n */\r\n public extendRange(rangeToExtend: Range3d, transform?: Transform) {\r\n const order = this.order;\r\n if (!transform) {\r\n this.allocateAndZeroBezierWorkData(order * 2 - 2, 0, 0);\r\n const bezier = this._workBezier!;\r\n const data = this._polygon.packedData;\r\n this.getPolePoint3d(0, this._workPoint0);\r\n rangeToExtend.extend(this._workPoint0);\r\n this.getPolePoint3d(order - 1, this._workPoint0);\r\n rangeToExtend.extend(this._workPoint0);\r\n // Example:\r\n // For x component ...\r\n // coefficients of (weighted x) are at axisIndex=0\r\n // deweighted polynomial is (x(s)/w(s))\r\n // its derivative (to be zeroed) is\r\n // (x'(s)*w(s) -x(s) * w'(s)) / w^2(s)\r\n // The coefficients of the derivatives are (degree times) differences of successive coffs.\r\n // Make the numerator zero to get extrema\r\n for (let axisIndex = 0; axisIndex < 3; axisIndex++) {\r\n bezier.zero();\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(\r\n bezier.coffs,\r\n data, 4, order,\r\n 1.0,\r\n axisIndex, 0.0,\r\n 3);\r\n BezierPolynomialAlgebra.accumulateScaledShiftedComponentTimesComponentDelta(\r\n bezier.coffs,\r\n data, 4, order,\r\n -1.0,\r\n 3, 0.0,\r\n axisIndex);\r\n const roots = bezier.roots(0.0, true);\r\n if (roots) {\r\n for (const r of roots) {\r\n this.fractionToPoint(r, this._workPoint0);\r\n rangeToExtend.extend(this._workPoint0);\r\n }\r\n }\r\n }\r\n } else {\r\n this.allocateAndZeroBezierWorkData(order * 2 - 2, order, order);\r\n const componentCoffs = this._workCoffsA!; // to hold transformed copy of x,y,z in turn.\r\n const weightCoffs = this._workCoffsB!; // to hold weights\r\n const bezier = this._workBezier!;\r\n\r\n this.getPolePoint3d(0, this._workPoint0);\r\n rangeToExtend.extendTransformedPoint(transform, this._workPoint0);\r\n this.getPolePoint3d(order - 1, this._workPoint0);\r\n rangeToExtend.extendTransformedPoint(transform, this._workPoint0);\r\n\r\n const data = this._polygon.packedData; // Example:\r\n // For x component ...\r\n // coefficients of (weighted x) are at axisIndex=0\r\n // deweighted polynomial is (x(s)/w(s))\r\n // its derivative (to be zeroed) is\r\n // (x'(s)*w(s) -x(s) * w'(s)) / w^2(s)\r\n // The coefficients of the derivatives are (degree times) differences of successive coffs.\r\n // Make the numerator zero to get extrema\r\n // apply one row of the transform to get the transformed coff by itself\r\n let weight;\r\n for (let axisIndex = 0; axisIndex < 3; axisIndex++) {\r\n bezier.zero();\r\n for (let i = 0, k = 0; i < order; i++, k += 4) {\r\n weight = data[k + 3];\r\n componentCoffs[i] = transform.multiplyComponentXYZW(axisIndex, data[k], data[k + 1], data[k + 2], weight);\r\n weightCoffs[i] = weight;\r\n }\r\n BezierPolynomialAlgebra.accumulateProductWithDifferences(bezier.coffs, componentCoffs, weightCoffs, 1.0);\r\n BezierPolynomialAlgebra.accumulateProductWithDifferences(bezier.coffs, weightCoffs, componentCoffs, -1.0);\r\n const roots = bezier.roots(0.0, true);\r\n if (roots && roots.length > 0) {\r\n for (const r of roots) {\r\n this.fractionToPoint(r, this._workPoint0);\r\n rangeToExtend.extendTransformedPoint(transform, this._workPoint0);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"]}
@@ -682,6 +682,7 @@ class ClosestPointStrokeHandler extends NewtonRotRStrokeHandler {
682
682
  }
683
683
  return this._closestPoint;
684
684
  }
685
+ needPrimaryGeometryForStrokes() { return true; }
685
686
  startCurvePrimitive(curve) {
686
687
  this._curve = curve;
687
688
  this._fractionA = 0.0;
@@ -1 +1 @@
1
- {"version":3,"file":"CurvePrimitive.js","sourceRoot":"","sources":["../../../src/curve/CurvePrimitive.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,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,KAAK,EAAE;YACT,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,4BAA4B,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5E,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAClE,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACM,WAAW,CAAC,QAAgB,EAAE,IAAW;QAC9C,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC/B,IAAI,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC;YAAE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACpC,CAAC;IACM,oBAAoB,CAAC,KAAc,EAAE,QAAgB,EAAE,OAAiB;QAC7E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,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 Curve\r\n */\r\nimport { InterpolationCurve3d } from \"../bspline/InterpolationCurve3d\";\r\nimport { Clipper } from \"../clipping/ClipUtils\";\r\nimport { StrokeCountMap } from \"../curve/Query/StrokeCountMap\";\r\nimport { AxisOrder, Geometry, PlaneAltitudeEvaluator } from \"../Geometry\";\r\nimport { AkimaCurve3d } from \"../bspline/AkimaCurve3d\";\r\nimport { BSplineCurve3d } from \"../bspline/BSplineCurve\";\r\nimport { BezierCurve3d } from \"../bspline/BezierCurve3d\";\r\nimport { CurveChainWithDistanceIndex } from \"./CurveChainWithDistanceIndex\";\r\nimport { DirectSpiral3d } from \"./spiral/DirectSpiral3d\";\r\nimport { IntegratedSpiral3d } from \"./spiral/IntegratedSpiral3d\";\r\nimport { IStrokeHandler } from \"../geometry3d/GeometryHandler\";\r\nimport { Matrix3d } from \"../geometry3d/Matrix3d\";\r\nimport { Plane3dByOriginAndUnitNormal } from \"../geometry3d/Plane3dByOriginAndUnitNormal\";\r\nimport { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Ray3d } from \"../geometry3d/Ray3d\";\r\nimport { Transform } from \"../geometry3d/Transform\";\r\nimport { Order2Bezier } from \"../numerics/BezierPolynomials\";\r\nimport { Newton1dUnboundedApproximateDerivative, NewtonEvaluatorRtoR } from \"../numerics/Newton\";\r\nimport { GaussMapper } from \"../numerics/Quadrature\";\r\nimport { Arc3d } from \"./Arc3d\";\r\nimport { CurveExtendOptions, VariantCurveExtendParameter } from \"./CurveExtendMode\";\r\nimport { CurveIntervalRole, CurveLocationDetail, CurveSearchStatus } from \"./CurveLocationDetail\";\r\nimport { GeometryQuery } from \"./GeometryQuery\";\r\nimport { LineSegment3d } from \"./LineSegment3d\";\r\nimport { LineString3d } from \"./LineString3d\";\r\nimport { StrokeOptions } from \"./StrokeOptions\";\r\n\r\n/** Describes the concrete type of a [[CurvePrimitive]]. Each type name maps to a specific subclass and can be used for type-switching in conditional statements.\r\n * - \"arc\" => [[Arc3d]]\r\n * - \"lineSegment\" => [[LineSegment3d]]\r\n * - \"lineString\" => [[LineString3d]]\r\n * - \"bsplineCurve\" => [[BSplineCurve3dBase]] which is an intermediate class implemented by [[BSplineCurve3d]] and [[BSplineCurve3dH]]\r\n * - \"bezierCurve\" => [[BezierCurveBase]] which is an intermediate class implemented by [[BezierCurve3d]] and [[BezierCurve3dH]]\r\n * - \"transitionSpiral\" => [[TransitionSpiral3d]]\r\n * - \"curveChainWithDistanceIndex\" => [[CurveChainWithDistanceIndex]]\r\n * @see [[AnyCurvePrimitive]] for a union type that supports compile-time type narrowing.\r\n * @public\r\n */\r\nexport type CurvePrimitiveType = \"arc\" | \"lineSegment\" | \"lineString\" | \"bsplineCurve\" | \"bezierCurve\" | \"transitionSpiral\" | \"curveChainWithDistanceIndex\" | \"interpolationCurve\" | \"akimaCurve\";\r\n\r\n/** Union type for subclasses of [[CurvePrimitive]]. Specific subclasses can be discriminated at compile- or run-time using [[CurvePrimitive.curvePrimitiveType]].\r\n * @public\r\n */\r\nexport type AnyCurvePrimitive = Arc3d | LineSegment3d | LineString3d | BSplineCurve3d | BezierCurve3d | DirectSpiral3d | IntegratedSpiral3d | CurveChainWithDistanceIndex | InterpolationCurve3d | AkimaCurve3d;\r\n\r\n/** function signature for callback which announces a pair of numbers, such as a fractional interval, along with a containing CurvePrimitive.\r\n * @public\r\n */\r\nexport type AnnounceNumberNumberCurvePrimitive = (a0: number, a1: number, cp: CurvePrimitive) => void;\r\n/** Function signature for a callback which announces a pair of numbers\r\n * @public\r\n */\r\n\r\nexport type AnnounceNumberNumber = (a0: number, a1: number) => void;\r\n/** Function signature for a callback which announces a curve primitive\r\n * @public\r\n */\r\nexport type AnnounceCurvePrimitive = (cp: CurvePrimitive) => void;\r\n/**\r\n * A curve primitive is bounded\r\n * A curve primitive maps fractions in 0..1 to points in space.\r\n * As the fraction proceeds from 0 towards 1, the point moves \"forward\" along the curve.\r\n * True distance along the curve is not always strictly proportional to fraction.\r\n * * LineSegment3d always has proportional fraction and distance\r\n * * an Arc3d which is true circular has proportional fraction and distance\r\n * * A LineString3d is not proportional (except for special case of all segments of equal length)\r\n * * A Spiral3d is proportional\r\n * * A BsplineCurve3d is only proportional for special cases.\r\n *\r\n * For fractions outside 0..1, the curve primitive class may either (a) return the near endpoint or (b) evaluate an extended curve.\r\n * @public\r\n */\r\nexport abstract class CurvePrimitive extends GeometryQuery {\r\n /** String name for schema properties */\r\n public readonly geometryCategory = \"curvePrimitive\";\r\n /** String name for schema properties */\r\n public abstract readonly curvePrimitiveType: CurvePrimitiveType;\r\n\r\n protected constructor() { super(); }\r\n /**\r\n * data attached during stroking for facets.\r\n */\r\n public strokeData?: StrokeCountMap;\r\n /**\r\n * data attached in curve cutting.\r\n * @internal\r\n */\r\n public startCut?: CurveLocationDetail;\r\n /**\r\n * data attached in curve cutting.\r\n * @internal\r\n */\r\n public endCut?: CurveLocationDetail;\r\n /**\r\n * data attached by various algorithms (e.g. Region booleans)\r\n */\r\n public parent?: any;\r\n\r\n /** Return the point (x,y,z) on the curve at fractional position.\r\n * @param fraction fractional position along the geometry.\r\n * @returns Returns a point on the curve.\r\n */\r\n public abstract fractionToPoint(fraction: number, result?: Point3d): Point3d;\r\n /** Return the point (x,y,z) and derivative on the curve at fractional position.\r\n *\r\n * * Note that this derivative is \"derivative of xyz with respect to fraction.\"\r\n * * this derivative shows the speed of the \"fractional point\" moving along the curve.\r\n * * this is not generally a unit vector. use fractionToPointAndUnitTangent for a unit vector.\r\n * @param fraction fractional position along the geometry.\r\n * @returns Returns a ray whose origin is the curve point and direction is the derivative with respect to the fraction.\r\n */\r\n public abstract fractionToPointAndDerivative(fraction: number, result?: Ray3d): Ray3d;\r\n /**\r\n * Returns a ray whose origin is the curve point and direction is the unit tangent.\r\n * @param fraction fractional position on the curve\r\n * @param result optional preallocated ray.\r\n */\r\n public fractionToPointAndUnitTangent(fraction: number, result?: Ray3d): Ray3d {\r\n const ray = this.fractionToPointAndDerivative(fraction, result);\r\n ray.trySetDirectionMagnitudeInPlace(1.0);\r\n return ray;\r\n }\r\n /**\r\n * Returns the (absolute) curvature magnitude.\r\n * * Base implementation in CurvePrimitive computes curvature from the first and second derivative vectors.\r\n * @param fraction fractional position on the curve\r\n */\r\n public fractionToCurvature(fraction: number): number | undefined {\r\n const data = this.fractionToPointAnd2Derivatives(fraction)!;\r\n const cross = data.vectorU.crossProduct(data.vectorV);\r\n const a = cross.magnitude();\r\n const b = data.vectorU.magnitude();\r\n return Geometry.conditionalDivideFraction(a, b * b * b);\r\n }\r\n\r\n /** Return a plane with\r\n *\r\n * * origin at fractional position along the curve\r\n * * vectorU is the first derivative, i.e. tangent vector with length equal to the rate of change with respect to the fraction.\r\n * * vectorV is the second derivative, i.e.derivative of vectorU.\r\n */\r\n public abstract fractionToPointAnd2Derivatives(fraction: number, result?: Plane3dByOriginAndVectors): Plane3dByOriginAndVectors | undefined;\r\n\r\n /** Construct a frenet frame:\r\n * * origin at the point on the curve\r\n * * x axis is unit vector along the curve (tangent)\r\n * * y axis is perpendicular and in the plane of the osculating circle.\r\n * * z axis perpendicular to those.\r\n */\r\n public fractionToFrenetFrame(fraction: number, result?: Transform): Transform | undefined {\r\n const plane = this.fractionToPointAnd2Derivatives(fraction);\r\n if (!plane) return undefined;\r\n let axes = Matrix3d.createRigidFromColumns(plane.vectorU, plane.vectorV, AxisOrder.XYZ);\r\n if (axes)\r\n return Transform.createRefs(plane.origin, axes, result);\r\n // 2nd derivative not distinct -- do arbitrary headsUP ...\r\n const perpVector = Matrix3d.createPerpendicularVectorFavorXYPlane(plane.vectorU, plane.vectorV);\r\n axes = Matrix3d.createRigidFromColumns(plane.vectorU, perpVector, AxisOrder.XYZ);\r\n if (axes)\r\n return Transform.createRefs(plane.origin, axes, result);\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Construct a point extrapolated along tangent at fraction.\r\n * @param fraction fractional position on the primitive\r\n * @param distance (signed) distance to move on the tangent.\r\n */\r\n public fractionAndDistanceToPointOnTangent(fraction: number, distance: number): Point3d {\r\n const ray = this.fractionToPointAndUnitTangent(fraction);\r\n return ray.fractionToPoint(distance);\r\n }\r\n\r\n /**\r\n * return the length of the curve.\r\n * * Curve length is always positive.\r\n */\r\n public curveLength(): number {\r\n const context = new CurveLengthContext();\r\n this.emitStrokableParts(context);\r\n return context.getSum();\r\n }\r\n /**\r\n * Returns a (high accuracy) length of the curve between fractional positions\r\n * * Curve length is always positive.\r\n * * Default implementation applies a generic gaussian integration.\r\n * * Most curve classes (certainly LineSegment, LineString, Arc) are expected to provide efficient implementations.\r\n */\r\n public curveLengthBetweenFractions(fraction0: number, fraction1: number): number {\r\n if (fraction0 === fraction1)\r\n return 0.0;\r\n const scale = this.getFractionToDistanceScale();\r\n if (scale !== undefined) {\r\n // We are in luck! simple proportions determine it all !!!\r\n // (for example, a LineSegment3d or a circular arc)\r\n const totalLength = this.curveLength();\r\n return Math.abs((fraction1 - fraction0) * totalLength);\r\n }\r\n const context = new CurveLengthContext(fraction0, fraction1);\r\n this.emitStrokableParts(context);\r\n return Math.abs(context.getSum());\r\n }\r\n\r\n /**\r\n *\r\n * * Run an integration (with a default gaussian quadrature) with a fixed fractional step\r\n * * This is typically called by specific curve type implementations of curveLengthBetweenFractions.\r\n * * For example, in Arc3d implementation of curveLengthBetweenFractions:\r\n * * If the Arc3d is true circular, it the arc is true circular, use the direct `arcLength = radius * sweepRadians`\r\n * * If the Arc3d is not true circular, call this method with an interval count appropriate to eccentricity and sweepRadians.\r\n * @returns Returns an integral estimated by numerical quadrature between the fractional positions.\r\n * @param fraction0 start fraction for integration\r\n * @param fraction1 end fraction for integration\r\n * @param numInterval number of quadrature intervals\r\n */\r\n public curveLengthWithFixedIntervalCountQuadrature(fraction0: number, fraction1: number, numInterval: number, numGauss: number = 5): number {\r\n if (fraction0 > fraction1) {\r\n const fSave = fraction0;\r\n fraction0 = fraction1;\r\n fraction1 = fSave;\r\n }\r\n const context = new CurveLengthContext(fraction0, fraction1, numGauss);\r\n context.announceIntervalForUniformStepStrokes(this, numInterval, fraction0, fraction1);\r\n return Math.abs(context.getSum());\r\n }\r\n\r\n /**\r\n *\r\n * * (Attempt to) find a position on the curve at a signed distance from start fraction.\r\n * * Return the position as a CurveLocationDetail.\r\n * * In the `CurveLocationDetail`, record:\r\n * * `fractional` position\r\n * * `fraction` = coordinates of the point\r\n * * `search\r\n * * `a` = (signed!) distance moved. If `allowExtension` is false and the move reached the start or end of the curve, this distance is smaller than the requested signedDistance.\r\n * * `curveSearchStatus` indicates one of:\r\n * * `error` (unusual) computation failed not supported for this curve.\r\n * * `success` full movement completed\r\n * * `stoppedAtBoundary` partial movement completed. This can be due to either\r\n * * `allowExtension` parameter sent as `false`\r\n * * the curve type (e.g. bspline) does not support extended range.\r\n * * if `allowExtension` is true, movement may still end at the startPoint or end point for curves that do not support extended geometry (specifically bsplines)\r\n * * if the curve returns a value (i.e. not `undefined`) for `curve.getFractionToDistanceScale()`, the base class carries out the computation\r\n * and returns a final location.\r\n * * LineSegment3d relies on this.\r\n * * If the curve does not implement the computation or the curve has zero length, the returned `CurveLocationDetail` has\r\n * * `fraction` = the value of `startFraction`\r\n * * `point` = result of `curve.fractionToPoint(startFraction)`\r\n * * `a` = 0\r\n * * `curveStartState` = `CurveSearchStatus.error`\r\n * @param startFraction fractional position where the move starts\r\n * @param signedDistance distance to move. Negative distance is backwards in the fraction space\r\n * @param allowExtension if true, all the move to go beyond the startPoint or endpoint of the curve. If false, do not allow movement beyond the startPoint or endpoint\r\n * @param result optional result.\r\n * @returns A CurveLocationDetail annotated as above. Note that if the curve does not support the calculation, there is still a result which contains the point at the input startFraction, with failure indicated in the `curveStartState` member\r\n */\r\n public moveSignedDistanceFromFraction(startFraction: number, signedDistance: number, allowExtension: boolean, result?: CurveLocationDetail): CurveLocationDetail {\r\n const scale = this.getFractionToDistanceScale();\r\n if (scale !== undefined) {\r\n // We are in luck! simple proportions determine it all !!!\r\n // (for example, a LineSegment3d or a circular arc)\r\n const totalLength = this.curveLength();\r\n const signedFractionMove = Geometry.conditionalDivideFraction(signedDistance, totalLength);\r\n if (signedFractionMove === undefined) {\r\n return CurveLocationDetail.createCurveFractionPointDistanceCurveSearchStatus(\r\n this, startFraction, this.fractionToPoint(startFraction), 0.0, CurveSearchStatus.error);\r\n }\r\n return CurveLocationDetail.createConditionalMoveSignedDistance(\r\n allowExtension,\r\n this,\r\n startFraction,\r\n startFraction + signedFractionMove,\r\n signedDistance,\r\n result);\r\n }\r\n return this.moveSignedDistanceFromFractionGeneric(startFraction, signedDistance, allowExtension, result);\r\n }\r\n /**\r\n * Generic algorithm to search for point at signed distance from a fractional startPoint.\r\n * * This will work for well for smooth curves.\r\n * * Curves with tangent or other low-order-derivative discontinuities may need to implement specialized algorithms.\r\n * * We need to find an endFraction which is the end-of-interval (usually upper) limit of integration of the tangent magnitude from startFraction to endFraction\r\n * * That integral is a function of endFraction.\r\n * * The derivative of that integral with respect to end fraction is the tangent magnitude at end fraction.\r\n * * Use that function and (easily evaluated!) derivative for a Newton iteration\r\n * * TO ALL WHO HAVE FUZZY MEMORIES OF CALCULUS CLASS: \"The derivative of the integral wrt upper limit is the value of the integrand there\" is the\r\n * fundamental theorem of integral calculus !!! The fundamental theorem is not just an abstraction !!! It is being used\r\n * here in its barest possible form !!!\r\n * * See https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus\r\n * @param startFraction\r\n * @param signedDistance\r\n * @param _allowExtension\r\n * @param result\r\n */\r\n protected moveSignedDistanceFromFractionGeneric(startFraction: number, signedDistance: number, allowExtension: boolean, result?: CurveLocationDetail): CurveLocationDetail {\r\n const limitFraction = signedDistance > 0.0 ? 1.0 : 0.0;\r\n const absDistance = Math.abs(signedDistance);\r\n const directionFactor = signedDistance < 0.0 ? -1.0 : 1.0;\r\n const availableLength = this.curveLengthBetweenFractions(startFraction, limitFraction); // that is always positive\r\n if (availableLength < absDistance && !allowExtension)\r\n return CurveLocationDetail.createConditionalMoveSignedDistance(allowExtension, this, startFraction, limitFraction, signedDistance, result);\r\n const fractionStep = absDistance / availableLength;\r\n let fractionB = Geometry.interpolate(startFraction, fractionStep, limitFraction);\r\n let fractionA = startFraction;\r\n let distanceA = 0.0;\r\n const tol = 1.0e-12 * availableLength;\r\n let numConverged = 0;\r\n const tangent = Ray3d.createXAxis();\r\n // on each loop entry:\r\n // fractionA is the most recent endOfInterval. (It may have been reached by a mixture of forward and backward step.)\r\n // distanceA is the distance to (the point at) fractionA\r\n // fractionB is the next end fraction\r\n for (let iterations = 0; iterations < 10; iterations++) {\r\n const distanceAB = this.curveLengthBetweenFractions(fractionA, fractionB);\r\n const directionAB = fractionB > fractionA ? directionFactor : -directionFactor;\r\n const distance0B = distanceA + directionAB * distanceAB;\r\n const distanceError = absDistance - distance0B;\r\n if (Math.abs(distanceError) < tol) {\r\n numConverged++;\r\n if (numConverged > 1)\r\n break;\r\n } else {\r\n numConverged = 0;\r\n }\r\n this.fractionToPointAndDerivative(fractionB, tangent);\r\n const tangentMagnitude = tangent.direction.magnitude();\r\n fractionA = fractionB;\r\n fractionB = fractionA + directionFactor * distanceError / tangentMagnitude;\r\n if (fractionA === fractionB) { // YES -- that is an exact equality test. When it happens, there's no need for confirming with another iteration.\r\n numConverged = 100;\r\n break;\r\n }\r\n distanceA = distance0B;\r\n }\r\n if (numConverged > 1)\r\n return CurveLocationDetail.createConditionalMoveSignedDistance(false, this, startFraction, fractionB, signedDistance, result);\r\n\r\n result = CurveLocationDetail.createCurveEvaluatedFraction(this, startFraction, result);\r\n result.a = 0.0;\r\n result.curveSearchStatus = CurveSearchStatus.error;\r\n return result;\r\n }\r\n\r\n /**\r\n * * Returns true if the curve's fraction queries extend beyond 0..1.\r\n * * Base class default implementation returns false.\r\n * * These class (and perhaps others in the future) will return true:\r\n * * LineSegment3d\r\n * * LineString3d\r\n * * Arc3d\r\n */\r\n public get isExtensibleFractionSpace(): boolean { return false; }\r\n /**\r\n * Compute a length which may be an fast approximation to the true length.\r\n * This is expected to be either (a) exact or (b) larger than the actual length, but by no more than\r\n * a small multiple, perhaps up to PI/2, but commonly much closer to 1.\r\n *\r\n * * An example use of this is for setting a tolerance which is a small multiple of the curve length.\r\n * * Simple line, circular arc, and transition spiral may return exact length\r\n * * Ellipse may return circumference of some circle or polygon that encloses the ellipse.\r\n * * bspline curve may return control polygon length\r\n * *\r\n */\r\n public abstract quickLength(): number;\r\n /** Search for the curve point that is closest to the spacePoint.\r\n *\r\n * * If the space point is exactly on the curve, this is the reverse of fractionToPoint.\r\n * * Since CurvePrimitive should always have start and end available as candidate points, this method should always succeed\r\n * @param spacePoint point in space\r\n * @param extend true to extend the curve (if possible), false for no extend, single CurveExtendOptions (for both directions), or array of distinct CurveExtendOptions for start and end.\r\n * @returns Returns a CurveLocationDetail structure that holds the details of the close point.\r\n */\r\n public closestPoint(spacePoint: Point3d, extend: VariantCurveExtendParameter): CurveLocationDetail | undefined {\r\n const strokeHandler = new ClosestPointStrokeHandler(spacePoint, extend);\r\n this.emitStrokableParts(strokeHandler);\r\n return strokeHandler.claimResult();\r\n }\r\n /**\r\n * Find intervals of this curvePrimitive that are interior to a clipper\r\n * @param clipper clip structure (e.g. clip planes)\r\n * @param announce (optional) function to be called announcing fractional intervals\" ` announce(fraction0, fraction1, curvePrimitive)`\r\n * @returns true if any \"in\" segments are announced.\r\n */\r\n public announceClipIntervals(_clipper: Clipper, _announce?: AnnounceNumberNumberCurvePrimitive): boolean {\r\n // DEFAULT IMPLEMENTATION -- no interior parts\r\n return false;\r\n }\r\n\r\n /** Return (if possible) a curve primitive which is a portion of this curve.\r\n * @param _fractionA [in] start fraction\r\n * @param _fractionB [in] end fraction\r\n */\r\n public clonePartialCurve(_fractionA: number, _fractionB: number): CurvePrimitive | undefined {\r\n return undefined;\r\n }\r\n /**\r\n * * If the curve primitive has distance-along-curve strictly proportional to curve fraction, return true\r\n * * If distance-along-the-curve is not proportional, return undefined.\r\n * * When defined, the scale factor is always the length of the curve.\r\n * * This scale factor is typically available for these curve types:\r\n * * * All `LineSegment3d`\r\n * * * Arc3d which is a true circular arc (axes perpendicular and of equal length).\r\n * * * CurveChainWithDistanceIndex\r\n * * This scale factor is undefined for these curve types:\r\n * * * Arc3d which is a true ellipse, i.e. unequal lengths of defining vectors or non-perpendicular defining vectors.\r\n * * * bspline and bezier curves\r\n * @returns scale factor or undefined\r\n */\r\n public getFractionToDistanceScale(): number | undefined { return undefined; }\r\n\r\n /** Reverse the curve's data so that its fractional stroking moves in the opposite direction. */\r\n public abstract reverseInPlace(): void;\r\n /**\r\n * Compute intersections with a plane.\r\n * * The intersections are appended to the result array.\r\n * * The base class implementation emits strokes to an AppendPlaneIntersectionStrokeHandler object, which uses a Newton iteration to get\r\n * high-accuracy intersection points within strokes.\r\n * * Derived classes should override this default implementation if there are easy analytic solutions.\r\n * * Derived classes are free to implement extended intersections (e.g. arc!!!)\r\n * @param plane The plane to be intersected.\r\n * @param result Array to receive intersections\r\n * @returns Return the number of CurveLocationDetail's added to the result array.\r\n */\r\n public appendPlaneIntersectionPoints(plane: PlaneAltitudeEvaluator, result: CurveLocationDetail[]): number {\r\n const strokeHandler = new AppendPlaneIntersectionStrokeHandler(plane, result);\r\n const n0 = result.length;\r\n this.emitStrokableParts(strokeHandler);\r\n return result.length - n0;\r\n }\r\n /**\r\n * Examine contents of an array of CurveLocationDetail.\r\n * Filter the intersections according to the parameters.\r\n * @param allowExtend if false, remove points on the extension.\r\n * @param applySnappedCoordinates if true, change the stored fractions and coordinates to exact end values. Otherwise\r\n * use the exact values only for purpose of updating the curveIntervalRole.\r\n * @param startEndFractionTolerance if nonzero, adjust fraction to 0 or 1 with this tolerance.\r\n * @param startEndXYZTolerance if nonzero, adjust to endpoint with this tolerance.\r\n * @internal\r\n */\r\n public static snapAndRestrictDetails(\r\n details: CurveLocationDetail[],\r\n allowExtend: boolean = true,\r\n applySnappedCoordinates: boolean = false,\r\n startEndFractionTolerance = Geometry.smallAngleRadians,\r\n startEndXYZTolerance = Geometry.smallMetricDistance) {\r\n const n0 = details.length;\r\n let acceptIndex = 0;\r\n const point0 = Point3d.create();\r\n const point1 = Point3d.create();\r\n let snappedCoordinates: Point3d | undefined;\r\n for (let candidateIndex = 0; candidateIndex < n0; candidateIndex++) {\r\n snappedCoordinates = undefined;\r\n const detail = details[candidateIndex];\r\n let fraction = detail.fraction;\r\n let accept = allowExtend || Geometry.isIn01(fraction);\r\n if (detail.curve) {\r\n detail.curve.startPoint(point0);\r\n detail.curve.endPoint(point1);\r\n }\r\n\r\n if (startEndFractionTolerance > 0) {\r\n if (Math.abs(fraction) < startEndFractionTolerance) {\r\n fraction = 0.0;\r\n accept = true;\r\n detail.intervalRole = CurveIntervalRole.isolatedAtVertex;\r\n snappedCoordinates = point0;\r\n }\r\n if (Math.abs(fraction - 1.0) < startEndFractionTolerance) {\r\n fraction = 1.0;\r\n accept = true;\r\n detail.intervalRole = CurveIntervalRole.isolatedAtVertex;\r\n snappedCoordinates = point1;\r\n if (detail.curve)\r\n snappedCoordinates = detail.curve.startPoint(point1);\r\n }\r\n }\r\n if (startEndXYZTolerance > 0 && detail.curve !== undefined) {\r\n // REMARK: always test both endpoints. If there is a cyclic fraction space, an intersection marked as \"after\" the end might have wrapped all the way to the beginning.\r\n if (detail.point.distance(point0) <= startEndXYZTolerance) {\r\n fraction = 0.0;\r\n detail.intervalRole = CurveIntervalRole.isolatedAtVertex;\r\n snappedCoordinates = point0;\r\n } else if (detail.point.distance(point1) <= startEndXYZTolerance) {\r\n fraction = 1.0;\r\n detail.intervalRole = CurveIntervalRole.isolatedAtVertex;\r\n snappedCoordinates = point1;\r\n }\r\n }\r\n if (accept) {\r\n if (applySnappedCoordinates) {\r\n detail.fraction = fraction;\r\n if (snappedCoordinates !== undefined)\r\n detail.point.setFrom(snappedCoordinates);\r\n }\r\n if (acceptIndex < candidateIndex)\r\n details[acceptIndex] = detail;\r\n acceptIndex++;\r\n }\r\n\r\n }\r\n if (acceptIndex < n0)\r\n details.length = acceptIndex;\r\n\r\n }\r\n\r\n /** Ask if the curve is within tolerance of a plane.\r\n * @returns Returns true if the curve is completely within tolerance of the plane.\r\n */\r\n public abstract isInPlane(plane: Plane3dByOriginAndUnitNormal): boolean;\r\n /** return the startPoint of the primitive. The default implementation returns fractionToPoint (0.0) */\r\n public startPoint(result?: Point3d): Point3d { return this.fractionToPoint(0.0, result); }\r\n /** return the end point of the primitive. The default implementation returns fractionToPoint(1.0) */\r\n public endPoint(result?: Point3d): Point3d { return this.fractionToPoint(1.0, result); }\r\n /** Add strokes to caller-supplied linestring */\r\n public abstract emitStrokes(dest: LineString3d, options?: StrokeOptions): void;\r\n /** Ask the curve to announce points and simple subcurve fragments for stroking.\r\n * See IStrokeHandler for description of the sequence of the method calls.\r\n */\r\n public abstract emitStrokableParts(dest: IStrokeHandler, options?: StrokeOptions): void;\r\n /**\r\n * return the stroke count required for given options.\r\n * * This returns a single number\r\n * * See computeComponentStrokeCountForOptions to get structured per-component counts and fraction mappings.\r\n * @param options StrokeOptions that determine count\r\n */\r\n public abstract computeStrokeCountForOptions(options?: StrokeOptions): number;\r\n\r\n /**\r\n * attach StrokeCountMap structure to this primitive (and recursively to any children)\r\n * * Base class implementation (here) gets the simple count from computeStrokeCountForOptions and attaches it.\r\n * * LineString3d, arc3d, BezierCurve3d, BezierCurve3dH accept that default.\r\n * * Subdivided primitives (linestring, bspline curve) implement themselves and attach a StrokeCountMap containing the\r\n * total count, and also containing an array of StrokeCountMap per component.\r\n * * For CurvePrimitiveWithDistanceIndex, the top level gets (only) a total count, and each child gets\r\n * its own StrokeCountMap with appropriate structure.\r\n * @param options StrokeOptions that determine count\r\n * @param parentStrokeMap optional map from parent. Its count, curveLength, and a1 values are increased with count and distance from this primitive.\r\n * @return sum of `a0+this.curveLength()`, for use as `a0` of successor in chain.\r\n */\r\n public computeAndAttachRecursiveStrokeCounts(options?: StrokeOptions, parentMap?: StrokeCountMap) {\r\n const n = this.computeStrokeCountForOptions(options);\r\n const a = this.curveLength();\r\n CurvePrimitive.installStrokeCountMap(\r\n this,\r\n StrokeCountMap.createWithCurvePrimitive(this, n, a, 0, a),\r\n parentMap);\r\n }\r\n\r\n /**\r\n * * evaluate strokes at fractions indicated in a StrokeCountMap.\r\n * * Base class implementation (here) gets the simple count from computeStrokeCountForOptions and strokes at uniform fractions.\r\n * * LineString3d, arc3d, BezierCurve3d, BezierCurve3dH accept that default.\r\n * * Subdivided primitives (linestring, bspline curve) implement themselves and evaluate within components.\r\n * * CurvePrimitiveWithDistanceIndex recurses to its children.\r\n * * if packedFraction and packedDerivative arrays are present in the LineString3d, fill them.\r\n * @param map = stroke count data.\r\n * @param linestring = receiver linestring.\r\n * @return number of strokes added. 0 if any errors matching the map to the curve primitive.\r\n */\r\n public addMappedStrokesToLineString3D(map: StrokeCountMap, linestring: LineString3d): number {\r\n const numPoint0 = linestring.numPoints();\r\n if (map.primitive && map.primitive === this && map.numStroke > 0) {\r\n for (let i = 0; i <= map.numStroke; i++) {\r\n const fraction = i / map.numStroke;\r\n linestring.appendFractionToPoint(this, fraction);\r\n }\r\n }\r\n return linestring.numPoints() - numPoint0;\r\n }\r\n\r\n /**\r\n * final install step to save curveMap in curve. If parentMap is given, update its length, count, and a1 fields\r\n * @param curve curve to receive the annotation\r\n * @param map\r\n * @param parentMap\r\n */\r\n public static installStrokeCountMap(curve: CurvePrimitive, curveMap: StrokeCountMap, parentMap?: StrokeCountMap) {\r\n if (parentMap)\r\n parentMap.addToCountAndLength(curveMap.numStroke, curveMap.curveLength);\r\n curve.strokeData = curveMap;\r\n }\r\n /**\r\n * Return an array containing only the curve primitives.\r\n * * This DEFAULT simply pushes `this` to the collectorArray.\r\n * * CurvePrimitiveWithDistanceIndex optionally collects its members.\r\n * @param collectorArray array to receive primitives (pushed -- the array is not cleared)\r\n * @param smallestPossiblePrimitives if false, CurvePrimitiveWithDistanceIndex returns only itself. If true, it recurses to its (otherwise hidden) children.\r\n */\r\n public collectCurvePrimitivesGo(collectorArray: CurvePrimitive[], _smallestPossiblePrimitives: boolean, _explodeLinestrings: boolean = false) {\r\n collectorArray.push(this);\r\n }\r\n\r\n /**\r\n * Return an array containing only the curve primitives.\r\n * * This DEFAULT captures the default result construction and calls collectCurvePrimitivesGo\r\n * @param collectorArray optional array to receive primitives. If present, new primitives are ADDED (without clearing the array.)\r\n * @param smallestPossiblePrimitives if false, CurvePrimitiveWithDistanceIndex returns only itself. If true, it recurses to its (otherwise hidden) children.\r\n */\r\n public collectCurvePrimitives(collectorArray?: CurvePrimitive[], smallestPossiblePrimitives: boolean = false,\r\n explodeLinestrings: boolean = false): CurvePrimitive[] {\r\n const results: CurvePrimitive[] = collectorArray === undefined ? [] : collectorArray;\r\n this.collectCurvePrimitivesGo(results, smallestPossiblePrimitives, explodeLinestrings);\r\n return results;\r\n }\r\n\r\n}\r\n\r\n/** Intermediate class for managing the parentCurve announcements from an IStrokeHandler */\r\nabstract class NewtonRotRStrokeHandler extends NewtonEvaluatorRtoR {\r\n protected _parentCurvePrimitive: CurvePrimitive | undefined;\r\n constructor() {\r\n super();\r\n this._parentCurvePrimitive = undefined;\r\n }\r\n /** retain the parentCurvePrimitive.\r\n * * Calling this method tells the handler that the parent curve is to be used for detail searches.\r\n * * Example: Transition spiral search is based on linestring first, then the exact spiral.\r\n * * Example: CurveChainWithDistanceIndex does NOT do this announcement -- the constituents act independently.\r\n */\r\n public startParentCurvePrimitive(curve: CurvePrimitive | undefined) { this._parentCurvePrimitive = curve; }\r\n /** Forget the parentCurvePrimitive */\r\n public endParentCurvePrimitive(_curve: CurvePrimitive | undefined) { this._parentCurvePrimitive = undefined; }\r\n}\r\n\r\nclass AppendPlaneIntersectionStrokeHandler extends NewtonRotRStrokeHandler implements IStrokeHandler {\r\n private _curve: CurvePrimitive | undefined;\r\n private _plane: PlaneAltitudeEvaluator;\r\n private _intersections: CurveLocationDetail[];\r\n private _fractionA: number = 0;\r\n private _functionA: number = 0;\r\n // private derivativeA: number; <---- Not currently used\r\n private _functionB: number = 0;\r\n private _fractionB: number = 0;\r\n private _derivativeB: number = 0;\r\n private _numThisCurve: number = 0;\r\n // scratch vars for use within methods.\r\n private _ray: Ray3d;\r\n private _newtonSolver: Newton1dUnboundedApproximateDerivative;\r\n\r\n // Return the first defined curve among: this.parentCurvePrimitive, this.curve;\r\n public effectiveCurve(): CurvePrimitive | undefined {\r\n if (this._parentCurvePrimitive)\r\n return this._parentCurvePrimitive;\r\n return this._curve;\r\n }\r\n public get getDerivativeB() { return this._derivativeB; } // <--- DerivativeB is not currently used anywhere. Provided getter to suppress lint error\r\n\r\n public constructor(plane: PlaneAltitudeEvaluator, intersections: CurveLocationDetail[]) {\r\n super();\r\n this._plane = plane;\r\n this._intersections = intersections;\r\n this.startCurvePrimitive(undefined);\r\n this._ray = Ray3d.createZero();\r\n this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);\r\n }\r\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\r\n this._curve = curve;\r\n this._fractionA = 0.0;\r\n this._numThisCurve = 0;\r\n this._functionA = 0.0;\r\n // this.derivativeA = 0.0;\r\n }\r\n public endCurvePrimitive() { }\r\n public announceIntervalForUniformStepStrokes(\r\n cp: CurvePrimitive,\r\n numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n this.startCurvePrimitive(cp);\r\n if (numStrokes < 1) numStrokes = 1;\r\n const df = 1.0 / numStrokes;\r\n for (let i = 0; i <= numStrokes; i++) {\r\n const fraction = Geometry.interpolate(fraction0, i * df, fraction1);\r\n cp.fractionToPointAndDerivative(fraction, this._ray);\r\n this.announcePointTangent(this._ray.origin, fraction, this._ray.direction);\r\n }\r\n }\r\n public announceSegmentInterval(\r\n _cp: CurvePrimitive,\r\n point0: Point3d,\r\n point1: Point3d,\r\n _numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n const h0 = this._plane.altitude(point0);\r\n const h1 = this._plane.altitude(point1);\r\n if (h0 * h1 > 0.0)\r\n return;\r\n const fraction01 = Order2Bezier.solveCoffs(h0, h1);\r\n // let numIntersection = 0;\r\n if (fraction01 !== undefined) {\r\n // numIntersection++;\r\n const fraction = Geometry.interpolate(fraction0, fraction01, fraction1);\r\n this._newtonSolver.setX(fraction);\r\n if (this._newtonSolver.runIterations()) {\r\n this.announceSolutionFraction(this._newtonSolver.getX());\r\n }\r\n // this.intersections.push(CurveLocationDetail.createCurveFractionPoint(cp, fraction, cp.fractionToPoint(fraction)));\r\n }\r\n }\r\n private announceSolutionFraction(fraction: number) {\r\n const curve = this.effectiveCurve();\r\n if (curve) {\r\n this._ray = curve.fractionToPointAndDerivative(fraction, this._ray);\r\n this._intersections.push(CurveLocationDetail.createCurveFractionPoint(curve, fraction, this._ray.origin));\r\n }\r\n }\r\n public evaluate(fraction: number): boolean {\r\n const curve = this.effectiveCurve();\r\n if (!curve)\r\n return false;\r\n this.currentF = this._plane.altitude(curve.fractionToPoint(fraction));\r\n return true;\r\n }\r\n /**\r\n * * ASSUME both the \"A\" and \"B\" evaluations (fraction, function, and derivative) are known.\r\n * * If function value changed sign between, interpolate an approximate root and improve it with\r\n * the newton solver.\r\n */\r\n private searchInterval() {\r\n if (this._functionA * this._functionB > 0) return;\r\n if (this._functionA === 0) this.announceSolutionFraction(this._fractionA);\r\n if (this._functionB === 0) this.announceSolutionFraction(this._fractionB);\r\n if (this._functionA * this._functionB < 0) {\r\n const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);\r\n if (fraction) {\r\n this._newtonSolver.setX(fraction);\r\n if (this._newtonSolver.runIterations())\r\n this.announceSolutionFraction(this._newtonSolver.getX());\r\n }\r\n }\r\n }\r\n /** Evaluate and save _functionB, _derivativeB, and _fractionB. */\r\n private evaluateB(xyz: Point3d, fraction: number, tangent: Vector3d) {\r\n this._functionB = this._plane.altitude(xyz);\r\n this._derivativeB = this._plane.velocity(tangent);\r\n this._fractionB = fraction;\r\n }\r\n /**\r\n * Announce point and tangent for evaluations.\r\n * * The function evaluation is saved as the \"B\" function point.\r\n * * The function point count is incremented\r\n * * If function point count is greater than 1, the current interval is searched.\r\n * * The just-evaluated point (\"B\") is saved as the \"old\" (\"A\") evaluation point.\r\n * @param xyz\r\n * @param fraction\r\n * @param tangent\r\n */\r\n public announcePointTangent(xyz: Point3d, fraction: number, tangent: Vector3d): void {\r\n this.evaluateB(xyz, fraction, tangent);\r\n if (this._numThisCurve++ > 0) this.searchInterval();\r\n this._functionA = this._functionB;\r\n this._fractionA = this._fractionB;\r\n }\r\n}\r\n\r\nclass CurveLengthContext implements IStrokeHandler {\r\n private _curve: CurvePrimitive | undefined;\r\n private _summedLength: number;\r\n private _ray: Ray3d;\r\n private _fraction0: number;\r\n private _fraction1: number;\r\n private _gaussMapper: GaussMapper;\r\n\r\n private tangentMagnitude(fraction: number): number {\r\n this._ray = (this._curve as CurvePrimitive).fractionToPointAndDerivative(fraction, this._ray);\r\n return this._ray.direction.magnitude();\r\n }\r\n public getSum() { return this._summedLength; }\r\n\r\n public constructor(fraction0: number = 0.0, fraction1: number = 1.0, numGaussPoints: number = 5) {\r\n this.startCurvePrimitive(undefined);\r\n this._summedLength = 0.0;\r\n this._ray = Ray3d.createZero();\r\n if (fraction0 < fraction1) {\r\n this._fraction0 = fraction0;\r\n this._fraction1 = fraction1;\r\n } else {\r\n this._fraction0 = fraction1;\r\n this._fraction1 = fraction0;\r\n }\r\n this._gaussMapper = new GaussMapper(numGaussPoints);\r\n }\r\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\r\n this._curve = curve;\r\n }\r\n public startParentCurvePrimitive(_curve: CurvePrimitive) { }\r\n public endParentCurvePrimitive(_curve: CurvePrimitive) { }\r\n\r\n public endCurvePrimitive() { }\r\n public announceIntervalForUniformStepStrokes(\r\n cp: CurvePrimitive,\r\n numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n if (fraction0 < this._fraction0) fraction0 = this._fraction0;\r\n if (fraction1 > this._fraction1) fraction1 = this._fraction1;\r\n if (fraction1 > fraction0) {\r\n this.startCurvePrimitive(cp);\r\n if (numStrokes < 1) numStrokes = 1;\r\n const df = 1.0 / numStrokes;\r\n for (let i = 1; i <= numStrokes; i++) {\r\n const fractionA = Geometry.interpolate(fraction0, (i - 1) * df, fraction1);\r\n const fractionB = i === numStrokes ? fraction1 : Geometry.interpolate(fraction0, (i) * df, fraction1);\r\n const numGauss = this._gaussMapper.mapXAndW(fractionA, fractionB);\r\n for (let k = 0; k < numGauss; k++) {\r\n this._summedLength += this._gaussMapper.gaussW[k] * this.tangentMagnitude(this._gaussMapper.gaussX[k]);\r\n }\r\n }\r\n }\r\n }\r\n public announceSegmentInterval(\r\n _cp: CurvePrimitive,\r\n point0: Point3d,\r\n point1: Point3d,\r\n _numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n const segmentLength = point0.distance(point1);\r\n if (this._fraction0 <= fraction0 && fraction1 <= this._fraction1)\r\n this._summedLength += segmentLength;\r\n else {\r\n let g0 = fraction0;\r\n let g1 = fraction1;\r\n if (g0 < this._fraction0) g0 = this._fraction0;\r\n if (g1 > this._fraction1) g1 = this._fraction1;\r\n if (g1 > g0) {\r\n this._summedLength += segmentLength * (g1 - g0) / (fraction1 - fraction0);\r\n }\r\n }\r\n }\r\n public announcePointTangent(_xyz: Point3d, _fraction: number, _tangent: Vector3d): void {\r\n // uh oh -- need to retain point for next interval\r\n }\r\n}\r\n// context for searching for closest point .. .\r\nclass ClosestPointStrokeHandler extends NewtonRotRStrokeHandler implements IStrokeHandler {\r\n private _curve: CurvePrimitive | undefined;\r\n private _closestPoint: CurveLocationDetail | undefined;\r\n private _spacePoint: Point3d;\r\n private _extend: VariantCurveExtendParameter;\r\n private _fractionA: number = 0;\r\n private _functionA: number = 0;\r\n private _functionB: number = 0;\r\n private _fractionB: number = 0;\r\n private _numThisCurve: number = 0;\r\n // scratch vars for use within methods.\r\n private _workPoint: Point3d;\r\n private _workRay: Ray3d;\r\n private _newtonSolver: Newton1dUnboundedApproximateDerivative;\r\n\r\n public constructor(spacePoint: Point3d, extend: VariantCurveExtendParameter) {\r\n super();\r\n this._spacePoint = spacePoint;\r\n this._workPoint = Point3d.create();\r\n this._workRay = Ray3d.createZero();\r\n this._closestPoint = undefined;\r\n this._extend = extend;\r\n this.startCurvePrimitive(undefined);\r\n this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);\r\n }\r\n\r\n public claimResult(): CurveLocationDetail | undefined {\r\n if (this._closestPoint) {\r\n this._newtonSolver.setX(this._closestPoint.fraction);\r\n this._curve = this._closestPoint.curve;\r\n if (this._newtonSolver.runIterations()) {\r\n let fraction = this._newtonSolver.getX();\r\n fraction = CurveExtendOptions.correctFraction(this._extend, fraction);\r\n this.announceSolutionFraction(fraction);\r\n }\r\n }\r\n return this._closestPoint;\r\n }\r\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\r\n this._curve = curve;\r\n this._fractionA = 0.0;\r\n this._numThisCurve = 0;\r\n this._functionA = 0.0;\r\n }\r\n public endCurvePrimitive() { }\r\n public announceIntervalForUniformStepStrokes(\r\n cp: CurvePrimitive,\r\n numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n this.startCurvePrimitive(cp);\r\n this.announceSolutionFraction(0.0); // test start point as closest\r\n this.announceSolutionFraction(1.0); // test end point as closest\r\n if (numStrokes < 1) numStrokes = 1;\r\n const df = 1.0 / numStrokes;\r\n for (let i = 0; i <= numStrokes; i++) {\r\n const fraction = Geometry.interpolate(fraction0, i * df, fraction1);\r\n cp.fractionToPointAndDerivative(fraction, this._workRay);\r\n this.announceRay(fraction, this._workRay);\r\n }\r\n }\r\n\r\n private announceCandidate(cp: CurvePrimitive, fraction: number, point: Point3d) {\r\n const distance = this._spacePoint.distance(point);\r\n if (this._closestPoint && distance > this._closestPoint.a)\r\n return;\r\n this._closestPoint = CurveLocationDetail.createCurveFractionPoint(cp, fraction, point, this._closestPoint);\r\n this._closestPoint.a = distance;\r\n if (this._parentCurvePrimitive !== undefined)\r\n this._closestPoint.curve = this._parentCurvePrimitive;\r\n }\r\n public announceSegmentInterval(\r\n cp: CurvePrimitive,\r\n point0: Point3d,\r\n point1: Point3d,\r\n _numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n let localFraction = this._spacePoint.fractionOfProjectionToLine(point0, point1, 0.0);\r\n // only consider extending the segment if the immediate caller says we are at endpoints ...\r\n if (!this._extend)\r\n localFraction = Geometry.clampToStartEnd(localFraction, 0.0, 1.0);\r\n else {\r\n if (fraction0 !== 0.0)\r\n localFraction = Math.max(localFraction, 0.0);\r\n if (fraction1 !== 1.0)\r\n localFraction = Math.min(localFraction, 1.0);\r\n }\r\n this._workPoint = point0.interpolate(localFraction, point1);\r\n const globalFraction = Geometry.interpolate(fraction0, localFraction, fraction1);\r\n this.announceCandidate(cp, globalFraction, this._workPoint);\r\n }\r\n private searchInterval() {\r\n if (this._functionA * this._functionB > 0) return;\r\n if (this._functionA === 0) this.announceSolutionFraction(this._fractionA);\r\n if (this._functionB === 0) this.announceSolutionFraction(this._fractionB);\r\n if (this._functionA * this._functionB < 0) {\r\n const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);\r\n if (fraction) {\r\n this._newtonSolver.setX(fraction);\r\n if (this._newtonSolver.runIterations())\r\n this.announceSolutionFraction(this._newtonSolver.getX());\r\n }\r\n }\r\n }\r\n private evaluateB(fractionB: number, dataB: Ray3d) {\r\n this._functionB = dataB.dotProductToPoint(this._spacePoint);\r\n this._fractionB = fractionB;\r\n }\r\n private announceSolutionFraction(fraction: number) {\r\n if (this._curve)\r\n this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));\r\n }\r\n public evaluate(fraction: number): boolean {\r\n let curve = this._curve;\r\n if (this._parentCurvePrimitive)\r\n curve = this._parentCurvePrimitive;\r\n if (curve) {\r\n this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);\r\n this.currentF = this._workRay.dotProductToPoint(this._spacePoint);\r\n return true;\r\n }\r\n return false;\r\n }\r\n public announceRay(fraction: number, data: Ray3d): void {\r\n this.evaluateB(fraction, data);\r\n if (this._numThisCurve++ > 0) this.searchInterval();\r\n this._functionA = this._functionB;\r\n this._fractionA = this._fractionB;\r\n }\r\n public announcePointTangent(point: Point3d, fraction: number, tangent: Vector3d) {\r\n this._workRay.set(point, tangent);\r\n this.announceRay(fraction, this._workRay);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CurvePrimitive.js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AAC;IACM,QAAQ,CAAC,QAAgB;QAC9B,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QACxB,IAAI,IAAI,CAAC,qBAAqB;YAC5B,KAAK,GAAG,IAAI,CAAC,qBAAqB,CAAC;QACrC,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,4BAA4B,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5E,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAClE,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACM,WAAW,CAAC,QAAgB,EAAE,IAAW;QAC9C,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC/B,IAAI,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC;YAAE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACpC,CAAC;IACM,oBAAoB,CAAC,KAAc,EAAE,QAAgB,EAAE,OAAiB;QAC7E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,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 Curve\r\n */\r\nimport { InterpolationCurve3d } from \"../bspline/InterpolationCurve3d\";\r\nimport { Clipper } from \"../clipping/ClipUtils\";\r\nimport { StrokeCountMap } from \"../curve/Query/StrokeCountMap\";\r\nimport { AxisOrder, Geometry, PlaneAltitudeEvaluator } from \"../Geometry\";\r\nimport { AkimaCurve3d } from \"../bspline/AkimaCurve3d\";\r\nimport { BSplineCurve3d } from \"../bspline/BSplineCurve\";\r\nimport { BezierCurve3d } from \"../bspline/BezierCurve3d\";\r\nimport { CurveChainWithDistanceIndex } from \"./CurveChainWithDistanceIndex\";\r\nimport { DirectSpiral3d } from \"./spiral/DirectSpiral3d\";\r\nimport { IntegratedSpiral3d } from \"./spiral/IntegratedSpiral3d\";\r\nimport { IStrokeHandler } from \"../geometry3d/GeometryHandler\";\r\nimport { Matrix3d } from \"../geometry3d/Matrix3d\";\r\nimport { Plane3dByOriginAndUnitNormal } from \"../geometry3d/Plane3dByOriginAndUnitNormal\";\r\nimport { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Ray3d } from \"../geometry3d/Ray3d\";\r\nimport { Transform } from \"../geometry3d/Transform\";\r\nimport { Order2Bezier } from \"../numerics/BezierPolynomials\";\r\nimport { Newton1dUnboundedApproximateDerivative, NewtonEvaluatorRtoR } from \"../numerics/Newton\";\r\nimport { GaussMapper } from \"../numerics/Quadrature\";\r\nimport { Arc3d } from \"./Arc3d\";\r\nimport { CurveExtendOptions, VariantCurveExtendParameter } from \"./CurveExtendMode\";\r\nimport { CurveIntervalRole, CurveLocationDetail, CurveSearchStatus } from \"./CurveLocationDetail\";\r\nimport { GeometryQuery } from \"./GeometryQuery\";\r\nimport { LineSegment3d } from \"./LineSegment3d\";\r\nimport { LineString3d } from \"./LineString3d\";\r\nimport { StrokeOptions } from \"./StrokeOptions\";\r\n\r\n/** Describes the concrete type of a [[CurvePrimitive]]. Each type name maps to a specific subclass and can be used for type-switching in conditional statements.\r\n * - \"arc\" => [[Arc3d]]\r\n * - \"lineSegment\" => [[LineSegment3d]]\r\n * - \"lineString\" => [[LineString3d]]\r\n * - \"bsplineCurve\" => [[BSplineCurve3dBase]] which is an intermediate class implemented by [[BSplineCurve3d]] and [[BSplineCurve3dH]]\r\n * - \"bezierCurve\" => [[BezierCurveBase]] which is an intermediate class implemented by [[BezierCurve3d]] and [[BezierCurve3dH]]\r\n * - \"transitionSpiral\" => [[TransitionSpiral3d]]\r\n * - \"curveChainWithDistanceIndex\" => [[CurveChainWithDistanceIndex]]\r\n * @see [[AnyCurvePrimitive]] for a union type that supports compile-time type narrowing.\r\n * @public\r\n */\r\nexport type CurvePrimitiveType = \"arc\" | \"lineSegment\" | \"lineString\" | \"bsplineCurve\" | \"bezierCurve\" | \"transitionSpiral\" | \"curveChainWithDistanceIndex\" | \"interpolationCurve\" | \"akimaCurve\";\r\n\r\n/** Union type for subclasses of [[CurvePrimitive]]. Specific subclasses can be discriminated at compile- or run-time using [[CurvePrimitive.curvePrimitiveType]].\r\n * @public\r\n */\r\nexport type AnyCurvePrimitive = Arc3d | LineSegment3d | LineString3d | BSplineCurve3d | BezierCurve3d | DirectSpiral3d | IntegratedSpiral3d | CurveChainWithDistanceIndex | InterpolationCurve3d | AkimaCurve3d;\r\n\r\n/** function signature for callback which announces a pair of numbers, such as a fractional interval, along with a containing CurvePrimitive.\r\n * @public\r\n */\r\nexport type AnnounceNumberNumberCurvePrimitive = (a0: number, a1: number, cp: CurvePrimitive) => void;\r\n/** Function signature for a callback which announces a pair of numbers\r\n * @public\r\n */\r\n\r\nexport type AnnounceNumberNumber = (a0: number, a1: number) => void;\r\n/** Function signature for a callback which announces a curve primitive\r\n * @public\r\n */\r\nexport type AnnounceCurvePrimitive = (cp: CurvePrimitive) => void;\r\n/**\r\n * A curve primitive is bounded\r\n * A curve primitive maps fractions in 0..1 to points in space.\r\n * As the fraction proceeds from 0 towards 1, the point moves \"forward\" along the curve.\r\n * True distance along the curve is not always strictly proportional to fraction.\r\n * * LineSegment3d always has proportional fraction and distance\r\n * * an Arc3d which is true circular has proportional fraction and distance\r\n * * A LineString3d is not proportional (except for special case of all segments of equal length)\r\n * * A Spiral3d is proportional\r\n * * A BsplineCurve3d is only proportional for special cases.\r\n *\r\n * For fractions outside 0..1, the curve primitive class may either (a) return the near endpoint or (b) evaluate an extended curve.\r\n * @public\r\n */\r\nexport abstract class CurvePrimitive extends GeometryQuery {\r\n /** String name for schema properties */\r\n public readonly geometryCategory = \"curvePrimitive\";\r\n /** String name for schema properties */\r\n public abstract readonly curvePrimitiveType: CurvePrimitiveType;\r\n\r\n protected constructor() { super(); }\r\n /**\r\n * data attached during stroking for facets.\r\n */\r\n public strokeData?: StrokeCountMap;\r\n /**\r\n * data attached in curve cutting.\r\n * @internal\r\n */\r\n public startCut?: CurveLocationDetail;\r\n /**\r\n * data attached in curve cutting.\r\n * @internal\r\n */\r\n public endCut?: CurveLocationDetail;\r\n /**\r\n * data attached by various algorithms (e.g. Region booleans)\r\n */\r\n public parent?: any;\r\n\r\n /** Return the point (x,y,z) on the curve at fractional position.\r\n * @param fraction fractional position along the geometry.\r\n * @returns Returns a point on the curve.\r\n */\r\n public abstract fractionToPoint(fraction: number, result?: Point3d): Point3d;\r\n /** Return the point (x,y,z) and derivative on the curve at fractional position.\r\n *\r\n * * Note that this derivative is \"derivative of xyz with respect to fraction.\"\r\n * * this derivative shows the speed of the \"fractional point\" moving along the curve.\r\n * * this is not generally a unit vector. use fractionToPointAndUnitTangent for a unit vector.\r\n * @param fraction fractional position along the geometry.\r\n * @returns Returns a ray whose origin is the curve point and direction is the derivative with respect to the fraction.\r\n */\r\n public abstract fractionToPointAndDerivative(fraction: number, result?: Ray3d): Ray3d;\r\n /**\r\n * Returns a ray whose origin is the curve point and direction is the unit tangent.\r\n * @param fraction fractional position on the curve\r\n * @param result optional preallocated ray.\r\n */\r\n public fractionToPointAndUnitTangent(fraction: number, result?: Ray3d): Ray3d {\r\n const ray = this.fractionToPointAndDerivative(fraction, result);\r\n ray.trySetDirectionMagnitudeInPlace(1.0);\r\n return ray;\r\n }\r\n /**\r\n * Returns the (absolute) curvature magnitude.\r\n * * Base implementation in CurvePrimitive computes curvature from the first and second derivative vectors.\r\n * @param fraction fractional position on the curve\r\n */\r\n public fractionToCurvature(fraction: number): number | undefined {\r\n const data = this.fractionToPointAnd2Derivatives(fraction)!;\r\n const cross = data.vectorU.crossProduct(data.vectorV);\r\n const a = cross.magnitude();\r\n const b = data.vectorU.magnitude();\r\n return Geometry.conditionalDivideFraction(a, b * b * b);\r\n }\r\n\r\n /** Return a plane with\r\n *\r\n * * origin at fractional position along the curve\r\n * * vectorU is the first derivative, i.e. tangent vector with length equal to the rate of change with respect to the fraction.\r\n * * vectorV is the second derivative, i.e.derivative of vectorU.\r\n */\r\n public abstract fractionToPointAnd2Derivatives(fraction: number, result?: Plane3dByOriginAndVectors): Plane3dByOriginAndVectors | undefined;\r\n\r\n /** Construct a frenet frame:\r\n * * origin at the point on the curve\r\n * * x axis is unit vector along the curve (tangent)\r\n * * y axis is perpendicular and in the plane of the osculating circle.\r\n * * z axis perpendicular to those.\r\n */\r\n public fractionToFrenetFrame(fraction: number, result?: Transform): Transform | undefined {\r\n const plane = this.fractionToPointAnd2Derivatives(fraction);\r\n if (!plane) return undefined;\r\n let axes = Matrix3d.createRigidFromColumns(plane.vectorU, plane.vectorV, AxisOrder.XYZ);\r\n if (axes)\r\n return Transform.createRefs(plane.origin, axes, result);\r\n // 2nd derivative not distinct -- do arbitrary headsUP ...\r\n const perpVector = Matrix3d.createPerpendicularVectorFavorXYPlane(plane.vectorU, plane.vectorV);\r\n axes = Matrix3d.createRigidFromColumns(plane.vectorU, perpVector, AxisOrder.XYZ);\r\n if (axes)\r\n return Transform.createRefs(plane.origin, axes, result);\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Construct a point extrapolated along tangent at fraction.\r\n * @param fraction fractional position on the primitive\r\n * @param distance (signed) distance to move on the tangent.\r\n */\r\n public fractionAndDistanceToPointOnTangent(fraction: number, distance: number): Point3d {\r\n const ray = this.fractionToPointAndUnitTangent(fraction);\r\n return ray.fractionToPoint(distance);\r\n }\r\n\r\n /**\r\n * return the length of the curve.\r\n * * Curve length is always positive.\r\n */\r\n public curveLength(): number {\r\n const context = new CurveLengthContext();\r\n this.emitStrokableParts(context);\r\n return context.getSum();\r\n }\r\n /**\r\n * Returns a (high accuracy) length of the curve between fractional positions\r\n * * Curve length is always positive.\r\n * * Default implementation applies a generic gaussian integration.\r\n * * Most curve classes (certainly LineSegment, LineString, Arc) are expected to provide efficient implementations.\r\n */\r\n public curveLengthBetweenFractions(fraction0: number, fraction1: number): number {\r\n if (fraction0 === fraction1)\r\n return 0.0;\r\n const scale = this.getFractionToDistanceScale();\r\n if (scale !== undefined) {\r\n // We are in luck! simple proportions determine it all !!!\r\n // (for example, a LineSegment3d or a circular arc)\r\n const totalLength = this.curveLength();\r\n return Math.abs((fraction1 - fraction0) * totalLength);\r\n }\r\n const context = new CurveLengthContext(fraction0, fraction1);\r\n this.emitStrokableParts(context);\r\n return Math.abs(context.getSum());\r\n }\r\n\r\n /**\r\n *\r\n * * Run an integration (with a default gaussian quadrature) with a fixed fractional step\r\n * * This is typically called by specific curve type implementations of curveLengthBetweenFractions.\r\n * * For example, in Arc3d implementation of curveLengthBetweenFractions:\r\n * * If the Arc3d is true circular, it the arc is true circular, use the direct `arcLength = radius * sweepRadians`\r\n * * If the Arc3d is not true circular, call this method with an interval count appropriate to eccentricity and sweepRadians.\r\n * @returns Returns an integral estimated by numerical quadrature between the fractional positions.\r\n * @param fraction0 start fraction for integration\r\n * @param fraction1 end fraction for integration\r\n * @param numInterval number of quadrature intervals\r\n */\r\n public curveLengthWithFixedIntervalCountQuadrature(fraction0: number, fraction1: number, numInterval: number, numGauss: number = 5): number {\r\n if (fraction0 > fraction1) {\r\n const fSave = fraction0;\r\n fraction0 = fraction1;\r\n fraction1 = fSave;\r\n }\r\n const context = new CurveLengthContext(fraction0, fraction1, numGauss);\r\n context.announceIntervalForUniformStepStrokes(this, numInterval, fraction0, fraction1);\r\n return Math.abs(context.getSum());\r\n }\r\n\r\n /**\r\n *\r\n * * (Attempt to) find a position on the curve at a signed distance from start fraction.\r\n * * Return the position as a CurveLocationDetail.\r\n * * In the `CurveLocationDetail`, record:\r\n * * `fractional` position\r\n * * `fraction` = coordinates of the point\r\n * * `search\r\n * * `a` = (signed!) distance moved. If `allowExtension` is false and the move reached the start or end of the curve, this distance is smaller than the requested signedDistance.\r\n * * `curveSearchStatus` indicates one of:\r\n * * `error` (unusual) computation failed not supported for this curve.\r\n * * `success` full movement completed\r\n * * `stoppedAtBoundary` partial movement completed. This can be due to either\r\n * * `allowExtension` parameter sent as `false`\r\n * * the curve type (e.g. bspline) does not support extended range.\r\n * * if `allowExtension` is true, movement may still end at the startPoint or end point for curves that do not support extended geometry (specifically bsplines)\r\n * * if the curve returns a value (i.e. not `undefined`) for `curve.getFractionToDistanceScale()`, the base class carries out the computation\r\n * and returns a final location.\r\n * * LineSegment3d relies on this.\r\n * * If the curve does not implement the computation or the curve has zero length, the returned `CurveLocationDetail` has\r\n * * `fraction` = the value of `startFraction`\r\n * * `point` = result of `curve.fractionToPoint(startFraction)`\r\n * * `a` = 0\r\n * * `curveStartState` = `CurveSearchStatus.error`\r\n * @param startFraction fractional position where the move starts\r\n * @param signedDistance distance to move. Negative distance is backwards in the fraction space\r\n * @param allowExtension if true, all the move to go beyond the startPoint or endpoint of the curve. If false, do not allow movement beyond the startPoint or endpoint\r\n * @param result optional result.\r\n * @returns A CurveLocationDetail annotated as above. Note that if the curve does not support the calculation, there is still a result which contains the point at the input startFraction, with failure indicated in the `curveStartState` member\r\n */\r\n public moveSignedDistanceFromFraction(startFraction: number, signedDistance: number, allowExtension: boolean, result?: CurveLocationDetail): CurveLocationDetail {\r\n const scale = this.getFractionToDistanceScale();\r\n if (scale !== undefined) {\r\n // We are in luck! simple proportions determine it all !!!\r\n // (for example, a LineSegment3d or a circular arc)\r\n const totalLength = this.curveLength();\r\n const signedFractionMove = Geometry.conditionalDivideFraction(signedDistance, totalLength);\r\n if (signedFractionMove === undefined) {\r\n return CurveLocationDetail.createCurveFractionPointDistanceCurveSearchStatus(\r\n this, startFraction, this.fractionToPoint(startFraction), 0.0, CurveSearchStatus.error);\r\n }\r\n return CurveLocationDetail.createConditionalMoveSignedDistance(\r\n allowExtension,\r\n this,\r\n startFraction,\r\n startFraction + signedFractionMove,\r\n signedDistance,\r\n result);\r\n }\r\n return this.moveSignedDistanceFromFractionGeneric(startFraction, signedDistance, allowExtension, result);\r\n }\r\n /**\r\n * Generic algorithm to search for point at signed distance from a fractional startPoint.\r\n * * This will work for well for smooth curves.\r\n * * Curves with tangent or other low-order-derivative discontinuities may need to implement specialized algorithms.\r\n * * We need to find an endFraction which is the end-of-interval (usually upper) limit of integration of the tangent magnitude from startFraction to endFraction\r\n * * That integral is a function of endFraction.\r\n * * The derivative of that integral with respect to end fraction is the tangent magnitude at end fraction.\r\n * * Use that function and (easily evaluated!) derivative for a Newton iteration\r\n * * TO ALL WHO HAVE FUZZY MEMORIES OF CALCULUS CLASS: \"The derivative of the integral wrt upper limit is the value of the integrand there\" is the\r\n * fundamental theorem of integral calculus !!! The fundamental theorem is not just an abstraction !!! It is being used\r\n * here in its barest possible form !!!\r\n * * See https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus\r\n * @param startFraction\r\n * @param signedDistance\r\n * @param _allowExtension\r\n * @param result\r\n */\r\n protected moveSignedDistanceFromFractionGeneric(startFraction: number, signedDistance: number, allowExtension: boolean, result?: CurveLocationDetail): CurveLocationDetail {\r\n const limitFraction = signedDistance > 0.0 ? 1.0 : 0.0;\r\n const absDistance = Math.abs(signedDistance);\r\n const directionFactor = signedDistance < 0.0 ? -1.0 : 1.0;\r\n const availableLength = this.curveLengthBetweenFractions(startFraction, limitFraction); // that is always positive\r\n if (availableLength < absDistance && !allowExtension)\r\n return CurveLocationDetail.createConditionalMoveSignedDistance(allowExtension, this, startFraction, limitFraction, signedDistance, result);\r\n const fractionStep = absDistance / availableLength;\r\n let fractionB = Geometry.interpolate(startFraction, fractionStep, limitFraction);\r\n let fractionA = startFraction;\r\n let distanceA = 0.0;\r\n const tol = 1.0e-12 * availableLength;\r\n let numConverged = 0;\r\n const tangent = Ray3d.createXAxis();\r\n // on each loop entry:\r\n // fractionA is the most recent endOfInterval. (It may have been reached by a mixture of forward and backward step.)\r\n // distanceA is the distance to (the point at) fractionA\r\n // fractionB is the next end fraction\r\n for (let iterations = 0; iterations < 10; iterations++) {\r\n const distanceAB = this.curveLengthBetweenFractions(fractionA, fractionB);\r\n const directionAB = fractionB > fractionA ? directionFactor : -directionFactor;\r\n const distance0B = distanceA + directionAB * distanceAB;\r\n const distanceError = absDistance - distance0B;\r\n if (Math.abs(distanceError) < tol) {\r\n numConverged++;\r\n if (numConverged > 1)\r\n break;\r\n } else {\r\n numConverged = 0;\r\n }\r\n this.fractionToPointAndDerivative(fractionB, tangent);\r\n const tangentMagnitude = tangent.direction.magnitude();\r\n fractionA = fractionB;\r\n fractionB = fractionA + directionFactor * distanceError / tangentMagnitude;\r\n if (fractionA === fractionB) { // YES -- that is an exact equality test. When it happens, there's no need for confirming with another iteration.\r\n numConverged = 100;\r\n break;\r\n }\r\n distanceA = distance0B;\r\n }\r\n if (numConverged > 1)\r\n return CurveLocationDetail.createConditionalMoveSignedDistance(false, this, startFraction, fractionB, signedDistance, result);\r\n\r\n result = CurveLocationDetail.createCurveEvaluatedFraction(this, startFraction, result);\r\n result.a = 0.0;\r\n result.curveSearchStatus = CurveSearchStatus.error;\r\n return result;\r\n }\r\n\r\n /**\r\n * * Returns true if the curve's fraction queries extend beyond 0..1.\r\n * * Base class default implementation returns false.\r\n * * These class (and perhaps others in the future) will return true:\r\n * * LineSegment3d\r\n * * LineString3d\r\n * * Arc3d\r\n */\r\n public get isExtensibleFractionSpace(): boolean { return false; }\r\n /**\r\n * Compute a length which may be an fast approximation to the true length.\r\n * This is expected to be either (a) exact or (b) larger than the actual length, but by no more than\r\n * a small multiple, perhaps up to PI/2, but commonly much closer to 1.\r\n *\r\n * * An example use of this is for setting a tolerance which is a small multiple of the curve length.\r\n * * Simple line, circular arc, and transition spiral may return exact length\r\n * * Ellipse may return circumference of some circle or polygon that encloses the ellipse.\r\n * * bspline curve may return control polygon length\r\n * *\r\n */\r\n public abstract quickLength(): number;\r\n /** Search for the curve point that is closest to the spacePoint.\r\n *\r\n * * If the space point is exactly on the curve, this is the reverse of fractionToPoint.\r\n * * Since CurvePrimitive should always have start and end available as candidate points, this method should always succeed\r\n * @param spacePoint point in space\r\n * @param extend true to extend the curve (if possible), false for no extend, single CurveExtendOptions (for both directions), or array of distinct CurveExtendOptions for start and end.\r\n * @returns Returns a CurveLocationDetail structure that holds the details of the close point.\r\n */\r\n public closestPoint(spacePoint: Point3d, extend: VariantCurveExtendParameter): CurveLocationDetail | undefined {\r\n const strokeHandler = new ClosestPointStrokeHandler(spacePoint, extend);\r\n this.emitStrokableParts(strokeHandler);\r\n return strokeHandler.claimResult();\r\n }\r\n /**\r\n * Find intervals of this curvePrimitive that are interior to a clipper\r\n * @param clipper clip structure (e.g. clip planes)\r\n * @param announce (optional) function to be called announcing fractional intervals\" ` announce(fraction0, fraction1, curvePrimitive)`\r\n * @returns true if any \"in\" segments are announced.\r\n */\r\n public announceClipIntervals(_clipper: Clipper, _announce?: AnnounceNumberNumberCurvePrimitive): boolean {\r\n // DEFAULT IMPLEMENTATION -- no interior parts\r\n return false;\r\n }\r\n\r\n /** Return (if possible) a curve primitive which is a portion of this curve.\r\n * @param _fractionA [in] start fraction\r\n * @param _fractionB [in] end fraction\r\n */\r\n public clonePartialCurve(_fractionA: number, _fractionB: number): CurvePrimitive | undefined {\r\n return undefined;\r\n }\r\n /**\r\n * * If the curve primitive has distance-along-curve strictly proportional to curve fraction, return true\r\n * * If distance-along-the-curve is not proportional, return undefined.\r\n * * When defined, the scale factor is always the length of the curve.\r\n * * This scale factor is typically available for these curve types:\r\n * * * All `LineSegment3d`\r\n * * * Arc3d which is a true circular arc (axes perpendicular and of equal length).\r\n * * * CurveChainWithDistanceIndex\r\n * * This scale factor is undefined for these curve types:\r\n * * * Arc3d which is a true ellipse, i.e. unequal lengths of defining vectors or non-perpendicular defining vectors.\r\n * * * bspline and bezier curves\r\n * @returns scale factor or undefined\r\n */\r\n public getFractionToDistanceScale(): number | undefined { return undefined; }\r\n\r\n /** Reverse the curve's data so that its fractional stroking moves in the opposite direction. */\r\n public abstract reverseInPlace(): void;\r\n /**\r\n * Compute intersections with a plane.\r\n * * The intersections are appended to the result array.\r\n * * The base class implementation emits strokes to an AppendPlaneIntersectionStrokeHandler object, which uses a Newton iteration to get\r\n * high-accuracy intersection points within strokes.\r\n * * Derived classes should override this default implementation if there are easy analytic solutions.\r\n * * Derived classes are free to implement extended intersections (e.g. arc!!!)\r\n * @param plane The plane to be intersected.\r\n * @param result Array to receive intersections\r\n * @returns Return the number of CurveLocationDetail's added to the result array.\r\n */\r\n public appendPlaneIntersectionPoints(plane: PlaneAltitudeEvaluator, result: CurveLocationDetail[]): number {\r\n const strokeHandler = new AppendPlaneIntersectionStrokeHandler(plane, result);\r\n const n0 = result.length;\r\n this.emitStrokableParts(strokeHandler);\r\n return result.length - n0;\r\n }\r\n /**\r\n * Examine contents of an array of CurveLocationDetail.\r\n * Filter the intersections according to the parameters.\r\n * @param allowExtend if false, remove points on the extension.\r\n * @param applySnappedCoordinates if true, change the stored fractions and coordinates to exact end values. Otherwise\r\n * use the exact values only for purpose of updating the curveIntervalRole.\r\n * @param startEndFractionTolerance if nonzero, adjust fraction to 0 or 1 with this tolerance.\r\n * @param startEndXYZTolerance if nonzero, adjust to endpoint with this tolerance.\r\n * @internal\r\n */\r\n public static snapAndRestrictDetails(\r\n details: CurveLocationDetail[],\r\n allowExtend: boolean = true,\r\n applySnappedCoordinates: boolean = false,\r\n startEndFractionTolerance = Geometry.smallAngleRadians,\r\n startEndXYZTolerance = Geometry.smallMetricDistance) {\r\n const n0 = details.length;\r\n let acceptIndex = 0;\r\n const point0 = Point3d.create();\r\n const point1 = Point3d.create();\r\n let snappedCoordinates: Point3d | undefined;\r\n for (let candidateIndex = 0; candidateIndex < n0; candidateIndex++) {\r\n snappedCoordinates = undefined;\r\n const detail = details[candidateIndex];\r\n let fraction = detail.fraction;\r\n let accept = allowExtend || Geometry.isIn01(fraction);\r\n if (detail.curve) {\r\n detail.curve.startPoint(point0);\r\n detail.curve.endPoint(point1);\r\n }\r\n\r\n if (startEndFractionTolerance > 0) {\r\n if (Math.abs(fraction) < startEndFractionTolerance) {\r\n fraction = 0.0;\r\n accept = true;\r\n detail.intervalRole = CurveIntervalRole.isolatedAtVertex;\r\n snappedCoordinates = point0;\r\n }\r\n if (Math.abs(fraction - 1.0) < startEndFractionTolerance) {\r\n fraction = 1.0;\r\n accept = true;\r\n detail.intervalRole = CurveIntervalRole.isolatedAtVertex;\r\n snappedCoordinates = point1;\r\n if (detail.curve)\r\n snappedCoordinates = detail.curve.startPoint(point1);\r\n }\r\n }\r\n if (startEndXYZTolerance > 0 && detail.curve !== undefined) {\r\n // REMARK: always test both endpoints. If there is a cyclic fraction space, an intersection marked as \"after\" the end might have wrapped all the way to the beginning.\r\n if (detail.point.distance(point0) <= startEndXYZTolerance) {\r\n fraction = 0.0;\r\n detail.intervalRole = CurveIntervalRole.isolatedAtVertex;\r\n snappedCoordinates = point0;\r\n } else if (detail.point.distance(point1) <= startEndXYZTolerance) {\r\n fraction = 1.0;\r\n detail.intervalRole = CurveIntervalRole.isolatedAtVertex;\r\n snappedCoordinates = point1;\r\n }\r\n }\r\n if (accept) {\r\n if (applySnappedCoordinates) {\r\n detail.fraction = fraction;\r\n if (snappedCoordinates !== undefined)\r\n detail.point.setFrom(snappedCoordinates);\r\n }\r\n if (acceptIndex < candidateIndex)\r\n details[acceptIndex] = detail;\r\n acceptIndex++;\r\n }\r\n\r\n }\r\n if (acceptIndex < n0)\r\n details.length = acceptIndex;\r\n\r\n }\r\n\r\n /** Ask if the curve is within tolerance of a plane.\r\n * @returns Returns true if the curve is completely within tolerance of the plane.\r\n */\r\n public abstract isInPlane(plane: Plane3dByOriginAndUnitNormal): boolean;\r\n /** return the startPoint of the primitive. The default implementation returns fractionToPoint (0.0) */\r\n public startPoint(result?: Point3d): Point3d { return this.fractionToPoint(0.0, result); }\r\n /** return the end point of the primitive. The default implementation returns fractionToPoint(1.0) */\r\n public endPoint(result?: Point3d): Point3d { return this.fractionToPoint(1.0, result); }\r\n /** Add strokes to caller-supplied linestring */\r\n public abstract emitStrokes(dest: LineString3d, options?: StrokeOptions): void;\r\n /** Ask the curve to announce points and simple subcurve fragments for stroking.\r\n * See IStrokeHandler for description of the sequence of the method calls.\r\n */\r\n public abstract emitStrokableParts(dest: IStrokeHandler, options?: StrokeOptions): void;\r\n /**\r\n * return the stroke count required for given options.\r\n * * This returns a single number\r\n * * See computeComponentStrokeCountForOptions to get structured per-component counts and fraction mappings.\r\n * @param options StrokeOptions that determine count\r\n */\r\n public abstract computeStrokeCountForOptions(options?: StrokeOptions): number;\r\n\r\n /**\r\n * attach StrokeCountMap structure to this primitive (and recursively to any children)\r\n * * Base class implementation (here) gets the simple count from computeStrokeCountForOptions and attaches it.\r\n * * LineString3d, arc3d, BezierCurve3d, BezierCurve3dH accept that default.\r\n * * Subdivided primitives (linestring, bspline curve) implement themselves and attach a StrokeCountMap containing the\r\n * total count, and also containing an array of StrokeCountMap per component.\r\n * * For CurvePrimitiveWithDistanceIndex, the top level gets (only) a total count, and each child gets\r\n * its own StrokeCountMap with appropriate structure.\r\n * @param options StrokeOptions that determine count\r\n * @param parentStrokeMap optional map from parent. Its count, curveLength, and a1 values are increased with count and distance from this primitive.\r\n * @return sum of `a0+this.curveLength()`, for use as `a0` of successor in chain.\r\n */\r\n public computeAndAttachRecursiveStrokeCounts(options?: StrokeOptions, parentMap?: StrokeCountMap) {\r\n const n = this.computeStrokeCountForOptions(options);\r\n const a = this.curveLength();\r\n CurvePrimitive.installStrokeCountMap(\r\n this,\r\n StrokeCountMap.createWithCurvePrimitive(this, n, a, 0, a),\r\n parentMap);\r\n }\r\n\r\n /**\r\n * * evaluate strokes at fractions indicated in a StrokeCountMap.\r\n * * Base class implementation (here) gets the simple count from computeStrokeCountForOptions and strokes at uniform fractions.\r\n * * LineString3d, arc3d, BezierCurve3d, BezierCurve3dH accept that default.\r\n * * Subdivided primitives (linestring, bspline curve) implement themselves and evaluate within components.\r\n * * CurvePrimitiveWithDistanceIndex recurses to its children.\r\n * * if packedFraction and packedDerivative arrays are present in the LineString3d, fill them.\r\n * @param map = stroke count data.\r\n * @param linestring = receiver linestring.\r\n * @return number of strokes added. 0 if any errors matching the map to the curve primitive.\r\n */\r\n public addMappedStrokesToLineString3D(map: StrokeCountMap, linestring: LineString3d): number {\r\n const numPoint0 = linestring.numPoints();\r\n if (map.primitive && map.primitive === this && map.numStroke > 0) {\r\n for (let i = 0; i <= map.numStroke; i++) {\r\n const fraction = i / map.numStroke;\r\n linestring.appendFractionToPoint(this, fraction);\r\n }\r\n }\r\n return linestring.numPoints() - numPoint0;\r\n }\r\n\r\n /**\r\n * final install step to save curveMap in curve. If parentMap is given, update its length, count, and a1 fields\r\n * @param curve curve to receive the annotation\r\n * @param map\r\n * @param parentMap\r\n */\r\n public static installStrokeCountMap(curve: CurvePrimitive, curveMap: StrokeCountMap, parentMap?: StrokeCountMap) {\r\n if (parentMap)\r\n parentMap.addToCountAndLength(curveMap.numStroke, curveMap.curveLength);\r\n curve.strokeData = curveMap;\r\n }\r\n /**\r\n * Return an array containing only the curve primitives.\r\n * * This DEFAULT simply pushes `this` to the collectorArray.\r\n * * CurvePrimitiveWithDistanceIndex optionally collects its members.\r\n * @param collectorArray array to receive primitives (pushed -- the array is not cleared)\r\n * @param smallestPossiblePrimitives if false, CurvePrimitiveWithDistanceIndex returns only itself. If true, it recurses to its (otherwise hidden) children.\r\n */\r\n public collectCurvePrimitivesGo(collectorArray: CurvePrimitive[], _smallestPossiblePrimitives: boolean, _explodeLinestrings: boolean = false) {\r\n collectorArray.push(this);\r\n }\r\n\r\n /**\r\n * Return an array containing only the curve primitives.\r\n * * This DEFAULT captures the default result construction and calls collectCurvePrimitivesGo\r\n * @param collectorArray optional array to receive primitives. If present, new primitives are ADDED (without clearing the array.)\r\n * @param smallestPossiblePrimitives if false, CurvePrimitiveWithDistanceIndex returns only itself. If true, it recurses to its (otherwise hidden) children.\r\n */\r\n public collectCurvePrimitives(collectorArray?: CurvePrimitive[], smallestPossiblePrimitives: boolean = false,\r\n explodeLinestrings: boolean = false): CurvePrimitive[] {\r\n const results: CurvePrimitive[] = collectorArray === undefined ? [] : collectorArray;\r\n this.collectCurvePrimitivesGo(results, smallestPossiblePrimitives, explodeLinestrings);\r\n return results;\r\n }\r\n\r\n}\r\n\r\n/** Intermediate class for managing the parentCurve announcements from an IStrokeHandler */\r\nabstract class NewtonRotRStrokeHandler extends NewtonEvaluatorRtoR {\r\n protected _parentCurvePrimitive: CurvePrimitive | undefined;\r\n constructor() {\r\n super();\r\n this._parentCurvePrimitive = undefined;\r\n }\r\n /** retain the parentCurvePrimitive.\r\n * * Calling this method tells the handler that the parent curve is to be used for detail searches.\r\n * * Example: Transition spiral search is based on linestring first, then the exact spiral.\r\n * * Example: CurveChainWithDistanceIndex does NOT do this announcement -- the constituents act independently.\r\n */\r\n public startParentCurvePrimitive(curve: CurvePrimitive | undefined) { this._parentCurvePrimitive = curve; }\r\n /** Forget the parentCurvePrimitive */\r\n public endParentCurvePrimitive(_curve: CurvePrimitive | undefined) { this._parentCurvePrimitive = undefined; }\r\n}\r\n\r\nclass AppendPlaneIntersectionStrokeHandler extends NewtonRotRStrokeHandler implements IStrokeHandler {\r\n private _curve: CurvePrimitive | undefined;\r\n private _plane: PlaneAltitudeEvaluator;\r\n private _intersections: CurveLocationDetail[];\r\n private _fractionA: number = 0;\r\n private _functionA: number = 0;\r\n // private derivativeA: number; <---- Not currently used\r\n private _functionB: number = 0;\r\n private _fractionB: number = 0;\r\n private _derivativeB: number = 0;\r\n private _numThisCurve: number = 0;\r\n // scratch vars for use within methods.\r\n private _ray: Ray3d;\r\n private _newtonSolver: Newton1dUnboundedApproximateDerivative;\r\n\r\n // Return the first defined curve among: this.parentCurvePrimitive, this.curve;\r\n public effectiveCurve(): CurvePrimitive | undefined {\r\n if (this._parentCurvePrimitive)\r\n return this._parentCurvePrimitive;\r\n return this._curve;\r\n }\r\n public get getDerivativeB() { return this._derivativeB; } // <--- DerivativeB is not currently used anywhere. Provided getter to suppress lint error\r\n\r\n public constructor(plane: PlaneAltitudeEvaluator, intersections: CurveLocationDetail[]) {\r\n super();\r\n this._plane = plane;\r\n this._intersections = intersections;\r\n this.startCurvePrimitive(undefined);\r\n this._ray = Ray3d.createZero();\r\n this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);\r\n }\r\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\r\n this._curve = curve;\r\n this._fractionA = 0.0;\r\n this._numThisCurve = 0;\r\n this._functionA = 0.0;\r\n // this.derivativeA = 0.0;\r\n }\r\n public endCurvePrimitive() { }\r\n public announceIntervalForUniformStepStrokes(\r\n cp: CurvePrimitive,\r\n numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n this.startCurvePrimitive(cp);\r\n if (numStrokes < 1) numStrokes = 1;\r\n const df = 1.0 / numStrokes;\r\n for (let i = 0; i <= numStrokes; i++) {\r\n const fraction = Geometry.interpolate(fraction0, i * df, fraction1);\r\n cp.fractionToPointAndDerivative(fraction, this._ray);\r\n this.announcePointTangent(this._ray.origin, fraction, this._ray.direction);\r\n }\r\n }\r\n public announceSegmentInterval(\r\n _cp: CurvePrimitive,\r\n point0: Point3d,\r\n point1: Point3d,\r\n _numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n const h0 = this._plane.altitude(point0);\r\n const h1 = this._plane.altitude(point1);\r\n if (h0 * h1 > 0.0)\r\n return;\r\n const fraction01 = Order2Bezier.solveCoffs(h0, h1);\r\n // let numIntersection = 0;\r\n if (fraction01 !== undefined) {\r\n // numIntersection++;\r\n const fraction = Geometry.interpolate(fraction0, fraction01, fraction1);\r\n this._newtonSolver.setX(fraction);\r\n if (this._newtonSolver.runIterations()) {\r\n this.announceSolutionFraction(this._newtonSolver.getX());\r\n }\r\n // this.intersections.push(CurveLocationDetail.createCurveFractionPoint(cp, fraction, cp.fractionToPoint(fraction)));\r\n }\r\n }\r\n private announceSolutionFraction(fraction: number) {\r\n const curve = this.effectiveCurve();\r\n if (curve) {\r\n this._ray = curve.fractionToPointAndDerivative(fraction, this._ray);\r\n this._intersections.push(CurveLocationDetail.createCurveFractionPoint(curve, fraction, this._ray.origin));\r\n }\r\n }\r\n public evaluate(fraction: number): boolean {\r\n const curve = this.effectiveCurve();\r\n if (!curve)\r\n return false;\r\n this.currentF = this._plane.altitude(curve.fractionToPoint(fraction));\r\n return true;\r\n }\r\n /**\r\n * * ASSUME both the \"A\" and \"B\" evaluations (fraction, function, and derivative) are known.\r\n * * If function value changed sign between, interpolate an approximate root and improve it with\r\n * the newton solver.\r\n */\r\n private searchInterval() {\r\n if (this._functionA * this._functionB > 0) return;\r\n if (this._functionA === 0) this.announceSolutionFraction(this._fractionA);\r\n if (this._functionB === 0) this.announceSolutionFraction(this._fractionB);\r\n if (this._functionA * this._functionB < 0) {\r\n const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);\r\n if (fraction) {\r\n this._newtonSolver.setX(fraction);\r\n if (this._newtonSolver.runIterations())\r\n this.announceSolutionFraction(this._newtonSolver.getX());\r\n }\r\n }\r\n }\r\n /** Evaluate and save _functionB, _derivativeB, and _fractionB. */\r\n private evaluateB(xyz: Point3d, fraction: number, tangent: Vector3d) {\r\n this._functionB = this._plane.altitude(xyz);\r\n this._derivativeB = this._plane.velocity(tangent);\r\n this._fractionB = fraction;\r\n }\r\n /**\r\n * Announce point and tangent for evaluations.\r\n * * The function evaluation is saved as the \"B\" function point.\r\n * * The function point count is incremented\r\n * * If function point count is greater than 1, the current interval is searched.\r\n * * The just-evaluated point (\"B\") is saved as the \"old\" (\"A\") evaluation point.\r\n * @param xyz\r\n * @param fraction\r\n * @param tangent\r\n */\r\n public announcePointTangent(xyz: Point3d, fraction: number, tangent: Vector3d): void {\r\n this.evaluateB(xyz, fraction, tangent);\r\n if (this._numThisCurve++ > 0) this.searchInterval();\r\n this._functionA = this._functionB;\r\n this._fractionA = this._fractionB;\r\n }\r\n}\r\n\r\nclass CurveLengthContext implements IStrokeHandler {\r\n private _curve: CurvePrimitive | undefined;\r\n private _summedLength: number;\r\n private _ray: Ray3d;\r\n private _fraction0: number;\r\n private _fraction1: number;\r\n private _gaussMapper: GaussMapper;\r\n\r\n private tangentMagnitude(fraction: number): number {\r\n this._ray = (this._curve as CurvePrimitive).fractionToPointAndDerivative(fraction, this._ray);\r\n return this._ray.direction.magnitude();\r\n }\r\n public getSum() { return this._summedLength; }\r\n\r\n public constructor(fraction0: number = 0.0, fraction1: number = 1.0, numGaussPoints: number = 5) {\r\n this.startCurvePrimitive(undefined);\r\n this._summedLength = 0.0;\r\n this._ray = Ray3d.createZero();\r\n if (fraction0 < fraction1) {\r\n this._fraction0 = fraction0;\r\n this._fraction1 = fraction1;\r\n } else {\r\n this._fraction0 = fraction1;\r\n this._fraction1 = fraction0;\r\n }\r\n this._gaussMapper = new GaussMapper(numGaussPoints);\r\n }\r\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\r\n this._curve = curve;\r\n }\r\n public startParentCurvePrimitive(_curve: CurvePrimitive) { }\r\n public endParentCurvePrimitive(_curve: CurvePrimitive) { }\r\n\r\n public endCurvePrimitive() { }\r\n public announceIntervalForUniformStepStrokes(\r\n cp: CurvePrimitive,\r\n numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n if (fraction0 < this._fraction0) fraction0 = this._fraction0;\r\n if (fraction1 > this._fraction1) fraction1 = this._fraction1;\r\n if (fraction1 > fraction0) {\r\n this.startCurvePrimitive(cp);\r\n if (numStrokes < 1) numStrokes = 1;\r\n const df = 1.0 / numStrokes;\r\n for (let i = 1; i <= numStrokes; i++) {\r\n const fractionA = Geometry.interpolate(fraction0, (i - 1) * df, fraction1);\r\n const fractionB = i === numStrokes ? fraction1 : Geometry.interpolate(fraction0, (i) * df, fraction1);\r\n const numGauss = this._gaussMapper.mapXAndW(fractionA, fractionB);\r\n for (let k = 0; k < numGauss; k++) {\r\n this._summedLength += this._gaussMapper.gaussW[k] * this.tangentMagnitude(this._gaussMapper.gaussX[k]);\r\n }\r\n }\r\n }\r\n }\r\n public announceSegmentInterval(\r\n _cp: CurvePrimitive,\r\n point0: Point3d,\r\n point1: Point3d,\r\n _numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n const segmentLength = point0.distance(point1);\r\n if (this._fraction0 <= fraction0 && fraction1 <= this._fraction1)\r\n this._summedLength += segmentLength;\r\n else {\r\n let g0 = fraction0;\r\n let g1 = fraction1;\r\n if (g0 < this._fraction0) g0 = this._fraction0;\r\n if (g1 > this._fraction1) g1 = this._fraction1;\r\n if (g1 > g0) {\r\n this._summedLength += segmentLength * (g1 - g0) / (fraction1 - fraction0);\r\n }\r\n }\r\n }\r\n public announcePointTangent(_xyz: Point3d, _fraction: number, _tangent: Vector3d): void {\r\n // uh oh -- need to retain point for next interval\r\n }\r\n}\r\n// context for searching for closest point .. .\r\nclass ClosestPointStrokeHandler extends NewtonRotRStrokeHandler implements IStrokeHandler {\r\n private _curve: CurvePrimitive | undefined;\r\n private _closestPoint: CurveLocationDetail | undefined;\r\n private _spacePoint: Point3d;\r\n private _extend: VariantCurveExtendParameter;\r\n private _fractionA: number = 0;\r\n private _functionA: number = 0;\r\n private _functionB: number = 0;\r\n private _fractionB: number = 0;\r\n private _numThisCurve: number = 0;\r\n // scratch vars for use within methods.\r\n private _workPoint: Point3d;\r\n private _workRay: Ray3d;\r\n private _newtonSolver: Newton1dUnboundedApproximateDerivative;\r\n\r\n public constructor(spacePoint: Point3d, extend: VariantCurveExtendParameter) {\r\n super();\r\n this._spacePoint = spacePoint;\r\n this._workPoint = Point3d.create();\r\n this._workRay = Ray3d.createZero();\r\n this._closestPoint = undefined;\r\n this._extend = extend;\r\n this.startCurvePrimitive(undefined);\r\n this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);\r\n }\r\n\r\n public claimResult(): CurveLocationDetail | undefined {\r\n if (this._closestPoint) {\r\n this._newtonSolver.setX(this._closestPoint.fraction);\r\n this._curve = this._closestPoint.curve;\r\n if (this._newtonSolver.runIterations()) {\r\n let fraction = this._newtonSolver.getX();\r\n fraction = CurveExtendOptions.correctFraction(this._extend, fraction);\r\n this.announceSolutionFraction(fraction);\r\n }\r\n }\r\n return this._closestPoint;\r\n }\r\n public needPrimaryGeometryForStrokes() { return true; }\r\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\r\n this._curve = curve;\r\n this._fractionA = 0.0;\r\n this._numThisCurve = 0;\r\n this._functionA = 0.0;\r\n }\r\n public endCurvePrimitive() { }\r\n public announceIntervalForUniformStepStrokes(\r\n cp: CurvePrimitive,\r\n numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n this.startCurvePrimitive(cp);\r\n this.announceSolutionFraction(0.0); // test start point as closest\r\n this.announceSolutionFraction(1.0); // test end point as closest\r\n if (numStrokes < 1) numStrokes = 1;\r\n const df = 1.0 / numStrokes;\r\n for (let i = 0; i <= numStrokes; i++) {\r\n const fraction = Geometry.interpolate(fraction0, i * df, fraction1);\r\n cp.fractionToPointAndDerivative(fraction, this._workRay);\r\n this.announceRay(fraction, this._workRay);\r\n }\r\n }\r\n\r\n private announceCandidate(cp: CurvePrimitive, fraction: number, point: Point3d) {\r\n const distance = this._spacePoint.distance(point);\r\n if (this._closestPoint && distance > this._closestPoint.a)\r\n return;\r\n this._closestPoint = CurveLocationDetail.createCurveFractionPoint(cp, fraction, point, this._closestPoint);\r\n this._closestPoint.a = distance;\r\n if (this._parentCurvePrimitive !== undefined)\r\n this._closestPoint.curve = this._parentCurvePrimitive;\r\n }\r\n public announceSegmentInterval(\r\n cp: CurvePrimitive,\r\n point0: Point3d,\r\n point1: Point3d,\r\n _numStrokes: number,\r\n fraction0: number,\r\n fraction1: number): void {\r\n let localFraction = this._spacePoint.fractionOfProjectionToLine(point0, point1, 0.0);\r\n // only consider extending the segment if the immediate caller says we are at endpoints ...\r\n if (!this._extend)\r\n localFraction = Geometry.clampToStartEnd(localFraction, 0.0, 1.0);\r\n else {\r\n if (fraction0 !== 0.0)\r\n localFraction = Math.max(localFraction, 0.0);\r\n if (fraction1 !== 1.0)\r\n localFraction = Math.min(localFraction, 1.0);\r\n }\r\n this._workPoint = point0.interpolate(localFraction, point1);\r\n const globalFraction = Geometry.interpolate(fraction0, localFraction, fraction1);\r\n this.announceCandidate(cp, globalFraction, this._workPoint);\r\n }\r\n private searchInterval() {\r\n if (this._functionA * this._functionB > 0) return;\r\n if (this._functionA === 0) this.announceSolutionFraction(this._fractionA);\r\n if (this._functionB === 0) this.announceSolutionFraction(this._fractionB);\r\n if (this._functionA * this._functionB < 0) {\r\n const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);\r\n if (fraction) {\r\n this._newtonSolver.setX(fraction);\r\n if (this._newtonSolver.runIterations())\r\n this.announceSolutionFraction(this._newtonSolver.getX());\r\n }\r\n }\r\n }\r\n private evaluateB(fractionB: number, dataB: Ray3d) {\r\n this._functionB = dataB.dotProductToPoint(this._spacePoint);\r\n this._fractionB = fractionB;\r\n }\r\n private announceSolutionFraction(fraction: number) {\r\n if (this._curve)\r\n this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));\r\n }\r\n public evaluate(fraction: number): boolean {\r\n let curve = this._curve;\r\n if (this._parentCurvePrimitive)\r\n curve = this._parentCurvePrimitive;\r\n if (curve) {\r\n this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);\r\n this.currentF = this._workRay.dotProductToPoint(this._spacePoint);\r\n return true;\r\n }\r\n return false;\r\n }\r\n public announceRay(fraction: number, data: Ray3d): void {\r\n this.evaluateB(fraction, data);\r\n if (this._numThisCurve++ > 0) this.searchInterval();\r\n this._functionA = this._functionB;\r\n this._fractionA = this._fractionB;\r\n }\r\n public announcePointTangent(point: Point3d, fraction: number, tangent: Vector3d) {\r\n this._workRay.set(point, tangent);\r\n this.announceRay(fraction, this._workRay);\r\n }\r\n}\r\n"]}
@@ -1599,14 +1599,7 @@ export class Sample {
1599
1599
  startTangent: Point3d.create(1, -1),
1600
1600
  endTangent: Point3d.create(-1, -1)
1601
1601
  })))));
1602
- /* result.push(CurveChainWithDistanceIndex.createCapture( // TODO: comment out until fix bloss exerciseClosestPt bug (1)
1603
- Path.create(
1604
- IntegratedSpiral3d.createRadiusRadiusBearingBearing(
1605
- Segment1d.create(0, 100),
1606
- AngleSweep.createStartEndDegrees(10, 75),
1607
- Segment1d.create(0, 1),
1608
- Transform.createOriginAndMatrix(Point3d.createZero(), Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(30))),
1609
- "bloss")!))!); */
1602
+ result.push(CurveChainWithDistanceIndex.createCapture(Path.create(IntegratedSpiral3d.createRadiusRadiusBearingBearing(Segment1d.create(0, 100), AngleSweep.createStartEndDegrees(10, 75), Segment1d.create(0, 1), Transform.createOriginAndMatrix(Point3d.createZero(), Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(30))), "bloss"))));
1610
1603
  result.push(CurveChainWithDistanceIndex.createCapture(Path.create(DirectSpiral3d.createDirectHalfCosine(Transform.createOriginAndMatrix(Point3d.createZero(), Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(110))), 50, 350, Segment1d.create(0, 1)))));
1611
1604
  return result;
1612
1605
  }