@itwin/core-geometry 5.0.0-dev.99 → 5.1.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/lib/cjs/Geometry.d.ts +11 -0
- package/lib/cjs/Geometry.d.ts.map +1 -1
- package/lib/cjs/Geometry.js +14 -0
- package/lib/cjs/Geometry.js.map +1 -1
- package/lib/cjs/curve/Arc3d.d.ts +3 -1
- package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
- package/lib/cjs/curve/Arc3d.js +36 -0
- package/lib/cjs/curve/Arc3d.js.map +1 -1
- package/lib/cjs/curve/CurveExtendMode.d.ts +13 -5
- package/lib/cjs/curve/CurveExtendMode.d.ts.map +1 -1
- package/lib/cjs/curve/CurveExtendMode.js +19 -15
- package/lib/cjs/curve/CurveExtendMode.js.map +1 -1
- package/lib/cjs/curve/CurvePrimitive.d.ts +67 -8
- package/lib/cjs/curve/CurvePrimitive.d.ts.map +1 -1
- package/lib/cjs/curve/CurvePrimitive.js +59 -6
- package/lib/cjs/curve/CurvePrimitive.js.map +1 -1
- package/lib/cjs/curve/LineString3d.d.ts +8 -7
- package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
- package/lib/cjs/curve/LineString3d.js +25 -22
- package/lib/cjs/curve/LineString3d.js.map +1 -1
- package/lib/cjs/curve/internalContexts/AnnounceTangentStrokeHandler.d.ts +71 -0
- package/lib/cjs/curve/internalContexts/AnnounceTangentStrokeHandler.d.ts.map +1 -0
- package/lib/cjs/curve/internalContexts/AnnounceTangentStrokeHandler.js +181 -0
- package/lib/cjs/curve/internalContexts/AnnounceTangentStrokeHandler.js.map +1 -0
- package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.d.ts +21 -5
- package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.js +42 -17
- package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.js.map +1 -1
- package/lib/cjs/curve/internalContexts/NewtonRtoRStrokeHandler.d.ts +5 -3
- package/lib/cjs/curve/internalContexts/NewtonRtoRStrokeHandler.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/NewtonRtoRStrokeHandler.js +5 -3
- package/lib/cjs/curve/internalContexts/NewtonRtoRStrokeHandler.js.map +1 -1
- package/lib/cjs/geometry3d/AngleSweep.d.ts +1 -1
- package/lib/cjs/geometry3d/AngleSweep.js +8 -8
- package/lib/cjs/geometry3d/AngleSweep.js.map +1 -1
- package/lib/cjs/geometry3d/GeometryHandler.d.ts +15 -16
- package/lib/cjs/geometry3d/GeometryHandler.d.ts.map +1 -1
- package/lib/cjs/geometry3d/GeometryHandler.js.map +1 -1
- package/lib/cjs/geometry3d/Matrix3d.d.ts +10 -11
- package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Matrix3d.js +11 -12
- package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
- package/lib/cjs/polyface/FacetOrientation.js +1 -1
- package/lib/cjs/polyface/FacetOrientation.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceData.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceData.js +2 -0
- package/lib/cjs/polyface/PolyfaceData.js.map +1 -1
- package/lib/cjs/topology/Triangulation.d.ts +3 -3
- package/lib/cjs/topology/Triangulation.d.ts.map +1 -1
- package/lib/cjs/topology/Triangulation.js +7 -7
- package/lib/cjs/topology/Triangulation.js.map +1 -1
- package/lib/esm/Geometry.d.ts +11 -0
- package/lib/esm/Geometry.d.ts.map +1 -1
- package/lib/esm/Geometry.js +14 -0
- package/lib/esm/Geometry.js.map +1 -1
- package/lib/esm/curve/Arc3d.d.ts +3 -1
- package/lib/esm/curve/Arc3d.d.ts.map +1 -1
- package/lib/esm/curve/Arc3d.js +36 -0
- package/lib/esm/curve/Arc3d.js.map +1 -1
- package/lib/esm/curve/CurveExtendMode.d.ts +13 -5
- package/lib/esm/curve/CurveExtendMode.d.ts.map +1 -1
- package/lib/esm/curve/CurveExtendMode.js +19 -15
- package/lib/esm/curve/CurveExtendMode.js.map +1 -1
- package/lib/esm/curve/CurvePrimitive.d.ts +67 -8
- package/lib/esm/curve/CurvePrimitive.d.ts.map +1 -1
- package/lib/esm/curve/CurvePrimitive.js +59 -6
- package/lib/esm/curve/CurvePrimitive.js.map +1 -1
- package/lib/esm/curve/LineString3d.d.ts +8 -7
- package/lib/esm/curve/LineString3d.d.ts.map +1 -1
- package/lib/esm/curve/LineString3d.js +25 -22
- package/lib/esm/curve/LineString3d.js.map +1 -1
- package/lib/esm/curve/internalContexts/AnnounceTangentStrokeHandler.d.ts +71 -0
- package/lib/esm/curve/internalContexts/AnnounceTangentStrokeHandler.d.ts.map +1 -0
- package/lib/esm/curve/internalContexts/AnnounceTangentStrokeHandler.js +177 -0
- package/lib/esm/curve/internalContexts/AnnounceTangentStrokeHandler.js.map +1 -0
- package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.d.ts +21 -5
- package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.js +42 -17
- package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.js.map +1 -1
- package/lib/esm/curve/internalContexts/NewtonRtoRStrokeHandler.d.ts +5 -3
- package/lib/esm/curve/internalContexts/NewtonRtoRStrokeHandler.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/NewtonRtoRStrokeHandler.js +5 -3
- package/lib/esm/curve/internalContexts/NewtonRtoRStrokeHandler.js.map +1 -1
- package/lib/esm/geometry3d/AngleSweep.d.ts +1 -1
- package/lib/esm/geometry3d/AngleSweep.js +8 -8
- package/lib/esm/geometry3d/AngleSweep.js.map +1 -1
- package/lib/esm/geometry3d/GeometryHandler.d.ts +15 -16
- package/lib/esm/geometry3d/GeometryHandler.d.ts.map +1 -1
- package/lib/esm/geometry3d/GeometryHandler.js.map +1 -1
- package/lib/esm/geometry3d/Matrix3d.d.ts +10 -11
- package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Matrix3d.js +11 -12
- package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
- package/lib/esm/polyface/FacetOrientation.js +1 -1
- package/lib/esm/polyface/FacetOrientation.js.map +1 -1
- package/lib/esm/polyface/PolyfaceData.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceData.js +2 -0
- package/lib/esm/polyface/PolyfaceData.js.map +1 -1
- package/lib/esm/topology/Triangulation.d.ts +3 -3
- package/lib/esm/topology/Triangulation.d.ts.map +1 -1
- package/lib/esm/topology/Triangulation.js +7 -7
- package/lib/esm/topology/Triangulation.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Curve
|
|
3
|
+
*/
|
|
4
|
+
import { IStrokeHandler } from "../../geometry3d/GeometryHandler";
|
|
5
|
+
import { Point3d, Vector3d } from "../../geometry3d/Point3dVector3d";
|
|
6
|
+
import { CurveLocationDetail } from "../CurveLocationDetail";
|
|
7
|
+
import { CurvePrimitive, TangentOptions } from "../CurvePrimitive";
|
|
8
|
+
import { NewtonRtoRStrokeHandler } from "./NewtonRtoRStrokeHandler";
|
|
9
|
+
/**
|
|
10
|
+
* Context for searching for the tangent(s) to a CurvePrimitive.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare class AnnounceTangentStrokeHandler extends NewtonRtoRStrokeHandler implements IStrokeHandler {
|
|
14
|
+
private _curve;
|
|
15
|
+
private _announceTangent;
|
|
16
|
+
private _spacePoint;
|
|
17
|
+
private _vectorToEye;
|
|
18
|
+
private _distanceTol;
|
|
19
|
+
private _distanceTolSquared;
|
|
20
|
+
private _fractionA;
|
|
21
|
+
private _functionA;
|
|
22
|
+
private _fractionB;
|
|
23
|
+
private _functionB;
|
|
24
|
+
private _numThisCurve;
|
|
25
|
+
private _fractionMRU?;
|
|
26
|
+
private _curveMRU?;
|
|
27
|
+
private _workRay;
|
|
28
|
+
private _workDetail?;
|
|
29
|
+
private _newtonSolver;
|
|
30
|
+
/** Constructor */
|
|
31
|
+
constructor(spacePoint: Point3d, announceTangent: (tangent: CurveLocationDetail) => any, options?: TangentOptions);
|
|
32
|
+
/** Specified by IStrokeHandler. */
|
|
33
|
+
needPrimaryGeometryForStrokes(): boolean;
|
|
34
|
+
/** Specified by IStrokeHandler. */
|
|
35
|
+
startCurvePrimitive(curve: CurvePrimitive | undefined): void;
|
|
36
|
+
/** Specified by IStrokeHandler. */
|
|
37
|
+
endCurvePrimitive(): void;
|
|
38
|
+
/** Specified by IStrokeHandler. */
|
|
39
|
+
announceIntervalForUniformStepStrokes(cp: CurvePrimitive, numStrokes: number, fraction0: number, fraction1: number): void;
|
|
40
|
+
private announceCandidate;
|
|
41
|
+
/** Specified by IStrokeHandler. */
|
|
42
|
+
announceSegmentInterval(cp: CurvePrimitive, point0: Point3d, point1: Point3d, _numStrokes: number, fraction0: number, fraction1: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Given a function `f` and (unordered) fractions `a` and `b`, search for and announce a root of `f` in this
|
|
45
|
+
* fractional interval.
|
|
46
|
+
* * This method searches for a root of `f` if and only if the stroke segment defined by `(a, f(a))` and
|
|
47
|
+
* `(b, f(b))` has a root. This is a HEURISTIC: given continuous `f` between `a` and `b`, a root of the stroke
|
|
48
|
+
* segment implies a root of `f`, but not vice-versa. Therefore, if the strokes are not sufficiently dense,
|
|
49
|
+
* this method can miss a root of `f`.
|
|
50
|
+
*/
|
|
51
|
+
private searchInterval;
|
|
52
|
+
private announceSolutionFraction;
|
|
53
|
+
/**
|
|
54
|
+
* Evaluate the univariate real-valued function for which we are finding roots.
|
|
55
|
+
* * For finding the tangents to curve `X` from point `Q` as seen in a view plane with normal `N`, this
|
|
56
|
+
* function is `f(t) := (Q - X(t)) dot (X'(t) cross N)`. The second vector in the dot product defines a
|
|
57
|
+
* _tangent plane_ at `X(t)`.
|
|
58
|
+
* * Either `pointAndDerivative` must be defined, or both `fraction` and `curve`.
|
|
59
|
+
* @param pointAndDerivative pre-evaluated curve
|
|
60
|
+
* @param fraction fraction at which to evaluate `curve`
|
|
61
|
+
* @param curve curve to evaluate at `fraction`
|
|
62
|
+
* @returns distance of `Q` from the tangent plane at `X(t)`.
|
|
63
|
+
*/
|
|
64
|
+
private evaluateFunction;
|
|
65
|
+
/** Specified by NewtonRtoRStrokeHandler. */
|
|
66
|
+
evaluate(fraction: number): boolean;
|
|
67
|
+
private announceRay;
|
|
68
|
+
/** Specified by IStrokeHandler. */
|
|
69
|
+
announcePointTangent(_point: Point3d, _fraction: number, _tangent: Vector3d): void;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=AnnounceTangentStrokeHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnnounceTangentStrokeHandler.d.ts","sourceRoot":"","sources":["../../../../src/curve/internalContexts/AnnounceTangentStrokeHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAGrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,uBAAwB,YAAW,cAAc;IACjG,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,gBAAgB,CAAwC;IAChE,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,YAAY,CAAW;IAC/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,mBAAmB,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S,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;CAGnF"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Curve
|
|
7
|
+
*/
|
|
8
|
+
import { assert } from "@itwin/core-bentley";
|
|
9
|
+
import { Geometry } from "../../Geometry";
|
|
10
|
+
import { Vector3d } from "../../geometry3d/Point3dVector3d";
|
|
11
|
+
import { Ray3d } from "../../geometry3d/Ray3d";
|
|
12
|
+
import { Newton1dUnboundedApproximateDerivative } from "../../numerics/Newton";
|
|
13
|
+
import { CurveLocationDetail } from "../CurveLocationDetail";
|
|
14
|
+
import { NewtonRtoRStrokeHandler } from "./NewtonRtoRStrokeHandler";
|
|
15
|
+
/**
|
|
16
|
+
* Context for searching for the tangent(s) to a CurvePrimitive.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export class AnnounceTangentStrokeHandler extends NewtonRtoRStrokeHandler {
|
|
20
|
+
_curve;
|
|
21
|
+
_announceTangent;
|
|
22
|
+
_spacePoint;
|
|
23
|
+
_vectorToEye;
|
|
24
|
+
_distanceTol;
|
|
25
|
+
_distanceTolSquared;
|
|
26
|
+
// fraction and function value on one side of an interval that may bracket a root
|
|
27
|
+
_fractionA = 0;
|
|
28
|
+
_functionA = 0;
|
|
29
|
+
// fraction and function value on the other side of an interval that may bracket a root
|
|
30
|
+
_fractionB = 0;
|
|
31
|
+
_functionB = 0;
|
|
32
|
+
_numThisCurve = 0;
|
|
33
|
+
// scratch vars to use within methods
|
|
34
|
+
_fractionMRU;
|
|
35
|
+
_curveMRU;
|
|
36
|
+
_workRay;
|
|
37
|
+
_workDetail;
|
|
38
|
+
_newtonSolver;
|
|
39
|
+
/** Constructor */
|
|
40
|
+
constructor(spacePoint, announceTangent, options) {
|
|
41
|
+
super();
|
|
42
|
+
this._announceTangent = announceTangent;
|
|
43
|
+
this._spacePoint = spacePoint;
|
|
44
|
+
this._vectorToEye = options?.vectorToEye ?? Vector3d.unitZ();
|
|
45
|
+
this._distanceTol = options?.distanceTol ?? Geometry.smallMetricDistance;
|
|
46
|
+
this._distanceTolSquared = this._distanceTol * this._distanceTol;
|
|
47
|
+
this._workRay = Ray3d.createZero();
|
|
48
|
+
this.startCurvePrimitive(undefined);
|
|
49
|
+
this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);
|
|
50
|
+
}
|
|
51
|
+
/** Specified by IStrokeHandler. */
|
|
52
|
+
needPrimaryGeometryForStrokes() {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
/** Specified by IStrokeHandler. */
|
|
56
|
+
startCurvePrimitive(curve) {
|
|
57
|
+
this._curve = curve;
|
|
58
|
+
this._fractionA = 0.0;
|
|
59
|
+
this._numThisCurve = 0;
|
|
60
|
+
this._functionA = 0.0;
|
|
61
|
+
}
|
|
62
|
+
/** Specified by IStrokeHandler. */
|
|
63
|
+
endCurvePrimitive() {
|
|
64
|
+
}
|
|
65
|
+
/** Specified by IStrokeHandler. */
|
|
66
|
+
announceIntervalForUniformStepStrokes(cp, numStrokes, fraction0, fraction1) {
|
|
67
|
+
this.startCurvePrimitive(cp);
|
|
68
|
+
if (numStrokes < 1)
|
|
69
|
+
numStrokes = 1;
|
|
70
|
+
const df = 1.0 / numStrokes;
|
|
71
|
+
for (let i = 0; i <= numStrokes; i++) {
|
|
72
|
+
const fraction = Geometry.interpolate(fraction0, i * df, fraction1);
|
|
73
|
+
cp.fractionToPointAndDerivative(fraction, this._workRay);
|
|
74
|
+
this.announceRay(fraction, this._workRay);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
announceCandidate(cp, fraction, point) {
|
|
78
|
+
if (this._parentCurvePrimitive)
|
|
79
|
+
cp = this._parentCurvePrimitive;
|
|
80
|
+
if (this._curveMRU === cp && Geometry.isAlmostEqualOptional(this._fractionMRU, fraction, Geometry.smallFloatingPoint))
|
|
81
|
+
return; // avoid announcing duplicate tangents in succession (e.g., at interior stroke point)
|
|
82
|
+
this._workDetail = CurveLocationDetail.createCurveFractionPoint(cp, fraction, point, this._workDetail);
|
|
83
|
+
this._announceTangent(this._workDetail);
|
|
84
|
+
this._fractionMRU = fraction;
|
|
85
|
+
this._curveMRU = cp;
|
|
86
|
+
}
|
|
87
|
+
/** Specified by IStrokeHandler. */
|
|
88
|
+
announceSegmentInterval(cp, point0, point1, _numStrokes, fraction0, fraction1) {
|
|
89
|
+
let fraction;
|
|
90
|
+
let point;
|
|
91
|
+
const distance0 = this._spacePoint.distanceSquared(point0);
|
|
92
|
+
const distance1 = this._spacePoint.distanceSquared(point1);
|
|
93
|
+
if (distance0 < distance1) {
|
|
94
|
+
fraction = fraction0;
|
|
95
|
+
point = point0;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
fraction = fraction1;
|
|
99
|
+
point = point1;
|
|
100
|
+
}
|
|
101
|
+
// evaluate at midpoint; the endpoints may be at corners, which have ambiguous tangent
|
|
102
|
+
const value = this.evaluateFunction(undefined, (fraction0 + fraction1) / 2, cp);
|
|
103
|
+
if (value !== undefined && Geometry.isDistanceWithinTol(value, this._distanceTol))
|
|
104
|
+
this.announceCandidate(cp, fraction, point);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Given a function `f` and (unordered) fractions `a` and `b`, search for and announce a root of `f` in this
|
|
108
|
+
* fractional interval.
|
|
109
|
+
* * This method searches for a root of `f` if and only if the stroke segment defined by `(a, f(a))` and
|
|
110
|
+
* `(b, f(b))` has a root. This is a HEURISTIC: given continuous `f` between `a` and `b`, a root of the stroke
|
|
111
|
+
* segment implies a root of `f`, but not vice-versa. Therefore, if the strokes are not sufficiently dense,
|
|
112
|
+
* this method can miss a root of `f`.
|
|
113
|
+
*/
|
|
114
|
+
searchInterval() {
|
|
115
|
+
// directly announce at endpoint if we are extra certain it's a root; Newton can miss it if it has multiplicity > 1
|
|
116
|
+
if (Geometry.isDistanceWithinTol(this._functionA, this._distanceTolSquared))
|
|
117
|
+
this.announceSolutionFraction(this._fractionA);
|
|
118
|
+
if (Geometry.isDistanceWithinTol(this._functionB, this._distanceTolSquared))
|
|
119
|
+
this.announceSolutionFraction(this._fractionB);
|
|
120
|
+
if (this._functionA * this._functionB < 0) {
|
|
121
|
+
// by the Intermediate Value Theorem, a root lies between fractionA and fractionB; use Newton to find it.
|
|
122
|
+
const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);
|
|
123
|
+
if (fraction) {
|
|
124
|
+
this._newtonSolver.setX(fraction);
|
|
125
|
+
if (this._newtonSolver.runIterations())
|
|
126
|
+
this.announceSolutionFraction(this._newtonSolver.getX());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
announceSolutionFraction(fraction) {
|
|
131
|
+
if (this._curve)
|
|
132
|
+
this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Evaluate the univariate real-valued function for which we are finding roots.
|
|
136
|
+
* * For finding the tangents to curve `X` from point `Q` as seen in a view plane with normal `N`, this
|
|
137
|
+
* function is `f(t) := (Q - X(t)) dot (X'(t) cross N)`. The second vector in the dot product defines a
|
|
138
|
+
* _tangent plane_ at `X(t)`.
|
|
139
|
+
* * Either `pointAndDerivative` must be defined, or both `fraction` and `curve`.
|
|
140
|
+
* @param pointAndDerivative pre-evaluated curve
|
|
141
|
+
* @param fraction fraction at which to evaluate `curve`
|
|
142
|
+
* @param curve curve to evaluate at `fraction`
|
|
143
|
+
* @returns distance of `Q` from the tangent plane at `X(t)`.
|
|
144
|
+
*/
|
|
145
|
+
evaluateFunction(pointAndDerivative, fraction, curve) {
|
|
146
|
+
if (pointAndDerivative)
|
|
147
|
+
this._workRay.setFrom(pointAndDerivative);
|
|
148
|
+
else if (fraction !== undefined && curve)
|
|
149
|
+
this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);
|
|
150
|
+
else
|
|
151
|
+
return undefined;
|
|
152
|
+
const cross = this._vectorToEye.unitCrossProduct(this._workRay.direction); // normalized so we return true distance
|
|
153
|
+
return cross ? cross.dotProductStartEnd(this._workRay.origin, this._spacePoint) : undefined;
|
|
154
|
+
}
|
|
155
|
+
/** Specified by NewtonRtoRStrokeHandler. */
|
|
156
|
+
evaluate(fraction) {
|
|
157
|
+
const curve = this._parentCurvePrimitive ?? this._curve;
|
|
158
|
+
const value = this.evaluateFunction(undefined, fraction, curve);
|
|
159
|
+
if (value === undefined)
|
|
160
|
+
return false;
|
|
161
|
+
this.currentF = value;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
announceRay(fraction, data) {
|
|
165
|
+
this._functionB = this.evaluateFunction(data);
|
|
166
|
+
this._fractionB = fraction;
|
|
167
|
+
if (this._numThisCurve++ > 0) // after the first stroke point, a stroke segment is defined, so we have an interval
|
|
168
|
+
this.searchInterval();
|
|
169
|
+
this._functionA = this._functionB;
|
|
170
|
+
this._fractionA = this._fractionB;
|
|
171
|
+
}
|
|
172
|
+
/** Specified by IStrokeHandler. */
|
|
173
|
+
announcePointTangent(_point, _fraction, _tangent) {
|
|
174
|
+
assert(false, "No callers expected. IStrokeHandler probably didn't need to specify this method.");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=AnnounceTangentStrokeHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnnounceTangentStrokeHandler.js","sourceRoot":"","sources":["../../../../src/curve/internalContexts/AnnounceTangentStrokeHandler.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,QAAQ,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C;IAC5B,oBAAoB,CAAC,MAAe,EAAE,SAAiB,EAAE,QAAkB;QAChF,MAAM,CAAC,KAAK,EAAE,kFAAkF,CAAC,CAAC;IACpG,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Curve\n */\n\nimport { assert } from \"@itwin/core-bentley\";\nimport { Geometry } from \"../../Geometry\";\nimport { IStrokeHandler } from \"../../geometry3d/GeometryHandler\";\nimport { Point3d, Vector3d } from \"../../geometry3d/Point3dVector3d\";\nimport { Ray3d } from \"../../geometry3d/Ray3d\";\nimport { Newton1dUnboundedApproximateDerivative } from \"../../numerics/Newton\";\nimport { CurveLocationDetail } from \"../CurveLocationDetail\";\nimport { CurvePrimitive, TangentOptions } from \"../CurvePrimitive\";\nimport { NewtonRtoRStrokeHandler } from \"./NewtonRtoRStrokeHandler\";\n\n/**\n * Context for searching for the tangent(s) to a CurvePrimitive.\n * @internal\n */\nexport class AnnounceTangentStrokeHandler extends NewtonRtoRStrokeHandler implements IStrokeHandler {\n private _curve: CurvePrimitive | undefined;\n private _announceTangent: (tangent: CurveLocationDetail) => any;\n private _spacePoint: Point3d;\n private _vectorToEye: Vector3d;\n private _distanceTol: number;\n private _distanceTolSquared: number;\n // fraction and function value on one side of an interval that may bracket a root\n private _fractionA: number = 0;\n private _functionA: number = 0;\n // fraction and function value on the other side of an interval that may bracket a root\n private _fractionB: number = 0;\n private _functionB: number = 0;\n private _numThisCurve: number = 0;\n // scratch vars to use within methods\n private _fractionMRU?: number;\n private _curveMRU?: CurvePrimitive;\n private _workRay: Ray3d;\n private _workDetail?: CurveLocationDetail;\n private _newtonSolver: Newton1dUnboundedApproximateDerivative;\n /** Constructor */\n public constructor(spacePoint: Point3d, announceTangent: (tangent: CurveLocationDetail) => any, options?: TangentOptions) {\n super();\n this._announceTangent = announceTangent;\n this._spacePoint = spacePoint;\n this._vectorToEye = options?.vectorToEye ?? Vector3d.unitZ();\n this._distanceTol = options?.distanceTol ?? Geometry.smallMetricDistance;\n this._distanceTolSquared = this._distanceTol * this._distanceTol;\n this._workRay = Ray3d.createZero();\n this.startCurvePrimitive(undefined);\n this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);\n }\n /** Specified by IStrokeHandler. */\n public needPrimaryGeometryForStrokes() {\n return true;\n }\n /** Specified by IStrokeHandler. */\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\n this._curve = curve;\n this._fractionA = 0.0;\n this._numThisCurve = 0;\n this._functionA = 0.0;\n }\n /** Specified by IStrokeHandler. */\n public endCurvePrimitive() {\n }\n /** Specified by IStrokeHandler. */\n public announceIntervalForUniformStepStrokes(\n cp: CurvePrimitive, numStrokes: number, fraction0: number, fraction1: number,\n ): void {\n this.startCurvePrimitive(cp);\n if (numStrokes < 1)\n numStrokes = 1;\n const df = 1.0 / numStrokes;\n for (let i = 0; i <= numStrokes; i++) {\n const fraction = Geometry.interpolate(fraction0, i * df, fraction1);\n cp.fractionToPointAndDerivative(fraction, this._workRay);\n this.announceRay(fraction, this._workRay);\n }\n }\n private announceCandidate(cp: CurvePrimitive, fraction: number, point: Point3d) {\n if (this._parentCurvePrimitive)\n cp = this._parentCurvePrimitive;\n if (this._curveMRU === cp && Geometry.isAlmostEqualOptional(this._fractionMRU, fraction, Geometry.smallFloatingPoint))\n return; // avoid announcing duplicate tangents in succession (e.g., at interior stroke point)\n this._workDetail = CurveLocationDetail.createCurveFractionPoint(cp, fraction, point, this._workDetail);\n this._announceTangent(this._workDetail);\n this._fractionMRU = fraction;\n this._curveMRU = cp;\n }\n /** Specified by IStrokeHandler. */\n public announceSegmentInterval(\n cp: CurvePrimitive, point0: Point3d, point1: Point3d, _numStrokes: number, fraction0: number, fraction1: number,\n ): void {\n let fraction: number;\n let point: Point3d;\n const distance0 = this._spacePoint.distanceSquared(point0);\n const distance1 = this._spacePoint.distanceSquared(point1);\n if (distance0 < distance1) {\n fraction = fraction0;\n point = point0;\n } else {\n fraction = fraction1;\n point = point1;\n }\n // evaluate at midpoint; the endpoints may be at corners, which have ambiguous tangent\n const value = this.evaluateFunction(undefined, (fraction0 + fraction1) / 2, cp);\n if (value !== undefined && Geometry.isDistanceWithinTol(value, this._distanceTol))\n this.announceCandidate(cp, fraction, point);\n }\n /**\n * Given a function `f` and (unordered) fractions `a` and `b`, search for and announce a root of `f` in this\n * fractional interval.\n * * This method searches for a root of `f` if and only if the stroke segment defined by `(a, f(a))` and\n * `(b, f(b))` has a root. This is a HEURISTIC: given continuous `f` between `a` and `b`, a root of the stroke\n * segment implies a root of `f`, but not vice-versa. Therefore, if the strokes are not sufficiently dense,\n * this method can miss a root of `f`.\n */\n private searchInterval() {\n // directly announce at endpoint if we are extra certain it's a root; Newton can miss it if it has multiplicity > 1\n if (Geometry.isDistanceWithinTol(this._functionA, this._distanceTolSquared))\n this.announceSolutionFraction(this._fractionA);\n if (Geometry.isDistanceWithinTol(this._functionB, this._distanceTolSquared))\n this.announceSolutionFraction(this._fractionB);\n if (this._functionA * this._functionB < 0) {\n // by the Intermediate Value Theorem, a root lies between fractionA and fractionB; use Newton to find it.\n const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);\n if (fraction) {\n this._newtonSolver.setX(fraction);\n if (this._newtonSolver.runIterations())\n this.announceSolutionFraction(this._newtonSolver.getX());\n }\n }\n }\n private announceSolutionFraction(fraction: number) {\n if (this._curve)\n this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));\n }\n /**\n * Evaluate the univariate real-valued function for which we are finding roots.\n * * For finding the tangents to curve `X` from point `Q` as seen in a view plane with normal `N`, this\n * function is `f(t) := (Q - X(t)) dot (X'(t) cross N)`. The second vector in the dot product defines a\n * _tangent plane_ at `X(t)`.\n * * Either `pointAndDerivative` must be defined, or both `fraction` and `curve`.\n * @param pointAndDerivative pre-evaluated curve\n * @param fraction fraction at which to evaluate `curve`\n * @param curve curve to evaluate at `fraction`\n * @returns distance of `Q` from the tangent plane at `X(t)`.\n */\n private evaluateFunction(pointAndDerivative?: Ray3d, fraction?: number, curve?: CurvePrimitive): number | undefined {\n if (pointAndDerivative)\n this._workRay.setFrom(pointAndDerivative);\n else if (fraction !== undefined && curve)\n this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);\n else\n return undefined;\n const cross = this._vectorToEye.unitCrossProduct(this._workRay.direction); // normalized so we return true distance\n return cross ? cross.dotProductStartEnd(this._workRay.origin, this._spacePoint) : undefined;\n }\n /** Specified by NewtonRtoRStrokeHandler. */\n public evaluate(fraction: number): boolean {\n const curve = this._parentCurvePrimitive ?? this._curve;\n const value = this.evaluateFunction(undefined, fraction, curve);\n if (value === undefined)\n return false;\n this.currentF = value;\n return true;\n }\n private announceRay(fraction: number, data: Ray3d): void {\n this._functionB = this.evaluateFunction(data)!;\n this._fractionB = fraction;\n if (this._numThisCurve++ > 0) // after the first stroke point, a stroke segment is defined, so we have an interval\n this.searchInterval();\n this._functionA = this._functionB;\n this._fractionA = this._fractionB;\n }\n /** Specified by IStrokeHandler. */\n public announcePointTangent(_point: Point3d, _fraction: number, _tangent: Vector3d) {\n assert(false, \"No callers expected. IStrokeHandler probably didn't need to specify this method.\");\n }\n}\n"]}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { IStrokeHandler } from "../../geometry3d/GeometryHandler";
|
|
5
5
|
import { Point3d, Vector3d } from "../../geometry3d/Point3dVector3d";
|
|
6
|
-
import { Ray3d } from "../../geometry3d/Ray3d";
|
|
7
6
|
import { VariantCurveExtendParameter } from "../CurveExtendMode";
|
|
8
7
|
import { CurveLocationDetail } from "../CurveLocationDetail";
|
|
9
8
|
import { CurvePrimitive } from "../CurvePrimitive";
|
|
@@ -19,13 +18,14 @@ export declare class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler i
|
|
|
19
18
|
private _extend;
|
|
20
19
|
private _fractionA;
|
|
21
20
|
private _functionA;
|
|
22
|
-
private _functionB;
|
|
23
21
|
private _fractionB;
|
|
22
|
+
private _functionB;
|
|
24
23
|
private _numThisCurve;
|
|
25
24
|
private _workPoint;
|
|
26
25
|
private _workRay;
|
|
27
26
|
private _newtonSolver;
|
|
28
|
-
|
|
27
|
+
/** Constructor */
|
|
28
|
+
constructor(spacePoint: Point3d, extend?: VariantCurveExtendParameter, result?: CurveLocationDetail);
|
|
29
29
|
claimResult(): CurveLocationDetail | undefined;
|
|
30
30
|
needPrimaryGeometryForStrokes(): boolean;
|
|
31
31
|
startCurvePrimitive(curve: CurvePrimitive | undefined): void;
|
|
@@ -33,11 +33,27 @@ export declare class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler i
|
|
|
33
33
|
announceIntervalForUniformStepStrokes(cp: CurvePrimitive, numStrokes: number, fraction0: number, fraction1: number): void;
|
|
34
34
|
private announceCandidate;
|
|
35
35
|
announceSegmentInterval(cp: CurvePrimitive, point0: Point3d, point1: Point3d, _numStrokes: number, fraction0: number, fraction1: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Given a function `f` and (unordered) fractions `a` and `b`, search for and announce a root of `f` in this
|
|
38
|
+
* fractional interval.
|
|
39
|
+
* * This method searches for a root of `f` if and only if the stroke segment defined by `(a, f(a))` and
|
|
40
|
+
* `(b, f(b))` has a root. This is a HEURISTIC: given continuous `f` between `a` and `b`, a root of the stroke
|
|
41
|
+
* segment implies a root of `f`, but not vice-versa. Therefore, if the strokes are not sufficiently dense,
|
|
42
|
+
* this method can miss a root of `f`.
|
|
43
|
+
*/
|
|
36
44
|
private searchInterval;
|
|
37
|
-
private evaluateB;
|
|
38
45
|
private announceSolutionFraction;
|
|
46
|
+
/**
|
|
47
|
+
* Evaluate the univariate real-valued function for which we are finding roots.
|
|
48
|
+
* * For finding the closest point to curve X from point Q, this function is `f(t) := Q-X(t) dot X'(t)`.
|
|
49
|
+
* * Either `pointAndDerivative` must be defined, or both `fraction` and `curve`.
|
|
50
|
+
* @param pointAndDerivative pre-evaluated curve
|
|
51
|
+
* @param fraction fraction at which to evaluate `curve`
|
|
52
|
+
* @param curve curve to evaluate at `fraction`
|
|
53
|
+
*/
|
|
54
|
+
private evaluateFunction;
|
|
39
55
|
evaluate(fraction: number): boolean;
|
|
40
|
-
announceRay
|
|
56
|
+
private announceRay;
|
|
41
57
|
announcePointTangent(point: Point3d, fraction: number, tangent: Vector3d): void;
|
|
42
58
|
}
|
|
43
59
|
//# sourceMappingURL=ClosestPointStrokeHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClosestPointStrokeHandler.d.ts","sourceRoot":"","sources":["../../../../src/curve/internalContexts/ClosestPointStrokeHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"ClosestPointStrokeHandler.d.ts","sourceRoot":"","sources":["../../../../src/curve/internalContexts/ClosestPointStrokeHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAGrE,OAAO,EAAsB,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;;GAGG;AACH,qBAAa,yBAA0B,SAAQ,uBAAwB,YAAW,cAAc;IAC9F,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,aAAa,CAAkC;IACvD,OAAO,CAAC,WAAW,CAAU;I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acePoint;
|
|
23
23
|
_extend;
|
|
24
|
+
// fraction and function value on one side of an interval that may bracket a root
|
|
24
25
|
_fractionA = 0;
|
|
25
26
|
_functionA = 0;
|
|
26
|
-
|
|
27
|
+
// fraction and function value on the other side of an interval that may bracket a root
|
|
27
28
|
_fractionB = 0;
|
|
29
|
+
_functionB = 0;
|
|
28
30
|
_numThisCurve = 0;
|
|
29
|
-
// scratch vars
|
|
31
|
+
// scratch vars to use within methods
|
|
30
32
|
_workPoint;
|
|
31
33
|
_workRay;
|
|
32
34
|
_newtonSolver;
|
|
35
|
+
/** Constructor */
|
|
33
36
|
constructor(spacePoint, extend, result) {
|
|
34
37
|
super();
|
|
35
38
|
this._spacePoint = spacePoint;
|
|
36
39
|
this._workPoint = Point3d.create();
|
|
37
40
|
this._workRay = Ray3d.createZero();
|
|
38
41
|
this._closestPoint = result;
|
|
39
|
-
this._extend = extend;
|
|
42
|
+
this._extend = extend ?? false;
|
|
40
43
|
this.startCurvePrimitive(undefined);
|
|
41
44
|
this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);
|
|
42
45
|
}
|
|
@@ -87,7 +90,7 @@ export class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler {
|
|
|
87
90
|
}
|
|
88
91
|
announceSegmentInterval(cp, point0, point1, _numStrokes, fraction0, fraction1) {
|
|
89
92
|
let localFraction = this._spacePoint.fractionOfProjectionToLine(point0, point1, 0.0);
|
|
90
|
-
// only consider extending the segment if the immediate caller says we are at endpoints
|
|
93
|
+
// only consider extending the segment if the immediate caller says we are at endpoints
|
|
91
94
|
if (!this._extend)
|
|
92
95
|
localFraction = Geometry.clampToStartEnd(localFraction, 0.0, 1.0);
|
|
93
96
|
else {
|
|
@@ -100,13 +103,22 @@ export class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler {
|
|
|
100
103
|
const globalFraction = Geometry.interpolate(fraction0, localFraction, fraction1);
|
|
101
104
|
this.announceCandidate(cp, globalFraction, this._workPoint);
|
|
102
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Given a function `f` and (unordered) fractions `a` and `b`, search for and announce a root of `f` in this
|
|
108
|
+
* fractional interval.
|
|
109
|
+
* * This method searches for a root of `f` if and only if the stroke segment defined by `(a, f(a))` and
|
|
110
|
+
* `(b, f(b))` has a root. This is a HEURISTIC: given continuous `f` between `a` and `b`, a root of the stroke
|
|
111
|
+
* segment implies a root of `f`, but not vice-versa. Therefore, if the strokes are not sufficiently dense,
|
|
112
|
+
* this method can miss a root of `f`.
|
|
113
|
+
*/
|
|
103
114
|
searchInterval() {
|
|
104
115
|
if (this._functionA * this._functionB > 0)
|
|
105
|
-
return;
|
|
116
|
+
return; // stroke segment has no root; ASSUME the function has no root either
|
|
106
117
|
if (this._functionA === 0)
|
|
107
118
|
this.announceSolutionFraction(this._fractionA);
|
|
108
119
|
if (this._functionB === 0)
|
|
109
120
|
this.announceSolutionFraction(this._fractionB);
|
|
121
|
+
// by the Intermediate Value Theorem, a root lies between fractionA and fractionB; use Newton to find it.
|
|
110
122
|
if (this._functionA * this._functionB < 0) {
|
|
111
123
|
const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);
|
|
112
124
|
if (fraction) {
|
|
@@ -116,28 +128,41 @@ export class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler {
|
|
|
116
128
|
}
|
|
117
129
|
}
|
|
118
130
|
}
|
|
119
|
-
evaluateB(fractionB, dataB) {
|
|
120
|
-
this._functionB = dataB.dotProductToPoint(this._spacePoint);
|
|
121
|
-
this._fractionB = fractionB;
|
|
122
|
-
}
|
|
123
131
|
announceSolutionFraction(fraction) {
|
|
124
132
|
if (this._curve)
|
|
125
133
|
this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));
|
|
126
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Evaluate the univariate real-valued function for which we are finding roots.
|
|
137
|
+
* * For finding the closest point to curve X from point Q, this function is `f(t) := Q-X(t) dot X'(t)`.
|
|
138
|
+
* * Either `pointAndDerivative` must be defined, or both `fraction` and `curve`.
|
|
139
|
+
* @param pointAndDerivative pre-evaluated curve
|
|
140
|
+
* @param fraction fraction at which to evaluate `curve`
|
|
141
|
+
* @param curve curve to evaluate at `fraction`
|
|
142
|
+
*/
|
|
143
|
+
evaluateFunction(pointAndDerivative, fraction, curve) {
|
|
144
|
+
if (pointAndDerivative)
|
|
145
|
+
this._workRay.setFrom(pointAndDerivative);
|
|
146
|
+
else if (fraction !== undefined && curve)
|
|
147
|
+
this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);
|
|
148
|
+
else
|
|
149
|
+
return undefined;
|
|
150
|
+
return this._workRay.dotProductToPoint(this._spacePoint);
|
|
151
|
+
}
|
|
127
152
|
evaluate(fraction) {
|
|
128
153
|
let curve = this._curve;
|
|
129
154
|
if (this._parentCurvePrimitive)
|
|
130
155
|
curve = this._parentCurvePrimitive;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return false;
|
|
156
|
+
const value = this.evaluateFunction(undefined, fraction, curve);
|
|
157
|
+
if (value === undefined)
|
|
158
|
+
return false;
|
|
159
|
+
this.currentF = value;
|
|
160
|
+
return true;
|
|
137
161
|
}
|
|
138
162
|
announceRay(fraction, data) {
|
|
139
|
-
this.
|
|
140
|
-
|
|
163
|
+
this._functionB = this.evaluateFunction(data);
|
|
164
|
+
this._fractionB = fraction;
|
|
165
|
+
if (this._numThisCurve++ > 0) // after the first stroke point, a stroke segment is defined, so we have an interval
|
|
141
166
|
this.searchInterval();
|
|
142
167
|
this._functionA = this._functionB;
|
|
143
168
|
this._fractionA = this._fractionB;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClosestPointStrokeHandler.js","sourceRoot":"","sources":["../../../../src/curve/internalContexts/ClosestPointStrokeHandler.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAA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;QAClC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Curve\n */\n\nimport { Geometry } from \"../../Geometry\";\nimport { IStrokeHandler } from \"../../geometry3d/GeometryHandler\";\nimport { Point3d, Vector3d } from \"../../geometry3d/Point3dVector3d\";\nimport { Ray3d } from \"../../geometry3d/Ray3d\";\nimport { Newton1dUnboundedApproximateDerivative } from \"../../numerics/Newton\";\nimport { CurveExtendOptions, VariantCurveExtendParameter } from \"../CurveExtendMode\";\nimport { CurveLocationDetail } from \"../CurveLocationDetail\";\nimport { CurvePrimitive } from \"../CurvePrimitive\";\nimport { NewtonRtoRStrokeHandler } from \"./NewtonRtoRStrokeHandler\";\n\n/**\n * Context for searching for the closest point to a CurvePrimitive.\n * @internal\n */\nexport class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler implements IStrokeHandler {\n private _curve: CurvePrimitive | undefined;\n private _closestPoint: CurveLocationDetail | undefined;\n private _spacePoint: Point3d;\n private _extend: VariantCurveExtendParameter;\n private _fractionA: number = 0;\n private _functionA: number = 0;\n private _functionB: number = 0;\n private _fractionB: number = 0;\n private _numThisCurve: number = 0;\n // scratch vars for use within methods.\n private _workPoint: Point3d;\n private _workRay: Ray3d;\n private _newtonSolver: Newton1dUnboundedApproximateDerivative;\n\n public constructor(spacePoint: Point3d, extend: VariantCurveExtendParameter, result?: CurveLocationDetail) {\n super();\n this._spacePoint = spacePoint;\n this._workPoint = Point3d.create();\n this._workRay = Ray3d.createZero();\n this._closestPoint = result;\n this._extend = extend;\n this.startCurvePrimitive(undefined);\n this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);\n }\n\n public claimResult(): CurveLocationDetail | undefined {\n if (this._closestPoint) {\n this._newtonSolver.setX(this._closestPoint.fraction);\n this._curve = this._closestPoint.curve;\n if (this._newtonSolver.runIterations()) {\n let fraction = this._newtonSolver.getX();\n fraction = CurveExtendOptions.correctFraction(this._extend, fraction);\n this.announceSolutionFraction(fraction);\n }\n }\n return this._closestPoint;\n }\n\n public needPrimaryGeometryForStrokes() {\n return true;\n }\n\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\n this._curve = curve;\n this._fractionA = 0.0;\n this._numThisCurve = 0;\n this._functionA = 0.0;\n }\n\n public endCurvePrimitive() {\n }\n\n public announceIntervalForUniformStepStrokes(cp: CurvePrimitive, numStrokes: number, fraction0: number, fraction1: number): void {\n this.startCurvePrimitive(cp);\n this.announceSolutionFraction(0.0); // test start point as closest\n this.announceSolutionFraction(1.0); // test end point as closest\n if (numStrokes < 1) numStrokes = 1;\n const df = 1.0 / numStrokes;\n for (let i = 0; i <= numStrokes; i++) {\n const fraction = Geometry.interpolate(fraction0, i * df, fraction1);\n cp.fractionToPointAndDerivative(fraction, this._workRay);\n this.announceRay(fraction, this._workRay);\n }\n }\n\n private announceCandidate(cp: CurvePrimitive, fraction: number, point: Point3d) {\n const distance = this._spacePoint.distance(point);\n if (this._closestPoint && distance > this._closestPoint.a)\n return;\n this._closestPoint = CurveLocationDetail.createCurveFractionPoint(cp, fraction, point, this._closestPoint);\n this._closestPoint.a = distance;\n if (this._parentCurvePrimitive !== undefined)\n this._closestPoint.curve = this._parentCurvePrimitive;\n }\n\n public announceSegmentInterval(cp: CurvePrimitive, point0: Point3d, point1: Point3d, _numStrokes: number, fraction0: number, fraction1: number): void {\n let localFraction = this._spacePoint.fractionOfProjectionToLine(point0, point1, 0.0);\n // only consider extending the segment if the immediate caller says we are at endpoints ...\n if (!this._extend)\n localFraction = Geometry.clampToStartEnd(localFraction, 0.0, 1.0);\n else {\n if (fraction0 !== 0.0)\n localFraction = Math.max(localFraction, 0.0);\n if (fraction1 !== 1.0)\n localFraction = Math.min(localFraction, 1.0);\n }\n this._workPoint = point0.interpolate(localFraction, point1);\n const globalFraction = Geometry.interpolate(fraction0, localFraction, fraction1);\n this.announceCandidate(cp, globalFraction, this._workPoint);\n }\n\n private searchInterval() {\n if (this._functionA * this._functionB > 0) return;\n if (this._functionA === 0) this.announceSolutionFraction(this._fractionA);\n if (this._functionB === 0) this.announceSolutionFraction(this._fractionB);\n if (this._functionA * this._functionB < 0) {\n const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);\n if (fraction) {\n this._newtonSolver.setX(fraction);\n if (this._newtonSolver.runIterations())\n this.announceSolutionFraction(this._newtonSolver.getX());\n }\n }\n }\n\n private evaluateB(fractionB: number, dataB: Ray3d) {\n this._functionB = dataB.dotProductToPoint(this._spacePoint);\n this._fractionB = fractionB;\n }\n\n private announceSolutionFraction(fraction: number) {\n if (this._curve)\n this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));\n }\n\n public evaluate(fraction: number): boolean {\n let curve = this._curve;\n if (this._parentCurvePrimitive)\n curve = this._parentCurvePrimitive;\n if (curve) {\n this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);\n this.currentF = this._workRay.dotProductToPoint(this._spacePoint);\n return true;\n }\n return false;\n }\n\n public announceRay(fraction: number, data: Ray3d): void {\n this.evaluateB(fraction, data);\n if (this._numThisCurve++ > 0) this.searchInterval();\n this._functionA = this._functionB;\n this._fractionA = this._fractionB;\n }\n\n public announcePointTangent(point: Point3d, fraction: number, tangent: Vector3d) {\n this._workRay.set(point, tangent);\n this.announceRay(fraction, this._workRay);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ClosestPointStrokeHandler.js","sourceRoot":"","sources":["../../../../src/curve/internalContexts/ClosestPointStrokeHandler.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAY,MAAM,kCAA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AC,cAAc,EAAE,CAAC;QACxB,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":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Curve\n */\n\nimport { Geometry } from \"../../Geometry\";\nimport { IStrokeHandler } from \"../../geometry3d/GeometryHandler\";\nimport { Point3d, Vector3d } from \"../../geometry3d/Point3dVector3d\";\nimport { Ray3d } from \"../../geometry3d/Ray3d\";\nimport { Newton1dUnboundedApproximateDerivative } from \"../../numerics/Newton\";\nimport { CurveExtendOptions, VariantCurveExtendParameter } from \"../CurveExtendMode\";\nimport { CurveLocationDetail } from \"../CurveLocationDetail\";\nimport { CurvePrimitive } from \"../CurvePrimitive\";\nimport { NewtonRtoRStrokeHandler } from \"./NewtonRtoRStrokeHandler\";\n\n/**\n * Context for searching for the closest point to a CurvePrimitive.\n * @internal\n */\nexport class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler implements IStrokeHandler {\n private _curve: CurvePrimitive | undefined;\n private _closestPoint: CurveLocationDetail | undefined;\n private _spacePoint: Point3d;\n private _extend: VariantCurveExtendParameter;\n // fraction and function value on one side of an interval that may bracket a root\n private _fractionA: number = 0;\n private _functionA: number = 0;\n // fraction and function value on the other side of an interval that may bracket a root\n private _fractionB: number = 0;\n private _functionB: number = 0;\n private _numThisCurve: number = 0;\n // scratch vars to use within methods\n private _workPoint: Point3d;\n private _workRay: Ray3d;\n private _newtonSolver: Newton1dUnboundedApproximateDerivative;\n /** Constructor */\n public constructor(spacePoint: Point3d, extend?: VariantCurveExtendParameter, result?: CurveLocationDetail) {\n super();\n this._spacePoint = spacePoint;\n this._workPoint = Point3d.create();\n this._workRay = Ray3d.createZero();\n this._closestPoint = result;\n this._extend = extend ?? false;\n this.startCurvePrimitive(undefined);\n this._newtonSolver = new Newton1dUnboundedApproximateDerivative(this);\n }\n public claimResult(): CurveLocationDetail | undefined {\n if (this._closestPoint) {\n this._newtonSolver.setX(this._closestPoint.fraction);\n this._curve = this._closestPoint.curve;\n if (this._newtonSolver.runIterations()) {\n let fraction = this._newtonSolver.getX();\n fraction = CurveExtendOptions.correctFraction(this._extend, fraction);\n this.announceSolutionFraction(fraction);\n }\n }\n return this._closestPoint;\n }\n public needPrimaryGeometryForStrokes() {\n return true;\n }\n public startCurvePrimitive(curve: CurvePrimitive | undefined) {\n this._curve = curve;\n this._fractionA = 0.0;\n this._numThisCurve = 0;\n this._functionA = 0.0;\n }\n public endCurvePrimitive() {\n }\n public announceIntervalForUniformStepStrokes(\n cp: CurvePrimitive, numStrokes: number, fraction0: number, fraction1: number,\n ): void {\n this.startCurvePrimitive(cp);\n this.announceSolutionFraction(0.0); // test start point as closest\n this.announceSolutionFraction(1.0); // test end point as closest\n if (numStrokes < 1)\n numStrokes = 1;\n const df = 1.0 / numStrokes;\n for (let i = 0; i <= numStrokes; i++) {\n const fraction = Geometry.interpolate(fraction0, i * df, fraction1);\n cp.fractionToPointAndDerivative(fraction, this._workRay);\n this.announceRay(fraction, this._workRay);\n }\n }\n private announceCandidate(cp: CurvePrimitive, fraction: number, point: Point3d) {\n const distance = this._spacePoint.distance(point);\n if (this._closestPoint && distance > this._closestPoint.a)\n return;\n this._closestPoint = CurveLocationDetail.createCurveFractionPoint(cp, fraction, point, this._closestPoint);\n this._closestPoint.a = distance;\n if (this._parentCurvePrimitive !== undefined)\n this._closestPoint.curve = this._parentCurvePrimitive;\n }\n public announceSegmentInterval(\n cp: CurvePrimitive, point0: Point3d, point1: Point3d, _numStrokes: number, fraction0: number, fraction1: number,\n ): void {\n let localFraction = this._spacePoint.fractionOfProjectionToLine(point0, point1, 0.0);\n // only consider extending the segment if the immediate caller says we are at endpoints\n if (!this._extend)\n localFraction = Geometry.clampToStartEnd(localFraction, 0.0, 1.0);\n else {\n if (fraction0 !== 0.0)\n localFraction = Math.max(localFraction, 0.0);\n if (fraction1 !== 1.0)\n localFraction = Math.min(localFraction, 1.0);\n }\n this._workPoint = point0.interpolate(localFraction, point1);\n const globalFraction = Geometry.interpolate(fraction0, localFraction, fraction1);\n this.announceCandidate(cp, globalFraction, this._workPoint);\n }\n /**\n * Given a function `f` and (unordered) fractions `a` and `b`, search for and announce a root of `f` in this\n * fractional interval.\n * * This method searches for a root of `f` if and only if the stroke segment defined by `(a, f(a))` and\n * `(b, f(b))` has a root. This is a HEURISTIC: given continuous `f` between `a` and `b`, a root of the stroke\n * segment implies a root of `f`, but not vice-versa. Therefore, if the strokes are not sufficiently dense,\n * this method can miss a root of `f`.\n */\n private searchInterval() {\n if (this._functionA * this._functionB > 0)\n return; // stroke segment has no root; ASSUME the function has no root either\n if (this._functionA === 0)\n this.announceSolutionFraction(this._fractionA);\n if (this._functionB === 0)\n this.announceSolutionFraction(this._fractionB);\n // by the Intermediate Value Theorem, a root lies between fractionA and fractionB; use Newton to find it.\n if (this._functionA * this._functionB < 0) {\n const fraction = Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);\n if (fraction) {\n this._newtonSolver.setX(fraction);\n if (this._newtonSolver.runIterations())\n this.announceSolutionFraction(this._newtonSolver.getX());\n }\n }\n }\n private announceSolutionFraction(fraction: number) {\n if (this._curve)\n this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));\n }\n /**\n * Evaluate the univariate real-valued function for which we are finding roots.\n * * For finding the closest point to curve X from point Q, this function is `f(t) := Q-X(t) dot X'(t)`.\n * * Either `pointAndDerivative` must be defined, or both `fraction` and `curve`.\n * @param pointAndDerivative pre-evaluated curve\n * @param fraction fraction at which to evaluate `curve`\n * @param curve curve to evaluate at `fraction`\n */\n private evaluateFunction(pointAndDerivative?: Ray3d, fraction?: number, curve?: CurvePrimitive): number | undefined {\n if (pointAndDerivative)\n this._workRay.setFrom(pointAndDerivative);\n else if (fraction !== undefined && curve)\n this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);\n else\n return undefined;\n return this._workRay.dotProductToPoint(this._spacePoint);\n }\n public evaluate(fraction: number): boolean {\n let curve = this._curve;\n if (this._parentCurvePrimitive)\n curve = this._parentCurvePrimitive;\n const value = this.evaluateFunction(undefined, fraction, curve);\n if (value === undefined)\n return false;\n this.currentF = value;\n return true;\n }\n private announceRay(fraction: number, data: Ray3d): void {\n this._functionB = this.evaluateFunction(data)!;\n this._fractionB = fraction;\n if (this._numThisCurve++ > 0) // after the first stroke point, a stroke segment is defined, so we have an interval\n this.searchInterval();\n this._functionA = this._functionB;\n this._fractionA = this._fractionB;\n }\n public announcePointTangent(point: Point3d, fraction: number, tangent: Vector3d) {\n this._workRay.set(point, tangent);\n this.announceRay(fraction, this._workRay);\n }\n}\n"]}
|
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { NewtonEvaluatorRtoR } from "../../numerics/Newton";
|
|
5
5
|
import { CurvePrimitive } from "../CurvePrimitive";
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Intermediate class for managing the parentCurve announcements from an IStrokeHandler.
|
|
7
8
|
* @internal
|
|
8
9
|
*/
|
|
9
10
|
export declare abstract class NewtonRtoRStrokeHandler extends NewtonEvaluatorRtoR {
|
|
10
11
|
protected _parentCurvePrimitive: CurvePrimitive | undefined;
|
|
11
12
|
constructor();
|
|
12
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Retain the parentCurvePrimitive.
|
|
13
15
|
* * Calling this method tells the handler that the parent curve is to be used for detail searches.
|
|
14
16
|
* * Example: Transition spiral search is based on linestring first, then the exact spiral.
|
|
15
|
-
* * Example: CurveChainWithDistanceIndex does NOT do this announcement
|
|
17
|
+
* * Example: CurveChainWithDistanceIndex does NOT do this announcement; the constituents act independently.
|
|
16
18
|
*/
|
|
17
19
|
startParentCurvePrimitive(curve: CurvePrimitive | undefined): void;
|
|
18
20
|
/** Forget the parentCurvePrimitive */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NewtonRtoRStrokeHandler.d.ts","sourceRoot":"","sources":["../../../../src/curve/internalContexts/NewtonRtoRStrokeHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD
|
|
1
|
+
{"version":3,"file":"NewtonRtoRStrokeHandler.d.ts","sourceRoot":"","sources":["../../../../src/curve/internalContexts/NewtonRtoRStrokeHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,8BAAsB,uBAAwB,SAAQ,mBAAmB;IACvE,SAAS,CAAC,qBAAqB,EAAE,cAAc,GAAG,SAAS,CAAC;;IAK5D;;;;;OAKG;IACI,yBAAyB,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI;IAGzE,sCAAsC;IAC/B,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI;CAGzE"}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* @module Curve
|
|
7
7
|
*/
|
|
8
8
|
import { NewtonEvaluatorRtoR } from "../../numerics/Newton";
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Intermediate class for managing the parentCurve announcements from an IStrokeHandler.
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
13
|
export class NewtonRtoRStrokeHandler extends NewtonEvaluatorRtoR {
|
|
@@ -15,10 +16,11 @@ export class NewtonRtoRStrokeHandler extends NewtonEvaluatorRtoR {
|
|
|
15
16
|
super();
|
|
16
17
|
this._parentCurvePrimitive = undefined;
|
|
17
18
|
}
|
|
18
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Retain the parentCurvePrimitive.
|
|
19
21
|
* * Calling this method tells the handler that the parent curve is to be used for detail searches.
|
|
20
22
|
* * Example: Transition spiral search is based on linestring first, then the exact spiral.
|
|
21
|
-
* * Example: CurveChainWithDistanceIndex does NOT do this announcement
|
|
23
|
+
* * Example: CurveChainWithDistanceIndex does NOT do this announcement; the constituents act independently.
|
|
22
24
|
*/
|
|
23
25
|
startParentCurvePrimitive(curve) {
|
|
24
26
|
this._parentCurvePrimitive = curve;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NewtonRtoRStrokeHandler.js","sourceRoot":"","sources":["../../../../src/curve/internalContexts/NewtonRtoRStrokeHandler.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D
|
|
1
|
+
{"version":3,"file":"NewtonRtoRStrokeHandler.js","sourceRoot":"","sources":["../../../../src/curve/internalContexts/NewtonRtoRStrokeHandler.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D;;;GAGG;AACH,MAAM,OAAgB,uBAAwB,SAAQ,mBAAmB;IAC7D,qBAAqB,CAA6B;IAC5D;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACzC,CAAC;IACD;;;;;OAKG;IACI,yBAAyB,CAAC,KAAiC;QAChE,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC;IACrC,CAAC;IACD,sCAAsC;IAC/B,uBAAuB,CAAC,MAAkC;QAC/D,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACzC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Curve\n */\n\nimport { NewtonEvaluatorRtoR } from \"../../numerics/Newton\";\nimport { CurvePrimitive } from \"../CurvePrimitive\";\n\n/**\n * Intermediate class for managing the parentCurve announcements from an IStrokeHandler.\n * @internal\n */\nexport abstract class NewtonRtoRStrokeHandler extends NewtonEvaluatorRtoR {\n protected _parentCurvePrimitive: CurvePrimitive | undefined;\n constructor() {\n super();\n this._parentCurvePrimitive = undefined;\n }\n /**\n * Retain the parentCurvePrimitive.\n * * Calling this method tells the handler that the parent curve is to be used for detail searches.\n * * Example: Transition spiral search is based on linestring first, then the exact spiral.\n * * Example: CurveChainWithDistanceIndex does NOT do this announcement; the constituents act independently.\n */\n public startParentCurvePrimitive(curve: CurvePrimitive | undefined): void {\n this._parentCurvePrimitive = curve;\n }\n /** Forget the parentCurvePrimitive */\n public endParentCurvePrimitive(_curve: CurvePrimitive | undefined): void {\n this._parentCurvePrimitive = undefined;\n }\n}\n"]}
|
|
@@ -119,7 +119,7 @@ export declare class AngleSweep implements BeJSONFunctions {
|
|
|
119
119
|
/** Convert fractional position in the sweep to strongly typed Angle object. */
|
|
120
120
|
fractionToAngle(fraction: number): Angle;
|
|
121
121
|
/**
|
|
122
|
-
* Return 2PI divided by the sweep radians
|
|
122
|
+
* Return 2PI divided by the sweep radians.
|
|
123
123
|
* * This is the number of fractional intervals required to cover a whole circle.
|
|
124
124
|
* @returns period of the sweep, or 1 if sweep is empty.
|
|
125
125
|
*/
|