@itwin/core-geometry 5.1.0-dev.20 → 5.1.0-dev.25
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/bspline/BSplineCurve.d.ts.map +1 -1
- package/lib/cjs/bspline/BSplineCurve.js +7 -1
- package/lib/cjs/bspline/BSplineCurve.js.map +1 -1
- package/lib/cjs/clipping/ClipUtils.d.ts.map +1 -1
- package/lib/cjs/clipping/ClipUtils.js +5 -3
- package/lib/cjs/clipping/ClipUtils.js.map +1 -1
- package/lib/cjs/curve/Arc3d.d.ts +1 -1
- package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
- package/lib/cjs/curve/Arc3d.js +1 -1
- package/lib/cjs/curve/Arc3d.js.map +1 -1
- package/lib/cjs/curve/CurveCollection.d.ts +31 -1
- package/lib/cjs/curve/CurveCollection.d.ts.map +1 -1
- package/lib/cjs/curve/CurveCollection.js +65 -0
- package/lib/cjs/curve/CurveCollection.js.map +1 -1
- package/lib/cjs/curve/CurveLocationDetail.d.ts +24 -24
- package/lib/cjs/curve/CurveLocationDetail.d.ts.map +1 -1
- package/lib/cjs/curve/CurveLocationDetail.js +24 -24
- package/lib/cjs/curve/CurveLocationDetail.js.map +1 -1
- package/lib/cjs/curve/CurvePrimitive.d.ts +2 -2
- package/lib/cjs/curve/CurvePrimitive.js.map +1 -1
- package/lib/cjs/curve/Query/PlanarSubdivision.d.ts +9 -5
- package/lib/cjs/curve/Query/PlanarSubdivision.d.ts.map +1 -1
- package/lib/cjs/curve/Query/PlanarSubdivision.js +20 -9
- package/lib/cjs/curve/Query/PlanarSubdivision.js.map +1 -1
- package/lib/cjs/curve/RegionMomentsXY.d.ts.map +1 -1
- package/lib/cjs/curve/RegionMomentsXY.js +14 -14
- package/lib/cjs/curve/RegionMomentsXY.js.map +1 -1
- package/lib/cjs/curve/RegionOps.d.ts +12 -0
- package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
- package/lib/cjs/curve/RegionOps.js +23 -3
- package/lib/cjs/curve/RegionOps.js.map +1 -1
- package/lib/cjs/curve/RegionOpsClassificationSweeps.d.ts +14 -13
- package/lib/cjs/curve/RegionOpsClassificationSweeps.d.ts.map +1 -1
- package/lib/cjs/curve/RegionOpsClassificationSweeps.js +46 -29
- package/lib/cjs/curve/RegionOpsClassificationSweeps.js.map +1 -1
- package/lib/cjs/curve/internalContexts/AnnounceTangentStrokeHandler.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +41 -17
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/cjs/geometry3d/AngleSweep.d.ts +10 -6
- package/lib/cjs/geometry3d/AngleSweep.d.ts.map +1 -1
- package/lib/cjs/geometry3d/AngleSweep.js +17 -6
- package/lib/cjs/geometry3d/AngleSweep.js.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/cjs/geometry4d/Point4d.d.ts +3 -2
- package/lib/cjs/geometry4d/Point4d.d.ts.map +1 -1
- package/lib/cjs/geometry4d/Point4d.js +9 -2
- package/lib/cjs/geometry4d/Point4d.js.map +1 -1
- package/lib/cjs/numerics/BezierPolynomials.d.ts +2 -0
- package/lib/cjs/numerics/BezierPolynomials.d.ts.map +1 -1
- package/lib/cjs/numerics/BezierPolynomials.js +11 -0
- package/lib/cjs/numerics/BezierPolynomials.js.map +1 -1
- package/lib/cjs/numerics/SmallSystem.d.ts.map +1 -1
- package/lib/cjs/numerics/SmallSystem.js +3 -3
- package/lib/cjs/numerics/SmallSystem.js.map +1 -1
- package/lib/cjs/polyface/IndexedPolyfaceVisitor.js +1 -1
- package/lib/cjs/polyface/IndexedPolyfaceVisitor.js.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphSearch.d.ts +1 -0
- package/lib/cjs/topology/HalfEdgeGraphSearch.d.ts.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphSearch.js +1 -0
- package/lib/cjs/topology/HalfEdgeGraphSearch.js.map +1 -1
- package/lib/esm/bspline/BSplineCurve.d.ts.map +1 -1
- package/lib/esm/bspline/BSplineCurve.js +7 -1
- package/lib/esm/bspline/BSplineCurve.js.map +1 -1
- package/lib/esm/clipping/ClipUtils.d.ts.map +1 -1
- package/lib/esm/clipping/ClipUtils.js +5 -3
- package/lib/esm/clipping/ClipUtils.js.map +1 -1
- package/lib/esm/curve/Arc3d.d.ts +1 -1
- package/lib/esm/curve/Arc3d.d.ts.map +1 -1
- package/lib/esm/curve/Arc3d.js +1 -1
- package/lib/esm/curve/Arc3d.js.map +1 -1
- package/lib/esm/curve/CurveCollection.d.ts +31 -1
- package/lib/esm/curve/CurveCollection.d.ts.map +1 -1
- package/lib/esm/curve/CurveCollection.js +65 -0
- package/lib/esm/curve/CurveCollection.js.map +1 -1
- package/lib/esm/curve/CurveLocationDetail.d.ts +24 -24
- package/lib/esm/curve/CurveLocationDetail.d.ts.map +1 -1
- package/lib/esm/curve/CurveLocationDetail.js +24 -24
- package/lib/esm/curve/CurveLocationDetail.js.map +1 -1
- package/lib/esm/curve/CurvePrimitive.d.ts +2 -2
- package/lib/esm/curve/CurvePrimitive.js.map +1 -1
- package/lib/esm/curve/Query/PlanarSubdivision.d.ts +9 -5
- package/lib/esm/curve/Query/PlanarSubdivision.d.ts.map +1 -1
- package/lib/esm/curve/Query/PlanarSubdivision.js +20 -9
- package/lib/esm/curve/Query/PlanarSubdivision.js.map +1 -1
- package/lib/esm/curve/RegionMomentsXY.d.ts.map +1 -1
- package/lib/esm/curve/RegionMomentsXY.js +14 -14
- package/lib/esm/curve/RegionMomentsXY.js.map +1 -1
- package/lib/esm/curve/RegionOps.d.ts +12 -0
- package/lib/esm/curve/RegionOps.d.ts.map +1 -1
- package/lib/esm/curve/RegionOps.js +23 -3
- package/lib/esm/curve/RegionOps.js.map +1 -1
- package/lib/esm/curve/RegionOpsClassificationSweeps.d.ts +14 -13
- package/lib/esm/curve/RegionOpsClassificationSweeps.d.ts.map +1 -1
- package/lib/esm/curve/RegionOpsClassificationSweeps.js +46 -29
- package/lib/esm/curve/RegionOpsClassificationSweeps.js.map +1 -1
- package/lib/esm/curve/internalContexts/AnnounceTangentStrokeHandler.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +41 -17
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/esm/geometry3d/AngleSweep.d.ts +10 -6
- package/lib/esm/geometry3d/AngleSweep.d.ts.map +1 -1
- package/lib/esm/geometry3d/AngleSweep.js +17 -6
- package/lib/esm/geometry3d/AngleSweep.js.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.d.ts +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/esm/geometry4d/Point4d.d.ts +3 -2
- package/lib/esm/geometry4d/Point4d.d.ts.map +1 -1
- package/lib/esm/geometry4d/Point4d.js +9 -2
- package/lib/esm/geometry4d/Point4d.js.map +1 -1
- package/lib/esm/numerics/BezierPolynomials.d.ts +2 -0
- package/lib/esm/numerics/BezierPolynomials.d.ts.map +1 -1
- package/lib/esm/numerics/BezierPolynomials.js +11 -0
- package/lib/esm/numerics/BezierPolynomials.js.map +1 -1
- package/lib/esm/numerics/SmallSystem.d.ts.map +1 -1
- package/lib/esm/numerics/SmallSystem.js +3 -3
- package/lib/esm/numerics/SmallSystem.js.map +1 -1
- package/lib/esm/polyface/IndexedPolyfaceVisitor.js +1 -1
- package/lib/esm/polyface/IndexedPolyfaceVisitor.js.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphSearch.d.ts +1 -0
- package/lib/esm/topology/HalfEdgeGraphSearch.d.ts.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphSearch.js +1 -0
- package/lib/esm/topology/HalfEdgeGraphSearch.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmallSystem.js","sourceRoot":"","sources":["../../../src/numerics/SmallSystem.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAW,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAW,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAGlE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,mBAAmB;AAEnB;;;GAGG;AACH,MAAM,OAAO,WAAW;IACtB;;;;;;;;OAQG;IACI,MAAM,CAAC,8CAA8C,CAAC,EAAW,EAAE,EAAW,EAAE,EAAW,EAAE,EAAW,EAC7G,MAAgB;QAChB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAEvB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAEvB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAEvB,MAAM,EAAE,GAAG,QAAQ,CAAC,gBAAgB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACrD,MAAM,EAAE,GAAG,QAAQ,CAAC,gBAAg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ACrC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAC7B,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAC9C,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU;QAE9C,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9E,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 Numerics\r\n */\r\n\r\nimport { Geometry } from \"../Geometry\";\r\nimport { Point2d, Vector2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { XAndY } from \"../geometry3d/XYZProps\";\r\nimport { Point4d } from \"../geometry4d/Point4d\";\r\nimport { BilinearPolynomial } from \"./Polynomials\";\r\n\r\n// cspell:word XYUV\r\n\r\n/**\r\n * static methods for commonly appearing sets of equations in 2 or 3 variables\r\n * @public\r\n */\r\nexport class SmallSystem {\r\n /**\r\n * Return true if lines (a0,a1) to (b0, b1) have a simple intersection.\r\n * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param a0 start point of line a\r\n * @param a1 end point of line a\r\n * @param b0 start point of line b\r\n * @param b1 end point of line b\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegment2dXYTransverseIntersectionUnbounded(a0: Point2d, a1: Point2d, b0: Point2d, b1: Point2d,\r\n result: Vector2d): boolean {\r\n const ux = a1.x - a0.x;\r\n const uy = a1.y - a0.y;\r\n\r\n const vx = b1.x - b0.x;\r\n const vy = b1.y - b0.y;\r\n\r\n const cx = b0.x - a0.x;\r\n const cy = b0.y - a0.y;\r\n\r\n const uv = Geometry.crossProductXYXY(ux, uy, vx, vy);\r\n const cv = Geometry.crossProductXYXY(cx, cy, vx, vy);\r\n const cu = Geometry.crossProductXYXY(ux, uy, cx, cy);\r\n const s = Geometry.conditionalDivideFraction(cv, uv);\r\n const t = Geometry.conditionalDivideFraction(cu, uv);\r\n if (s !== undefined && t !== undefined) {\r\n result.set(s, -t);\r\n return true;\r\n }\r\n result.set(0, 0);\r\n return false;\r\n }\r\n /**\r\n * * (ax0,ay0) to (ax0+ux,ay0+uy) are line A.\r\n * * (bx0,by0) to (bx0+vx,by0+vy) are lineB.\r\n * * Return true if the lines have a simple intersection.\r\n * * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegmentXYUVTransverseIntersectionUnbounded(\r\n ax0: number, ay0: number, ux: number, uy: number,\r\n bx0: number, by0: number, vx: number, vy: number,\r\n result: Vector2d): boolean {\r\n\r\n const cx = bx0 - ax0;\r\n const cy = by0 - ay0;\r\n\r\n const uv = Geometry.crossProductXYXY(ux, uy, vx, vy);\r\n const cv = Geometry.crossProductXYXY(cx, cy, vx, vy);\r\n const cu = Geometry.crossProductXYXY(ux, uy, cx, cy);\r\n const s = Geometry.conditionalDivideFraction(cv, uv);\r\n const t = Geometry.conditionalDivideFraction(cu, uv);\r\n if (s !== undefined && t !== undefined) {\r\n result.set(s, -t);\r\n return true;\r\n }\r\n result.set(0, 0);\r\n return false;\r\n }\r\n\r\n /**\r\n * Return true if lines (a0,a1) to (b0, b1) have a simple intersection using only xy parts\r\n * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param a0 start point of line a\r\n * @param a1 end point of line a\r\n * @param b0 start point of line b\r\n * @param b1 end point of line b\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegment3dXYTransverseIntersectionUnbounded(a0: Point3d, a1: Point3d, b0: Point3d, b1: Point3d,\r\n result: Vector2d): boolean {\r\n const ux = a1.x - a0.x;\r\n const uy = a1.y - a0.y;\r\n\r\n const vx = b1.x - b0.x;\r\n const vy = b1.y - b0.y;\r\n\r\n const cx = b0.x - a0.x;\r\n const cy = b0.y - a0.y;\r\n\r\n const uv = Geometry.crossProductXYXY(ux, uy, vx, vy);\r\n const cv = Geometry.crossProductXYXY(cx, cy, vx, vy);\r\n const cu = Geometry.crossProductXYXY(ux, uy, cx, cy);\r\n const s = Geometry.conditionalDivideFraction(cv, uv);\r\n const t = Geometry.conditionalDivideFraction(cu, uv);\r\n if (s !== undefined && t !== undefined) {\r\n result.set(s, -t);\r\n return true;\r\n }\r\n result.set(0, 0);\r\n return false;\r\n }\r\n\r\n /**\r\n * Return true if lines (a0,a1) to (b0, b1) have a simple intersection using only xy parts of WEIGHTED 4D Points\r\n * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param hA0 homogeneous start point of line a\r\n * @param hA1 homogeneous end point of line a\r\n * @param hB0 homogeneous start point of line b\r\n * @param hB1 homogeneous end point of line b\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegment3dHXYTransverseIntersectionUnbounded(hA0: Point4d, hA1: Point4d, hB0: Point4d, hB1: Point4d, result?: Vector2d): Vector2d | undefined {\r\n // Considering only x,y,w parts....\r\n // Point Q along B is (in full homogeneous) `(1-lambda) B0 + lambda 1`\r\n // PointQ is colinear with A0,A1 when the determinant det (A0,A1,Q) is zero. (Each column takes xyw parts)\r\n const alpha0 = Geometry.tripleProduct(\r\n hA0.x, hA1.x, hB0.x,\r\n hA0.y, hA1.y, hB0.y,\r\n hA0.w, hA1.w, hB0.w);\r\n const alpha1 = Geometry.tripleProduct(\r\n hA0.x, hA1.x, hB1.x,\r\n hA0.y, hA1.y, hB1.y,\r\n hA0.w, hA1.w, hB1.w);\r\n const fractionB = Geometry.conditionalDivideFraction(-alpha0, alpha1 - alpha0);\r\n if (fractionB !== undefined) {\r\n const beta0 = Geometry.tripleProduct(\r\n hB0.x, hB1.x, hA0.x,\r\n hB0.y, hB1.y, hA0.y,\r\n hB0.w, hB1.w, hA0.w);\r\n const beta1 = Geometry.tripleProduct(\r\n hB0.x, hB1.x, hA1.x,\r\n hB0.y, hB1.y, hA1.y,\r\n hB0.w, hB1.w, hA1.w);\r\n const fractionA = Geometry.conditionalDivideFraction(-beta0, beta1 - beta0);\r\n if (fractionA !== undefined)\r\n return Vector2d.create(fractionA, fractionB, result);\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Return the line fraction at which the (homogeneous) line is closest to a space point as viewed in xy only.\r\n * @param hA0 homogeneous start point of line a\r\n * @param hA1 homogeneous end point of line a\r\n * @param spacePoint homogeneous point in space\r\n */\r\n public static lineSegment3dHXYClosestPointUnbounded(hA0: Point4d, hA1: Point4d, spacePoint: Point4d): number | undefined {\r\n // Considering only x,y,w parts....\r\n // weighted difference of (A1 w0 - A0 w1) is (cartesian) tangent vector along the line as viewed.\r\n // The perpendicular (pure vector) W = (-y,x) flip is the direction of projection\r\n // Point Q along A is (in full homogeneous) `(1-lambda) A0 + lambda 1 A1`\r\n // PointQ is colinear with spacePoint and and W when the xyw homogeneous determinant | Q W spacePoint | is zero.\r\n const tx = hA1.x * hA0.w - hA0.x * hA1.w;\r\n const ty = hA1.y * hA0.w - hA0.y * hA1.w;\r\n const det0 = Geometry.tripleProduct(\r\n hA0.x, -ty, spacePoint.x,\r\n hA0.y, tx, spacePoint.y,\r\n hA0.w, 0, spacePoint.w);\r\n const det1 = Geometry.tripleProduct(\r\n hA1.x, -ty, spacePoint.x,\r\n hA1.y, tx, spacePoint.y,\r\n hA1.w, 0, spacePoint.w);\r\n return Geometry.conditionalDivideFraction(-det0, det1 - det0);\r\n }\r\n\r\n /**\r\n * Return the line fraction at which the line is closest to a space point as viewed in xy only.\r\n * @param pointA0 start point\r\n * @param pointA1 end point\r\n * @param spacePoint point in space\r\n */\r\n public static lineSegment3dXYClosestPointUnbounded(pointA0: XAndY, pointA1: XAndY, spacePoint: XAndY): number | undefined {\r\n // Considering only x,y parts....\r\n const ux = pointA1.x - pointA0.x;\r\n const uy = pointA1.y - pointA0.y;\r\n const uu = ux * ux + uy * uy;\r\n const vx = spacePoint.x - pointA0.x;\r\n const vy = spacePoint.y - pointA0.y;\r\n const uv = ux * vx + uy * vy;\r\n return Geometry.conditionalDivideFraction(uv, uu);\r\n }\r\n\r\n /**\r\n * Return the line fraction at which the line is closest to a space point\r\n * @param pointA0 start point\r\n * @param pointA1 end point\r\n * @param spacePoint point in space\r\n */\r\n public static lineSegment3dClosestPointUnbounded(pointA0: Point3d, pointA1: Point3d, spacePoint: Point3d): number | undefined {\r\n const ux = pointA1.x - pointA0.x;\r\n const uy = pointA1.y - pointA0.y;\r\n const uz = pointA1.z - pointA0.z;\r\n const uu = ux * ux + uy * uy + uz * uz;\r\n const vx = spacePoint.x - pointA0.x;\r\n const vy = spacePoint.y - pointA0.y;\r\n const vz = spacePoint.z - pointA0.z;\r\n const uv = ux * vx + uy * vy + uz * vz;\r\n return Geometry.conditionalDivideFraction(uv, uu);\r\n }\r\n\r\n /**\r\n * Return true if lines (a0,a1) to (b0, b1) have closest approach (go by each other) in 3d\r\n * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param a0 start point of line a\r\n * @param a1 end point of line a\r\n * @param b0 start point of line b\r\n * @param b1 end point of line b\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegment3dClosestApproachUnbounded(a0: Point3d, a1: Point3d, b0: Point3d, b1: Point3d,\r\n result: Vector2d): boolean {\r\n return this.ray3dXYZUVWClosestApproachUnbounded(\r\n a0.x, a0.y, a0.z,\r\n a1.x - a0.x, a1.y - a0.y, a1.z - a0.z,\r\n b0.x, b0.y, b0.z,\r\n b1.x - b0.x, b1.y - b0.y, b1.z - b0.z,\r\n result);\r\n }\r\n /**\r\n * Return true if the given rays have closest approach (go by each other) in 3d\r\n * Return the fractional (not xy) coordinates as x and y parts of a Point2d.\r\n * @param ax x-coordinate of the origin of the first ray\r\n * @param ay y-coordinate of the origin of the first ray\r\n * @param az z-coordinate of the origin of the first ray\r\n * @param au x-coordinate of the direction vector of the first ray\r\n * @param av y-coordinate of the direction vector of the first ray\r\n * @param aw z-coordinate of the direction vector of the first ray\r\n * @param bx x-coordinate of the origin of the second ray\r\n * @param by y-coordinate of the origin of the second ray\r\n * @param bz z-coordinate of the origin of the second ray\r\n * @param bu x-coordinate of the direction vector of the second ray\r\n * @param bv y-coordinate of the direction vector of the second ray\r\n * @param bw z-coordinate of the direction vector of the second ray\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static ray3dXYZUVWClosestApproachUnbounded(\r\n ax: number, ay: number, az: number, au: number, av: number, aw: number,\r\n bx: number, by: number, bz: number, bu: number, bv: number, bw: number,\r\n result: Vector2d): boolean {\r\n\r\n const cx = bx - ax;\r\n const cy = by - ay;\r\n const cz = bz - az;\r\n\r\n const uu = Geometry.hypotenuseSquaredXYZ(au, av, aw);\r\n const vv = Geometry.hypotenuseSquaredXYZ(bu, bv, bw);\r\n const uv = Geometry.dotProductXYZXYZ(au, av, aw, bu, bv, bw);\r\n const cu = Geometry.dotProductXYZXYZ(cx, cy, cz, au, av, aw);\r\n const cv = Geometry.dotProductXYZXYZ(cx, cy, cz, bu, bv, bw);\r\n return SmallSystem.linearSystem2d(uu, -uv, uv, -vv, cu, cv, result);\r\n }\r\n /**\r\n * Solve the pair of linear equations\r\n * * `ux * x + vx * y = cx`\r\n * * `uy * x + vy * y = cy`\r\n * @param ux xx coefficient\r\n * @param vx xy coefficient\r\n * @param uy yx coefficient\r\n * @param vy yy coefficient\r\n * @param cx x right hand side\r\n * @param cy y right hand side\r\n * @param result (x,y) solution (MUST be preallocated by caller)\r\n */\r\n public static linearSystem2d(\r\n ux: number, vx: number, // first row of matrix\r\n uy: number, vy: number, // second row of matrix\r\n cx: number, cy: number, // right side\r\n result: Vector2d,\r\n ): boolean {\r\n const uv = Geometry.crossProductXYXY(ux, uy, vx, vy);\r\n const cv = Geometry.crossProductXYXY(cx, cy, vx, vy);\r\n const cu = Geometry.crossProductXYXY(ux, uy, cx, cy);\r\n const s = Geometry.conditionalDivideFraction(cv, uv);\r\n const t = Geometry.conditionalDivideFraction(cu, uv);\r\n if (s !== undefined && t !== undefined) {\r\n result.set(s, t);\r\n return true;\r\n }\r\n result.set(0, 0);\r\n return false;\r\n }\r\n /**\r\n * Solve a linear system:\r\n * * x equation: `axx * u + axy * v + axz * w = cx`\r\n * * y equation: `ayx * u + ayy * v + ayz * w = cy`\r\n * * z equation: `azx * u + azy * v + azz * w = cz`\r\n * @param axx row 0, column 0 coefficient\r\n * @param axy row 0, column 1 coefficient\r\n * @param axz row 0, column 1 coefficient\r\n * @param ayx row 1, column 0 coefficient\r\n * @param ayy row 1, column 1 coefficient\r\n * @param ayz row 1, column 2 coefficient\r\n * @param azx row 2, column 0 coefficient\r\n * @param azy row 2, column 1 coefficient\r\n * @param azz row 2, column 2 coefficient\r\n * @param cx right hand side row 0 coefficient\r\n * @param cy right hand side row 1 coefficient\r\n * @param cz right hand side row 2 coefficient\r\n * @param result optional result.\r\n * @returns solution vector (u,v,w) or `undefined` if system is singular.\r\n */\r\n public static linearSystem3d(\r\n axx: number, axy: number, axz: number, // first row of matrix\r\n ayx: number, ayy: number, ayz: number, // second row of matrix\r\n azx: number, azy: number, azz: number, // second row of matrix\r\n cx: number, cy: number, cz: number, // right side\r\n result?: Vector3d,\r\n ): Vector3d | undefined {\r\n // determinants of various combinations of columns ...\r\n const detXYZ = Geometry.tripleProduct(axx, ayx, azx, axy, ayy, azy, axz, ayz, azz);\r\n const detCYZ = Geometry.tripleProduct(cx, cy, cz, axy, ayy, azy, axz, ayz, azz);\r\n const detXCZ = Geometry.tripleProduct(axx, ayx, azx, cx, cy, cz, axz, ayz, azz);\r\n const detXYC = Geometry.tripleProduct(axx, ayx, azx, axy, ayy, azy, cx, cy, cz);\r\n const s = Geometry.conditionalDivideFraction(detCYZ, detXYZ);\r\n const t = Geometry.conditionalDivideFraction(detXCZ, detXYZ);\r\n const u = Geometry.conditionalDivideFraction(detXYC, detXYZ);\r\n if (s !== undefined && t !== undefined && u !== undefined) {\r\n return Vector3d.create(s, t, u, result);\r\n }\r\n return undefined;\r\n }\r\n /**\r\n * Compute the intersection of three planes.\r\n * @param xyzA point on the first plane\r\n * @param normalA normal of the first plane\r\n * @param xyzB point on the second plane\r\n * @param normalB normal of the second plane\r\n * @param xyzC point on the third plane\r\n * @param normalC normal of the third plane\r\n * @param result optional result\r\n * @returns intersection point of the three planes (as a Vector3d), or undefined if at least two planes are parallel.\r\n */\r\n public static intersect3Planes(\r\n xyzA: Point3d, normalA: Vector3d,\r\n xyzB: Point3d, normalB: Vector3d,\r\n xyzC: Point3d, normalC: Vector3d, result?: Vector3d): Vector3d | undefined {\r\n return this.linearSystem3d(\r\n normalA.x, normalA.y, normalA.z,\r\n normalB.x, normalB.y, normalB.z,\r\n normalC.x, normalC.y, normalC.z,\r\n Geometry.dotProductXYZXYZ(xyzA.x, xyzA.y, xyzA.z, normalA.x, normalA.y, normalA.z),\r\n Geometry.dotProductXYZXYZ(xyzB.x, xyzB.y, xyzB.z, normalB.x, normalB.y, normalB.z),\r\n Geometry.dotProductXYZXYZ(xyzC.x, xyzC.y, xyzC.z, normalC.x, normalC.y, normalC.z), result);\r\n }\r\n\r\n /**\r\n * * in rowB, replace `rowB[j] += a * rowB[pivot] * rowA[j] / rowA[pivot]` for `j>pivot`\r\n * @param rowA row that does not change\r\n * @param pivotIndex index of pivot (divisor) in rowA.\r\n * @param rowB row where elimination occurs.\r\n */\r\n public static eliminateFromPivot(rowA: Float64Array, pivotIndex: number, rowB: Float64Array, a: number): boolean {\r\n const n = rowA.length;\r\n let q = Geometry.conditionalDivideFraction(rowB[pivotIndex], rowA[pivotIndex]);\r\n if (q === undefined) return false;\r\n q *= a;\r\n for (let j = pivotIndex + 1; j < n; j++)\r\n rowB[j] += q * rowA[j];\r\n return true;\r\n }\r\n /**\r\n * Solve a pair of bilinear equations\r\n * * First equation: `a0 + b0 * u + c0 * v + d0 * u * v = 0`\r\n * * Second equation: `a1 + b1 * u + c1 * v + d1 * u * v = 0`\r\n */\r\n public static solveBilinearPair(\r\n a0: number, b0: number, c0: number, d0: number,\r\n a1: number, b1: number, c1: number, d1: number,\r\n ): Point2d[] | undefined {\r\n return BilinearPolynomial.solveBilinearPair(a0, b0, c0, d0, a1, b1, c1, d1);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"SmallSystem.js","sourceRoot":"","sources":["../../../src/numerics/SmallSystem.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAW,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAW,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAGlE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,mBAAmB;AAEnB;;;GAGG;AACH,MAAM,OAAO,WAAW;IACtB;;;;;;;;OAQG;IACI,MAAM,CAAC,8CAA8C,CAAC,EAAW,EAAE,EAAW,EAAE,EAAW,EAAE,EAAW,EAC7G,MAAgB;QAChB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAEvB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACvB,MAAM,EAAE,GAAG,E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G,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,IAAI,CAAC,GAAG,QAAQ,CAAC,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAClC,CAAC,IAAI,CAAC,CAAC;QACP,KAAK,IAAI,CAAC,GAAG,UAAU,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YACrC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAC7B,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAC9C,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU;QAE9C,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9E,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 Numerics\r\n */\r\n\r\nimport { Geometry } from \"../Geometry\";\r\nimport { Point2d, Vector2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { XAndY } from \"../geometry3d/XYZProps\";\r\nimport { Point4d } from \"../geometry4d/Point4d\";\r\nimport { BilinearPolynomial } from \"./Polynomials\";\r\n\r\n// cspell:word XYUV\r\n\r\n/**\r\n * static methods for commonly appearing sets of equations in 2 or 3 variables\r\n * @public\r\n */\r\nexport class SmallSystem {\r\n /**\r\n * Return true if lines (a0,a1) to (b0, b1) have a simple intersection.\r\n * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param a0 start point of line a\r\n * @param a1 end point of line a\r\n * @param b0 start point of line b\r\n * @param b1 end point of line b\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegment2dXYTransverseIntersectionUnbounded(a0: Point2d, a1: Point2d, b0: Point2d, b1: Point2d,\r\n result: Vector2d): boolean {\r\n const ux = a1.x - a0.x;\r\n const uy = a1.y - a0.y;\r\n\r\n const vx = b1.x - b0.x;\r\n const vy = b1.y - b0.y;\r\n\r\n const cx = b0.x - a0.x;\r\n const cy = b0.y - a0.y;\r\n\r\n const uv = Geometry.crossProductXYXY(ux, uy, vx, vy);\r\n const cv = Geometry.crossProductXYXY(cx, cy, vx, vy);\r\n const cu = Geometry.crossProductXYXY(ux, uy, cx, cy);\r\n const s = Geometry.conditionalDivideFraction(cv, uv);\r\n const t = Geometry.conditionalDivideFraction(cu, uv);\r\n if (s !== undefined && t !== undefined) {\r\n result.set(s, -t);\r\n return true;\r\n }\r\n result.set(0, 0);\r\n return false;\r\n }\r\n /**\r\n * * (ax0,ay0) to (ax0+ux,ay0+uy) are line A.\r\n * * (bx0,by0) to (bx0+vx,by0+vy) are lineB.\r\n * * Return true if the lines have a simple intersection.\r\n * * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegmentXYUVTransverseIntersectionUnbounded(\r\n ax0: number, ay0: number, ux: number, uy: number,\r\n bx0: number, by0: number, vx: number, vy: number,\r\n result: Vector2d): boolean {\r\n\r\n const cx = bx0 - ax0;\r\n const cy = by0 - ay0;\r\n\r\n const uv = Geometry.crossProductXYXY(ux, uy, vx, vy);\r\n const cv = Geometry.crossProductXYXY(cx, cy, vx, vy);\r\n const cu = Geometry.crossProductXYXY(ux, uy, cx, cy);\r\n const s = Geometry.conditionalDivideFraction(cv, uv);\r\n const t = Geometry.conditionalDivideFraction(cu, uv);\r\n if (s !== undefined && t !== undefined) {\r\n result.set(s, -t);\r\n return true;\r\n }\r\n result.set(0, 0);\r\n return false;\r\n }\r\n\r\n /**\r\n * Return true if lines (a0,a1) to (b0, b1) have a simple intersection using only xy parts\r\n * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param a0 start point of line a\r\n * @param a1 end point of line a\r\n * @param b0 start point of line b\r\n * @param b1 end point of line b\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegment3dXYTransverseIntersectionUnbounded(a0: Point3d, a1: Point3d, b0: Point3d, b1: Point3d,\r\n result: Vector2d): boolean {\r\n const ux = a1.x - a0.x;\r\n const uy = a1.y - a0.y;\r\n\r\n const vx = b1.x - b0.x;\r\n const vy = b1.y - b0.y;\r\n\r\n const cx = b0.x - a0.x;\r\n const cy = b0.y - a0.y;\r\n\r\n const uv = Geometry.crossProductXYXY(ux, uy, vx, vy);\r\n const cv = Geometry.crossProductXYXY(cx, cy, vx, vy);\r\n const cu = Geometry.crossProductXYXY(ux, uy, cx, cy);\r\n const s = Geometry.conditionalDivideFraction(cv, uv);\r\n const t = Geometry.conditionalDivideFraction(cu, uv);\r\n if (s !== undefined && t !== undefined) {\r\n result.set(s, -t);\r\n return true;\r\n }\r\n result.set(0, 0);\r\n return false;\r\n }\r\n\r\n /**\r\n * Return true if lines (a0,a1) to (b0, b1) have a simple intersection using only xy parts of WEIGHTED 4D Points\r\n * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param hA0 homogeneous start point of line a\r\n * @param hA1 homogeneous end point of line a\r\n * @param hB0 homogeneous start point of line b\r\n * @param hB1 homogeneous end point of line b\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegment3dHXYTransverseIntersectionUnbounded(hA0: Point4d, hA1: Point4d, hB0: Point4d, hB1: Point4d, result?: Vector2d): Vector2d | undefined {\r\n // Considering only x,y,w parts....\r\n // Point Q along B is (in full homogeneous) `(1-lambda) B0 + lambda 1`\r\n // PointQ is colinear with A0,A1 when the determinant det (A0,A1,Q) is zero. (Each column takes xyw parts)\r\n const alpha0 = Geometry.tripleProduct(\r\n hA0.x, hA1.x, hB0.x,\r\n hA0.y, hA1.y, hB0.y,\r\n hA0.w, hA1.w, hB0.w);\r\n const alpha1 = Geometry.tripleProduct(\r\n hA0.x, hA1.x, hB1.x,\r\n hA0.y, hA1.y, hB1.y,\r\n hA0.w, hA1.w, hB1.w);\r\n const fractionB = Geometry.conditionalDivideFraction(-alpha0, alpha1 - alpha0);\r\n if (fractionB !== undefined) {\r\n const beta0 = Geometry.tripleProduct(\r\n hB0.x, hB1.x, hA0.x,\r\n hB0.y, hB1.y, hA0.y,\r\n hB0.w, hB1.w, hA0.w);\r\n const beta1 = Geometry.tripleProduct(\r\n hB0.x, hB1.x, hA1.x,\r\n hB0.y, hB1.y, hA1.y,\r\n hB0.w, hB1.w, hA1.w);\r\n const fractionA = Geometry.conditionalDivideFraction(-beta0, beta1 - beta0);\r\n if (fractionA !== undefined)\r\n return Vector2d.create(fractionA, fractionB, result);\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Return the line fraction at which the (homogeneous) line is closest to a space point as viewed in xy only.\r\n * @param hA0 homogeneous start point of line a\r\n * @param hA1 homogeneous end point of line a\r\n * @param spacePoint homogeneous point in space\r\n */\r\n public static lineSegment3dHXYClosestPointUnbounded(hA0: Point4d, hA1: Point4d, spacePoint: Point4d): number | undefined {\r\n // Considering only x,y,w parts.\r\n // weighted difference of (A1 w0 - A0 w1) is (cartesian) tangent vector along the line as viewed.\r\n // The perpendicular (pure vector) W = (-y,x) flip is the direction of projection.\r\n // Point Q along A is (in full homogeneous) `(1-lambda) A0 + lambda 1 A1`.\r\n // PointQ is colinear with spacePoint and and W when the xyw homogeneous determinant | Q W spacePoint | is zero.\r\n const tx = hA1.x * hA0.w - hA0.x * hA1.w;\r\n const ty = hA1.y * hA0.w - hA0.y * hA1.w;\r\n const det0 = Geometry.tripleProduct(\r\n hA0.x, -ty, spacePoint.x,\r\n hA0.y, tx, spacePoint.y,\r\n hA0.w, 0, spacePoint.w,\r\n );\r\n const det1 = Geometry.tripleProduct(\r\n hA1.x, -ty, spacePoint.x,\r\n hA1.y, tx, spacePoint.y,\r\n hA1.w, 0, spacePoint.w,\r\n );\r\n return Geometry.conditionalDivideFraction(-det0, det1 - det0);\r\n }\r\n\r\n /**\r\n * Return the line fraction at which the line is closest to a space point as viewed in xy only.\r\n * @param pointA0 start point\r\n * @param pointA1 end point\r\n * @param spacePoint point in space\r\n */\r\n public static lineSegment3dXYClosestPointUnbounded(pointA0: XAndY, pointA1: XAndY, spacePoint: XAndY): number | undefined {\r\n // Considering only x,y parts....\r\n const ux = pointA1.x - pointA0.x;\r\n const uy = pointA1.y - pointA0.y;\r\n const uu = ux * ux + uy * uy;\r\n const vx = spacePoint.x - pointA0.x;\r\n const vy = spacePoint.y - pointA0.y;\r\n const uv = ux * vx + uy * vy;\r\n return Geometry.conditionalDivideFraction(uv, uu);\r\n }\r\n\r\n /**\r\n * Return the line fraction at which the line is closest to a space point\r\n * @param pointA0 start point\r\n * @param pointA1 end point\r\n * @param spacePoint point in space\r\n */\r\n public static lineSegment3dClosestPointUnbounded(pointA0: Point3d, pointA1: Point3d, spacePoint: Point3d): number | undefined {\r\n const ux = pointA1.x - pointA0.x;\r\n const uy = pointA1.y - pointA0.y;\r\n const uz = pointA1.z - pointA0.z;\r\n const uu = ux * ux + uy * uy + uz * uz;\r\n const vx = spacePoint.x - pointA0.x;\r\n const vy = spacePoint.y - pointA0.y;\r\n const vz = spacePoint.z - pointA0.z;\r\n const uv = ux * vx + uy * vy + uz * vz;\r\n return Geometry.conditionalDivideFraction(uv, uu);\r\n }\r\n\r\n /**\r\n * Return true if lines (a0,a1) to (b0, b1) have closest approach (go by each other) in 3d\r\n * Return the fractional (not xy) coordinates in result.x, result.y\r\n * @param a0 start point of line a\r\n * @param a1 end point of line a\r\n * @param b0 start point of line b\r\n * @param b1 end point of line b\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static lineSegment3dClosestApproachUnbounded(a0: Point3d, a1: Point3d, b0: Point3d, b1: Point3d,\r\n result: Vector2d): boolean {\r\n return this.ray3dXYZUVWClosestApproachUnbounded(\r\n a0.x, a0.y, a0.z,\r\n a1.x - a0.x, a1.y - a0.y, a1.z - a0.z,\r\n b0.x, b0.y, b0.z,\r\n b1.x - b0.x, b1.y - b0.y, b1.z - b0.z,\r\n result);\r\n }\r\n /**\r\n * Return true if the given rays have closest approach (go by each other) in 3d\r\n * Return the fractional (not xy) coordinates as x and y parts of a Point2d.\r\n * @param ax x-coordinate of the origin of the first ray\r\n * @param ay y-coordinate of the origin of the first ray\r\n * @param az z-coordinate of the origin of the first ray\r\n * @param au x-coordinate of the direction vector of the first ray\r\n * @param av y-coordinate of the direction vector of the first ray\r\n * @param aw z-coordinate of the direction vector of the first ray\r\n * @param bx x-coordinate of the origin of the second ray\r\n * @param by y-coordinate of the origin of the second ray\r\n * @param bz z-coordinate of the origin of the second ray\r\n * @param bu x-coordinate of the direction vector of the second ray\r\n * @param bv y-coordinate of the direction vector of the second ray\r\n * @param bw z-coordinate of the direction vector of the second ray\r\n * @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.\r\n */\r\n public static ray3dXYZUVWClosestApproachUnbounded(\r\n ax: number, ay: number, az: number, au: number, av: number, aw: number,\r\n bx: number, by: number, bz: number, bu: number, bv: number, bw: number,\r\n result: Vector2d): boolean {\r\n\r\n const cx = bx - ax;\r\n const cy = by - ay;\r\n const cz = bz - az;\r\n\r\n const uu = Geometry.hypotenuseSquaredXYZ(au, av, aw);\r\n const vv = Geometry.hypotenuseSquaredXYZ(bu, bv, bw);\r\n const uv = Geometry.dotProductXYZXYZ(au, av, aw, bu, bv, bw);\r\n const cu = Geometry.dotProductXYZXYZ(cx, cy, cz, au, av, aw);\r\n const cv = Geometry.dotProductXYZXYZ(cx, cy, cz, bu, bv, bw);\r\n return SmallSystem.linearSystem2d(uu, -uv, uv, -vv, cu, cv, result);\r\n }\r\n /**\r\n * Solve the pair of linear equations\r\n * * `ux * x + vx * y = cx`\r\n * * `uy * x + vy * y = cy`\r\n * @param ux xx coefficient\r\n * @param vx xy coefficient\r\n * @param uy yx coefficient\r\n * @param vy yy coefficient\r\n * @param cx x right hand side\r\n * @param cy y right hand side\r\n * @param result (x,y) solution (MUST be preallocated by caller)\r\n */\r\n public static linearSystem2d(\r\n ux: number, vx: number, // first row of matrix\r\n uy: number, vy: number, // second row of matrix\r\n cx: number, cy: number, // right side\r\n result: Vector2d,\r\n ): boolean {\r\n const uv = Geometry.crossProductXYXY(ux, uy, vx, vy);\r\n const cv = Geometry.crossProductXYXY(cx, cy, vx, vy);\r\n const cu = Geometry.crossProductXYXY(ux, uy, cx, cy);\r\n const s = Geometry.conditionalDivideFraction(cv, uv);\r\n const t = Geometry.conditionalDivideFraction(cu, uv);\r\n if (s !== undefined && t !== undefined) {\r\n result.set(s, t);\r\n return true;\r\n }\r\n result.set(0, 0);\r\n return false;\r\n }\r\n /**\r\n * Solve a linear system:\r\n * * x equation: `axx * u + axy * v + axz * w = cx`\r\n * * y equation: `ayx * u + ayy * v + ayz * w = cy`\r\n * * z equation: `azx * u + azy * v + azz * w = cz`\r\n * @param axx row 0, column 0 coefficient\r\n * @param axy row 0, column 1 coefficient\r\n * @param axz row 0, column 1 coefficient\r\n * @param ayx row 1, column 0 coefficient\r\n * @param ayy row 1, column 1 coefficient\r\n * @param ayz row 1, column 2 coefficient\r\n * @param azx row 2, column 0 coefficient\r\n * @param azy row 2, column 1 coefficient\r\n * @param azz row 2, column 2 coefficient\r\n * @param cx right hand side row 0 coefficient\r\n * @param cy right hand side row 1 coefficient\r\n * @param cz right hand side row 2 coefficient\r\n * @param result optional result.\r\n * @returns solution vector (u,v,w) or `undefined` if system is singular.\r\n */\r\n public static linearSystem3d(\r\n axx: number, axy: number, axz: number, // first row of matrix\r\n ayx: number, ayy: number, ayz: number, // second row of matrix\r\n azx: number, azy: number, azz: number, // second row of matrix\r\n cx: number, cy: number, cz: number, // right side\r\n result?: Vector3d,\r\n ): Vector3d | undefined {\r\n // determinants of various combinations of columns ...\r\n const detXYZ = Geometry.tripleProduct(axx, ayx, azx, axy, ayy, azy, axz, ayz, azz);\r\n const detCYZ = Geometry.tripleProduct(cx, cy, cz, axy, ayy, azy, axz, ayz, azz);\r\n const detXCZ = Geometry.tripleProduct(axx, ayx, azx, cx, cy, cz, axz, ayz, azz);\r\n const detXYC = Geometry.tripleProduct(axx, ayx, azx, axy, ayy, azy, cx, cy, cz);\r\n const s = Geometry.conditionalDivideFraction(detCYZ, detXYZ);\r\n const t = Geometry.conditionalDivideFraction(detXCZ, detXYZ);\r\n const u = Geometry.conditionalDivideFraction(detXYC, detXYZ);\r\n if (s !== undefined && t !== undefined && u !== undefined) {\r\n return Vector3d.create(s, t, u, result);\r\n }\r\n return undefined;\r\n }\r\n /**\r\n * Compute the intersection of three planes.\r\n * @param xyzA point on the first plane\r\n * @param normalA normal of the first plane\r\n * @param xyzB point on the second plane\r\n * @param normalB normal of the second plane\r\n * @param xyzC point on the third plane\r\n * @param normalC normal of the third plane\r\n * @param result optional result\r\n * @returns intersection point of the three planes (as a Vector3d), or undefined if at least two planes are parallel.\r\n */\r\n public static intersect3Planes(\r\n xyzA: Point3d, normalA: Vector3d,\r\n xyzB: Point3d, normalB: Vector3d,\r\n xyzC: Point3d, normalC: Vector3d, result?: Vector3d): Vector3d | undefined {\r\n return this.linearSystem3d(\r\n normalA.x, normalA.y, normalA.z,\r\n normalB.x, normalB.y, normalB.z,\r\n normalC.x, normalC.y, normalC.z,\r\n Geometry.dotProductXYZXYZ(xyzA.x, xyzA.y, xyzA.z, normalA.x, normalA.y, normalA.z),\r\n Geometry.dotProductXYZXYZ(xyzB.x, xyzB.y, xyzB.z, normalB.x, normalB.y, normalB.z),\r\n Geometry.dotProductXYZXYZ(xyzC.x, xyzC.y, xyzC.z, normalC.x, normalC.y, normalC.z), result);\r\n }\r\n\r\n /**\r\n * * in rowB, replace `rowB[j] += a * rowB[pivot] * rowA[j] / rowA[pivot]` for `j>pivot`\r\n * @param rowA row that does not change\r\n * @param pivotIndex index of pivot (divisor) in rowA.\r\n * @param rowB row where elimination occurs.\r\n */\r\n public static eliminateFromPivot(rowA: Float64Array, pivotIndex: number, rowB: Float64Array, a: number): boolean {\r\n const n = rowA.length;\r\n let q = Geometry.conditionalDivideFraction(rowB[pivotIndex], rowA[pivotIndex]);\r\n if (q === undefined) return false;\r\n q *= a;\r\n for (let j = pivotIndex + 1; j < n; j++)\r\n rowB[j] += q * rowA[j];\r\n return true;\r\n }\r\n /**\r\n * Solve a pair of bilinear equations\r\n * * First equation: `a0 + b0 * u + c0 * v + d0 * u * v = 0`\r\n * * Second equation: `a1 + b1 * u + c1 * v + d1 * u * v = 0`\r\n */\r\n public static solveBilinearPair(\r\n a0: number, b0: number, c0: number, d0: number,\r\n a1: number, b1: number, c1: number, d1: number,\r\n ): Point2d[] | undefined {\r\n return BilinearPolynomial.solveBilinearPair(a0, b0, c0, d0, a1, b1, c1, d1);\r\n }\r\n}\r\n"]}
|
|
@@ -200,7 +200,7 @@ export class IndexedPolyfaceVisitor extends PolyfaceData {
|
|
|
200
200
|
*/
|
|
201
201
|
export class IndexedPolyfaceSubsetVisitor extends IndexedPolyfaceVisitor {
|
|
202
202
|
_facetIndices;
|
|
203
|
-
_currentSubsetIndex; // index within _facetIndices
|
|
203
|
+
_currentSubsetIndex; // index within _facetIndices
|
|
204
204
|
_nextSubsetIndex; // index within _facetIndices
|
|
205
205
|
constructor(polyface, facetIndices, numWrap) {
|
|
206
206
|
super(polyface, numWrap);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I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AsB;QACpC,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IACnC,CAAC;IACD;;;;;;;;;;;;MAYE;IACK,MAAM,CAAC,sBAAsB,CAClC,IAA8C,EAC9C,gBAA0B,QAAQ,CAAC,KAAK,EAAE,EAC1C,YAAmB,KAAK,CAAC,gBAAgB,EAAE,EAC3C,UAAkB,CAAC;QAEnB,IAAI,IAAI,YAAY,eAAe;YACjC,OAAO,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9F,MAAM,OAAO,GAAG,IAAI,CAAC;QACrB,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC1C,KAAK,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC;YACjD,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC;gBACpD,SAAS,CAAC,mBAAmB;YAC/B,IAAI,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,GAAG;gBAC7C,SAAS,CAAC,uCAAuC;YACnD,IAAI,WAAW,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,0BAA0B,CAAC,SAAS,CAAC;gBACzF,SAAS,CAAC,oBAAoB;YAChC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,4BAA4B,CAAC,mBAAmB,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACrG,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 Polyface\r\n */\r\n\r\nimport { Geometry } from \"../Geometry\";\r\nimport { Angle } from \"../geometry3d/Angle\";\r\nimport { Point2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { PolygonOps } from \"../geometry3d/PolygonOps\";\r\nimport { IndexedPolyface, PolyfaceVisitor } from \"./Polyface\";\r\nimport { PolyfaceData } from \"./PolyfaceData\";\r\n\r\n/**\r\n * An `IndexedPolyfaceVisitor` is an iterator-like object that \"visits\" facets of a mesh.\r\n * * The visitor extends `PolyfaceData`, so it can at any time hold all the data of a single facet.\r\n * @public\r\n */\r\nexport class IndexedPolyfaceVisitor extends PolyfaceData implements PolyfaceVisitor {\r\n private _currentFacetIndex: number;\r\n private _nextFacetIndex: number;\r\n private _numWrap: number;\r\n private _numEdges: number;\r\n private _polyface: IndexedPolyface;\r\n // to be called from static factory method that validates the polyface\r\n protected constructor(polyface: IndexedPolyface, numWrap: number) {\r\n super(polyface.data.normalCount > 0, polyface.data.paramCount > 0, polyface.data.colorCount > 0, polyface.twoSided);\r\n this._polyface = polyface;\r\n this._numWrap = numWrap;\r\n if (polyface.data.auxData)\r\n this.auxData = polyface.data.auxData.createForVisitor();\r\n if (polyface.data.edgeMateIndex)\r\n this.edgeMateIndex = [];\r\n this._numEdges = 0;\r\n this._nextFacetIndex = 0;\r\n this._currentFacetIndex = -1;\r\n this.reset();\r\n }\r\n /** Return the client polyface object. */\r\n public clientPolyface(): IndexedPolyface {\r\n return this._polyface;\r\n }\r\n /** Return the number of facets this visitor is able to visit. */\r\n public getVisitableFacetCount(): number {\r\n return this._polyface.facetCount;\r\n }\r\n /**\r\n * Set the number of vertices replicated in visitor arrays (both data and index arrays).\r\n * * 0,1,2 are the most common as numWrap.\r\n * * Example: suppose `[6,7,8]` is the pointIndex array representing a triangle. First edge would be `6,7`. Second\r\n * edge is `7,8`. Third edge is `8,6`. To access `6` for the third edge, we have to go back to the start of array.\r\n * Therefore, it is useful to store `6` at the end of pointIndex array, i.e., `[6,7,8,6]` meaning `numWrap = 1`.\r\n * Continuing this example, `numWrap = 2` (i.e., `[6,7,8,6,7]`) is useful when each vertex visit requires the next\r\n * two points, e.g., to form two adjacent vectors for a cross product.\r\n */\r\n public setNumWrap(numWrap: number) {\r\n this._numWrap = numWrap;\r\n }\r\n /**\r\n * Return the number of edges in the current facet.\r\n * * If `numWrap > 0` for this visitor, the number of edges is smaller than the number of points.\r\n */\r\n public get numEdgesThisFacet(): number {\r\n return this._numEdges;\r\n }\r\n /** Create a visitor for iterating the facets of `polyface`. */\r\n public static create(polyface: IndexedPolyface, numWrap: number): IndexedPolyfaceVisitor {\r\n return new IndexedPolyfaceVisitor(polyface, numWrap);\r\n }\r\n /** Advance the iterator to a particular facet in the client polyface. */\r\n public moveToReadIndex(facetIndex: number): boolean {\r\n if (!this._polyface.isValidFacetIndex(facetIndex))\r\n return false;\r\n const numEdges = this._polyface.numEdgeInFacet(facetIndex);\r\n if (this._currentFacetIndex !== facetIndex || numEdges + this._numWrap !== this.pointCount) {\r\n this._currentFacetIndex = facetIndex;\r\n this._numEdges = numEdges;\r\n this.resizeAllArrays(this._numEdges + this._numWrap);\r\n this.gatherIndexedData(\r\n this._polyface.data,\r\n this._polyface.facetIndex0(this._currentFacetIndex),\r\n this._polyface.facetIndex1(this._currentFacetIndex),\r\n this._numWrap,\r\n );\r\n }\r\n this._nextFacetIndex = facetIndex + 1;\r\n return true;\r\n }\r\n /** Advance the iterator to a the 'next' facet in the client polyface. */\r\n public moveToNextFacet(): boolean {\r\n if (this._nextFacetIndex !== this._currentFacetIndex)\r\n return this.moveToReadIndex(this._nextFacetIndex);\r\n this._nextFacetIndex++;\r\n return true;\r\n }\r\n /** Restart the visitor at the first facet. */\r\n public reset(): void {\r\n this.moveToReadIndex(0);\r\n this._nextFacetIndex = 0; // so immediate moveToNextFacet stays here.\r\n }\r\n /**\r\n * Attempts to extract the distance parameter for the given vertex `index` on the current facet.\r\n * Returns the distance parameter as a point. Returns `undefined` on failure.\r\n */\r\n public tryGetDistanceParameter(index: number, result?: Point2d): Point2d | undefined {\r\n if (index < 0 || index >= this.numEdgesThisFacet)\r\n return undefined;\r\n if (this.param === undefined || this._polyface.data.face.length === 0)\r\n return undefined;\r\n const faceData = this._polyface.tryGetFaceData(this._currentFacetIndex);\r\n if (!faceData)\r\n return undefined;\r\n return faceData.convertParamXYToDistance(\r\n this.param.getXAtUncheckedPointIndex(index),\r\n this.param.getYAtUncheckedPointIndex(index),\r\n result,\r\n );\r\n }\r\n /**\r\n * Attempts to extract the normalized parameter (0,1) for the given vertex `index` on the current facet.\r\n * Returns the normalized parameter as a point. Returns `undefined` on failure.\r\n */\r\n public tryGetNormalizedParameter(index: number, result?: Point2d): Point2d | undefined {\r\n if (index < 0 || index >= this.numEdgesThisFacet)\r\n return undefined;\r\n if (this.param === undefined || this._polyface.data.face.length === 0)\r\n return undefined;\r\n const faceData = this._polyface.tryGetFaceData(this._currentFacetIndex);\r\n if (!faceData)\r\n return undefined;\r\n return faceData.convertParamXYToNormalized(\r\n this.param.getXAtUncheckedPointIndex(index),\r\n this.param.getYAtUncheckedPointIndex(index),\r\n result,\r\n );\r\n }\r\n /** Return the facetIndex of the currently referenced facet in the client polyface. */\r\n public currentReadIndex(): number {\r\n return this._currentFacetIndex;\r\n }\r\n /** Return the point index of vertex `i` within the currently loaded facet. */\r\n public clientPointIndex(i: number): number {\r\n return this.pointIndex[i];\r\n }\r\n /** Return the param index of vertex `i` within the currently loaded facet. */\r\n public clientParamIndex(i: number): number {\r\n return this.paramIndex ? this.paramIndex[i] : -1;\r\n }\r\n /** Return the normal index of vertex `i` within the currently loaded facet. */\r\n public clientNormalIndex(i: number): number {\r\n return this.normalIndex ? this.normalIndex[i] : -1;\r\n }\r\n /** Return the color index of vertex `i` within the currently loaded facet. */\r\n public clientColorIndex(i: number): number {\r\n return this.colorIndex ? this.colorIndex[i] : -1;\r\n }\r\n /** Return the aux data index of vertex `i` within the currently loaded facet. */\r\n public clientAuxIndex(i: number): number {\r\n return this.auxData ? this.auxData.indices[i] : -1;\r\n }\r\n /** Clear the contents of the data arrays. */\r\n public clearArrays(): void {\r\n this.point.length = 0;\r\n this.edgeVisible.length = 0;\r\n if (this.param !== undefined)\r\n this.param.length = 0;\r\n if (this.normal !== undefined)\r\n this.normal.length = 0;\r\n if (this.color !== undefined)\r\n this.color.length = 0;\r\n // TODO: auxData? taggedNumericData?\r\n }\r\n /** Transfer data from a specified `index` of the `other` visitor as new data in this visitor. */\r\n public pushDataFrom(other: PolyfaceVisitor, index: number): void {\r\n this.point.pushFromGrowableXYZArray(other.point, index);\r\n this.edgeVisible.push(other.edgeVisible[index]);\r\n if (this.param && other.param && index < other.param.length)\r\n this.param.pushFromGrowableXYArray(other.param, index);\r\n if (this.normal && other.normal && index < other.normal.length)\r\n this.normal.pushFromGrowableXYZArray(other.normal, index);\r\n if (this.color && other.color && index < other.color.length)\r\n this.color.push(other.color[index]);\r\n // TODO: auxData? taggedNumericData?\r\n }\r\n /**\r\n * Transfer interpolated data from the other visitor.\r\n * * All data values are interpolated at `fraction` between `other` values at `index0` and `index1`.\r\n */\r\n public pushInterpolatedDataFrom(other: PolyfaceVisitor, index0: number, fraction: number, index1: number): void {\r\n if (index0 > index1)\r\n this.pushInterpolatedDataFrom(other, index1, 1.0 - fraction, index0);\r\n this.point.pushInterpolatedFromGrowableXYZArray(other.point, index0, fraction, index1);\r\n const newVisibility = (((index0 + 1) % other.edgeVisible.length) === index1) ? other.edgeVisible[index0] : false;\r\n this.edgeVisible.push(newVisibility); // interpolation along an edge preserves visibility of original edge\r\n if (this.param && other.param && index0 < other.param.length && index1 < other.param.length)\r\n this.param.pushInterpolatedFromGrowableXYArray(other.param, index0, fraction, index1);\r\n if (this.normal && other.normal && index0 < other.normal.length && index1 < other.normal.length)\r\n this.normal.pushInterpolatedFromGrowableXYZArray(other.normal, index0, fraction, index1);\r\n if (this.color && other.color && index0 < other.color.length && index1 < other.color.length)\r\n this.color.push(Geometry.interpolateColor(other.color[index0], fraction, other.color[index1]));\r\n // TODO: auxData? taggedNumericData?\r\n }\r\n /** Create a visitor for a subset of the facets visitable by the instance. */\r\n public createSubsetVisitor(facetIndices: number[], numWrap: number = 0): IndexedPolyfaceSubsetVisitor {\r\n return IndexedPolyfaceSubsetVisitor.createSubsetVisitor(this._polyface, facetIndices, numWrap);\r\n }\r\n}\r\n\r\n/**\r\n * An `IndexedPolyfaceSubsetVisitor` is an `IndexedPolyfaceVisitor` which only visits a subset of facets in the polyface.\r\n * * The subset is defined by an array of facet indices provided when this visitor is created.\r\n * * Input indices (e.g., for `moveToReadIndex`) are understood to be indices into the subset array.\r\n * @public\r\n */\r\nexport class IndexedPolyfaceSubsetVisitor extends IndexedPolyfaceVisitor {\r\n private _facetIndices: number[];\r\n private _currentSubsetIndex: number; // index within _facetIndices, or -1 after construction\r\n private _nextSubsetIndex: number; // index within _facetIndices\r\n\r\n private constructor(polyface: IndexedPolyface, facetIndices: number[], numWrap: number) {\r\n super(polyface, numWrap);\r\n this._facetIndices = facetIndices.slice();\r\n this._currentSubsetIndex = -1;\r\n this._nextSubsetIndex = 0;\r\n this.reset();\r\n }\r\n private isValidSubsetIndex(index: number): boolean {\r\n return index >= 0 && index < this._facetIndices.length;\r\n }\r\n /**\r\n * Create a visitor for iterating a subset of the facets of `polyface`.\r\n * @param polyface reference to the client polyface, supplying facets\r\n * @param facetIndices array of indices of facets in the client polyface to visit. This array is cloned.\r\n * @param numWrap number of vertices replicated in the visitor arrays to facilitate simpler caller code. Default is zero.\r\n */\r\n public static createSubsetVisitor(\r\n polyface: IndexedPolyface, facetIndices: number[], numWrap: number = 0,\r\n ): IndexedPolyfaceSubsetVisitor {\r\n return new IndexedPolyfaceSubsetVisitor(polyface, facetIndices, numWrap);\r\n }\r\n /**\r\n * Advance the iterator to a particular facet in the subset of client polyface facets.\r\n * @param subsetIndex index into the subset array, not to be confused with the client facet index.\r\n * @return whether the iterator was successfully moved.\r\n */\r\n public override moveToReadIndex(subsetIndex: number): boolean {\r\n if (this.isValidSubsetIndex(subsetIndex)) {\r\n this._currentSubsetIndex = subsetIndex;\r\n this._nextSubsetIndex = subsetIndex + 1;\r\n return super.moveToReadIndex(this._facetIndices[subsetIndex]);\r\n }\r\n return false;\r\n }\r\n /**\r\n * Advance the iterator to the next facet in the subset of client polyface facets.\r\n * @return whether the iterator was successfully moved.\r\n */\r\n public override moveToNextFacet(): boolean {\r\n if (this._nextSubsetIndex !== this._currentSubsetIndex)\r\n return this.moveToReadIndex(this._nextSubsetIndex);\r\n this._nextSubsetIndex++;\r\n return true;\r\n }\r\n /** Restart the visitor at the first facet. */\r\n public override reset(): void {\r\n if (this._facetIndices) { // avoid crash during super ctor when we aren't yet initialized\r\n this.moveToReadIndex(0);\r\n this._nextSubsetIndex = 0; // so immediate moveToNextFacet stays here.\r\n }\r\n }\r\n /**\r\n * Return the client polyface facet index (aka \"readIndex\") for the given subset index.\r\n * @param subsetIndex index into the subset array. Default is the subset index of the currently visited facet.\r\n * @return valid client polyface facet index, or `undefined` if invalid subset index.\r\n */\r\n public parentFacetIndex(subsetIndex?: number): number | undefined {\r\n if (undefined === subsetIndex)\r\n subsetIndex = this._currentSubsetIndex;\r\n return this.isValidSubsetIndex(subsetIndex) ? this._facetIndices[subsetIndex] : undefined;\r\n }\r\n /** Return the number of facets this visitor is able to visit. */\r\n public override getVisitableFacetCount(): number {\r\n return this._facetIndices.length;\r\n }\r\n /**\r\n * Create a visitor for those mesh facets with normal in the same half-space as the given vector.\r\n * * For example, to visit the top facets of a tiled terrain mesh but skip the \"skirt\" facets, pass\r\n * `compareVector = Vector3d.unitZ()` and a suitable `sideAngle` tolerance. Note that this will also\r\n * filter out *interior* facets that are nearly vertical, not just the \"skirt\" facets on the boundary.\r\n * @param mesh the mesh from which to select facets\r\n * @param compareVector vector to which to compare facet normals. The visitor will visit only those facets\r\n * with normals in the same half-space as this vector. Default is 001.\r\n * @param sideAngle optional angular tolerance to filter the facets near the border between half-spaces.\r\n * The visitor will *not* visit facets whose normals are nearly perpendicular to `compareVector`.\r\n * Default is [[Geometry.smallAngleRadians]].\r\n * @param numWrap optional number of entries replicated in visitor arrays. Default is 0.\r\n */\r\n public static createNormalComparison(\r\n mesh: IndexedPolyface | IndexedPolyfaceVisitor,\r\n compareVector: Vector3d = Vector3d.unitZ(),\r\n sideAngle: Angle = Angle.createSmallAngle(),\r\n numWrap: number = 0,\r\n ): IndexedPolyfaceSubsetVisitor {\r\n if (mesh instanceof IndexedPolyface)\r\n return this.createNormalComparison(mesh.createVisitor(), compareVector, sideAngle, numWrap);\r\n const visitor = mesh;\r\n const facets: number[] = [];\r\n const facetNormal = Vector3d.createZero();\r\n for (visitor.reset(); visitor.moveToNextFacet();) {\r\n if (!PolygonOps.unitNormal(visitor.point, facetNormal))\r\n continue; // degenerate facet\r\n if (facetNormal.dotProduct(compareVector) < 0.0)\r\n continue; // ignore facet facing other half-space\r\n if (facetNormal.angleFromPerpendicular(compareVector).isMagnitudeLessThanOrEqual(sideAngle))\r\n continue; // ignore side facet\r\n facets.push(visitor.currentReadIndex());\r\n }\r\n return IndexedPolyfaceSubsetVisitor.createSubsetVisitor(visitor.clientPolyface(), facets, numWrap);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"IndexedPolyfaceVisitor.js","sourceRoot":"","sources":["../../../src/polyface/IndexedPolyfaceVisitor.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,eAAe,EAAmB,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAA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,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC1C,KAAK,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC;YACjD,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC;gBACpD,SAAS,CAAC,mBAAmB;YAC/B,IAAI,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,GAAG;gBAC7C,SAAS,CAAC,uCAAuC;YACnD,IAAI,WAAW,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,0BAA0B,CAAC,SAAS,CAAC;gBACzF,SAAS,CAAC,oBAAoB;YAChC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,4BAA4B,CAAC,mBAAmB,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACrG,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 Polyface\r\n */\r\n\r\nimport { Geometry } from \"../Geometry\";\r\nimport { Angle } from \"../geometry3d/Angle\";\r\nimport { Point2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { PolygonOps } from \"../geometry3d/PolygonOps\";\r\nimport { IndexedPolyface, PolyfaceVisitor } from \"./Polyface\";\r\nimport { PolyfaceData } from \"./PolyfaceData\";\r\n\r\n/**\r\n * An `IndexedPolyfaceVisitor` is an iterator-like object that \"visits\" facets of a mesh.\r\n * * The visitor extends `PolyfaceData`, so it can at any time hold all the data of a single facet.\r\n * @public\r\n */\r\nexport class IndexedPolyfaceVisitor extends PolyfaceData implements PolyfaceVisitor {\r\n private _currentFacetIndex: number;\r\n private _nextFacetIndex: number;\r\n private _numWrap: number;\r\n private _numEdges: number;\r\n private _polyface: IndexedPolyface;\r\n // to be called from static factory method that validates the polyface\r\n protected constructor(polyface: IndexedPolyface, numWrap: number) {\r\n super(polyface.data.normalCount > 0, polyface.data.paramCount > 0, polyface.data.colorCount > 0, polyface.twoSided);\r\n this._polyface = polyface;\r\n this._numWrap = numWrap;\r\n if (polyface.data.auxData)\r\n this.auxData = polyface.data.auxData.createForVisitor();\r\n if (polyface.data.edgeMateIndex)\r\n this.edgeMateIndex = [];\r\n this._numEdges = 0;\r\n this._nextFacetIndex = 0;\r\n this._currentFacetIndex = -1;\r\n this.reset();\r\n }\r\n /** Return the client polyface object. */\r\n public clientPolyface(): IndexedPolyface {\r\n return this._polyface;\r\n }\r\n /** Return the number of facets this visitor is able to visit. */\r\n public getVisitableFacetCount(): number {\r\n return this._polyface.facetCount;\r\n }\r\n /**\r\n * Set the number of vertices replicated in visitor arrays (both data and index arrays).\r\n * * 0,1,2 are the most common as numWrap.\r\n * * Example: suppose `[6,7,8]` is the pointIndex array representing a triangle. First edge would be `6,7`. Second\r\n * edge is `7,8`. Third edge is `8,6`. To access `6` for the third edge, we have to go back to the start of array.\r\n * Therefore, it is useful to store `6` at the end of pointIndex array, i.e., `[6,7,8,6]` meaning `numWrap = 1`.\r\n * Continuing this example, `numWrap = 2` (i.e., `[6,7,8,6,7]`) is useful when each vertex visit requires the next\r\n * two points, e.g., to form two adjacent vectors for a cross product.\r\n */\r\n public setNumWrap(numWrap: number) {\r\n this._numWrap = numWrap;\r\n }\r\n /**\r\n * Return the number of edges in the current facet.\r\n * * If `numWrap > 0` for this visitor, the number of edges is smaller than the number of points.\r\n */\r\n public get numEdgesThisFacet(): number {\r\n return this._numEdges;\r\n }\r\n /** Create a visitor for iterating the facets of `polyface`. */\r\n public static create(polyface: IndexedPolyface, numWrap: number): IndexedPolyfaceVisitor {\r\n return new IndexedPolyfaceVisitor(polyface, numWrap);\r\n }\r\n /** Advance the iterator to a particular facet in the client polyface. */\r\n public moveToReadIndex(facetIndex: number): boolean {\r\n if (!this._polyface.isValidFacetIndex(facetIndex))\r\n return false;\r\n const numEdges = this._polyface.numEdgeInFacet(facetIndex);\r\n if (this._currentFacetIndex !== facetIndex || numEdges + this._numWrap !== this.pointCount) {\r\n this._currentFacetIndex = facetIndex;\r\n this._numEdges = numEdges;\r\n this.resizeAllArrays(this._numEdges + this._numWrap);\r\n this.gatherIndexedData(\r\n this._polyface.data,\r\n this._polyface.facetIndex0(this._currentFacetIndex),\r\n this._polyface.facetIndex1(this._currentFacetIndex),\r\n this._numWrap,\r\n );\r\n }\r\n this._nextFacetIndex = facetIndex + 1;\r\n return true;\r\n }\r\n /** Advance the iterator to a the 'next' facet in the client polyface. */\r\n public moveToNextFacet(): boolean {\r\n if (this._nextFacetIndex !== this._currentFacetIndex)\r\n return this.moveToReadIndex(this._nextFacetIndex);\r\n this._nextFacetIndex++;\r\n return true;\r\n }\r\n /** Restart the visitor at the first facet. */\r\n public reset(): void {\r\n this.moveToReadIndex(0);\r\n this._nextFacetIndex = 0; // so immediate moveToNextFacet stays here.\r\n }\r\n /**\r\n * Attempts to extract the distance parameter for the given vertex `index` on the current facet.\r\n * Returns the distance parameter as a point. Returns `undefined` on failure.\r\n */\r\n public tryGetDistanceParameter(index: number, result?: Point2d): Point2d | undefined {\r\n if (index < 0 || index >= this.numEdgesThisFacet)\r\n return undefined;\r\n if (this.param === undefined || this._polyface.data.face.length === 0)\r\n return undefined;\r\n const faceData = this._polyface.tryGetFaceData(this._currentFacetIndex);\r\n if (!faceData)\r\n return undefined;\r\n return faceData.convertParamXYToDistance(\r\n this.param.getXAtUncheckedPointIndex(index),\r\n this.param.getYAtUncheckedPointIndex(index),\r\n result,\r\n );\r\n }\r\n /**\r\n * Attempts to extract the normalized parameter (0,1) for the given vertex `index` on the current facet.\r\n * Returns the normalized parameter as a point. Returns `undefined` on failure.\r\n */\r\n public tryGetNormalizedParameter(index: number, result?: Point2d): Point2d | undefined {\r\n if (index < 0 || index >= this.numEdgesThisFacet)\r\n return undefined;\r\n if (this.param === undefined || this._polyface.data.face.length === 0)\r\n return undefined;\r\n const faceData = this._polyface.tryGetFaceData(this._currentFacetIndex);\r\n if (!faceData)\r\n return undefined;\r\n return faceData.convertParamXYToNormalized(\r\n this.param.getXAtUncheckedPointIndex(index),\r\n this.param.getYAtUncheckedPointIndex(index),\r\n result,\r\n );\r\n }\r\n /** Return the facetIndex of the currently referenced facet in the client polyface. */\r\n public currentReadIndex(): number {\r\n return this._currentFacetIndex;\r\n }\r\n /** Return the point index of vertex `i` within the currently loaded facet. */\r\n public clientPointIndex(i: number): number {\r\n return this.pointIndex[i];\r\n }\r\n /** Return the param index of vertex `i` within the currently loaded facet. */\r\n public clientParamIndex(i: number): number {\r\n return this.paramIndex ? this.paramIndex[i] : -1;\r\n }\r\n /** Return the normal index of vertex `i` within the currently loaded facet. */\r\n public clientNormalIndex(i: number): number {\r\n return this.normalIndex ? this.normalIndex[i] : -1;\r\n }\r\n /** Return the color index of vertex `i` within the currently loaded facet. */\r\n public clientColorIndex(i: number): number {\r\n return this.colorIndex ? this.colorIndex[i] : -1;\r\n }\r\n /** Return the aux data index of vertex `i` within the currently loaded facet. */\r\n public clientAuxIndex(i: number): number {\r\n return this.auxData ? this.auxData.indices[i] : -1;\r\n }\r\n /** Clear the contents of the data arrays. */\r\n public clearArrays(): void {\r\n this.point.length = 0;\r\n this.edgeVisible.length = 0;\r\n if (this.param !== undefined)\r\n this.param.length = 0;\r\n if (this.normal !== undefined)\r\n this.normal.length = 0;\r\n if (this.color !== undefined)\r\n this.color.length = 0;\r\n // TODO: auxData? taggedNumericData?\r\n }\r\n /** Transfer data from a specified `index` of the `other` visitor as new data in this visitor. */\r\n public pushDataFrom(other: PolyfaceVisitor, index: number): void {\r\n this.point.pushFromGrowableXYZArray(other.point, index);\r\n this.edgeVisible.push(other.edgeVisible[index]);\r\n if (this.param && other.param && index < other.param.length)\r\n this.param.pushFromGrowableXYArray(other.param, index);\r\n if (this.normal && other.normal && index < other.normal.length)\r\n this.normal.pushFromGrowableXYZArray(other.normal, index);\r\n if (this.color && other.color && index < other.color.length)\r\n this.color.push(other.color[index]);\r\n // TODO: auxData? taggedNumericData?\r\n }\r\n /**\r\n * Transfer interpolated data from the other visitor.\r\n * * All data values are interpolated at `fraction` between `other` values at `index0` and `index1`.\r\n */\r\n public pushInterpolatedDataFrom(other: PolyfaceVisitor, index0: number, fraction: number, index1: number): void {\r\n if (index0 > index1)\r\n this.pushInterpolatedDataFrom(other, index1, 1.0 - fraction, index0);\r\n this.point.pushInterpolatedFromGrowableXYZArray(other.point, index0, fraction, index1);\r\n const newVisibility = (((index0 + 1) % other.edgeVisible.length) === index1) ? other.edgeVisible[index0] : false;\r\n this.edgeVisible.push(newVisibility); // interpolation along an edge preserves visibility of original edge\r\n if (this.param && other.param && index0 < other.param.length && index1 < other.param.length)\r\n this.param.pushInterpolatedFromGrowableXYArray(other.param, index0, fraction, index1);\r\n if (this.normal && other.normal && index0 < other.normal.length && index1 < other.normal.length)\r\n this.normal.pushInterpolatedFromGrowableXYZArray(other.normal, index0, fraction, index1);\r\n if (this.color && other.color && index0 < other.color.length && index1 < other.color.length)\r\n this.color.push(Geometry.interpolateColor(other.color[index0], fraction, other.color[index1]));\r\n // TODO: auxData? taggedNumericData?\r\n }\r\n /** Create a visitor for a subset of the facets visitable by the instance. */\r\n public createSubsetVisitor(facetIndices: number[], numWrap: number = 0): IndexedPolyfaceSubsetVisitor {\r\n return IndexedPolyfaceSubsetVisitor.createSubsetVisitor(this._polyface, facetIndices, numWrap);\r\n }\r\n}\r\n\r\n/**\r\n * An `IndexedPolyfaceSubsetVisitor` is an `IndexedPolyfaceVisitor` which only visits a subset of facets in the polyface.\r\n * * The subset is defined by an array of facet indices provided when this visitor is created.\r\n * * Input indices (e.g., for `moveToReadIndex`) are understood to be indices into the subset array.\r\n * @public\r\n */\r\nexport class IndexedPolyfaceSubsetVisitor extends IndexedPolyfaceVisitor {\r\n private _facetIndices: number[];\r\n private _currentSubsetIndex: number; // index within _facetIndices\r\n private _nextSubsetIndex: number; // index within _facetIndices\r\n\r\n private constructor(polyface: IndexedPolyface, facetIndices: number[], numWrap: number) {\r\n super(polyface, numWrap);\r\n this._facetIndices = facetIndices.slice();\r\n this._currentSubsetIndex = -1;\r\n this._nextSubsetIndex = 0;\r\n this.reset();\r\n }\r\n private isValidSubsetIndex(index: number): boolean {\r\n return index >= 0 && index < this._facetIndices.length;\r\n }\r\n /**\r\n * Create a visitor for iterating a subset of the facets of `polyface`.\r\n * @param polyface reference to the client polyface, supplying facets\r\n * @param facetIndices array of indices of facets in the client polyface to visit. This array is cloned.\r\n * @param numWrap number of vertices replicated in the visitor arrays to facilitate simpler caller code. Default is zero.\r\n */\r\n public static createSubsetVisitor(\r\n polyface: IndexedPolyface, facetIndices: number[], numWrap: number = 0,\r\n ): IndexedPolyfaceSubsetVisitor {\r\n return new IndexedPolyfaceSubsetVisitor(polyface, facetIndices, numWrap);\r\n }\r\n /**\r\n * Advance the iterator to a particular facet in the subset of client polyface facets.\r\n * @param subsetIndex index into the subset array, not to be confused with the client facet index.\r\n * @return whether the iterator was successfully moved.\r\n */\r\n public override moveToReadIndex(subsetIndex: number): boolean {\r\n if (this.isValidSubsetIndex(subsetIndex)) {\r\n this._currentSubsetIndex = subsetIndex;\r\n this._nextSubsetIndex = subsetIndex + 1;\r\n return super.moveToReadIndex(this._facetIndices[subsetIndex]);\r\n }\r\n return false;\r\n }\r\n /**\r\n * Advance the iterator to the next facet in the subset of client polyface facets.\r\n * @return whether the iterator was successfully moved.\r\n */\r\n public override moveToNextFacet(): boolean {\r\n if (this._nextSubsetIndex !== this._currentSubsetIndex)\r\n return this.moveToReadIndex(this._nextSubsetIndex);\r\n this._nextSubsetIndex++;\r\n return true;\r\n }\r\n /** Restart the visitor at the first facet. */\r\n public override reset(): void {\r\n if (this._facetIndices) { // avoid crash during super ctor when we aren't yet initialized\r\n this.moveToReadIndex(0);\r\n this._nextSubsetIndex = 0; // so immediate moveToNextFacet stays here.\r\n }\r\n }\r\n /**\r\n * Return the client polyface facet index (aka \"readIndex\") for the given subset index.\r\n * @param subsetIndex index into the subset array. Default is the subset index of the currently visited facet.\r\n * @return valid client polyface facet index, or `undefined` if invalid subset index.\r\n */\r\n public parentFacetIndex(subsetIndex?: number): number | undefined {\r\n if (undefined === subsetIndex)\r\n subsetIndex = this._currentSubsetIndex;\r\n return this.isValidSubsetIndex(subsetIndex) ? this._facetIndices[subsetIndex] : undefined;\r\n }\r\n /** Return the number of facets this visitor is able to visit. */\r\n public override getVisitableFacetCount(): number {\r\n return this._facetIndices.length;\r\n }\r\n /**\r\n * Create a visitor for those mesh facets with normal in the same half-space as the given vector.\r\n * * For example, to visit the top facets of a tiled terrain mesh but skip the \"skirt\" facets, pass\r\n * `compareVector = Vector3d.unitZ()` and a suitable `sideAngle` tolerance. Note that this will also\r\n * filter out *interior* facets that are nearly vertical, not just the \"skirt\" facets on the boundary.\r\n * @param mesh the mesh from which to select facets\r\n * @param compareVector vector to which to compare facet normals. The visitor will visit only those facets\r\n * with normals in the same half-space as this vector. Default is 001.\r\n * @param sideAngle optional angular tolerance to filter the facets near the border between half-spaces.\r\n * The visitor will *not* visit facets whose normals are nearly perpendicular to `compareVector`.\r\n * Default is [[Geometry.smallAngleRadians]].\r\n * @param numWrap optional number of entries replicated in visitor arrays. Default is 0.\r\n */\r\n public static createNormalComparison(\r\n mesh: IndexedPolyface | IndexedPolyfaceVisitor,\r\n compareVector: Vector3d = Vector3d.unitZ(),\r\n sideAngle: Angle = Angle.createSmallAngle(),\r\n numWrap: number = 0,\r\n ): IndexedPolyfaceSubsetVisitor {\r\n if (mesh instanceof IndexedPolyface)\r\n return this.createNormalComparison(mesh.createVisitor(), compareVector, sideAngle, numWrap);\r\n const visitor = mesh;\r\n const facets: number[] = [];\r\n const facetNormal = Vector3d.createZero();\r\n for (visitor.reset(); visitor.moveToNextFacet();) {\r\n if (!PolygonOps.unitNormal(visitor.point, facetNormal))\r\n continue; // degenerate facet\r\n if (facetNormal.dotProduct(compareVector) < 0.0)\r\n continue; // ignore facet facing other half-space\r\n if (facetNormal.angleFromPerpendicular(compareVector).isMagnitudeLessThanOrEqual(sideAngle))\r\n continue; // ignore side facet\r\n facets.push(visitor.currentReadIndex());\r\n }\r\n return IndexedPolyfaceSubsetVisitor.createSubsetVisitor(visitor.clientPolyface(), facets, numWrap);\r\n }\r\n}\r\n"]}
|
|
@@ -44,6 +44,7 @@ export declare class HalfEdgeGraphSearch {
|
|
|
44
44
|
static collectFaceAreaSummary(source: HalfEdgeGraph | HalfEdge[], collectAllNodes?: boolean, areaFunction?: NodeToNumberFunction): SignedDataSummary<HalfEdge>;
|
|
45
45
|
/**
|
|
46
46
|
* Search the graph for the face with the most negative area.
|
|
47
|
+
* * If the graph has exactly one connected component, this is its outer face.
|
|
47
48
|
* @param oneCandidateNodePerFace graph or an array containing one node from each face to be considered.
|
|
48
49
|
* @returns node on the negative area face with largest absolute area, or `undefined` if no negative area face.
|
|
49
50
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HalfEdgeGraphSearch.d.ts","sourceRoot":"","sources":["../../../src/topology/HalfEdgeGraphSearch.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,yBAAyB,EAAgB,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/H,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKxD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;CAChC;AACD;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,YAAY,CAAU;IAC9B;;;;O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I;IAoBP;;;;;;;;;OASG;WACW,mCAAmC,CAAC,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,GAAG,QAAQ,EAAE,EAAE;CAkBlH"}
|
|
@@ -65,6 +65,7 @@ export class HalfEdgeGraphSearch {
|
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Search the graph for the face with the most negative area.
|
|
68
|
+
* * If the graph has exactly one connected component, this is its outer face.
|
|
68
69
|
* @param oneCandidateNodePerFace graph or an array containing one node from each face to be considered.
|
|
69
70
|
* @returns node on the negative area face with largest absolute area, or `undefined` if no negative area face.
|
|
70
71
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HalfEdgeGraphSearch.js","sourceRoot":"","sources":["../../../src/topology/HalfEdgeGraphSearch.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAY,aAAa,EAAE,YAAY,EAAiE,MAAM,SAAS,CAAC;AAC/H,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAWhE;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACrB,WAAW,CAAe;IAC1B,YAAY,CAAU;IAC9B;;;;OAIG;IACH,YAAmB,IAAkB,EAAE,cAAuB,IAAI;QAChE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IACD,0EAA0E;IACnE,QAAQ,CAAC,IAAc;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC;IAChE,CAAC;CACF;AACD;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAC9B;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAAC,IAAc;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oBACtC,MAAM,CAAC,8FAA8F;YACzG,CAAC;QACH,CAAC;IACH,CAAC;IACD;;;;;;;;;OASG;IACI,MAAM,CAAC,mCAAmC,CAAC,KAAoB,EAAE,YAA0B;QAChG,+EAA+E;QAC/E,MAAM,KAAK,GAAiB,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,cAAc,GAAG,CAAC,IAAc,EAAW,EAAE;YACjD,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACvF,CAAC,CAAC;QACF,MAAM,sBAAsB,GAAG,CAAC,IAAc,EAAE,OAAe,EAAE,EAAE;YACjE,IAAI,OAAO,KAAK,CAAC;gBACf,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACjB,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC,CAAC;QACF,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YACtC,IAAI,CAAC,mCAAmC,CAAC,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,sBAAsB,CAAC,CAAC;QACpG,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,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 Topology\r\n */\r\nimport { Range1d } from \"../geometry3d/Range\";\r\nimport { HalfEdge, HalfEdgeGraph, HalfEdgeMask, HalfEdgeToBooleanFunction, NodeFunction, NodeToNumberFunction } from \"./Graph\";\r\nimport { SignedDataSummary } from \"./SignedDataSummary\";\r\nimport { XYParitySearchContext } from \"./XYParitySearchContext\";\r\n\r\n// cspell:word internaldocs\r\n\r\n/**\r\n * Interface for an object that executes boolean tests on edges.\r\n * @internal\r\n */\r\nexport interface HalfEdgeTestObject {\r\n testEdge(h: HalfEdge): boolean;\r\n}\r\n/**\r\n * Class to test match of half edge mask.\r\n * @internal\r\n */\r\nexport class HalfEdgeMaskTester {\r\n private _targetMask: HalfEdgeMask;\r\n private _targetValue: boolean;\r\n /**\r\n * Constructor\r\n * @param mask mask to test in `testEdge` function\r\n * @param targetValue value to match for true return\r\n */\r\n public constructor(mask: HalfEdgeMask, targetValue: boolean = true) {\r\n this._targetMask = mask;\r\n this._targetValue = targetValue;\r\n }\r\n /** Return true if the value of the targetMask matches the targetValue. */\r\n public testEdge(edge: HalfEdge): boolean {\r\n return edge.isMaskSet(this._targetMask) === this._targetValue;\r\n }\r\n}\r\n/**\r\n * Class for different types of searches for HalfEdgeGraph.\r\n * @internal\r\n */\r\nexport class HalfEdgeGraphSearch {\r\n /**\r\n * Static method for face area computation -- useful as function parameter in `collectFaceAreaSummary`.\r\n * * This simply calls `node.signedFaceArea()`\r\n * @param node instance for signedFaceArea call.\r\n */\r\n public static signedFaceArea(node: HalfEdge): number {\r\n return node.signedFaceArea();\r\n }\r\n /**\r\n * Return a summary of face data (e.g., area) as computed by the callback on the faces of the graph.\r\n * * Callers with curved edge graphs must supply their own area function.\r\n * @param source graph or array of nodes to examine.\r\n * @param collectAllNodes flag to pass to the `SignedDataSummary` constructor to control collection of nodes.\r\n * @param areaFunction function to obtain area (or other numeric value). Default computes polygonal face area.\r\n */\r\n public static collectFaceAreaSummary(\r\n source: HalfEdgeGraph | HalfEdge[],\r\n collectAllNodes: boolean = false,\r\n areaFunction: NodeToNumberFunction = (node) => HalfEdgeGraphSearch.signedFaceArea(node),\r\n ): SignedDataSummary<HalfEdge> {\r\n const result = new SignedDataSummary<HalfEdge>(collectAllNodes);\r\n let allFaces: HalfEdge[];\r\n if (source instanceof HalfEdgeGraph)\r\n allFaces = source.collectFaceLoops();\r\n else\r\n allFaces = source;\r\n for (const node of allFaces) {\r\n const area = areaFunction(node);\r\n result.announceItem(node, area);\r\n }\r\n return result;\r\n }\r\n /**\r\n * Search the graph for the face with the most negative area.\r\n * @param oneCandidateNodePerFace graph or an array containing one node from each face to be considered.\r\n * @returns node on the negative area face with largest absolute area, or `undefined` if no negative area face.\r\n */\r\n public static findMinimumAreaFace(\r\n oneCandidateNodePerFace: HalfEdgeGraph | HalfEdge[], faceAreaFunction?: NodeToNumberFunction,\r\n ): HalfEdge | undefined {\r\n const summary = HalfEdgeGraphSearch.collectFaceAreaSummary(oneCandidateNodePerFace, false, faceAreaFunction);\r\n return summary.largestNegativeItem;\r\n }\r\n /**\r\n * Test if the graph is triangulated.\r\n * * Return `false` if:\r\n * * number of positive area faces with more than 3 edges is larger than `numPositiveExceptionsAllowed`.\r\n * * graph has more than 1 negative area face when `allowMultipleNegativeAreaFaces` is `false`.\r\n * * 2-edge faces are ignored.\r\n */\r\n public static isTriangulatedCCW(\r\n source: HalfEdgeGraph | HalfEdge[],\r\n allowMultipleNegativeAreaFaces: boolean = true,\r\n numPositiveExceptionsAllowed: number = 0,\r\n ): boolean {\r\n let allFaces: HalfEdge[];\r\n if (source instanceof HalfEdgeGraph)\r\n allFaces = source.collectFaceLoops();\r\n else\r\n allFaces = source;\r\n let numNegative = 0;\r\n let numPositiveExceptions = 0;\r\n for (const node of allFaces) {\r\n const numEdges = node.countEdgesAroundFace();\r\n if (numEdges >= 3) {\r\n const area = node.signedFaceArea();\r\n if (area > 0) {\r\n if (numEdges > 3) {\r\n numPositiveExceptions++;\r\n if (numPositiveExceptions > numPositiveExceptionsAllowed)\r\n return false;\r\n }\r\n } else {\r\n numNegative++;\r\n if (numNegative > 1) {\r\n if (!allowMultipleNegativeAreaFaces)\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n /**\r\n * Process a face during graph traversal.\r\n * @param faceSeed a node in the face.\r\n * @param mask mask to set on each node of the face.\r\n * @param allNodeStack array appended with each node of the face.\r\n * @param onePerFaceStack array appended with `faceSeed`.\r\n */\r\n private static pushAndMaskAllNodesInFace(\r\n faceSeed: HalfEdge, mask: number, allNodeStack: HalfEdge[], onePerFaceStack: HalfEdge[],\r\n ): void {\r\n onePerFaceStack.push(faceSeed);\r\n faceSeed.collectAroundFace((node: HalfEdge) => {\r\n node.setMask(mask);\r\n allNodeStack.push(node);\r\n });\r\n }\r\n /**\r\n * Traverse (via Depth First Search) to all accessible faces from the given seed.\r\n * @param faceSeed first node to start the traverse.\r\n * @param visitMask mask applied to all faces as visited.\r\n * @param parityEdgeTester function to test if an edge is adjacent to two faces of opposite parity, e.g., a boundary\r\n * edge that separates an \"interior\" face and an \"exterior\" face. If `parityEdgeTester` is not supplied and `parityMask`\r\n * is supplied, the default parity rule is to alternate parity state in a \"bullseye\" pattern starting at the seed face,\r\n * with each successive concentric ring of faces at constant topological distance from the seed face receiving the\r\n * opposite parity state of the previous ring.\r\n * @param parityMask mask to apply to the first face and faces that share the same parity as the first face, as\r\n * determined by the parity rule. If this is `NULL_MASK`, there is no record of parity. If (non-null) parity mask\r\n * is given, on return it is entirely set or entirely clear around each face.\r\n * @returns an array that contains one representative node in each face of the connected component.\r\n */\r\n private static parityFloodFromSeed(\r\n faceSeed: HalfEdge,\r\n visitMask: HalfEdgeMask,\r\n parityEdgeTester: HalfEdgeTestObject | undefined,\r\n parityMask: HalfEdgeMask,\r\n ): HalfEdge[] {\r\n const faces: HalfEdge[] = [];\r\n if (faceSeed.isMaskSet(visitMask))\r\n return faces; // empty array\r\n const allMasks = parityMask | visitMask;\r\n const stack: HalfEdge[] = [];\r\n // the seed face is arbitrarily assigned the parity mask\r\n HalfEdgeGraphSearch.pushAndMaskAllNodesInFace(faceSeed, allMasks, stack, faces);\r\n while (stack.length > 0) {\r\n const p = stack.pop()!;\r\n const mate = p.edgeMate;\r\n if (!mate)\r\n continue;\r\n if (!mate.isMaskSet(visitMask)) {\r\n let newState = p.isMaskSet(parityMask);\r\n if (!parityEdgeTester || parityEdgeTester.testEdge(p))\r\n newState = !newState;\r\n HalfEdgeGraphSearch.pushAndMaskAllNodesInFace(mate, newState ? allMasks : visitMask, stack, faces);\r\n }\r\n }\r\n return faces;\r\n }\r\n /**\r\n * * Correct the parity mask in the faces of a component.\r\n * * It is assumed that the parity mask is applied _consistently_ throughout the supplied faces, but maybe\r\n * not _correctly_.\r\n * * A consistently applied parity mask is \"correct\" if it is set on the negative area (\"exterior\") face of\r\n * a connected component.\r\n * * This method finds a face with negative area and toggles the mask throughout the input faces if this face\r\n * lacks the parity mask.\r\n * * In a properly merged planar subdivision there should be only one true negative area face per component.\r\n */\r\n private static correctParityInSingleComponent(parityMask: HalfEdgeMask, faces: HalfEdge[]): void {\r\n const exteriorHalfEdge = HalfEdgeGraphSearch.findMinimumAreaFace(faces);\r\n if (!exteriorHalfEdge) {\r\n // graph has all degenerate faces; do nothing\r\n } else if (exteriorHalfEdge.isMaskSet(parityMask)) {\r\n // all should be well; nothing to do\r\n } else {\r\n for (const faceSeed of faces) {\r\n if (faceSeed.isMaskSet(parityMask)) {\r\n faceSeed.clearMaskAroundFace(parityMask);\r\n } else {\r\n faceSeed.setMaskAroundFace(parityMask);\r\n }\r\n }\r\n }\r\n }\r\n /** Apply `correctParityInSingleComponent` to each array in components (quick exit if `parityMask` is `NULL_MASK`). */\r\n private static correctParityInComponentArrays(parityMask: HalfEdgeMask, components: HalfEdge[][]): void {\r\n if (parityMask === HalfEdgeMask.NULL_MASK)\r\n return;\r\n for (const facesInComponent of components)\r\n HalfEdgeGraphSearch.correctParityInSingleComponent(parityMask, facesInComponent);\r\n }\r\n /**\r\n * Collect connected components of the graph (via Depth First Search).\r\n * @param graph graph to inspect.\r\n * @param parityEdgeTester (optional) function to test if an edge is adjacent to two faces of opposite parity,\r\n * e.g., a boundary edge that separates an \"interior\" face and an \"exterior\" face. If `parityEdgeTester` is not\r\n * supplied and `parityMask` is supplied, the default parity rule is to alternate parity state in a \"bullseye\"\r\n * pattern starting at the seed face, with each successive concentric ring of faces at constant topological\r\n * distance from the seed face receiving the opposite parity state of the previous ring.\r\n * @param parityMask (optional) mask to apply to the first face and faces that share the same parity as the\r\n * first face, as determined by the parity rule. If this is `NULL_MASK`, there is no record of parity. If\r\n * (non-null) parity mask is given, on return it is entirely set or entirely clear around each face.\r\n * @returns the components of the graph, each component represented by an array of nodes, one node per face\r\n * of the component. In other words, entry [i][j] is a HalfEdge in the j_th face loop of the i_th component.\r\n */\r\n public static collectConnectedComponentsWithExteriorParityMasks(\r\n graph: HalfEdgeGraph,\r\n parityEdgeTester: HalfEdgeTestObject | undefined,\r\n parityMask: HalfEdgeMask = HalfEdgeMask.NULL_MASK,\r\n ): HalfEdge[][] {\r\n // Illustration of the algorithm can be found at geometry/internaldocs/Graph.md\r\n const components = [];\r\n const visitMask = HalfEdgeMask.VISITED;\r\n const allMasks = parityMask | visitMask;\r\n graph.clearMask(allMasks);\r\n for (const faceSeed of graph.allHalfEdges) {\r\n if (!faceSeed.isMaskSet(visitMask)) {\r\n const newFaces = HalfEdgeGraphSearch.parityFloodFromSeed(faceSeed, visitMask, parityEdgeTester, parityMask);\r\n // parityFloodFromSeed does not return an empty array because it is called on an unvisited faceSeed\r\n components.push(newFaces);\r\n }\r\n }\r\n HalfEdgeGraphSearch.correctParityInComponentArrays(parityMask, components);\r\n return components;\r\n }\r\n /**\r\n * Breadth First Search through connected component of a graph.\r\n * @param component vector of nodes, one per face.\r\n * @param seed seed node in component.\r\n * @param visitMask mask to apply to visited nodes. Assumed cleared throughout component.\r\n * @param ignoreMask (optional) mask preset on faces to ignore. Default value is `HalfEdgeMask.EXTERIOR` to\r\n * ignore exterior faces. Pass `HalfEdgeMask.NULL_MASK` to process all faces.\r\n * @param maxFaceCount (optional) maximum number of faces in the component. Should be positive; otherwise\r\n * `Infinity` is used.\r\n * @returns node at which to start next component if maximum face count exceeded, or undefined.\r\n */\r\n private static exploreComponent(\r\n component: HalfEdge[],\r\n seed: HalfEdge,\r\n visitMask: HalfEdgeMask,\r\n ignoreMask: HalfEdgeMask = HalfEdgeMask.EXTERIOR,\r\n maxFaceCount: number = Infinity,\r\n ): HalfEdge | undefined {\r\n if (maxFaceCount <= 0)\r\n maxFaceCount = Infinity;\r\n const boundaryMask: HalfEdgeMask = visitMask | ignoreMask;\r\n let numFaces = 0;\r\n const candidates: HalfEdge[] = []; // the queue\r\n candidates.push(seed);\r\n while (candidates.length !== 0 && numFaces < maxFaceCount) {\r\n // shift is O(n) and may be inefficient for large queues; if needed, we can replace\r\n // queue by circular array or implement the queue using 2 stacks; both are O(1)\r\n const node = candidates.shift()!;\r\n if (node.isMaskSet(boundaryMask))\r\n continue;\r\n component.push(node);\r\n ++numFaces;\r\n const enqueueNeighboringFaces: NodeFunction = (heNode: HalfEdge) => {\r\n heNode.setMask(visitMask);\r\n const neighbor = heNode.vertexSuccessor;\r\n if (!neighbor.isMaskSet(boundaryMask))\r\n candidates.push(neighbor);\r\n };\r\n node.collectAroundFace(enqueueNeighboringFaces);\r\n }\r\n if (candidates.length === 0)\r\n return undefined;\r\n else {\r\n const front = candidates[0];\r\n while (candidates.length !== 0) {\r\n // try to find a node at the boundary of both the geometry and previous component\r\n const node = candidates.shift()!; // shift may be inefficient for large queues\r\n if (node.vertexSuccessor.isMaskSet(ignoreMask))\r\n return node;\r\n if (node.edgeMate.isMaskSet(ignoreMask))\r\n return node;\r\n }\r\n return front;\r\n }\r\n }\r\n /**\r\n * Collect connected components of the graph (via Breadth First Search).\r\n * @param graph graph to inspect.\r\n * @param maxFaceCount (optional) maximum number of faces in each component. Should be positive; otherwise\r\n * `Infinity` is used.\r\n * @param ignoreMask (optional) mask preset on faces to ignore. Default value is `HalfEdgeMask.EXTERIOR` to ignore\r\n * exterior faces. Pass `HalfEdgeMask.NULL_MASK` to process all faces.\r\n * @returns the components of the graph, each component represented by an array of nodes, one node per face\r\n * of the component. In other words, entry [i][j] is a HalfEdge in the j_th face loop of the i_th component.\r\n */\r\n public static collectConnectedComponents(\r\n graph: HalfEdgeGraph,\r\n maxFaceCount: number = Infinity,\r\n ignoreMask: HalfEdgeMask = HalfEdgeMask.EXTERIOR,\r\n ): HalfEdge[][] {\r\n const components: HalfEdge[][] = [];\r\n if (graph.countMask(ignoreMask) === 0)\r\n ignoreMask = HalfEdgeMask.NULL_MASK;\r\n const visitMask = HalfEdgeMask.VISITED;\r\n const boundaryMask: HalfEdgeMask = visitMask | ignoreMask;\r\n // Starting with the input node, look ahead for a boundary face. Failing that, return the input node.\r\n // Starting all floods at the boundary reduces the chance of ending up with a ring-shaped component at the boundary.\r\n const findNextFloodSeed = (index: number) => {\r\n for (let i = index; i < graph.countNodes(); ++i) {\r\n if (!graph.allHalfEdges[i].isMaskSet(boundaryMask)\r\n && graph.allHalfEdges[i].edgeMate.isMaskSet(boundaryMask)) {\r\n index = i;\r\n break;\r\n }\r\n }\r\n return index;\r\n };\r\n for (let i = 0; i < graph.countNodes(); ++i) {\r\n if (graph.allHalfEdges[i].isMaskSet(boundaryMask))\r\n continue;\r\n const i0 = findNextFloodSeed(i);\r\n let seed: HalfEdge | undefined = graph.allHalfEdges[i0];\r\n do { // flood this component\r\n const component: HalfEdge[] = [];\r\n seed = HalfEdgeGraphSearch.exploreComponent(component, seed, visitMask, ignoreMask, maxFaceCount);\r\n if (component.length !== 0)\r\n components.push(component);\r\n } while (seed !== undefined);\r\n if (!graph.allHalfEdges[i].isMaskSet(visitMask))\r\n --i; // reprocess this node\r\n }\r\n return components;\r\n }\r\n /**\r\n * Test if test point (xTest,yTest) is inside/outside a face or on an edge.\r\n * @param seedNode any node on the face loop.\r\n * @param xTest x coordinate of the test point.\r\n * @param yTest y coordinate of the test point.\r\n * @returns 0 if ON, 1 if IN, -1 if OUT.\r\n */\r\n public static pointInOrOnFaceXY(seedNode: HalfEdge, xTest: number, yTest: number): number | undefined {\r\n const context = new XYParitySearchContext(xTest, yTest);\r\n // walk around looking for an accepted node to start the search (seedNode is usually ok)\r\n let nodeA = seedNode;\r\n let nodeB = seedNode.faceSuccessor;\r\n for (; ; nodeA = nodeB) {\r\n if (context.tryStartEdge(nodeA.x, nodeA.y, nodeB.x, nodeB.y))\r\n break;\r\n if (nodeB === seedNode) {\r\n // the test point and the face are all on line \"y = yTest\"\r\n const range = Range1d.createXX(nodeB.x, nodeB.faceSuccessor.x);\r\n return range.containsX(xTest) ? 0 : -1;\r\n }\r\n nodeB = nodeA.faceSuccessor;\r\n }\r\n // nodeB is the real start node for search, so stop when we revisit it. For each edge, accumulate parity and hits\r\n let nodeC = nodeB.faceSuccessor;\r\n for (; ;) {\r\n if (!context.advance(nodeC.x, nodeC.y)) {\r\n return context.classifyCounts();\r\n }\r\n if (nodeC === nodeB)\r\n break;\r\n nodeC = nodeC.faceSuccessor;\r\n }\r\n return context.classifyCounts();\r\n }\r\n /**\r\n * Collect boundary edges starting from `seed`.\r\n * * If `seed` is not a boundary node or is already visited, the function exists early.\r\n * @param seed start node.\r\n * @param visitMask mask to set on processed nodes.\r\n * @param isBoundaryEdge function to test if an edge in a boundary edge.\r\n * @param announceEdgeInBoundary callback invoked on each edge in the boundary loop in order. The counter is zero\r\n * for the first edge, and incremented with each successive edge.\r\n */\r\n public static collectExtendedBoundaryLoopFromSeed(\r\n seed: HalfEdge,\r\n visitMask: HalfEdgeMask,\r\n isBoundaryEdge: HalfEdgeToBooleanFunction,\r\n announceEdgeInBoundary: (edge: HalfEdge, counter: number) => void,\r\n ): void {\r\n let counter = 0;\r\n while (!seed.getMask(visitMask) && isBoundaryEdge(seed)) {\r\n announceEdgeInBoundary(seed, counter++);\r\n seed.setMask(visitMask);\r\n const vertexBase = seed.faceSuccessor;\r\n let candidateAroundVertex = vertexBase;\r\n for (; ;) {\r\n if (candidateAroundVertex.getMask(visitMask)) // end of boundary loop\r\n return;\r\n if (isBoundaryEdge(candidateAroundVertex)) {\r\n seed = candidateAroundVertex;\r\n break;\r\n }\r\n candidateAroundVertex = candidateAroundVertex.vertexPredecessor;\r\n if (candidateAroundVertex === vertexBase)\r\n break; // prevent infinite loop in case exteriorMask is not set on the edge mate of the boundary edge\r\n }\r\n }\r\n }\r\n /**\r\n * Collect boundary edges in the graph.\r\n * * A boundary edge is defined by `exteriorMask` being set on only its \"exterior\" edge mate.\r\n * * Each boundary edge is identified in the output by its edge mate that lacks `exteriorMask`.\r\n * * Each inner array is ordered in the output so that its boundary edges form a connected path. If `exteriorMask`\r\n * is preset consistently around each \"exterior\" face, these paths are loops.\r\n * @param graph the graph to query\r\n * @param exteriorMask mask preset on exactly one side of boundary edges\r\n * @returns array of boundary loops, each loop an array of the unmasked mates of boundary edges\r\n */\r\n public static collectExtendedBoundaryLoopsInGraph(graph: HalfEdgeGraph, exteriorMask: HalfEdgeMask): HalfEdge[][] {\r\n // Illustration of the algorithm can be found at geometry/internaldocs/Graph.md\r\n const loops: HalfEdge[][] = [];\r\n const visitMask = graph.grabMask(true);\r\n const isBoundaryEdge = (edge: HalfEdge): boolean => {\r\n return edge.getMask(exteriorMask) === 0 && edge.edgeMate.getMask(exteriorMask) !== 0;\r\n };\r\n const announceEdgeInBoundary = (edge: HalfEdge, counter: number) => {\r\n if (counter === 0)\r\n loops.push([]);\r\n loops[loops.length - 1].push(edge);\r\n };\r\n for (const seed of graph.allHalfEdges) {\r\n this.collectExtendedBoundaryLoopFromSeed(seed, visitMask, isBoundaryEdge, announceEdgeInBoundary);\r\n }\r\n graph.dropMask(visitMask);\r\n return loops;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"HalfEdgeGraphSearch.js","sourceRoot":"","sources":["../../../src/topology/HalfEdgeGraphSearch.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAY,aAAa,EAAE,YAAY,EAAiE,MAAM,SAAS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AC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC,CAAC;QACF,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YACtC,IAAI,CAAC,mCAAmC,CAAC,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,sBAAsB,CAAC,CAAC;QACpG,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,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 Topology\r\n */\r\nimport { Range1d } from \"../geometry3d/Range\";\r\nimport { HalfEdge, HalfEdgeGraph, HalfEdgeMask, HalfEdgeToBooleanFunction, NodeFunction, NodeToNumberFunction } from \"./Graph\";\r\nimport { SignedDataSummary } from \"./SignedDataSummary\";\r\nimport { XYParitySearchContext } from \"./XYParitySearchContext\";\r\n\r\n// cspell:word internaldocs\r\n\r\n/**\r\n * Interface for an object that executes boolean tests on edges.\r\n * @internal\r\n */\r\nexport interface HalfEdgeTestObject {\r\n testEdge(h: HalfEdge): boolean;\r\n}\r\n/**\r\n * Class to test match of half edge mask.\r\n * @internal\r\n */\r\nexport class HalfEdgeMaskTester {\r\n private _targetMask: HalfEdgeMask;\r\n private _targetValue: boolean;\r\n /**\r\n * Constructor\r\n * @param mask mask to test in `testEdge` function\r\n * @param targetValue value to match for true return\r\n */\r\n public constructor(mask: HalfEdgeMask, targetValue: boolean = true) {\r\n this._targetMask = mask;\r\n this._targetValue = targetValue;\r\n }\r\n /** Return true if the value of the targetMask matches the targetValue. */\r\n public testEdge(edge: HalfEdge): boolean {\r\n return edge.isMaskSet(this._targetMask) === this._targetValue;\r\n }\r\n}\r\n/**\r\n * Class for different types of searches for HalfEdgeGraph.\r\n * @internal\r\n */\r\nexport class HalfEdgeGraphSearch {\r\n /**\r\n * Static method for face area computation -- useful as function parameter in `collectFaceAreaSummary`.\r\n * * This simply calls `node.signedFaceArea()`\r\n * @param node instance for signedFaceArea call.\r\n */\r\n public static signedFaceArea(node: HalfEdge): number {\r\n return node.signedFaceArea();\r\n }\r\n /**\r\n * Return a summary of face data (e.g., area) as computed by the callback on the faces of the graph.\r\n * * Callers with curved edge graphs must supply their own area function.\r\n * @param source graph or array of nodes to examine.\r\n * @param collectAllNodes flag to pass to the `SignedDataSummary` constructor to control collection of nodes.\r\n * @param areaFunction function to obtain area (or other numeric value). Default computes polygonal face area.\r\n */\r\n public static collectFaceAreaSummary(\r\n source: HalfEdgeGraph | HalfEdge[],\r\n collectAllNodes: boolean = false,\r\n areaFunction: NodeToNumberFunction = (node) => HalfEdgeGraphSearch.signedFaceArea(node),\r\n ): SignedDataSummary<HalfEdge> {\r\n const result = new SignedDataSummary<HalfEdge>(collectAllNodes);\r\n let allFaces: HalfEdge[];\r\n if (source instanceof HalfEdgeGraph)\r\n allFaces = source.collectFaceLoops();\r\n else\r\n allFaces = source;\r\n for (const node of allFaces) {\r\n const area = areaFunction(node);\r\n result.announceItem(node, area);\r\n }\r\n return result;\r\n }\r\n /**\r\n * Search the graph for the face with the most negative area.\r\n * * If the graph has exactly one connected component, this is its outer face.\r\n * @param oneCandidateNodePerFace graph or an array containing one node from each face to be considered.\r\n * @returns node on the negative area face with largest absolute area, or `undefined` if no negative area face.\r\n */\r\n public static findMinimumAreaFace(\r\n oneCandidateNodePerFace: HalfEdgeGraph | HalfEdge[], faceAreaFunction?: NodeToNumberFunction,\r\n ): HalfEdge | undefined {\r\n const summary = HalfEdgeGraphSearch.collectFaceAreaSummary(oneCandidateNodePerFace, false, faceAreaFunction);\r\n return summary.largestNegativeItem;\r\n }\r\n /**\r\n * Test if the graph is triangulated.\r\n * * Return `false` if:\r\n * * number of positive area faces with more than 3 edges is larger than `numPositiveExceptionsAllowed`.\r\n * * graph has more than 1 negative area face when `allowMultipleNegativeAreaFaces` is `false`.\r\n * * 2-edge faces are ignored.\r\n */\r\n public static isTriangulatedCCW(\r\n source: HalfEdgeGraph | HalfEdge[],\r\n allowMultipleNegativeAreaFaces: boolean = true,\r\n numPositiveExceptionsAllowed: number = 0,\r\n ): boolean {\r\n let allFaces: HalfEdge[];\r\n if (source instanceof HalfEdgeGraph)\r\n allFaces = source.collectFaceLoops();\r\n else\r\n allFaces = source;\r\n let numNegative = 0;\r\n let numPositiveExceptions = 0;\r\n for (const node of allFaces) {\r\n const numEdges = node.countEdgesAroundFace();\r\n if (numEdges >= 3) {\r\n const area = node.signedFaceArea();\r\n if (area > 0) {\r\n if (numEdges > 3) {\r\n numPositiveExceptions++;\r\n if (numPositiveExceptions > numPositiveExceptionsAllowed)\r\n return false;\r\n }\r\n } else {\r\n numNegative++;\r\n if (numNegative > 1) {\r\n if (!allowMultipleNegativeAreaFaces)\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n /**\r\n * Process a face during graph traversal.\r\n * @param faceSeed a node in the face.\r\n * @param mask mask to set on each node of the face.\r\n * @param allNodeStack array appended with each node of the face.\r\n * @param onePerFaceStack array appended with `faceSeed`.\r\n */\r\n private static pushAndMaskAllNodesInFace(\r\n faceSeed: HalfEdge, mask: number, allNodeStack: HalfEdge[], onePerFaceStack: HalfEdge[],\r\n ): void {\r\n onePerFaceStack.push(faceSeed);\r\n faceSeed.collectAroundFace((node: HalfEdge) => {\r\n node.setMask(mask);\r\n allNodeStack.push(node);\r\n });\r\n }\r\n /**\r\n * Traverse (via Depth First Search) to all accessible faces from the given seed.\r\n * @param faceSeed first node to start the traverse.\r\n * @param visitMask mask applied to all faces as visited.\r\n * @param parityEdgeTester function to test if an edge is adjacent to two faces of opposite parity, e.g., a boundary\r\n * edge that separates an \"interior\" face and an \"exterior\" face. If `parityEdgeTester` is not supplied and `parityMask`\r\n * is supplied, the default parity rule is to alternate parity state in a \"bullseye\" pattern starting at the seed face,\r\n * with each successive concentric ring of faces at constant topological distance from the seed face receiving the\r\n * opposite parity state of the previous ring.\r\n * @param parityMask mask to apply to the first face and faces that share the same parity as the first face, as\r\n * determined by the parity rule. If this is `NULL_MASK`, there is no record of parity. If (non-null) parity mask\r\n * is given, on return it is entirely set or entirely clear around each face.\r\n * @returns an array that contains one representative node in each face of the connected component.\r\n */\r\n private static parityFloodFromSeed(\r\n faceSeed: HalfEdge,\r\n visitMask: HalfEdgeMask,\r\n parityEdgeTester: HalfEdgeTestObject | undefined,\r\n parityMask: HalfEdgeMask,\r\n ): HalfEdge[] {\r\n const faces: HalfEdge[] = [];\r\n if (faceSeed.isMaskSet(visitMask))\r\n return faces; // empty array\r\n const allMasks = parityMask | visitMask;\r\n const stack: HalfEdge[] = [];\r\n // the seed face is arbitrarily assigned the parity mask\r\n HalfEdgeGraphSearch.pushAndMaskAllNodesInFace(faceSeed, allMasks, stack, faces);\r\n while (stack.length > 0) {\r\n const p = stack.pop()!;\r\n const mate = p.edgeMate;\r\n if (!mate)\r\n continue;\r\n if (!mate.isMaskSet(visitMask)) {\r\n let newState = p.isMaskSet(parityMask);\r\n if (!parityEdgeTester || parityEdgeTester.testEdge(p))\r\n newState = !newState;\r\n HalfEdgeGraphSearch.pushAndMaskAllNodesInFace(mate, newState ? allMasks : visitMask, stack, faces);\r\n }\r\n }\r\n return faces;\r\n }\r\n /**\r\n * * Correct the parity mask in the faces of a component.\r\n * * It is assumed that the parity mask is applied _consistently_ throughout the supplied faces, but maybe\r\n * not _correctly_.\r\n * * A consistently applied parity mask is \"correct\" if it is set on the negative area (\"exterior\") face of\r\n * a connected component.\r\n * * This method finds a face with negative area and toggles the mask throughout the input faces if this face\r\n * lacks the parity mask.\r\n * * In a properly merged planar subdivision there should be only one true negative area face per component.\r\n */\r\n private static correctParityInSingleComponent(parityMask: HalfEdgeMask, faces: HalfEdge[]): void {\r\n const exteriorHalfEdge = HalfEdgeGraphSearch.findMinimumAreaFace(faces);\r\n if (!exteriorHalfEdge) {\r\n // graph has all degenerate faces; do nothing\r\n } else if (exteriorHalfEdge.isMaskSet(parityMask)) {\r\n // all should be well; nothing to do\r\n } else {\r\n for (const faceSeed of faces) {\r\n if (faceSeed.isMaskSet(parityMask)) {\r\n faceSeed.clearMaskAroundFace(parityMask);\r\n } else {\r\n faceSeed.setMaskAroundFace(parityMask);\r\n }\r\n }\r\n }\r\n }\r\n /** Apply `correctParityInSingleComponent` to each array in components (quick exit if `parityMask` is `NULL_MASK`). */\r\n private static correctParityInComponentArrays(parityMask: HalfEdgeMask, components: HalfEdge[][]): void {\r\n if (parityMask === HalfEdgeMask.NULL_MASK)\r\n return;\r\n for (const facesInComponent of components)\r\n HalfEdgeGraphSearch.correctParityInSingleComponent(parityMask, facesInComponent);\r\n }\r\n /**\r\n * Collect connected components of the graph (via Depth First Search).\r\n * @param graph graph to inspect.\r\n * @param parityEdgeTester (optional) function to test if an edge is adjacent to two faces of opposite parity,\r\n * e.g., a boundary edge that separates an \"interior\" face and an \"exterior\" face. If `parityEdgeTester` is not\r\n * supplied and `parityMask` is supplied, the default parity rule is to alternate parity state in a \"bullseye\"\r\n * pattern starting at the seed face, with each successive concentric ring of faces at constant topological\r\n * distance from the seed face receiving the opposite parity state of the previous ring.\r\n * @param parityMask (optional) mask to apply to the first face and faces that share the same parity as the\r\n * first face, as determined by the parity rule. If this is `NULL_MASK`, there is no record of parity. If\r\n * (non-null) parity mask is given, on return it is entirely set or entirely clear around each face.\r\n * @returns the components of the graph, each component represented by an array of nodes, one node per face\r\n * of the component. In other words, entry [i][j] is a HalfEdge in the j_th face loop of the i_th component.\r\n */\r\n public static collectConnectedComponentsWithExteriorParityMasks(\r\n graph: HalfEdgeGraph,\r\n parityEdgeTester: HalfEdgeTestObject | undefined,\r\n parityMask: HalfEdgeMask = HalfEdgeMask.NULL_MASK,\r\n ): HalfEdge[][] {\r\n // Illustration of the algorithm can be found at geometry/internaldocs/Graph.md\r\n const components = [];\r\n const visitMask = HalfEdgeMask.VISITED;\r\n const allMasks = parityMask | visitMask;\r\n graph.clearMask(allMasks);\r\n for (const faceSeed of graph.allHalfEdges) {\r\n if (!faceSeed.isMaskSet(visitMask)) {\r\n const newFaces = HalfEdgeGraphSearch.parityFloodFromSeed(faceSeed, visitMask, parityEdgeTester, parityMask);\r\n // parityFloodFromSeed does not return an empty array because it is called on an unvisited faceSeed\r\n components.push(newFaces);\r\n }\r\n }\r\n HalfEdgeGraphSearch.correctParityInComponentArrays(parityMask, components);\r\n return components;\r\n }\r\n /**\r\n * Breadth First Search through connected component of a graph.\r\n * @param component vector of nodes, one per face.\r\n * @param seed seed node in component.\r\n * @param visitMask mask to apply to visited nodes. Assumed cleared throughout component.\r\n * @param ignoreMask (optional) mask preset on faces to ignore. Default value is `HalfEdgeMask.EXTERIOR` to\r\n * ignore exterior faces. Pass `HalfEdgeMask.NULL_MASK` to process all faces.\r\n * @param maxFaceCount (optional) maximum number of faces in the component. Should be positive; otherwise\r\n * `Infinity` is used.\r\n * @returns node at which to start next component if maximum face count exceeded, or undefined.\r\n */\r\n private static exploreComponent(\r\n component: HalfEdge[],\r\n seed: HalfEdge,\r\n visitMask: HalfEdgeMask,\r\n ignoreMask: HalfEdgeMask = HalfEdgeMask.EXTERIOR,\r\n maxFaceCount: number = Infinity,\r\n ): HalfEdge | undefined {\r\n if (maxFaceCount <= 0)\r\n maxFaceCount = Infinity;\r\n const boundaryMask: HalfEdgeMask = visitMask | ignoreMask;\r\n let numFaces = 0;\r\n const candidates: HalfEdge[] = []; // the queue\r\n candidates.push(seed);\r\n while (candidates.length !== 0 && numFaces < maxFaceCount) {\r\n // shift is O(n) and may be inefficient for large queues; if needed, we can replace\r\n // queue by circular array or implement the queue using 2 stacks; both are O(1)\r\n const node = candidates.shift()!;\r\n if (node.isMaskSet(boundaryMask))\r\n continue;\r\n component.push(node);\r\n ++numFaces;\r\n const enqueueNeighboringFaces: NodeFunction = (heNode: HalfEdge) => {\r\n heNode.setMask(visitMask);\r\n const neighbor = heNode.vertexSuccessor;\r\n if (!neighbor.isMaskSet(boundaryMask))\r\n candidates.push(neighbor);\r\n };\r\n node.collectAroundFace(enqueueNeighboringFaces);\r\n }\r\n if (candidates.length === 0)\r\n return undefined;\r\n else {\r\n const front = candidates[0];\r\n while (candidates.length !== 0) {\r\n // try to find a node at the boundary of both the geometry and previous component\r\n const node = candidates.shift()!; // shift may be inefficient for large queues\r\n if (node.vertexSuccessor.isMaskSet(ignoreMask))\r\n return node;\r\n if (node.edgeMate.isMaskSet(ignoreMask))\r\n return node;\r\n }\r\n return front;\r\n }\r\n }\r\n /**\r\n * Collect connected components of the graph (via Breadth First Search).\r\n * @param graph graph to inspect.\r\n * @param maxFaceCount (optional) maximum number of faces in each component. Should be positive; otherwise\r\n * `Infinity` is used.\r\n * @param ignoreMask (optional) mask preset on faces to ignore. Default value is `HalfEdgeMask.EXTERIOR` to ignore\r\n * exterior faces. Pass `HalfEdgeMask.NULL_MASK` to process all faces.\r\n * @returns the components of the graph, each component represented by an array of nodes, one node per face\r\n * of the component. In other words, entry [i][j] is a HalfEdge in the j_th face loop of the i_th component.\r\n */\r\n public static collectConnectedComponents(\r\n graph: HalfEdgeGraph,\r\n maxFaceCount: number = Infinity,\r\n ignoreMask: HalfEdgeMask = HalfEdgeMask.EXTERIOR,\r\n ): HalfEdge[][] {\r\n const components: HalfEdge[][] = [];\r\n if (graph.countMask(ignoreMask) === 0)\r\n ignoreMask = HalfEdgeMask.NULL_MASK;\r\n const visitMask = HalfEdgeMask.VISITED;\r\n const boundaryMask: HalfEdgeMask = visitMask | ignoreMask;\r\n // Starting with the input node, look ahead for a boundary face. Failing that, return the input node.\r\n // Starting all floods at the boundary reduces the chance of ending up with a ring-shaped component at the boundary.\r\n const findNextFloodSeed = (index: number) => {\r\n for (let i = index; i < graph.countNodes(); ++i) {\r\n if (!graph.allHalfEdges[i].isMaskSet(boundaryMask)\r\n && graph.allHalfEdges[i].edgeMate.isMaskSet(boundaryMask)) {\r\n index = i;\r\n break;\r\n }\r\n }\r\n return index;\r\n };\r\n for (let i = 0; i < graph.countNodes(); ++i) {\r\n if (graph.allHalfEdges[i].isMaskSet(boundaryMask))\r\n continue;\r\n const i0 = findNextFloodSeed(i);\r\n let seed: HalfEdge | undefined = graph.allHalfEdges[i0];\r\n do { // flood this component\r\n const component: HalfEdge[] = [];\r\n seed = HalfEdgeGraphSearch.exploreComponent(component, seed, visitMask, ignoreMask, maxFaceCount);\r\n if (component.length !== 0)\r\n components.push(component);\r\n } while (seed !== undefined);\r\n if (!graph.allHalfEdges[i].isMaskSet(visitMask))\r\n --i; // reprocess this node\r\n }\r\n return components;\r\n }\r\n /**\r\n * Test if test point (xTest,yTest) is inside/outside a face or on an edge.\r\n * @param seedNode any node on the face loop.\r\n * @param xTest x coordinate of the test point.\r\n * @param yTest y coordinate of the test point.\r\n * @returns 0 if ON, 1 if IN, -1 if OUT.\r\n */\r\n public static pointInOrOnFaceXY(seedNode: HalfEdge, xTest: number, yTest: number): number | undefined {\r\n const context = new XYParitySearchContext(xTest, yTest);\r\n // walk around looking for an accepted node to start the search (seedNode is usually ok)\r\n let nodeA = seedNode;\r\n let nodeB = seedNode.faceSuccessor;\r\n for (; ; nodeA = nodeB) {\r\n if (context.tryStartEdge(nodeA.x, nodeA.y, nodeB.x, nodeB.y))\r\n break;\r\n if (nodeB === seedNode) {\r\n // the test point and the face are all on line \"y = yTest\"\r\n const range = Range1d.createXX(nodeB.x, nodeB.faceSuccessor.x);\r\n return range.containsX(xTest) ? 0 : -1;\r\n }\r\n nodeB = nodeA.faceSuccessor;\r\n }\r\n // nodeB is the real start node for search, so stop when we revisit it. For each edge, accumulate parity and hits\r\n let nodeC = nodeB.faceSuccessor;\r\n for (; ;) {\r\n if (!context.advance(nodeC.x, nodeC.y)) {\r\n return context.classifyCounts();\r\n }\r\n if (nodeC === nodeB)\r\n break;\r\n nodeC = nodeC.faceSuccessor;\r\n }\r\n return context.classifyCounts();\r\n }\r\n /**\r\n * Collect boundary edges starting from `seed`.\r\n * * If `seed` is not a boundary node or is already visited, the function exists early.\r\n * @param seed start node.\r\n * @param visitMask mask to set on processed nodes.\r\n * @param isBoundaryEdge function to test if an edge in a boundary edge.\r\n * @param announceEdgeInBoundary callback invoked on each edge in the boundary loop in order. The counter is zero\r\n * for the first edge, and incremented with each successive edge.\r\n */\r\n public static collectExtendedBoundaryLoopFromSeed(\r\n seed: HalfEdge,\r\n visitMask: HalfEdgeMask,\r\n isBoundaryEdge: HalfEdgeToBooleanFunction,\r\n announceEdgeInBoundary: (edge: HalfEdge, counter: number) => void,\r\n ): void {\r\n let counter = 0;\r\n while (!seed.getMask(visitMask) && isBoundaryEdge(seed)) {\r\n announceEdgeInBoundary(seed, counter++);\r\n seed.setMask(visitMask);\r\n const vertexBase = seed.faceSuccessor;\r\n let candidateAroundVertex = vertexBase;\r\n for (; ;) {\r\n if (candidateAroundVertex.getMask(visitMask)) // end of boundary loop\r\n return;\r\n if (isBoundaryEdge(candidateAroundVertex)) {\r\n seed = candidateAroundVertex;\r\n break;\r\n }\r\n candidateAroundVertex = candidateAroundVertex.vertexPredecessor;\r\n if (candidateAroundVertex === vertexBase)\r\n break; // prevent infinite loop in case exteriorMask is not set on the edge mate of the boundary edge\r\n }\r\n }\r\n }\r\n /**\r\n * Collect boundary edges in the graph.\r\n * * A boundary edge is defined by `exteriorMask` being set on only its \"exterior\" edge mate.\r\n * * Each boundary edge is identified in the output by its edge mate that lacks `exteriorMask`.\r\n * * Each inner array is ordered in the output so that its boundary edges form a connected path. If `exteriorMask`\r\n * is preset consistently around each \"exterior\" face, these paths are loops.\r\n * @param graph the graph to query\r\n * @param exteriorMask mask preset on exactly one side of boundary edges\r\n * @returns array of boundary loops, each loop an array of the unmasked mates of boundary edges\r\n */\r\n public static collectExtendedBoundaryLoopsInGraph(graph: HalfEdgeGraph, exteriorMask: HalfEdgeMask): HalfEdge[][] {\r\n // Illustration of the algorithm can be found at geometry/internaldocs/Graph.md\r\n const loops: HalfEdge[][] = [];\r\n const visitMask = graph.grabMask(true);\r\n const isBoundaryEdge = (edge: HalfEdge): boolean => {\r\n return edge.getMask(exteriorMask) === 0 && edge.edgeMate.getMask(exteriorMask) !== 0;\r\n };\r\n const announceEdgeInBoundary = (edge: HalfEdge, counter: number) => {\r\n if (counter === 0)\r\n loops.push([]);\r\n loops[loops.length - 1].push(edge);\r\n };\r\n for (const seed of graph.allHalfEdges) {\r\n this.collectExtendedBoundaryLoopFromSeed(seed, visitMask, isBoundaryEdge, announceEdgeInBoundary);\r\n }\r\n graph.dropMask(visitMask);\r\n return loops;\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-geometry",
|
|
3
|
-
"version": "5.1.0-dev.
|
|
3
|
+
"version": "5.1.0-dev.25",
|
|
4
4
|
"description": "iTwin.js Core Geometry library",
|
|
5
5
|
"main": "lib/cjs/core-geometry.js",
|
|
6
6
|
"module": "lib/esm/core-geometry.js",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"rimraf": "^6.0.1",
|
|
32
32
|
"typescript": "~5.6.2",
|
|
33
33
|
"vitest": "^3.0.6",
|
|
34
|
-
"@itwin/build-tools": "5.1.0-dev.
|
|
34
|
+
"@itwin/build-tools": "5.1.0-dev.25"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"flatbuffers": "~1.12.0",
|
|
38
|
-
"@itwin/core-bentley": "5.1.0-dev.
|
|
38
|
+
"@itwin/core-bentley": "5.1.0-dev.25"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "npm run -s build:cjs && npm run -s build:esm",
|