@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,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Curve
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AnnounceTangentStrokeHandler = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const Geometry_1 = require("../../Geometry");
|
|
13
|
+
const Point3dVector3d_1 = require("../../geometry3d/Point3dVector3d");
|
|
14
|
+
const Ray3d_1 = require("../../geometry3d/Ray3d");
|
|
15
|
+
const Newton_1 = require("../../numerics/Newton");
|
|
16
|
+
const CurveLocationDetail_1 = require("../CurveLocationDetail");
|
|
17
|
+
const NewtonRtoRStrokeHandler_1 = require("./NewtonRtoRStrokeHandler");
|
|
18
|
+
/**
|
|
19
|
+
* Context for searching for the tangent(s) to a CurvePrimitive.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
class AnnounceTangentStrokeHandler extends NewtonRtoRStrokeHandler_1.NewtonRtoRStrokeHandler {
|
|
23
|
+
_curve;
|
|
24
|
+
_announceTangent;
|
|
25
|
+
_spacePoint;
|
|
26
|
+
_vectorToEye;
|
|
27
|
+
_distanceTol;
|
|
28
|
+
_distanceTolSquared;
|
|
29
|
+
// fraction and function value on one side of an interval that may bracket a root
|
|
30
|
+
_fractionA = 0;
|
|
31
|
+
_functionA = 0;
|
|
32
|
+
// fraction and function value on the other side of an interval that may bracket a root
|
|
33
|
+
_fractionB = 0;
|
|
34
|
+
_functionB = 0;
|
|
35
|
+
_numThisCurve = 0;
|
|
36
|
+
// scratch vars to use within methods
|
|
37
|
+
_fractionMRU;
|
|
38
|
+
_curveMRU;
|
|
39
|
+
_workRay;
|
|
40
|
+
_workDetail;
|
|
41
|
+
_newtonSolver;
|
|
42
|
+
/** Constructor */
|
|
43
|
+
constructor(spacePoint, announceTangent, options) {
|
|
44
|
+
super();
|
|
45
|
+
this._announceTangent = announceTangent;
|
|
46
|
+
this._spacePoint = spacePoint;
|
|
47
|
+
this._vectorToEye = options?.vectorToEye ?? Point3dVector3d_1.Vector3d.unitZ();
|
|
48
|
+
this._distanceTol = options?.distanceTol ?? Geometry_1.Geometry.smallMetricDistance;
|
|
49
|
+
this._distanceTolSquared = this._distanceTol * this._distanceTol;
|
|
50
|
+
this._workRay = Ray3d_1.Ray3d.createZero();
|
|
51
|
+
this.startCurvePrimitive(undefined);
|
|
52
|
+
this._newtonSolver = new Newton_1.Newton1dUnboundedApproximateDerivative(this);
|
|
53
|
+
}
|
|
54
|
+
/** Specified by IStrokeHandler. */
|
|
55
|
+
needPrimaryGeometryForStrokes() {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
/** Specified by IStrokeHandler. */
|
|
59
|
+
startCurvePrimitive(curve) {
|
|
60
|
+
this._curve = curve;
|
|
61
|
+
this._fractionA = 0.0;
|
|
62
|
+
this._numThisCurve = 0;
|
|
63
|
+
this._functionA = 0.0;
|
|
64
|
+
}
|
|
65
|
+
/** Specified by IStrokeHandler. */
|
|
66
|
+
endCurvePrimitive() {
|
|
67
|
+
}
|
|
68
|
+
/** Specified by IStrokeHandler. */
|
|
69
|
+
announceIntervalForUniformStepStrokes(cp, numStrokes, fraction0, fraction1) {
|
|
70
|
+
this.startCurvePrimitive(cp);
|
|
71
|
+
if (numStrokes < 1)
|
|
72
|
+
numStrokes = 1;
|
|
73
|
+
const df = 1.0 / numStrokes;
|
|
74
|
+
for (let i = 0; i <= numStrokes; i++) {
|
|
75
|
+
const fraction = Geometry_1.Geometry.interpolate(fraction0, i * df, fraction1);
|
|
76
|
+
cp.fractionToPointAndDerivative(fraction, this._workRay);
|
|
77
|
+
this.announceRay(fraction, this._workRay);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
announceCandidate(cp, fraction, point) {
|
|
81
|
+
if (this._parentCurvePrimitive)
|
|
82
|
+
cp = this._parentCurvePrimitive;
|
|
83
|
+
if (this._curveMRU === cp && Geometry_1.Geometry.isAlmostEqualOptional(this._fractionMRU, fraction, Geometry_1.Geometry.smallFloatingPoint))
|
|
84
|
+
return; // avoid announcing duplicate tangents in succession (e.g., at interior stroke point)
|
|
85
|
+
this._workDetail = CurveLocationDetail_1.CurveLocationDetail.createCurveFractionPoint(cp, fraction, point, this._workDetail);
|
|
86
|
+
this._announceTangent(this._workDetail);
|
|
87
|
+
this._fractionMRU = fraction;
|
|
88
|
+
this._curveMRU = cp;
|
|
89
|
+
}
|
|
90
|
+
/** Specified by IStrokeHandler. */
|
|
91
|
+
announceSegmentInterval(cp, point0, point1, _numStrokes, fraction0, fraction1) {
|
|
92
|
+
let fraction;
|
|
93
|
+
let point;
|
|
94
|
+
const distance0 = this._spacePoint.distanceSquared(point0);
|
|
95
|
+
const distance1 = this._spacePoint.distanceSquared(point1);
|
|
96
|
+
if (distance0 < distance1) {
|
|
97
|
+
fraction = fraction0;
|
|
98
|
+
point = point0;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
fraction = fraction1;
|
|
102
|
+
point = point1;
|
|
103
|
+
}
|
|
104
|
+
// evaluate at midpoint; the endpoints may be at corners, which have ambiguous tangent
|
|
105
|
+
const value = this.evaluateFunction(undefined, (fraction0 + fraction1) / 2, cp);
|
|
106
|
+
if (value !== undefined && Geometry_1.Geometry.isDistanceWithinTol(value, this._distanceTol))
|
|
107
|
+
this.announceCandidate(cp, fraction, point);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Given a function `f` and (unordered) fractions `a` and `b`, search for and announce a root of `f` in this
|
|
111
|
+
* fractional interval.
|
|
112
|
+
* * This method searches for a root of `f` if and only if the stroke segment defined by `(a, f(a))` and
|
|
113
|
+
* `(b, f(b))` has a root. This is a HEURISTIC: given continuous `f` between `a` and `b`, a root of the stroke
|
|
114
|
+
* segment implies a root of `f`, but not vice-versa. Therefore, if the strokes are not sufficiently dense,
|
|
115
|
+
* this method can miss a root of `f`.
|
|
116
|
+
*/
|
|
117
|
+
searchInterval() {
|
|
118
|
+
// directly announce at endpoint if we are extra certain it's a root; Newton can miss it if it has multiplicity > 1
|
|
119
|
+
if (Geometry_1.Geometry.isDistanceWithinTol(this._functionA, this._distanceTolSquared))
|
|
120
|
+
this.announceSolutionFraction(this._fractionA);
|
|
121
|
+
if (Geometry_1.Geometry.isDistanceWithinTol(this._functionB, this._distanceTolSquared))
|
|
122
|
+
this.announceSolutionFraction(this._fractionB);
|
|
123
|
+
if (this._functionA * this._functionB < 0) {
|
|
124
|
+
// by the Intermediate Value Theorem, a root lies between fractionA and fractionB; use Newton to find it.
|
|
125
|
+
const fraction = Geometry_1.Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);
|
|
126
|
+
if (fraction) {
|
|
127
|
+
this._newtonSolver.setX(fraction);
|
|
128
|
+
if (this._newtonSolver.runIterations())
|
|
129
|
+
this.announceSolutionFraction(this._newtonSolver.getX());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
announceSolutionFraction(fraction) {
|
|
134
|
+
if (this._curve)
|
|
135
|
+
this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Evaluate the univariate real-valued function for which we are finding roots.
|
|
139
|
+
* * For finding the tangents to curve `X` from point `Q` as seen in a view plane with normal `N`, this
|
|
140
|
+
* function is `f(t) := (Q - X(t)) dot (X'(t) cross N)`. The second vector in the dot product defines a
|
|
141
|
+
* _tangent plane_ at `X(t)`.
|
|
142
|
+
* * Either `pointAndDerivative` must be defined, or both `fraction` and `curve`.
|
|
143
|
+
* @param pointAndDerivative pre-evaluated curve
|
|
144
|
+
* @param fraction fraction at which to evaluate `curve`
|
|
145
|
+
* @param curve curve to evaluate at `fraction`
|
|
146
|
+
* @returns distance of `Q` from the tangent plane at `X(t)`.
|
|
147
|
+
*/
|
|
148
|
+
evaluateFunction(pointAndDerivative, fraction, curve) {
|
|
149
|
+
if (pointAndDerivative)
|
|
150
|
+
this._workRay.setFrom(pointAndDerivative);
|
|
151
|
+
else if (fraction !== undefined && curve)
|
|
152
|
+
this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);
|
|
153
|
+
else
|
|
154
|
+
return undefined;
|
|
155
|
+
const cross = this._vectorToEye.unitCrossProduct(this._workRay.direction); // normalized so we return true distance
|
|
156
|
+
return cross ? cross.dotProductStartEnd(this._workRay.origin, this._spacePoint) : undefined;
|
|
157
|
+
}
|
|
158
|
+
/** Specified by NewtonRtoRStrokeHandler. */
|
|
159
|
+
evaluate(fraction) {
|
|
160
|
+
const curve = this._parentCurvePrimitive ?? this._curve;
|
|
161
|
+
const value = this.evaluateFunction(undefined, fraction, curve);
|
|
162
|
+
if (value === undefined)
|
|
163
|
+
return false;
|
|
164
|
+
this.currentF = value;
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
announceRay(fraction, data) {
|
|
168
|
+
this._functionB = this.evaluateFunction(data);
|
|
169
|
+
this._fractionB = fraction;
|
|
170
|
+
if (this._numThisCurve++ > 0) // after the first stroke point, a stroke segment is defined, so we have an interval
|
|
171
|
+
this.searchInterval();
|
|
172
|
+
this._functionA = this._functionB;
|
|
173
|
+
this._fractionA = this._fractionB;
|
|
174
|
+
}
|
|
175
|
+
/** Specified by IStrokeHandler. */
|
|
176
|
+
announcePointTangent(_point, _fraction, _tangent) {
|
|
177
|
+
(0, core_bentley_1.assert)(false, "No callers expected. IStrokeHandler probably didn't need to specify this method.");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.AnnounceTangentStrokeHandler = AnnounceTangentStrokeHandler;
|
|
181
|
+
//# 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,sDAA6C;AAC7C,6CAA0C;AAE1C,sEAAqE;AACrE,kDAA+C;AAC/C,kDAA+E;AAC/E,gEAA6D;AAE7D,uEAAoE;AAEpE;;;GAGG;AACH,MAAa,4BAA6B,SAAQ,iDAAuB;IAC/D,MAAM,CAA6B;IACnC,gBAAgB,CAAwC;IACxD,WAAW,CAAU;IACrB,YAAY,CAAW;IACvB,YAAY,CAAS;IACrB,mBAAmB,CAAS;IACpC,iFAAiF;IACzE,UAAU,GAAW,CAAC,CAAC;IACvB,UAAU,GAAW,CAAC,CAAC;IAC/B,uFAAuF;IAC/E,UAAU,GAAW,CAAC,CAAC;IACvB,UAAU,GAAW,CAAC,CAAC;IACvB,aAAa,GAAW,CAAC,CAAC;IAClC,qCAAqC;IAC7B,YAAY,CAAU;IACtB,SAAS,CAAkB;IAC3B,QAAQ,CAAQ;IAChB,WAAW,CAAuB;IAClC,aAAa,CAAyC;IAC9D,kBAAkB;IAClB,YAAmB,UAAmB,EAAE,eAAsD,EAAE,OAAwB;QACtH,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,WAAW,IAAI,0BAAQ,CAAC,KAAK,EAAE,CAAC;QAC7D,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,WAAW,IAAI,mBAAQ,CAAC,mBAAmB,CAAC;QACzE,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACj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,GAAG,IAAI,CAAC,UAAU,CAAC;IACpC,CAAC;IACD,mCAAmC;IAC5B,oBAAoB,CAAC,MAAe,EAAE,SAAiB,EAAE,QAAkB;QAChF,IAAA,qBAAM,EAAC,KAAK,EAAE,kFAAkF,CAAC,CAAC;IACpG,CAAC;CACF;AAhKD,oEAgKC","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,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ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler_1.NewtonRtoRStro
|
|
|
24
24
|
_closestPoint;
|
|
25
25
|
_spacePoint;
|
|
26
26
|
_extend;
|
|
27
|
+
// fraction and function value on one side of an interval that may bracket a root
|
|
27
28
|
_fractionA = 0;
|
|
28
29
|
_functionA = 0;
|
|
29
|
-
|
|
30
|
+
// fraction and function value on the other side of an interval that may bracket a root
|
|
30
31
|
_fractionB = 0;
|
|
32
|
+
_functionB = 0;
|
|
31
33
|
_numThisCurve = 0;
|
|
32
|
-
// scratch vars
|
|
34
|
+
// scratch vars to use within methods
|
|
33
35
|
_workPoint;
|
|
34
36
|
_workRay;
|
|
35
37
|
_newtonSolver;
|
|
38
|
+
/** Constructor */
|
|
36
39
|
constructor(spacePoint, extend, result) {
|
|
37
40
|
super();
|
|
38
41
|
this._spacePoint = spacePoint;
|
|
39
42
|
this._workPoint = Point3dVector3d_1.Point3d.create();
|
|
40
43
|
this._workRay = Ray3d_1.Ray3d.createZero();
|
|
41
44
|
this._closestPoint = result;
|
|
42
|
-
this._extend = extend;
|
|
45
|
+
this._extend = extend ?? false;
|
|
43
46
|
this.startCurvePrimitive(undefined);
|
|
44
47
|
this._newtonSolver = new Newton_1.Newton1dUnboundedApproximateDerivative(this);
|
|
45
48
|
}
|
|
@@ -90,7 +93,7 @@ class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler_1.NewtonRtoRStro
|
|
|
90
93
|
}
|
|
91
94
|
announceSegmentInterval(cp, point0, point1, _numStrokes, fraction0, fraction1) {
|
|
92
95
|
let localFraction = this._spacePoint.fractionOfProjectionToLine(point0, point1, 0.0);
|
|
93
|
-
// only consider extending the segment if the immediate caller says we are at endpoints
|
|
96
|
+
// only consider extending the segment if the immediate caller says we are at endpoints
|
|
94
97
|
if (!this._extend)
|
|
95
98
|
localFraction = Geometry_1.Geometry.clampToStartEnd(localFraction, 0.0, 1.0);
|
|
96
99
|
else {
|
|
@@ -103,13 +106,22 @@ class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler_1.NewtonRtoRStro
|
|
|
103
106
|
const globalFraction = Geometry_1.Geometry.interpolate(fraction0, localFraction, fraction1);
|
|
104
107
|
this.announceCandidate(cp, globalFraction, this._workPoint);
|
|
105
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Given a function `f` and (unordered) fractions `a` and `b`, search for and announce a root of `f` in this
|
|
111
|
+
* fractional interval.
|
|
112
|
+
* * This method searches for a root of `f` if and only if the stroke segment defined by `(a, f(a))` and
|
|
113
|
+
* `(b, f(b))` has a root. This is a HEURISTIC: given continuous `f` between `a` and `b`, a root of the stroke
|
|
114
|
+
* segment implies a root of `f`, but not vice-versa. Therefore, if the strokes are not sufficiently dense,
|
|
115
|
+
* this method can miss a root of `f`.
|
|
116
|
+
*/
|
|
106
117
|
searchInterval() {
|
|
107
118
|
if (this._functionA * this._functionB > 0)
|
|
108
|
-
return;
|
|
119
|
+
return; // stroke segment has no root; ASSUME the function has no root either
|
|
109
120
|
if (this._functionA === 0)
|
|
110
121
|
this.announceSolutionFraction(this._fractionA);
|
|
111
122
|
if (this._functionB === 0)
|
|
112
123
|
this.announceSolutionFraction(this._fractionB);
|
|
124
|
+
// by the Intermediate Value Theorem, a root lies between fractionA and fractionB; use Newton to find it.
|
|
113
125
|
if (this._functionA * this._functionB < 0) {
|
|
114
126
|
const fraction = Geometry_1.Geometry.inverseInterpolate(this._fractionA, this._functionA, this._fractionB, this._functionB);
|
|
115
127
|
if (fraction) {
|
|
@@ -119,28 +131,41 @@ class ClosestPointStrokeHandler extends NewtonRtoRStrokeHandler_1.NewtonRtoRStro
|
|
|
119
131
|
}
|
|
120
132
|
}
|
|
121
133
|
}
|
|
122
|
-
evaluateB(fractionB, dataB) {
|
|
123
|
-
this._functionB = dataB.dotProductToPoint(this._spacePoint);
|
|
124
|
-
this._fractionB = fractionB;
|
|
125
|
-
}
|
|
126
134
|
announceSolutionFraction(fraction) {
|
|
127
135
|
if (this._curve)
|
|
128
136
|
this.announceCandidate(this._curve, fraction, this._curve.fractionToPoint(fraction));
|
|
129
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Evaluate the univariate real-valued function for which we are finding roots.
|
|
140
|
+
* * For finding the closest point to curve X from point Q, this function is `f(t) := Q-X(t) dot X'(t)`.
|
|
141
|
+
* * Either `pointAndDerivative` must be defined, or both `fraction` and `curve`.
|
|
142
|
+
* @param pointAndDerivative pre-evaluated curve
|
|
143
|
+
* @param fraction fraction at which to evaluate `curve`
|
|
144
|
+
* @param curve curve to evaluate at `fraction`
|
|
145
|
+
*/
|
|
146
|
+
evaluateFunction(pointAndDerivative, fraction, curve) {
|
|
147
|
+
if (pointAndDerivative)
|
|
148
|
+
this._workRay.setFrom(pointAndDerivative);
|
|
149
|
+
else if (fraction !== undefined && curve)
|
|
150
|
+
this._workRay = curve.fractionToPointAndDerivative(fraction, this._workRay);
|
|
151
|
+
else
|
|
152
|
+
return undefined;
|
|
153
|
+
return this._workRay.dotProductToPoint(this._spacePoint);
|
|
154
|
+
}
|
|
130
155
|
evaluate(fraction) {
|
|
131
156
|
let curve = this._curve;
|
|
132
157
|
if (this._parentCurvePrimitive)
|
|
133
158
|
curve = this._parentCurvePrimitive;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return false;
|
|
159
|
+
const value = this.evaluateFunction(undefined, fraction, curve);
|
|
160
|
+
if (value === undefined)
|
|
161
|
+
return false;
|
|
162
|
+
this.currentF = value;
|
|
163
|
+
return true;
|
|
140
164
|
}
|
|
141
165
|
announceRay(fraction, data) {
|
|
142
|
-
this.
|
|
143
|
-
|
|
166
|
+
this._functionB = this.evaluateFunction(data);
|
|
167
|
+
this._fractionB = fraction;
|
|
168
|
+
if (this._numThisCurve++ > 0) // after the first stroke point, a stroke segment is defined, so we have an interval
|
|
144
169
|
this.searchInterval();
|
|
145
170
|
this._functionA = this._functionB;
|
|
146
171
|
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,6CAA0C;AAE1C,sEAAqE;AACrE,kDAA+C;AAC/C,kDAA+E;AAC/E,wDAAqF;AACrF,gEAA6D;AAE7D,uEAAoE;AAEpE;;;GAGG;AACH,MAAa,yBAA0B,SAAQ,iDAAuB;IAC5D,MAAM,CAA6B;IACnC,aAAa,CAAkC;IAC/C,WAAW,CAAU;IACrB,OAAO,CAA8B;IACrC,UAAU,GAAW,CAAC,CAAC;IACvB,UAAU,GAAW,CAAC,CAAC;IACvB,UAAU,GAAW,CAAC,CAAC;IACvB,UAAU,GAAW,CAAC,CAAC;IACvB,aAAa,GAAW,CAAC,CAAC;IAClC,uCAAuC;IAC/B,UAAU,CAAU;IACpB,QAAQ,CAAQ;IAChB,aAAa,CAAyC;IAE9D,YAAmB,UAAmB,EAAE,MAAmC,EAAE,MAA4B;QACvG,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,yBAAO,CAAC,MAAM,EAAE,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,aAAK,CAAC,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,IAAI,+CAAsC,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;IAEM,WAAW;QAChB,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YACrD,IAAI,CAAC,MAA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AC5C,CAAC;CACF;AA3ID,8DA2IC","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,6CAA0C;AAE1C,sEAAqE;AACrE,kDAA+C;AAC/C,kDAA+E;AAC/E,wDAAqF;AACrF,gEAA6D;AAE7D,uEAAoE;AAEpE;;;GAGG;AACH,MAAa,yBAA0B,SAAQ,iDAA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QAAQ,CAAC,CAAC;IAC5C,CAAC;CACF;AA/JD,8DA+JC","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"}
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.NewtonRtoRStrokeHandler = void 0;
|
|
11
11
|
const Newton_1 = require("../../numerics/Newton");
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Intermediate class for managing the parentCurve announcements from an IStrokeHandler.
|
|
13
14
|
* @internal
|
|
14
15
|
*/
|
|
15
16
|
class NewtonRtoRStrokeHandler extends Newton_1.NewtonEvaluatorRtoR {
|
|
@@ -18,10 +19,11 @@ class NewtonRtoRStrokeHandler extends Newton_1.NewtonEvaluatorRtoR {
|
|
|
18
19
|
super();
|
|
19
20
|
this._parentCurvePrimitive = undefined;
|
|
20
21
|
}
|
|
21
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Retain the parentCurvePrimitive.
|
|
22
24
|
* * Calling this method tells the handler that the parent curve is to be used for detail searches.
|
|
23
25
|
* * Example: Transition spiral search is based on linestring first, then the exact spiral.
|
|
24
|
-
* * Example: CurveChainWithDistanceIndex does NOT do this announcement
|
|
26
|
+
* * Example: CurveChainWithDistanceIndex does NOT do this announcement; the constituents act independently.
|
|
25
27
|
*/
|
|
26
28
|
startParentCurvePrimitive(curve) {
|
|
27
29
|
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,kDAA4D;AAG5D
|
|
1
|
+
{"version":3,"file":"NewtonRtoRStrokeHandler.js","sourceRoot":"","sources":["../../../../src/curve/internalContexts/NewtonRtoRStrokeHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,kDAA4D;AAG5D;;;GAGG;AACH,MAAsB,uBAAwB,SAAQ,4BAAmB;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;AAnBD,0DAmBC","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
|
*/
|