@itwin/core-geometry 4.2.0-dev.7 → 4.2.0-dev.8
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/lib/cjs/clipping/ClipPlane.d.ts +10 -7
- package/lib/cjs/clipping/ClipPlane.d.ts.map +1 -1
- package/lib/cjs/clipping/ClipPlane.js +5 -3
- package/lib/cjs/clipping/ClipPlane.js.map +1 -1
- package/lib/cjs/clipping/ClipUtils.d.ts +16 -4
- package/lib/cjs/clipping/ClipUtils.d.ts.map +1 -1
- package/lib/cjs/clipping/ClipUtils.js +77 -2
- package/lib/cjs/clipping/ClipUtils.js.map +1 -1
- package/lib/cjs/clipping/ConvexClipPlaneSet.d.ts +3 -2
- package/lib/cjs/clipping/ConvexClipPlaneSet.d.ts.map +1 -1
- package/lib/cjs/clipping/ConvexClipPlaneSet.js +3 -2
- package/lib/cjs/clipping/ConvexClipPlaneSet.js.map +1 -1
- package/lib/cjs/clipping/UnionOfConvexClipPlaneSets.d.ts +2 -2
- package/lib/cjs/clipping/UnionOfConvexClipPlaneSets.js +2 -2
- package/lib/cjs/clipping/UnionOfConvexClipPlaneSets.js.map +1 -1
- package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
- package/lib/cjs/curve/Arc3d.js.map +1 -1
- package/lib/cjs/curve/CoordinateXYZ.d.ts +15 -15
- package/lib/cjs/curve/CoordinateXYZ.d.ts.map +1 -1
- package/lib/cjs/curve/CoordinateXYZ.js +15 -15
- package/lib/cjs/curve/CoordinateXYZ.js.map +1 -1
- package/lib/cjs/curve/CurveChain.d.ts +4 -2
- package/lib/cjs/curve/CurveChain.d.ts.map +1 -1
- package/lib/cjs/curve/CurveChain.js.map +1 -1
- package/lib/cjs/curve/CurveCollection.d.ts +1 -1
- package/lib/cjs/curve/CurveCollection.d.ts.map +1 -1
- package/lib/cjs/curve/CurveCollection.js +1 -1
- package/lib/cjs/curve/CurveCollection.js.map +1 -1
- package/lib/cjs/curve/CurveCurveCloseApproachXY.d.ts +18 -7
- package/lib/cjs/curve/CurveCurveCloseApproachXY.d.ts.map +1 -1
- package/lib/cjs/curve/CurveCurveCloseApproachXY.js +17 -5
- package/lib/cjs/curve/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/cjs/curve/CurveCurveIntersectXY.d.ts +2 -2
- package/lib/cjs/curve/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/cjs/curve/CurveCurveIntersectXY.js +12 -10
- package/lib/cjs/curve/CurveCurveIntersectXY.js.map +1 -1
- package/lib/cjs/curve/Path.d.ts +1 -1
- package/lib/cjs/curve/Path.d.ts.map +1 -1
- package/lib/cjs/curve/Path.js +1 -1
- package/lib/cjs/curve/Path.js.map +1 -1
- package/lib/cjs/curve/UnionRegion.js +1 -1
- package/lib/cjs/curve/UnionRegion.js.map +1 -1
- package/lib/cjs/geometry3d/FrameBuilder.d.ts +29 -25
- package/lib/cjs/geometry3d/FrameBuilder.d.ts.map +1 -1
- package/lib/cjs/geometry3d/FrameBuilder.js +42 -29
- package/lib/cjs/geometry3d/FrameBuilder.js.map +1 -1
- package/lib/esm/clipping/ClipPlane.d.ts +10 -7
- package/lib/esm/clipping/ClipPlane.d.ts.map +1 -1
- package/lib/esm/clipping/ClipPlane.js +5 -3
- package/lib/esm/clipping/ClipPlane.js.map +1 -1
- package/lib/esm/clipping/ClipUtils.d.ts +16 -4
- package/lib/esm/clipping/ClipUtils.d.ts.map +1 -1
- package/lib/esm/clipping/ClipUtils.js +77 -2
- package/lib/esm/clipping/ClipUtils.js.map +1 -1
- package/lib/esm/clipping/ConvexClipPlaneSet.d.ts +3 -2
- package/lib/esm/clipping/ConvexClipPlaneSet.d.ts.map +1 -1
- package/lib/esm/clipping/ConvexClipPlaneSet.js +3 -2
- package/lib/esm/clipping/ConvexClipPlaneSet.js.map +1 -1
- package/lib/esm/clipping/UnionOfConvexClipPlaneSets.d.ts +2 -2
- package/lib/esm/clipping/UnionOfConvexClipPlaneSets.js +2 -2
- package/lib/esm/clipping/UnionOfConvexClipPlaneSets.js.map +1 -1
- package/lib/esm/curve/Arc3d.d.ts.map +1 -1
- package/lib/esm/curve/Arc3d.js.map +1 -1
- package/lib/esm/curve/CoordinateXYZ.d.ts +15 -15
- package/lib/esm/curve/CoordinateXYZ.d.ts.map +1 -1
- package/lib/esm/curve/CoordinateXYZ.js +15 -15
- package/lib/esm/curve/CoordinateXYZ.js.map +1 -1
- package/lib/esm/curve/CurveChain.d.ts +4 -2
- package/lib/esm/curve/CurveChain.d.ts.map +1 -1
- package/lib/esm/curve/CurveChain.js.map +1 -1
- package/lib/esm/curve/CurveCollection.d.ts +1 -1
- package/lib/esm/curve/CurveCollection.d.ts.map +1 -1
- package/lib/esm/curve/CurveCollection.js +1 -1
- package/lib/esm/curve/CurveCollection.js.map +1 -1
- package/lib/esm/curve/CurveCurveCloseApproachXY.d.ts +18 -7
- package/lib/esm/curve/CurveCurveCloseApproachXY.d.ts.map +1 -1
- package/lib/esm/curve/CurveCurveCloseApproachXY.js +17 -5
- package/lib/esm/curve/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/esm/curve/CurveCurveIntersectXY.d.ts +2 -2
- package/lib/esm/curve/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/esm/curve/CurveCurveIntersectXY.js +12 -10
- package/lib/esm/curve/CurveCurveIntersectXY.js.map +1 -1
- package/lib/esm/curve/Path.d.ts +1 -1
- package/lib/esm/curve/Path.d.ts.map +1 -1
- package/lib/esm/curve/Path.js +1 -1
- package/lib/esm/curve/Path.js.map +1 -1
- package/lib/esm/curve/UnionRegion.js +1 -1
- package/lib/esm/curve/UnionRegion.js.map +1 -1
- package/lib/esm/geometry3d/FrameBuilder.d.ts +29 -25
- package/lib/esm/geometry3d/FrameBuilder.d.ts.map +1 -1
- package/lib/esm/geometry3d/FrameBuilder.js +42 -29
- package/lib/esm/geometry3d/FrameBuilder.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrameBuilder.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/FrameBuilder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FrameBuilder.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/FrameBuilder.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAa,eAAe,EAAY,MAAM,aAAa,CAAC;AAGnE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAAuB;IAEvC,OAAO,CAAC,6BAA6B;IASrC,kDAAkD;IAC3C,KAAK;;IASZ;;;;OAIG;IACI,iBAAiB,CAAC,eAAe,GAAE,OAAe,GAAG,SAAS,GAAG,SAAS;IAuBjF,kGAAkG;IAC3F,oBAAoB,CAAC,MAAM,CAAC,EAAE,QAAQ;IAK7C,8DAA8D;IAC9D,IAAW,SAAS,IAAI,OAAO,CAE9B;IACD;;OAEG;IACI,gBAAgB,IAAI,MAAM;IASjC;;OAEG;IACI,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;IAU5C,6BAA6B;IACtB,cAAc,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM;IA0B/C;;;OAGG;IACI,QAAQ,CAAC,IAAI,EAAE,GAAG;IAkEzB;;;;;OAKG;WACW,sBAAsB,CAAC,eAAe,EAAE,QAAQ,GAAG,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,GAAG,SAAS;IAgCpH;;;;;OAKG;WACW,6BAA6B,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,GAAG,SAAS;IAWpF;;;;;OAKG;WACW,0BAA0B,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,GAAG,SAAS;IAalF;;;;;;OAMG;WACW,yBAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,GAAG,SAAS;IASjF;;;;;;;;OAQG;WACW,kCAAkC,CAC9C,KAAK,EAAE,OAAO,EACd,WAAW,GAAE,eAA4D,EACzE,SAAS,GAAE,MAAU,EACrB,SAAS,GAAE,MAAU,EACrB,SAAS,GAAE,MAAU,EACrB,iBAAiB,GAAE,MAAY,GAAG,SAAS;CAe9C"}
|
|
@@ -13,7 +13,6 @@ import { CurveCollection } from "../curve/CurveCollection";
|
|
|
13
13
|
import { CurvePrimitive } from "../curve/CurvePrimitive";
|
|
14
14
|
import { LineSegment3d } from "../curve/LineSegment3d";
|
|
15
15
|
import { LineString3d } from "../curve/LineString3d";
|
|
16
|
-
/* eslint-disable @typescript-eslint/naming-convention, no-empty */
|
|
17
16
|
import { AxisOrder, AxisScaleSelect, Geometry } from "../Geometry";
|
|
18
17
|
import { GrowableXYZArray } from "./GrowableXYZArray";
|
|
19
18
|
import { Matrix3d } from "./Matrix3d";
|
|
@@ -21,6 +20,7 @@ import { Point3d, Vector3d } from "./Point3dVector3d";
|
|
|
21
20
|
import { Point3dArray } from "./PointHelpers";
|
|
22
21
|
import { PolygonOps } from "./PolygonOps";
|
|
23
22
|
import { Transform } from "./Transform";
|
|
23
|
+
/* eslint-disable @typescript-eslint/naming-convention, no-empty */
|
|
24
24
|
/**
|
|
25
25
|
* Helper class to accumulate points and vectors until there is enough data to define a coordinate system.
|
|
26
26
|
*
|
|
@@ -28,10 +28,10 @@ import { Transform } from "./Transform";
|
|
|
28
28
|
* * create the FrameBuilder and make calls to announcePoint and announceVector.
|
|
29
29
|
* * the frame will be fully determined by an origin and two vectors.
|
|
30
30
|
* * the first call to announcePoint will set the origin.
|
|
31
|
-
* *
|
|
32
|
-
* *
|
|
31
|
+
* * additional calls to announcePoint will produce announceVector call with the vector from the origin.
|
|
32
|
+
* * after each announcement, call getValidatedFrame(false)
|
|
33
33
|
* * getValidatedFrame will succeed when it has two independent vectors.
|
|
34
|
-
* *
|
|
34
|
+
* * To build a left handed frame,
|
|
35
35
|
* * an origin and 3 independent vectors are required.
|
|
36
36
|
* * announce as above, but query with getValidatedFrame (true).
|
|
37
37
|
* * this will use the third vector to select right or left handed frame.
|
|
@@ -46,11 +46,18 @@ export class FrameBuilder {
|
|
|
46
46
|
}
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
|
-
/**
|
|
50
|
-
clear() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
/** Clear all accumulated point and vector data */
|
|
50
|
+
clear() {
|
|
51
|
+
this._origin = undefined;
|
|
52
|
+
this._vector0 = undefined;
|
|
53
|
+
this._vector1 = undefined;
|
|
54
|
+
this._vector2 = undefined;
|
|
55
|
+
}
|
|
56
|
+
constructor() {
|
|
57
|
+
this.clear();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Try to assemble the data into a non-singular transform.
|
|
54
61
|
* * If allowLeftHanded is false, vector0 and vector1 determine a right handed coordinate system.
|
|
55
62
|
* * if allowLeftHanded is true, the z vector of the right handed system can be flipped to agree with vector2 direction.
|
|
56
63
|
*/
|
|
@@ -85,8 +92,11 @@ export class FrameBuilder {
|
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
94
|
/** Ask if there is a defined origin for the evolving frame */
|
|
88
|
-
get hasOrigin() {
|
|
89
|
-
|
|
95
|
+
get hasOrigin() {
|
|
96
|
+
return this._origin !== undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Return the number of vectors saved. Because the save process checks numerics, this should be the rank of the system.
|
|
90
100
|
*/
|
|
91
101
|
savedVectorCount() {
|
|
92
102
|
if (!this._vector0)
|
|
@@ -97,7 +107,9 @@ export class FrameBuilder {
|
|
|
97
107
|
return 2;
|
|
98
108
|
return 3;
|
|
99
109
|
}
|
|
100
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Announce a new point. If this point is different from the origin, also compute and announce the vector from the origin.
|
|
112
|
+
*/
|
|
101
113
|
announcePoint(point) {
|
|
102
114
|
if (!this._origin) {
|
|
103
115
|
this._origin = point.clone();
|
|
@@ -108,7 +120,7 @@ export class FrameBuilder {
|
|
|
108
120
|
return this.savedVectorCount();
|
|
109
121
|
return this.announceVector(this._origin.vectorTo(point));
|
|
110
122
|
}
|
|
111
|
-
/**
|
|
123
|
+
/** Announce a new vector. */
|
|
112
124
|
announceVector(vector) {
|
|
113
125
|
if (vector.isAlmostZero)
|
|
114
126
|
return this.savedVectorCount();
|
|
@@ -135,8 +147,9 @@ export class FrameBuilder {
|
|
|
135
147
|
// fall through if prior vectors are all there -- no need for the new one.
|
|
136
148
|
return 3;
|
|
137
149
|
}
|
|
138
|
-
/**
|
|
139
|
-
*
|
|
150
|
+
/**
|
|
151
|
+
* Inspect the content of the data. Announce points and vectors. Return when savedVectorCount becomes sufficient
|
|
152
|
+
* for a coordinate system.
|
|
140
153
|
*/
|
|
141
154
|
announce(data) {
|
|
142
155
|
if (this.savedVectorCount() > 1)
|
|
@@ -217,11 +230,11 @@ export class FrameBuilder {
|
|
|
217
230
|
}
|
|
218
231
|
}
|
|
219
232
|
}
|
|
220
|
-
/**
|
|
221
|
-
*
|
|
222
|
-
* *
|
|
223
|
-
* *
|
|
224
|
-
* *
|
|
233
|
+
/**
|
|
234
|
+
* Create a localToWorld frame for the given data.
|
|
235
|
+
* * origin is at first point.
|
|
236
|
+
* * x axis in direction of first nonzero vector present or implied by the input.
|
|
237
|
+
* * y axis is perpendicular to x and contains (in positive side) the next vector present or implied by the input.
|
|
225
238
|
*/
|
|
226
239
|
static createRightHandedFrame(defaultUpVector, ...params) {
|
|
227
240
|
const builder = new FrameBuilder();
|
|
@@ -256,10 +269,11 @@ export class FrameBuilder {
|
|
|
256
269
|
}
|
|
257
270
|
return undefined;
|
|
258
271
|
}
|
|
259
|
-
/**
|
|
272
|
+
/**
|
|
273
|
+
* Create a transform containing points or vectors in the given data.
|
|
260
274
|
* * The xy columns of the transform contain the first points or vectors of the data.
|
|
261
275
|
* * The z column is perpendicular to that xy plane.
|
|
262
|
-
* * The calculation favors the first points found.
|
|
276
|
+
* * The calculation favors the first points found. It does not try to get a "best" plane.
|
|
263
277
|
*/
|
|
264
278
|
static createRightHandedLocalToWorld(...params) {
|
|
265
279
|
const builder = new FrameBuilder();
|
|
@@ -272,10 +286,9 @@ export class FrameBuilder {
|
|
|
272
286
|
return undefined;
|
|
273
287
|
}
|
|
274
288
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* point most distant from that line.
|
|
289
|
+
* Try to create a frame whose xy plane is through points.
|
|
290
|
+
* * If 3 or more distinct points are present, the x axis is from the first point to the most distant, and y
|
|
291
|
+
* direction is toward the point most distant from that line.
|
|
279
292
|
* @param points array of points
|
|
280
293
|
*/
|
|
281
294
|
static createFrameToDistantPoints(points) {
|
|
@@ -292,10 +305,10 @@ export class FrameBuilder {
|
|
|
292
305
|
return undefined;
|
|
293
306
|
}
|
|
294
307
|
/**
|
|
295
|
-
*
|
|
308
|
+
* Try to create a frame whose xy plane is through points, with the points appearing CCW in the local frame.
|
|
296
309
|
*
|
|
297
|
-
* *
|
|
298
|
-
* point most distant from that line.
|
|
310
|
+
* * If 3 or more distinct points are present, the x axis is from the first point to the most distant, and y
|
|
311
|
+
* direction is toward the point most distant from that line.
|
|
299
312
|
* @param points array of points
|
|
300
313
|
*/
|
|
301
314
|
static createFrameWithCCWPolygon(points) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrameBuilder.js","sourceRoot":"","sources":["../../../src/geometry3d/FrameBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,0CAA0C;AAC1C,OAAO,EAAE,cAAc,EAAE,MA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CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACnH,CAAC,GAAG,QAAQ,CAAC,0BAA0B,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;SACpH;QACD,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACrH,CAAC;CAEF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\n// import { Point2d } from \"./Geometry2d\";\r\nimport { BSplineCurve3d } from \"../bspline/BSplineCurve\";\r\nimport { InterpolationCurve3d } from \"../bspline/InterpolationCurve3d\";\r\nimport { Arc3d } from \"../curve/Arc3d\";\r\nimport { CurveCollection } from \"../curve/CurveCollection\";\r\nimport { CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { LineSegment3d } from \"../curve/LineSegment3d\";\r\nimport { LineString3d } from \"../curve/LineString3d\";\r\n/* eslint-disable @typescript-eslint/naming-convention, no-empty */\r\nimport { AxisOrder, AxisScaleSelect, Geometry } from \"../Geometry\";\r\nimport { GrowableXYZArray } from \"./GrowableXYZArray\";\r\nimport { Matrix3d } from \"./Matrix3d\";\r\nimport { Point3d, Vector3d } from \"./Point3dVector3d\";\r\nimport { Point3dArray } from \"./PointHelpers\";\r\nimport { PolygonOps } from \"./PolygonOps\";\r\nimport { Range3d } from \"./Range\";\r\nimport { Transform } from \"./Transform\";\r\n\r\n/**\r\n * Helper class to accumulate points and vectors until there is enough data to define a coordinate system.\r\n *\r\n * * For the common case of building a right handed frame:\r\n * * create the FrameBuilder and make calls to announcePoint and announceVector.\r\n * * the frame will be fully determined by an origin and two vectors.\r\n * * the first call to announcePoint will set the origin.\r\n * * additional calls to announcePoint will produce announceVector call with the vector from the origin.\r\n * * After each announcement, call getValidatedFrame(false)\r\n * * getValidatedFrame will succeed when it has two independent vectors.\r\n * * to build a left handed frame,\r\n * * an origin and 3 independent vectors are required.\r\n * * announce as above, but query with getValidatedFrame (true).\r\n * * this will use the third vector to select right or left handed frame.\r\n * @public\r\n */\r\nexport class FrameBuilder {\r\n private _origin: undefined | Point3d;\r\n private _vector0: undefined | Vector3d;\r\n private _vector1: undefined | Vector3d;\r\n private _vector2: undefined | Vector3d;\r\n // test if both vectors are defined and have significant angle between.\r\n private areStronglyIndependentVectors(vector0: Vector3d, vector1: Vector3d, radiansTolerance: number = Geometry.smallAngleRadians): boolean {\r\n if (vector0 !== undefined && vector1 !== undefined) {\r\n const q = vector0.smallerUnorientedRadiansTo(vector1);\r\n return q > radiansTolerance;\r\n }\r\n return false;\r\n }\r\n /** clear all accumulated point and vector data */\r\n public clear() { this._origin = undefined; this._vector0 = undefined; this._vector1 = undefined; this._vector2 = undefined; }\r\n constructor() { this.clear(); }\r\n /** Try to assemble the data into a non-singular transform.\r\n *\r\n * * If allowLeftHanded is false, vector0 and vector1 determine a right handed coordinate system.\r\n * * if allowLeftHanded is true, the z vector of the right handed system can be flipped to agree with vector2 direction.\r\n */\r\n public getValidatedFrame(allowLeftHanded: boolean = false): Transform | undefined {\r\n if (this._origin && this._vector0 && this._vector1) {\r\n if (!allowLeftHanded) {\r\n const matrix = Matrix3d.createRigidFromColumns(this._vector0, this._vector1, AxisOrder.XYZ);\r\n if (matrix)\r\n return Transform.createOriginAndMatrix(this._origin, matrix);\r\n // uh oh -- vector1 was not really independent. clear everything after vector0.\r\n this._vector1 = this._vector2 = undefined;\r\n } else if (this._vector2) {\r\n const matrix = Matrix3d.createRigidFromColumns(this._vector0, this._vector1, AxisOrder.XYZ);\r\n if (matrix) {\r\n if (this._vector0.tripleProduct(this._vector1, this._vector2) < 0)\r\n matrix.scaleColumns(1.0, 1.0, -1.0);\r\n return Transform.createOriginAndMatrix(this._origin, matrix);\r\n }\r\n // uh oh again -- clear vector1 and vector2, re-announce vector2 as possible vector1??\r\n const vector2 = this._vector2;\r\n this._vector1 = this._vector2 = undefined;\r\n this.announceVector(vector2);\r\n }\r\n }\r\n return undefined;\r\n }\r\n /** If vector0 is known but vector1 is not, make vector1 the cross of the up-vector and vector0 */\r\n public applyDefaultUpVector(vector?: Vector3d) {\r\n if (vector && this._vector0 && !this._vector1 && !vector.isParallelTo(this._vector0)) {\r\n this._vector1 = vector.crossProduct(this._vector0);\r\n }\r\n }\r\n /** Ask if there is a defined origin for the evolving frame */\r\n public get hasOrigin(): boolean { return this._origin !== undefined; }\r\n /** Return the number of vectors saved. Because the save process checks numerics, this should be the rank of the system.\r\n */\r\n public savedVectorCount(): number {\r\n if (!this._vector0)\r\n return 0;\r\n if (!this._vector1)\r\n return 1;\r\n if (!this._vector2)\r\n return 2;\r\n return 3;\r\n }\r\n /** announce a new point. If this point is different from the origin, also compute and announce the vector from the origin.*/\r\n public announcePoint(point: Point3d): number {\r\n if (!this._origin) {\r\n this._origin = point.clone();\r\n return this.savedVectorCount();\r\n }\r\n // the new point may provide an additional vector\r\n if (this._origin.isAlmostEqual(point))\r\n return this.savedVectorCount();\r\n return this.announceVector(this._origin.vectorTo(point));\r\n }\r\n /** announce a new vector. */\r\n public announceVector(vector: Vector3d): number {\r\n if (vector.isAlmostZero)\r\n return this.savedVectorCount();\r\n\r\n if (!this._vector0) { this._vector0 = vector.clone(this._vector0); return 1; }\r\n\r\n if (!this._vector1) {\r\n if (this.areStronglyIndependentVectors(vector, this._vector0, 1.0e-5)) {\r\n this._vector1 = vector.clone(this._vector1);\r\n return 2;\r\n }\r\n return 1;\r\n }\r\n\r\n // vector0 and vector1 are independent.\r\n if (!this._vector2) {\r\n const unitPerpendicular = this._vector0.unitCrossProduct(this._vector1);\r\n if (unitPerpendicular && !Geometry.isSameCoordinate(0, unitPerpendicular.dotProduct(vector))) {\r\n this._vector2 = vector.clone(this._vector2);\r\n return 3;\r\n }\r\n return 2;\r\n }\r\n // fall through if prior vectors are all there -- no need for the new one.\r\n return 3;\r\n }\r\n /** Inspect the content of the data. Announce points and vectors. Return when savedVectorCount becomes\r\n * sufficient for a coordinate system.\r\n */\r\n public announce(data: any) {\r\n if (this.savedVectorCount() > 1) return;\r\n if (data instanceof Point3d)\r\n this.announcePoint(data);\r\n else if (data instanceof Vector3d)\r\n this.announceVector(data);\r\n else if (Array.isArray(data)) {\r\n for (const child of data) {\r\n if (this.savedVectorCount() > 1)\r\n break;\r\n this.announce(child);\r\n }\r\n } else if (data instanceof CurvePrimitive) {\r\n if (data instanceof LineSegment3d) {\r\n this.announcePoint(data.startPoint());\r\n this.announcePoint(data.endPoint());\r\n } else if (data instanceof Arc3d) {\r\n const ray = data.fractionToPointAndDerivative(0.0);\r\n this.announcePoint(ray.origin);\r\n this.announceVector(ray.direction);\r\n this.announceVector(data.matrixRef.columnZCrossVector(ray.direction));\r\n } else if (data instanceof LineString3d) {\r\n for (const point of data.points) {\r\n this.announcePoint(point);\r\n if (this.savedVectorCount() > 1)\r\n break;\r\n }\r\n } else if (data instanceof BSplineCurve3d) {\r\n const point = Point3d.create();\r\n for (let i = 0; this.savedVectorCount() < 2; i++) {\r\n if (data.getPolePoint3d(i, point) instanceof Point3d)\r\n this.announcePoint(point);\r\n else break;\r\n }\r\n } else if (data instanceof InterpolationCurve3d) {\r\n const point = Point3d.create();\r\n for (let i = 0; this.savedVectorCount() < 2; i++) {\r\n if (i < data.options.fitPoints.length) {\r\n point.setFrom(data.options.fitPoints[i]);\r\n this.announcePoint(point);\r\n } else break;\r\n }\r\n } else { // unimplemented CurvePrimitive type\r\n const frame = data.fractionToFrenetFrame(0.0);\r\n if (undefined !== frame) {\r\n this.announcePoint(frame.getOrigin());\r\n this.announceVector(frame.matrix.getColumn(0));\r\n this.announceVector(frame.matrix.getColumn(1));\r\n }\r\n }\r\n } else if (data instanceof CurveCollection) {\r\n if (data.children)\r\n for (const child of data.children) {\r\n this.announce(child);\r\n if (this.savedVectorCount() > 1)\r\n break;\r\n }\r\n } else if (data instanceof GrowableXYZArray) {\r\n const point = Point3d.create();\r\n for (let i = 0; this.savedVectorCount() < 2; i++) {\r\n if (data.getPoint3dAtCheckedPointIndex(i, point) instanceof Point3d)\r\n this.announcePoint(point);\r\n else break;\r\n }\r\n }\r\n }\r\n /** create a localToWorld frame for the given data.\r\n *\r\n * * origin is at first point\r\n * * x axis in direction of first nonzero vector present or implied by the input.\r\n * * y axis is perpendicular to x and contains (in positive side) the next vector present or implied by the input.\r\n */\r\n public static createRightHandedFrame(defaultUpVector: Vector3d | undefined, ...params: any[]): Transform | undefined {\r\n const builder = new FrameBuilder();\r\n for (const data of params) {\r\n builder.announce(data);\r\n builder.applyDefaultUpVector(defaultUpVector);\r\n const result = builder.getValidatedFrame(false);\r\n if (result !== undefined) {\r\n if (defaultUpVector) {\r\n if (result.matrix.dotColumnZ(defaultUpVector) < 0.0)\r\n result.matrix.scaleColumnsInPlace(1, -1, -1);\r\n }\r\n return result;\r\n }\r\n }\r\n\r\n const evaluatePrimitiveFrame = (curve: CurvePrimitive): Transform | undefined => {\r\n return curve.fractionToFrenetFrame(0.0);\r\n };\r\n\r\n // try direct evaluation of curve primitives using the above lambda\r\n for (const data of params) {\r\n if (data instanceof CurvePrimitive) {\r\n return evaluatePrimitiveFrame(data);\r\n } else if (data instanceof CurveCollection) {\r\n const children = data.collectCurvePrimitives();\r\n for (const curve of children) {\r\n const frenetFrame = evaluatePrimitiveFrame(curve);\r\n if (frenetFrame)\r\n return frenetFrame;\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n /** create a transform containing points or vectors in the given data.\r\n * * The xy columns of the transform contain the first points or vectors of the data.\r\n * * The z column is perpendicular to that xy plane.\r\n * * The calculation favors the first points found. It does not try to get a \"best\" plane.\r\n */\r\n public static createRightHandedLocalToWorld(...params: any[]): Transform | undefined {\r\n const builder = new FrameBuilder();\r\n for (const data of params) {\r\n builder.announce(data);\r\n const localToWorld = builder.getValidatedFrame(false);\r\n if (localToWorld !== undefined)\r\n return localToWorld;\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * try to create a frame whose xy plane is through points.\r\n *\r\n * * if 3 or more distinct points are present, the x axis is from the first point to the most distance, and y direction is toward the\r\n * point most distant from that line.\r\n * @param points array of points\r\n */\r\n public static createFrameToDistantPoints(points: Point3d[]): Transform | undefined {\r\n if (points.length > 2) {\r\n const origin = points[0].clone();\r\n const vector01 = Vector3d.create();\r\n Point3dArray.indexOfMostDistantPoint(points, points[0], vector01);\r\n const vector02 = Vector3d.create();\r\n Point3dArray.indexOfPointWithMaxCrossProductMagnitude(points, origin, vector01, vector02);\r\n const matrix = Matrix3d.createRigidFromColumns(vector01, vector02, AxisOrder.XYZ);\r\n if (matrix)\r\n return Transform.createRefs(origin, matrix);\r\n }\r\n return undefined;\r\n }\r\n /**\r\n * try to create a frame whose xy plane is through points, with the points appearing CCW in the local frame.\r\n *\r\n * * if 3 or more distinct points are present, the x axis is from the first point to the most distance, and y direction is toward the\r\n * point most distant from that line.\r\n * @param points array of points\r\n */\r\n public static createFrameWithCCWPolygon(points: Point3d[]): Transform | undefined {\r\n if (points.length > 2) {\r\n const ray = PolygonOps.centroidAreaNormal(points);\r\n if (ray) {\r\n return ray.toRigidZFrame();\r\n }\r\n }\r\n return undefined;\r\n }\r\n /**\r\n * Create the localToWorld transform from a range to axes of its parent coordinate system.\r\n * @param range [in] range to inspect\r\n * @param fractionX [in] fractional coordinate of frame origin x\r\n * @param fractionY [in] fractional coordinate of frame origin y\r\n * @param fractionZ [in] fractional coordinate of frame origin z\r\n * @param scaleSelect [in] selects size of localToWorld axes.\r\n * @param defaultAxisLength [in] if true and any axis length is 0, that axis vector takes this physical length.\r\n */\r\n public static createLocalToWorldTransformInRange(\r\n range: Range3d,\r\n scaleSelect: AxisScaleSelect = AxisScaleSelect.NonUniformRangeContainment,\r\n fractionX: number = 0,\r\n fractionY: number = 0,\r\n fractionZ: number = 0,\r\n defaultAxisLength: number = 1.0): Transform {\r\n if (range.isNull)\r\n return Transform.createIdentity();\r\n let a = 1.0;\r\n let b = 1.0;\r\n let c = 1.0;\r\n if (scaleSelect === AxisScaleSelect.LongestRangeDirection) {\r\n a = b = c = Geometry.correctSmallMetricDistance(range.maxLength(), defaultAxisLength);\r\n } else if (scaleSelect === AxisScaleSelect.NonUniformRangeContainment) {\r\n a = Geometry.correctSmallMetricDistance(range.xLength(), defaultAxisLength) * Geometry.maxAbsDiff(fractionX, 0, 1);\r\n b = Geometry.correctSmallMetricDistance(range.yLength(), defaultAxisLength) * Geometry.maxAbsDiff(fractionY, 0, 1);\r\n c = Geometry.correctSmallMetricDistance(range.zLength(), defaultAxisLength) * Geometry.maxAbsDiff(fractionZ, 0, 1);\r\n }\r\n return Transform.createRefs(range.fractionToPoint(fractionX, fractionY, fractionZ), Matrix3d.createScale(a, b, c));\r\n }\r\n\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"FrameBuilder.js","sourceRoot":"","sources":["../../../src/geometry3d/FrameBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,0CAA0C;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;A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,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACrH,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\n// import { Point2d } from \"./Geometry2d\";\r\nimport { BSplineCurve3d } from \"../bspline/BSplineCurve\";\r\nimport { InterpolationCurve3d } from \"../bspline/InterpolationCurve3d\";\r\nimport { Arc3d } from \"../curve/Arc3d\";\r\nimport { CurveCollection } from \"../curve/CurveCollection\";\r\nimport { CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { LineSegment3d } from \"../curve/LineSegment3d\";\r\nimport { LineString3d } from \"../curve/LineString3d\";\r\nimport { AxisOrder, AxisScaleSelect, Geometry } from \"../Geometry\";\r\nimport { GrowableXYZArray } from \"./GrowableXYZArray\";\r\nimport { Matrix3d } from \"./Matrix3d\";\r\nimport { Point3d, Vector3d } from \"./Point3dVector3d\";\r\nimport { Point3dArray } from \"./PointHelpers\";\r\nimport { PolygonOps } from \"./PolygonOps\";\r\nimport { Range3d } from \"./Range\";\r\nimport { Transform } from \"./Transform\";\r\n\r\n/* eslint-disable @typescript-eslint/naming-convention, no-empty */\r\n\r\n/**\r\n * Helper class to accumulate points and vectors until there is enough data to define a coordinate system.\r\n *\r\n * * For the common case of building a right handed frame:\r\n * * create the FrameBuilder and make calls to announcePoint and announceVector.\r\n * * the frame will be fully determined by an origin and two vectors.\r\n * * the first call to announcePoint will set the origin.\r\n * * additional calls to announcePoint will produce announceVector call with the vector from the origin.\r\n * * after each announcement, call getValidatedFrame(false)\r\n * * getValidatedFrame will succeed when it has two independent vectors.\r\n * * To build a left handed frame,\r\n * * an origin and 3 independent vectors are required.\r\n * * announce as above, but query with getValidatedFrame (true).\r\n * * this will use the third vector to select right or left handed frame.\r\n * @public\r\n */\r\nexport class FrameBuilder {\r\n private _origin: undefined | Point3d;\r\n private _vector0: undefined | Vector3d;\r\n private _vector1: undefined | Vector3d;\r\n private _vector2: undefined | Vector3d;\r\n // test if both vectors are defined and have significant angle between.\r\n private areStronglyIndependentVectors(\r\n vector0: Vector3d, vector1: Vector3d, radiansTolerance: number = Geometry.smallAngleRadians,\r\n ): boolean {\r\n if (vector0 !== undefined && vector1 !== undefined) {\r\n const q = vector0.smallerUnorientedRadiansTo(vector1);\r\n return q > radiansTolerance;\r\n }\r\n return false;\r\n }\r\n /** Clear all accumulated point and vector data */\r\n public clear() {\r\n this._origin = undefined;\r\n this._vector0 = undefined;\r\n this._vector1 = undefined;\r\n this._vector2 = undefined;\r\n }\r\n constructor() {\r\n this.clear();\r\n }\r\n /**\r\n * Try to assemble the data into a non-singular transform.\r\n * * If allowLeftHanded is false, vector0 and vector1 determine a right handed coordinate system.\r\n * * if allowLeftHanded is true, the z vector of the right handed system can be flipped to agree with vector2 direction.\r\n */\r\n public getValidatedFrame(allowLeftHanded: boolean = false): Transform | undefined {\r\n if (this._origin && this._vector0 && this._vector1) {\r\n if (!allowLeftHanded) {\r\n const matrix = Matrix3d.createRigidFromColumns(this._vector0, this._vector1, AxisOrder.XYZ);\r\n if (matrix)\r\n return Transform.createOriginAndMatrix(this._origin, matrix);\r\n // uh oh -- vector1 was not really independent. clear everything after vector0.\r\n this._vector1 = this._vector2 = undefined;\r\n } else if (this._vector2) {\r\n const matrix = Matrix3d.createRigidFromColumns(this._vector0, this._vector1, AxisOrder.XYZ);\r\n if (matrix) {\r\n if (this._vector0.tripleProduct(this._vector1, this._vector2) < 0)\r\n matrix.scaleColumns(1.0, 1.0, -1.0);\r\n return Transform.createOriginAndMatrix(this._origin, matrix);\r\n }\r\n // uh oh again -- clear vector1 and vector2, re-announce vector2 as possible vector1??\r\n const vector2 = this._vector2;\r\n this._vector1 = this._vector2 = undefined;\r\n this.announceVector(vector2);\r\n }\r\n }\r\n return undefined;\r\n }\r\n /** If vector0 is known but vector1 is not, make vector1 the cross of the up-vector and vector0 */\r\n public applyDefaultUpVector(vector?: Vector3d) {\r\n if (vector && this._vector0 && !this._vector1 && !vector.isParallelTo(this._vector0)) {\r\n this._vector1 = vector.crossProduct(this._vector0);\r\n }\r\n }\r\n /** Ask if there is a defined origin for the evolving frame */\r\n public get hasOrigin(): boolean {\r\n return this._origin !== undefined;\r\n }\r\n /**\r\n * Return the number of vectors saved. Because the save process checks numerics, this should be the rank of the system.\r\n */\r\n public savedVectorCount(): number {\r\n if (!this._vector0)\r\n return 0;\r\n if (!this._vector1)\r\n return 1;\r\n if (!this._vector2)\r\n return 2;\r\n return 3;\r\n }\r\n /**\r\n * Announce a new point. If this point is different from the origin, also compute and announce the vector from the origin.\r\n */\r\n public announcePoint(point: Point3d): number {\r\n if (!this._origin) {\r\n this._origin = point.clone();\r\n return this.savedVectorCount();\r\n }\r\n // the new point may provide an additional vector\r\n if (this._origin.isAlmostEqual(point))\r\n return this.savedVectorCount();\r\n return this.announceVector(this._origin.vectorTo(point));\r\n }\r\n /** Announce a new vector. */\r\n public announceVector(vector: Vector3d): number {\r\n if (vector.isAlmostZero)\r\n return this.savedVectorCount();\r\n if (!this._vector0) {\r\n this._vector0 = vector.clone(this._vector0);\r\n return 1;\r\n }\r\n if (!this._vector1) {\r\n if (this.areStronglyIndependentVectors(vector, this._vector0, 1.0e-5)) {\r\n this._vector1 = vector.clone(this._vector1);\r\n return 2;\r\n }\r\n return 1;\r\n }\r\n // vector0 and vector1 are independent.\r\n if (!this._vector2) {\r\n const unitPerpendicular = this._vector0.unitCrossProduct(this._vector1);\r\n if (unitPerpendicular && !Geometry.isSameCoordinate(0, unitPerpendicular.dotProduct(vector))) {\r\n this._vector2 = vector.clone(this._vector2);\r\n return 3;\r\n }\r\n return 2;\r\n }\r\n // fall through if prior vectors are all there -- no need for the new one.\r\n return 3;\r\n }\r\n /**\r\n * Inspect the content of the data. Announce points and vectors. Return when savedVectorCount becomes sufficient\r\n * for a coordinate system.\r\n */\r\n public announce(data: any) {\r\n if (this.savedVectorCount() > 1) return;\r\n if (data instanceof Point3d)\r\n this.announcePoint(data);\r\n else if (data instanceof Vector3d)\r\n this.announceVector(data);\r\n else if (Array.isArray(data)) {\r\n for (const child of data) {\r\n if (this.savedVectorCount() > 1)\r\n break;\r\n this.announce(child);\r\n }\r\n } else if (data instanceof CurvePrimitive) {\r\n if (data instanceof LineSegment3d) {\r\n this.announcePoint(data.startPoint());\r\n this.announcePoint(data.endPoint());\r\n } else if (data instanceof Arc3d) {\r\n const ray = data.fractionToPointAndDerivative(0.0);\r\n this.announcePoint(ray.origin);\r\n this.announceVector(ray.direction);\r\n this.announceVector(data.matrixRef.columnZCrossVector(ray.direction));\r\n } else if (data instanceof LineString3d) {\r\n for (const point of data.points) {\r\n this.announcePoint(point);\r\n if (this.savedVectorCount() > 1)\r\n break;\r\n }\r\n } else if (data instanceof BSplineCurve3d) {\r\n const point = Point3d.create();\r\n for (let i = 0; this.savedVectorCount() < 2; i++) {\r\n if (data.getPolePoint3d(i, point) instanceof Point3d)\r\n this.announcePoint(point);\r\n else break;\r\n }\r\n } else if (data instanceof InterpolationCurve3d) {\r\n const point = Point3d.create();\r\n for (let i = 0; this.savedVectorCount() < 2; i++) {\r\n if (i < data.options.fitPoints.length) {\r\n point.setFrom(data.options.fitPoints[i]);\r\n this.announcePoint(point);\r\n } else break;\r\n }\r\n } else { // unimplemented CurvePrimitive type\r\n const frame = data.fractionToFrenetFrame(0.0);\r\n if (undefined !== frame) {\r\n this.announcePoint(frame.getOrigin());\r\n this.announceVector(frame.matrix.getColumn(0));\r\n this.announceVector(frame.matrix.getColumn(1));\r\n }\r\n }\r\n } else if (data instanceof CurveCollection) {\r\n if (data.children)\r\n for (const child of data.children) {\r\n this.announce(child);\r\n if (this.savedVectorCount() > 1)\r\n break;\r\n }\r\n } else if (data instanceof GrowableXYZArray) {\r\n const point = Point3d.create();\r\n for (let i = 0; this.savedVectorCount() < 2; i++) {\r\n if (data.getPoint3dAtCheckedPointIndex(i, point) instanceof Point3d)\r\n this.announcePoint(point);\r\n else break;\r\n }\r\n }\r\n }\r\n /**\r\n * Create a localToWorld frame for the given data.\r\n * * origin is at first point.\r\n * * x axis in direction of first nonzero vector present or implied by the input.\r\n * * y axis is perpendicular to x and contains (in positive side) the next vector present or implied by the input.\r\n */\r\n public static createRightHandedFrame(defaultUpVector: Vector3d | undefined, ...params: any[]): Transform | undefined {\r\n const builder = new FrameBuilder();\r\n for (const data of params) {\r\n builder.announce(data);\r\n builder.applyDefaultUpVector(defaultUpVector);\r\n const result = builder.getValidatedFrame(false);\r\n if (result !== undefined) {\r\n if (defaultUpVector) {\r\n if (result.matrix.dotColumnZ(defaultUpVector) < 0.0)\r\n result.matrix.scaleColumnsInPlace(1, -1, -1);\r\n }\r\n return result;\r\n }\r\n }\r\n const evaluatePrimitiveFrame = (curve: CurvePrimitive): Transform | undefined => {\r\n return curve.fractionToFrenetFrame(0.0);\r\n };\r\n // try direct evaluation of curve primitives using the above lambda\r\n for (const data of params) {\r\n if (data instanceof CurvePrimitive) {\r\n return evaluatePrimitiveFrame(data);\r\n } else if (data instanceof CurveCollection) {\r\n const children = data.collectCurvePrimitives();\r\n for (const curve of children) {\r\n const frenetFrame = evaluatePrimitiveFrame(curve);\r\n if (frenetFrame)\r\n return frenetFrame;\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n /**\r\n * Create a transform containing points or vectors in the given data.\r\n * * The xy columns of the transform contain the first points or vectors of the data.\r\n * * The z column is perpendicular to that xy plane.\r\n * * The calculation favors the first points found. It does not try to get a \"best\" plane.\r\n */\r\n public static createRightHandedLocalToWorld(...params: any[]): Transform | undefined {\r\n const builder = new FrameBuilder();\r\n for (const data of params) {\r\n builder.announce(data);\r\n const localToWorld = builder.getValidatedFrame(false);\r\n if (localToWorld !== undefined)\r\n return localToWorld;\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Try to create a frame whose xy plane is through points.\r\n * * If 3 or more distinct points are present, the x axis is from the first point to the most distant, and y\r\n * direction is toward the point most distant from that line.\r\n * @param points array of points\r\n */\r\n public static createFrameToDistantPoints(points: Point3d[]): Transform | undefined {\r\n if (points.length > 2) {\r\n const origin = points[0].clone();\r\n const vector01 = Vector3d.create();\r\n Point3dArray.indexOfMostDistantPoint(points, points[0], vector01);\r\n const vector02 = Vector3d.create();\r\n Point3dArray.indexOfPointWithMaxCrossProductMagnitude(points, origin, vector01, vector02);\r\n const matrix = Matrix3d.createRigidFromColumns(vector01, vector02, AxisOrder.XYZ);\r\n if (matrix)\r\n return Transform.createRefs(origin, matrix);\r\n }\r\n return undefined;\r\n }\r\n /**\r\n * Try to create a frame whose xy plane is through points, with the points appearing CCW in the local frame.\r\n *\r\n * * If 3 or more distinct points are present, the x axis is from the first point to the most distant, and y\r\n * direction is toward the point most distant from that line.\r\n * @param points array of points\r\n */\r\n public static createFrameWithCCWPolygon(points: Point3d[]): Transform | undefined {\r\n if (points.length > 2) {\r\n const ray = PolygonOps.centroidAreaNormal(points);\r\n if (ray) {\r\n return ray.toRigidZFrame();\r\n }\r\n }\r\n return undefined;\r\n }\r\n /**\r\n * Create the localToWorld transform from a range to axes of its parent coordinate system.\r\n * @param range [in] range to inspect\r\n * @param fractionX [in] fractional coordinate of frame origin x\r\n * @param fractionY [in] fractional coordinate of frame origin y\r\n * @param fractionZ [in] fractional coordinate of frame origin z\r\n * @param scaleSelect [in] selects size of localToWorld axes.\r\n * @param defaultAxisLength [in] if true and any axis length is 0, that axis vector takes this physical length.\r\n */\r\n public static createLocalToWorldTransformInRange(\r\n range: Range3d,\r\n scaleSelect: AxisScaleSelect = AxisScaleSelect.NonUniformRangeContainment,\r\n fractionX: number = 0,\r\n fractionY: number = 0,\r\n fractionZ: number = 0,\r\n defaultAxisLength: number = 1.0): Transform {\r\n if (range.isNull)\r\n return Transform.createIdentity();\r\n let a = 1.0;\r\n let b = 1.0;\r\n let c = 1.0;\r\n if (scaleSelect === AxisScaleSelect.LongestRangeDirection) {\r\n a = b = c = Geometry.correctSmallMetricDistance(range.maxLength(), defaultAxisLength);\r\n } else if (scaleSelect === AxisScaleSelect.NonUniformRangeContainment) {\r\n a = Geometry.correctSmallMetricDistance(range.xLength(), defaultAxisLength) * Geometry.maxAbsDiff(fractionX, 0, 1);\r\n b = Geometry.correctSmallMetricDistance(range.yLength(), defaultAxisLength) * Geometry.maxAbsDiff(fractionY, 0, 1);\r\n c = Geometry.correctSmallMetricDistance(range.zLength(), defaultAxisLength) * Geometry.maxAbsDiff(fractionZ, 0, 1);\r\n }\r\n return Transform.createRefs(range.fractionToPoint(fractionX, fractionY, fractionZ), Matrix3d.createScale(a, b, c));\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-geometry",
|
|
3
|
-
"version": "4.2.0-dev.
|
|
3
|
+
"version": "4.2.0-dev.8",
|
|
4
4
|
"description": "iTwin.js Core Geometry library",
|
|
5
5
|
"main": "lib/cjs/core-geometry.js",
|
|
6
6
|
"module": "lib/esm/core-geometry.js",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"nyc": "^15.1.0",
|
|
36
36
|
"rimraf": "^3.0.2",
|
|
37
37
|
"typescript": "~5.0.2",
|
|
38
|
-
"@itwin/build-tools": "4.2.0-dev.
|
|
38
|
+
"@itwin/build-tools": "4.2.0-dev.8"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"flatbuffers": "~1.12.0",
|
|
42
|
-
"@itwin/core-bentley": "4.2.0-dev.
|
|
42
|
+
"@itwin/core-bentley": "4.2.0-dev.8"
|
|
43
43
|
},
|
|
44
44
|
"nyc": {
|
|
45
45
|
"extends": "./node_modules/@itwin/build-tools/.nycrc",
|