@itwin/core-geometry 4.3.0-dev.14 → 4.3.0-dev.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"ClipUtils.js","sourceRoot":"","sources":["../../../src/clipping/ClipUtils.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAA4D,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEnH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG1E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EA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WAAW,KAAK,SAAS;QAC3B,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;SAClC;QACH,KAAK,MAAM,CAAC,IAAI,SAAS;YACvB,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvB;IACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AACvB,CAAC;AACD;;;;;;;;;GASG;AACH,SAAS,mBAAmB,CAC1B,MAAsB,EACtB,SAA6B,EAC7B,UAA0C,EAC1C,WAA2C,EAC3C,cAA8C,EAC9C,UAAiC;IAEjC,IAAI,WAAW,CAAC;IAChB,IAAI,MAAM,KAAK,cAAc,CAAC,QAAQ;QACpC,WAAW,GAAG,UAAU,CAAC;SACtB,IAAI,MAAM,KAAK,cAAc,CAAC,SAAS;QAC1C,WAAW,GAAG,WAAW,CAAC;SACvB,IAAI,MAAM,KAAK,cAAc,CAAC,cAAc;QAC/C,WAAW,GAAG,cAAc,CAAC;IAC/B,4EAA4E;IAC5E,IAAI,WAAW,KAAK,SAAS;QAC3B,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;SAClC;QACH,KAAK,MAAM,CAAC,IAAI,SAAS;YACvB,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvB;IACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AACvB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\nimport { Arc3d } from \"../curve/Arc3d\";\r\nimport { AnyCurve, AnyRegion } from \"../curve/CurveTypes\";\r\nimport { BagOfCurves } from \"../curve/CurveCollection\";\r\nimport { CurveFactory } from \"../curve/CurveFactory\";\r\nimport { AnnounceNumberNumber, AnnounceNumberNumberCurvePrimitive, CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { GeometryQuery } from \"../curve/GeometryQuery\";\r\nimport { LineString3d } from \"../curve/LineString3d\";\r\nimport { Loop } from \"../curve/Loop\";\r\nimport { Path } from \"../curve/Path\";\r\nimport { RegionBinaryOpType, RegionOps } from \"../curve/RegionOps\";\r\nimport { UnionRegion } from \"../curve/UnionRegion\";\r\nimport { Geometry } from \"../Geometry\";\r\nimport { FrameBuilder } from \"../geometry3d/FrameBuilder\";\r\nimport { GrowableFloat64Array } from \"../geometry3d/GrowableFloat64Array\";\r\nimport { GrowableXYZArray } from \"../geometry3d/GrowableXYZArray\";\r\nimport { IndexedXYZCollection } from \"../geometry3d/IndexedXYZCollection\";\r\nimport { Plane3dByOriginAndUnitNormal } from \"../geometry3d/Plane3dByOriginAndUnitNormal\";\r\nimport { Point3dArrayCarrier } from \"../geometry3d/Point3dArrayCarrier\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Range1d, Range3d } from \"../geometry3d/Range\";\r\nimport { GrowableXYZArrayCache } from \"../geometry3d/ReusableObjectCache\";\r\nimport { Transform } from \"../geometry3d/Transform\";\r\nimport { XAndY } from \"../geometry3d/XYZProps\";\r\nimport { PolyfaceBuilder } from \"../polyface/PolyfaceBuilder\";\r\nimport { ClipPlane } from \"./ClipPlane\";\r\nimport { ClipPrimitive } from \"./ClipPrimitive\";\r\nimport { ClipVector } from \"./ClipVector\";\r\nimport { ConvexClipPlaneSet } from \"./ConvexClipPlaneSet\";\r\nimport { LineStringOffsetClipperContext } from \"./internalContexts/LineStringOffsetClipperContext\";\r\nimport { UnionOfConvexClipPlaneSets } from \"./UnionOfConvexClipPlaneSets\";\r\n\r\n/**\r\n * Enumerated type for describing where geometry lies with respect to clipping planes.\r\n * @public\r\n */\r\nexport enum ClipPlaneContainment {\r\n /** All points inside. */\r\n StronglyInside = 1,\r\n /** Inside/outside state unknown. */\r\n Ambiguous = 2,\r\n /** All points outside. */\r\n StronglyOutside = 3,\r\n}\r\n/**\r\n * Enumeration of ways to handle an intermediate fragment from a clipping step.\r\n * @public\r\n */\r\nexport enum ClipStepAction {\r\n /** Pass fragments directly to final accepted \"in\" state. */\r\n acceptIn = 1,\r\n /** Pass fragments directly to final accepted \"out\" state. */\r\n acceptOut = -1,\r\n /** Forward fragments to subsequent steps. */\r\n passToNextStep = 0,\r\n}\r\n\r\n/**\r\n * Enumerated type for describing what must yet be done to clip a piece of geometry.\r\n * @public\r\n */\r\nexport enum ClipStatus {\r\n /** Some geometry may cross the clip boundaries */\r\n ClipRequired,\r\n /** Geometry is clearly outside */\r\n TrivialReject,\r\n /** Geometry is clearly inside */\r\n TrivialAccept,\r\n}\r\n\r\n/**\r\n * An object containing clipping planes that can be used to clip geometry.\r\n * @public\r\n */\r\nexport interface Clipper {\r\n /** Test if `point` is on or inside the Clipper's volume. */\r\n isPointOnOrInside(point: Point3d, tolerance?: number): boolean;\r\n /**\r\n * Find the parts of the line segment (if any) that is within the convex clip volume.\r\n * * The line segment is defined by `pointA` and `pointB`.\r\n * * The input fractional interval from `fraction0` to `fraction1` (increasing) is the active part to consider.\r\n * * To clip to the usual bounded line segment, start with fractions (0,1).\r\n * If the clip volume is unbounded, the line interval may also be unbounded.\r\n * * An unbounded line portion will have fraction coordinates positive or negative `Number.MAX_VALUE`.\r\n * @param f0 fraction that is the initial lower fraction of the active interval (e.g., 0.0 for bounded segment).\r\n * @param f1 fraction that is the initial upper fraction of the active interval (e.g., 1.0 for bounded segment).\r\n * @param pointA segment start (fraction 0)\r\n * @param pointB segment end (fraction 1)\r\n * @param announce function to be called to announce a fraction interval that is within the convex clip volume.\r\n * @returns true if a segment was announced, false if entirely outside.\r\n */\r\n announceClippedSegmentIntervals(\r\n f0: number, f1: number, pointA: Point3d, pointB: Point3d, announce?: AnnounceNumberNumber\r\n ): boolean;\r\n /**\r\n * Find the portion (or portions) of the arc (if any) that are within the convex clip volume.\r\n * @param arc the arc to be clipped.\r\n * @param announce function to be called to announce a fraction intervals that are within the convex clip volume.\r\n * @returns true if one or more arcs portions were announced, false if entirely outside.\r\n */\r\n announceClippedArcIntervals(arc: Arc3d, announce?: AnnounceNumberNumberCurvePrimitive): boolean;\r\n /**\r\n * Optional polygon clip method.\r\n * * This is expected to be implemented by planar clip structures.\r\n * * This is unimplemented for curve clippers (e.g. sphere) for which polygon clip result has curved edges.\r\n * * The input polygon must be convex.\r\n */\r\n appendPolygonClip?: AppendPolygonClipFunction;\r\n}\r\n/**\r\n * Signature of method to execute polygon clip, distributing fragments of xyz among insideFragments and outsideFragments\r\n * @param xyz convex polygon. This is not changed.\r\n * @param insideFragments Array to receive \"inside\" fragments. Each fragment is a GrowableXYZArray grabbed from\r\n * the cache. This is NOT cleared.\r\n * @param outsideFragments Array to receive \"outside\" fragments. Each fragment is a GrowableXYZArray grabbed from\r\n * the cache. This is NOT cleared.\r\n * @param arrayCache cache for reusable GrowableXYZArray.\r\n */\r\ntype AppendPolygonClipFunction = (\r\n xyz: IndexedXYZCollection,\r\n insideFragments: GrowableXYZArray[],\r\n outsideFragments: GrowableXYZArray[],\r\n arrayCache: GrowableXYZArrayCache\r\n) => void;\r\n\r\n/**\r\n * Interface for clipping convex polygons.\r\n * Supported by:\r\n * * AlternatingCCTreeNode\r\n * * ConvexClipPlaneSet\r\n * @public\r\n */\r\nexport interface PolygonClipper {\r\n appendPolygonClip: AppendPolygonClipFunction;\r\n}\r\n/**\r\n * Class whose various static methods are functions for clipping geometry\r\n * @public\r\n */\r\nexport class ClipUtilities {\r\n // on-demand scratch objects for method implementations. If you use one, make sure it isn't already being used in scope.\r\n private static _workTransform?: Transform;\r\n private static _workRange?: Range3d;\r\n private static _workClipper?: ConvexClipPlaneSet;\r\n\r\n private static _selectIntervals01TestPoint = Point3d.create();\r\n /**\r\n * Augment the unsortedFractionsArray with 0 and 1\r\n * * sort\r\n * * test the midpoint of each interval with `clipper.isPointOnOrInside`\r\n * * pass accepted intervals to `announce(f0,f1,curve)`\r\n */\r\n public static selectIntervals01(\r\n curve: CurvePrimitive,\r\n unsortedFractions: GrowableFloat64Array,\r\n clipper: Clipper,\r\n announce?: AnnounceNumberNumberCurvePrimitive,\r\n ): boolean {\r\n unsortedFractions.push(0);\r\n unsortedFractions.push(1);\r\n unsortedFractions.sort();\r\n let f0 = unsortedFractions.atUncheckedIndex(0);\r\n let f1;\r\n let fMid;\r\n const testPoint = ClipUtilities._selectIntervals01TestPoint;\r\n const n = unsortedFractions.length;\r\n for (let i = 1; i < n; i++) {\r\n f1 = unsortedFractions.atUncheckedIndex(i);\r\n if (f1 > f0 + Geometry.smallFraction) {\r\n fMid = 0.5 * (f0 + f1);\r\n if (fMid >= 0.0 && fMid <= 1.0) {\r\n curve.fractionToPoint(fMid, testPoint);\r\n if (clipper.isPointOnOrInside(testPoint)) {\r\n if (announce)\r\n announce(f0, f1, curve);\r\n else\r\n return true;\r\n }\r\n }\r\n f0 = f1;\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Announce triples of (low, high, cp) for each entry in intervals.\r\n * @param intervals source array\r\n * @param cp CurvePrimitive for announcement\r\n * @param announce function to receive data\r\n */\r\n public static announceNNC(\r\n intervals: Range1d[], cp: CurvePrimitive, announce?: AnnounceNumberNumberCurvePrimitive,\r\n ): boolean {\r\n if (announce) {\r\n for (const ab of intervals) {\r\n announce(ab.low, ab.high, cp);\r\n }\r\n }\r\n return intervals.length > 0;\r\n }\r\n /**\r\n * Compute and return portions of the input curve that are within the clipper.\r\n * @param curve input curve, unmodified\r\n * @param clipper used to compute the clipped components\r\n * @return array of clipped curves\r\n */\r\n public static collectClippedCurves(curve: CurvePrimitive, clipper: Clipper): CurvePrimitive[] {\r\n const result: CurvePrimitive[] = [];\r\n curve.announceClipIntervals(\r\n clipper,\r\n (fraction0: number, fraction1: number, curveA: CurvePrimitive) => {\r\n if (fraction1 !== fraction0) {\r\n const partialCurve = curveA.clonePartialCurve(fraction0, fraction1);\r\n if (partialCurve)\r\n result.push(partialCurve);\r\n }\r\n },\r\n );\r\n return result;\r\n }\r\n /**\r\n * Compute and return the portions of the input region that are within the clipper.\r\n * @param region input region, unmodified\r\n * @param clipper used to compute the clipped components\r\n * @return clipped subregion, as a single `AnyRegion`\r\n */\r\n public static clipAnyRegion(region: AnyRegion, clipper: Clipper): AnyRegion | undefined {\r\n let result: UnionRegion | undefined;\r\n // Create \"local region\" which is the result of rotating region to make\r\n // it parallel to the xy-plane and then translating it to the xy-plane.\r\n const localToWorld = ClipUtilities._workTransform = FrameBuilder.createRightHandedFrame(undefined, region, ClipUtilities._workTransform);\r\n if (!localToWorld)\r\n return result;\r\n const worldToLocal = localToWorld?.inverse();\r\n if (!worldToLocal)\r\n return result;\r\n const localRegion = region.cloneTransformed(worldToLocal) as AnyRegion;\r\n if (!localRegion)\r\n return result;\r\n // We can only clip convex polygons with our clipper machinery, but the input region doesn't have to be\r\n // convex or even a polygon. We get around this limitation by using a Boolean operation, which admits\r\n // *any* planar regions, albeit in local coordinates. First, we clip a rectangle that covers the input region\r\n // (in world coordinates), then we intersect the resulting fragments with the input region in local coordinates.\r\n // Finally, we assemble the results into a UnionRegion back in world coordinates.\r\n const localRegionRange = ClipUtilities._workRange = localRegion.range();\r\n const xLength = localRegionRange.xLength();\r\n const yLength = localRegionRange.yLength();\r\n const rectangle = LineString3d.createRectangleXY(localRegionRange.low, xLength, yLength, true);\r\n rectangle.tryTransformInPlace(localToWorld);\r\n // Clip the rectangle to produce fragment(s) which we can Boolean intersect with the input region.\r\n const insideFragments: GrowableXYZArray[] = [];\r\n const outsideFragments: GrowableXYZArray[] = [];\r\n const cache = new GrowableXYZArrayCache();\r\n clipper.appendPolygonClip?.(rectangle.packedPoints, insideFragments, outsideFragments, cache);\r\n if (insideFragments.length === 0)\r\n return result;\r\n // Create the \"clipped region\".\r\n for (const fragment of insideFragments) {\r\n const loop = Loop.createPolygon(fragment);\r\n loop.tryTransformInPlace(worldToLocal);\r\n const clippedLocalRegion = RegionOps.regionBooleanXY(localRegion, loop, RegionBinaryOpType.Intersection);\r\n if (clippedLocalRegion) {\r\n clippedLocalRegion.tryTransformInPlace(localToWorld);\r\n if (!result)\r\n result = (clippedLocalRegion instanceof UnionRegion) ? clippedLocalRegion : UnionRegion.create(clippedLocalRegion);\r\n else if (!result.tryAddChild(clippedLocalRegion))\r\n result.children.push(...(clippedLocalRegion as UnionRegion).children);\r\n }\r\n }\r\n return result;\r\n }\r\n /**\r\n * Compute and return portions of the input curve or region that are within the clipper.\r\n * @param curve input curve or region, unmodified\r\n * @param clipper used to compute the clipped components\r\n * @return array of clipped components of the input curve or region that lie inside the clipper\r\n */\r\n public static clipAnyCurve(curve: AnyCurve, clipper: Clipper): AnyCurve[] {\r\n if (curve instanceof CurvePrimitive)\r\n return ClipUtilities.collectClippedCurves(curve, clipper);\r\n if (curve.isAnyRegion()) {\r\n const ret = ClipUtilities.clipAnyRegion(curve, clipper);\r\n return ret ? [ret] : [];\r\n }\r\n const result: AnyCurve[] = [];\r\n if (curve instanceof Path || curve instanceof BagOfCurves) {\r\n for (const child of curve.children) {\r\n const partialClip = ClipUtilities.clipAnyCurve(child, clipper);\r\n result.push(...partialClip);\r\n }\r\n }\r\n return result;\r\n }\r\n /**\r\n * Clip a polygon down to regions defined by each shape of a ClipShape.\r\n * @return An multidimensional array of points, where each array is the boundary of part of the remaining polygon.\r\n */\r\n public static clipPolygonToClipShape(polygon: Point3d[], clipShape: ClipPrimitive): Point3d[][] {\r\n const outputA = this.clipPolygonToClipShapeReturnGrowableXYZArrays(polygon, clipShape);\r\n const output = [];\r\n for (const g of outputA)\r\n output.push(g.getPoint3dArray());\r\n return output;\r\n }\r\n /**\r\n * Clip a polygon down to regions defined by each shape of a ClipShape.\r\n * @return An multidimensional array of points, where each array is the boundary of part of the remaining polygon.\r\n */\r\n public static clipPolygonToClipShapeReturnGrowableXYZArrays(\r\n polygon: Point3d[], clipShape: ClipPrimitive,\r\n ): GrowableXYZArray[] {\r\n const output: GrowableXYZArray[] = [];\r\n const clipper = clipShape.fetchClipPlanesRef();\r\n // NEEDS WORK -- what if it is a mask !!!!\r\n if (clipper) {\r\n clipper.polygonClip(polygon, output);\r\n }\r\n return output;\r\n }\r\n /**\r\n * Given an array of points, test for trivial containment conditions.\r\n * * ClipStatus.TrivialAccept if all points are in any one of the convexSet's.\r\n * * ClipStatus.ClipRequired if (in any single convexSet) there were points on both sides of any single plane.\r\n * * ClipStatus.TrivialReject if neither of those occurred.\r\n */\r\n public static pointSetSingleClipStatus(\r\n points: GrowableXYZArray, planeSet: UnionOfConvexClipPlaneSets, tolerance: number,\r\n ): ClipStatus {\r\n if (planeSet.convexSets.length === 0)\r\n return ClipStatus.TrivialAccept;\r\n\r\n for (const convexSet of planeSet.convexSets) {\r\n let allOutsideSinglePlane = false, anyOutside = false;\r\n\r\n for (const plane of convexSet.planes) {\r\n let numInside = 0, numOutside = 0;\r\n const planeDistance = plane.distance - tolerance;\r\n\r\n const currPt = Point3d.create();\r\n const currVec = Vector3d.create();\r\n for (let i = 0; i < points.length; i++) {\r\n points.getPoint3dAtUncheckedPointIndex(i, currPt);\r\n currVec.setFrom(currPt);\r\n currVec.dotProduct(plane.inwardNormalRef) > planeDistance ? numInside++ : numOutside++;\r\n }\r\n\r\n anyOutside = (numOutside !== 0) ? true : anyOutside;\r\n if (numInside === 0) {\r\n allOutsideSinglePlane = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!anyOutside) // totally inside this set - no clip required\r\n return ClipStatus.TrivialAccept;\r\n if (!allOutsideSinglePlane)\r\n return ClipStatus.ClipRequired;\r\n }\r\n return ClipStatus.TrivialReject;\r\n }\r\n /**\r\n * Emit point loops for intersection of a convex set with a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static announceLoopsOfConvexClipPlaneSetIntersectRange(\r\n convexSet: ConvexClipPlaneSet | ClipPlane,\r\n range: Range3d,\r\n loopFunction: (loopPoints: GrowableXYZArray) => void,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): void {\r\n const work = new GrowableXYZArray();\r\n if (includeConvexSetFaces) {\r\n // Clip convexSet planes to the range and to the rest of the convexSet . .\r\n if (convexSet instanceof ConvexClipPlaneSet) {\r\n for (const plane of convexSet.planes) {\r\n if (ignoreInvisiblePlanes && plane.invisible)\r\n continue;\r\n const pointsClippedToRange = plane.intersectRange(range, true);\r\n const finalPoints = new GrowableXYZArray();\r\n if (pointsClippedToRange) {\r\n convexSet.polygonClip(pointsClippedToRange, finalPoints, work, plane);\r\n if (finalPoints.length > 0)\r\n loopFunction(finalPoints);\r\n }\r\n }\r\n } else { // `convexSet` is just one plane ...\r\n if (ignoreInvisiblePlanes && convexSet.invisible) {\r\n // skip it !\r\n } else {\r\n const pointsClippedToRange = convexSet.intersectRange(range, true);\r\n if (pointsClippedToRange)\r\n loopFunction(pointsClippedToRange);\r\n }\r\n }\r\n }\r\n\r\n if (includeRangeFaces) {\r\n // clip range faces to the convex set . . .\r\n const corners = range.corners();\r\n for (let i = 0; i < 6; i++) {\r\n const indices = Range3d.faceCornerIndices(i);\r\n const finalPoints = new GrowableXYZArray();\r\n const lineString = LineString3d.createIndexedPoints(corners, indices);\r\n if (convexSet instanceof ConvexClipPlaneSet) {\r\n convexSet.polygonClip(lineString.packedPoints, finalPoints, work);\r\n if (finalPoints.length > 0)\r\n loopFunction(finalPoints);\r\n } else {\r\n convexSet.clipConvexPolygonInPlace(lineString.packedPoints, work);\r\n if (lineString.packedPoints.length > 0)\r\n loopFunction(lineString.packedPoints);\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * Return a (possibly empty) array of geometry (Loops !!) which are facets of the intersection of the convex set\r\n * intersecting a range.\r\n * * Return zero length array for (a) null range or (b) no intersections\r\n * @param allClippers convex or union clipper\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static loopsOfConvexClipPlaneIntersectionWithRange(\r\n allClippers: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPlane,\r\n range: Range3d,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): GeometryQuery[] {\r\n const result: GeometryQuery[] = [];\r\n if (allClippers instanceof UnionOfConvexClipPlaneSets) {\r\n for (const clipper of allClippers.convexSets) {\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(clipper, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.push(Loop.createPolygon(points));\r\n },\r\n includeConvexSetFaces, includeRangeFaces, ignoreInvisiblePlanes);\r\n }\r\n } else if (allClippers instanceof ConvexClipPlaneSet || allClippers instanceof ClipPlane) {\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(allClippers, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.push(Loop.createPolygon(points));\r\n },\r\n includeConvexSetFaces, includeRangeFaces, ignoreInvisiblePlanes);\r\n }\r\n return result;\r\n }\r\n /**\r\n * Return the (possibly null) range of the intersection of the convex set with a range.\r\n * * The convex set is permitted to be unbounded (e.g. a single plane). The range parameter provides bounds.\r\n * @param convexSet convex set for intersection.\r\n * @param range range to intersect\r\n */\r\n public static rangeOfConvexClipPlaneSetIntersectionWithRange(convexSet: ConvexClipPlaneSet, range: Range3d): Range3d {\r\n const result = Range3d.createNull();\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(convexSet, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.extendArray(points);\r\n },\r\n true, true, false);\r\n return result;\r\n }\r\n /**\r\n * Return the range of various types of clippers\r\n * * `ConvexClipPlaneSet` -- dispatch to `rangeOfConvexClipPlaneSetIntersectionWithRange`\r\n * * `UnionOfConvexClipPlaneSet` -- union of ranges of member `ConvexClipPlaneSet`\r\n * * `ClipPrimitive` -- access its `UnionOfConvexClipPlaneSet`.\r\n * * `ClipVector` -- intersection of the ranges of its `ClipPrimitive`.\r\n * * `undefined` -- entire input range.\r\n * * If `observeInvisibleFlag` is false, the \"invisible\" properties are ignored, and this effectively returns the range of the edge work of the members\r\n * * If `observeInvisibleFlag` is true, the \"invisible\" properties are observed, and \"invisible\" parts do not restrict the range.\r\n * @param clipper\r\n * @param range non-null range.\r\n * @param observeInvisibleFlag indicates how \"invisible\" bit is applied for ClipPrimitive.\r\n */\r\n public static rangeOfClipperIntersectionWithRange(\r\n clipper: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPrimitive | ClipVector | undefined,\r\n range: Range3d,\r\n observeInvisibleFlag: boolean = true,\r\n ): Range3d {\r\n if (clipper === undefined)\r\n return range.clone();\r\n if (clipper instanceof ConvexClipPlaneSet)\r\n return this.rangeOfConvexClipPlaneSetIntersectionWithRange(clipper, range);\r\n if (clipper instanceof UnionOfConvexClipPlaneSets) {\r\n const rangeUnion = Range3d.createNull();\r\n for (const c of clipper.convexSets) {\r\n const rangeC = this.rangeOfConvexClipPlaneSetIntersectionWithRange(c, range);\r\n rangeUnion.extendRange(rangeC);\r\n }\r\n return rangeUnion;\r\n }\r\n if (clipper instanceof ClipPrimitive) {\r\n if (observeInvisibleFlag && clipper.invisible)\r\n return range.clone();\r\n return this.rangeOfClipperIntersectionWithRange(clipper.fetchClipPlanesRef(), range);\r\n }\r\n if (clipper instanceof ClipVector) {\r\n const rangeIntersection = range.clone();\r\n for (const c of clipper.clips) {\r\n if (observeInvisibleFlag && c.invisible) {\r\n // trivial range tests do not expose the effects. Assume the hole allows everything.\r\n } else {\r\n const rangeC = this.rangeOfClipperIntersectionWithRange(c, range, observeInvisibleFlag);\r\n rangeIntersection.intersect(rangeC, rangeIntersection);\r\n }\r\n }\r\n return rangeIntersection;\r\n\r\n }\r\n return range.clone();\r\n }\r\n /**\r\n * Test if various types of clippers have any intersection with a range.\r\n * * This follows the same logic as `rangeOfClipperIntersectionWithRange` but attempts to exit at earliest point of confirmed intersection\r\n * * `ConvexClipPlaneSet` -- dispatch to `doesConvexClipPlaneSetIntersectRange`\r\n * * `UnionOfConvexClipPlaneSet` -- union of ranges of member `ConvexClipPlaneSet`\r\n * * `ClipPrimitive` -- access its `UnionOfConvexClipPlaneSet`.\r\n * * `ClipVector` -- intersection of the ranges of its `ClipPrimitive`.\r\n * * `undefined` -- entire input range.\r\n * * If `observeInvisibleFlag` is false, the \"invisible\" properties are ignored, and holes do not affect the result.\r\n * * If `observeInvisibleFlag` is true, the \"invisible\" properties are observed, and may affect the result.\r\n * @param clipper\r\n * @param range non-null range.\r\n * @param observeInvisibleFlag indicates how \"invisible\" bit is applied for ClipPrimitive.\r\n */\r\n public static doesClipperIntersectRange(\r\n clipper: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPrimitive | ClipVector | undefined,\r\n range: Range3d,\r\n observeInvisibleFlag: boolean = true,\r\n ): boolean {\r\n if (clipper === undefined)\r\n return true;\r\n\r\n if (clipper instanceof ConvexClipPlaneSet)\r\n return this.doesConvexClipPlaneSetIntersectRange(clipper, range);\r\n\r\n if (clipper instanceof UnionOfConvexClipPlaneSets) {\r\n for (const c of clipper.convexSets) {\r\n if (this.doesConvexClipPlaneSetIntersectRange(c, range))\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n if (clipper instanceof ClipPrimitive) {\r\n if (observeInvisibleFlag && clipper.invisible) // um is there an easy way to detect range-completely-inside?\r\n return true;\r\n return this.doesClipperIntersectRange(clipper.fetchClipPlanesRef(), range);\r\n }\r\n\r\n if (clipper instanceof ClipVector) {\r\n const rangeIntersection = range.clone();\r\n for (const c of clipper.clips) {\r\n if (observeInvisibleFlag && c.invisible) {\r\n // trivial range tests do not expose the effects. Assume the hole allows everything.\r\n } else {\r\n const rangeC = this.rangeOfClipperIntersectionWithRange(c, range, observeInvisibleFlag);\r\n rangeIntersection.intersect(rangeC, rangeIntersection);\r\n }\r\n }\r\n return !rangeIntersection.isNull;\r\n }\r\n /** If the case statement above is complete for the variant inputs, this is unreachable .. */\r\n return false;\r\n }\r\n /**\r\n * Emit point loops for intersection of a convex set with a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static doesConvexClipPlaneSetIntersectRange(\r\n convexSet: ConvexClipPlaneSet,\r\n range: Range3d,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): boolean {\r\n const work = new GrowableXYZArray();\r\n if (includeConvexSetFaces) {\r\n // Clip convexSet planes to the range and to the rest of the convexSet . .\r\n for (const plane of convexSet.planes) {\r\n if (ignoreInvisiblePlanes && plane.invisible)\r\n continue;\r\n const pointsClippedToRange = plane.intersectRange(range, true);\r\n if (pointsClippedToRange) {\r\n const finalPoints = new GrowableXYZArray();\r\n convexSet.polygonClip(pointsClippedToRange, finalPoints, work, plane);\r\n if (finalPoints.length > 0)\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n if (includeRangeFaces) {\r\n // clip range faces to the convex set . . .\r\n const corners = range.corners();\r\n for (let i = 0; i < 6; i++) {\r\n const indices = Range3d.faceCornerIndices(i);\r\n const finalPoints = new GrowableXYZArray();\r\n const lineString = LineString3d.createIndexedPoints(corners, indices);\r\n convexSet.polygonClip(lineString.packedPoints, finalPoints, work);\r\n if (finalPoints.length > 0)\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Test for intersection of two ranges in different local coordinates.\r\n * * Useful for clash detection of elements in iModels, using their stored (tight) local ranges and placement transforms.\r\n * @param range0 range in local coordinates of first geometry\r\n * @param local0ToWorld placement transform for first geometry\r\n * @param range1 range in local coordinates of second geometry\r\n * @param local1ToWorld placement transform for second geometry. Assumed to be invertible.\r\n * @param range1Margin optional signed local distance to expand/contract the second range before intersection. Positive expands.\r\n * @return whether the local ranges are adjacent or intersect. Also returns false if local1ToWorld is singular.\r\n */\r\n public static doLocalRangesIntersect(\r\n range0: Range3d, local0ToWorld: Transform, range1: Range3d, local1ToWorld: Transform, range1Margin?: number,\r\n ): boolean {\r\n const worldToLocal1 = ClipUtilities._workTransform = local1ToWorld.inverse(ClipUtilities._workTransform);\r\n if (!worldToLocal1)\r\n return false;\r\n let myRange1 = range1;\r\n if (range1Margin) {\r\n myRange1 = ClipUtilities._workRange = range1.clone(ClipUtilities._workRange);\r\n myRange1.expandInPlace(range1Margin);\r\n }\r\n // convert range0 into a clipper in local1 coordinates, then intersect with range1\r\n const local0ToLocal1 = worldToLocal1.multiplyTransformTransform(local0ToWorld, worldToLocal1);\r\n const builder = PolyfaceBuilder.create();\r\n builder.addTransformedRangeMesh(local0ToLocal1, range0);\r\n const mesh0 = builder.claimPolyface();\r\n const clipper = ClipUtilities._workClipper = ConvexClipPlaneSet.createConvexPolyface(mesh0, ClipUtilities._workClipper).clipper;\r\n return ClipUtilities.doesClipperIntersectRange(clipper, myRange1);\r\n }\r\n /**\r\n * Test if `obj` is a `Clipper` object.\r\n * * This is implemented by testing for each of the methods in the `Clipper` interface.\r\n */\r\n public static isClipper(obj: any): boolean {\r\n if (obj) {\r\n if (obj.isPointOnOrInside\r\n && obj.announceClippedSegmentIntervals\r\n && obj.announceClippedArcIntervals)\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Specialized logic for replacing clip fragments by an equivalent singleton.\r\n * * If there are baseCount + 1 or fewer fragments, do nothing.\r\n * * If there are more than baseCount+1 fragments:\r\n * * drop them all to the cache\r\n * * push a copy of the singleton.\r\n * * The use case for this is that a multi-step clipper (e.g. UnionOfConvexClipPlaneSets) may produce many fragments,\r\n * and then be able to determine that they really are the original pre-clip polygon unchanged.\r\n * * The baseCount+1 case is the case where the entire original singleton is still a singleton and can be left alone.\r\n * * Calling this replacer shuffles the original back into the fragment array, and drops the fragments.\r\n * * This determination is solely within the logic of the caller.\r\n * @param shards array of fragments\r\n * @param baseCount original count\r\n * @param singleton single array which may be a replacement for multiple fragments\r\n * @param cache cache for array management\r\n */\r\n public static restoreSingletonInPlaceOfMultipleShards(\r\n fragments: GrowableXYZArray[] | undefined, baseCount: number, singleton: IndexedXYZCollection, arrayCache: GrowableXYZArrayCache,\r\n ): void {\r\n if (fragments && fragments.length > baseCount + 1) {\r\n while (fragments.length > baseCount) {\r\n const f = fragments.pop();\r\n arrayCache.dropToCache(f);\r\n }\r\n fragments.push(arrayCache.grabAndFill(singleton));\r\n }\r\n }\r\n /**\r\n * Create a UnionOfConvexClipPlaneSets for a volume defined by a path and offsets.\r\n * @param points points along the path.\r\n * @param positiveOffsetLeft offset to left. 0 is clip on the path.\r\n * @param positiveOffsetRight offset to the right. 0 is clip on the path.\r\n * @param z0 z for lower clipping plane. If undefined, unbounded in positive z\r\n * @param z1 z for upper clipping plane. If undefined, unbounded in negative z.\r\n * @alpha\r\n */\r\n public static createXYOffsetClipFromLineString(\r\n points: Point3d[] | IndexedXYZCollection, leftOffset: number, rightOffset: number, z0: number, z1: number,\r\n ): UnionOfConvexClipPlaneSets {\r\n if (Array.isArray(points)) {\r\n return LineStringOffsetClipperContext.createClipBetweenOffsets(\r\n new Point3dArrayCarrier(points), leftOffset, rightOffset, z0, z1);\r\n }\r\n return LineStringOffsetClipperContext.createClipBetweenOffsets(points, leftOffset, rightOffset, z0, z1);\r\n }\r\n /** If data.length >= minLength threshold, push it to destination; if smaller drop it back to the cache. */\r\n public static captureOrDrop(\r\n data: GrowableXYZArray, minLength: number, destination: GrowableXYZArray[], cache: GrowableXYZArrayCache,\r\n ): void {\r\n if (data.length >= minLength)\r\n destination.push(data);\r\n else\r\n cache.dropToCache(data);\r\n }\r\n /**\r\n * Find the portion of a line within a half-plane clip.\r\n * * The half-plane clip is to the left of the line from clipA to clipB.\r\n * * The original clipped segment has fractions 0 and 1 at respective segment points.\r\n * * Caller initializes the interval\r\n * * This method reduces the interval size.\r\n * * See clipSegmentToCCWTriangleXY for typical use.\r\n * @param linePointA First point of clip line\r\n * @param linePointB Second point of clip line\r\n * @param segmentPoint0 First point of clipped segment\r\n * @param segmentPoint1 Second point of clipped segment\r\n * @param interval Live interval.\r\n * @param absoluteTolerance absolute tolerance for both cross product values to indicate \"on\" the line\r\n */\r\n public static clipSegmentToLLeftOfLineXY(\r\n linePointA: XAndY, linePointB: XAndY, segmentPoint0: XAndY, segmentPoint1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n const ux = linePointB.x - linePointA.x;\r\n const uy = linePointB.y - linePointA.y;\r\n // negative is in positive is out ...\r\n const h0 = -(ux * (segmentPoint0.y - linePointA.y) - uy * (segmentPoint0.x - linePointA.x));\r\n const h1 = -(ux * (segmentPoint1.y - linePointA.y) - uy * (segmentPoint1.x - linePointA.x));\r\n if (h0 < absoluteTolerance && h1 < absoluteTolerance) {\r\n // The entire segment is in .....\r\n return;\r\n }\r\n if (h0 * h1 > 0.0) {\r\n if (h0 > 0.0)\r\n interval.setNull();\r\n } else if (h0 * h1 < 0.0) {\r\n // strict crossing with safe fraction . . .\r\n const fraction = -h0 / (h1 - h0);\r\n if (h0 < 0.0) {\r\n return interval.intersectRangeXXInPlace(0.0, fraction);\r\n } else {\r\n return interval.intersectRangeXXInPlace(fraction, 1.0);\r\n }\r\n } else {\r\n // There is an exact hit at one end, possibly non-zero at the other ... the sign of either determines which side is in play\r\n // A zero and a zero or negative is entirely in, which does not alter the prior clip.\r\n if (h0 > 0.0) {\r\n interval.intersectRangeXXInPlace(1.0, 1.0);\r\n } else if (h1 > 0.0) {\r\n interval.intersectRangeXXInPlace(0.0, 0.0);\r\n }\r\n }\r\n }\r\n /**\r\n * Clip an interval of a line segment to a triangle.\r\n * * Triangle is assumed CCW\r\n * @param pointA point of triangle.\r\n * @param pointB point of triangle.\r\n * @param pointC point of triangle.\r\n * @param segment0 start of segment\r\n * @param segment1 end of segment\r\n * @param interval Pre-initialized interval of live part of segment\r\n * @param absoluteTolerance absolute tolerance for begin \"on a line\"\r\n */\r\n public static clipSegmentToCCWTriangleXY(\r\n pointA: XAndY, pointB: XAndY, pointC: XAndY, segment0: XAndY, segment1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointA, pointB, segment0, segment1, interval, absoluteTolerance);\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointB, pointC, segment0, segment1, interval, absoluteTolerance);\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointC, pointA, segment0, segment1, interval, absoluteTolerance);\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * Find the portion of a line within a half-plane clip.\r\n * * The half-plane clip is to the left of the line from clipA to clipB.\r\n * * The original clipped segment has fractions 0 and 1 at respective segment points.\r\n * * Caller initializes the interval\r\n * * This method reduces the interval size.\r\n * * See clipSegmentToCCWTriangleXY for typical use.\r\n * @param linePointA First point of clip line\r\n * @param linePointB Second point of clip line\r\n * @param segmentPoint0 First point of clipped segment\r\n * @param segmentPoint1 Second point of clipped segment\r\n * @param interval Live interval.\r\n * @param absoluteTolerance absolute tolerance for both cross product values to indicate \"on\" the line\r\n */\r\n public static clipSegmentBelowPlaneXY(\r\n plane: Plane3dByOriginAndUnitNormal, segmentPoint0: XAndY, segmentPoint1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n // negative is in positive is out ...\r\n const h0 = plane.altitudeXY(segmentPoint0.x, segmentPoint0.y);\r\n const h1 = plane.altitudeXY(segmentPoint1.x, segmentPoint1.y);\r\n if (h0 < absoluteTolerance && h1 < absoluteTolerance) {\r\n // The entire segment is in ..... the interval is unaffected.\r\n return;\r\n }\r\n if (h0 * h1 > 0.0) {\r\n if (h0 > 0.0)\r\n interval.setNull();\r\n } else if (h0 * h1 < 0.0) {\r\n // strict crossing with safe fraction . . .\r\n const fraction = -h0 / (h1 - h0);\r\n if (h0 < 0.0) {\r\n return interval.intersectRangeXXInPlace(0.0, fraction);\r\n } else {\r\n return interval.intersectRangeXXInPlace(fraction, 1.0);\r\n }\r\n } else {\r\n // There is an exact hit at one end, possibly non-zero at the other ... the sign of either determines which side is in play\r\n // A zero and a zero or negative is entirely in, which does not alter the prior clip.\r\n if (h0 > 0.0) {\r\n interval.intersectRangeXXInPlace(1.0, 1.0);\r\n } else if (h1 > 0.0) {\r\n interval.intersectRangeXXInPlace(0.0, 0.0);\r\n }\r\n }\r\n }\r\n /**\r\n * Clip an interval of a line segment to an array of planes\r\n * * plane normals assumed OUTWARD\r\n * * planeAltitude is typically a tolerance a tolerance distance.\r\n * * positive altitude makes tha plane move in the direction of the unit normal.\r\n * @param planes array of planes\r\n * @param segment0 start of segment\r\n * @param segment1 end of segment\r\n * @param interval Pre-initialized interval of live part of segment\r\n * @param absoluteTolerance absolute tolerance for begin \"on a line\"\r\n */\r\n public static clipSegmentBelowPlanesXY(\r\n planes: Plane3dByOriginAndUnitNormal[], segment0: XAndY, segment1: XAndY, interval: Range1d, signedAltitude: number = 1.0e-14,\r\n ): void {\r\n const numPlanes = planes.length;\r\n for (let i = 0; (!interval.isNull) && i < numPlanes; i++) {\r\n this.clipSegmentBelowPlaneXY(planes[i], segment0, segment1, interval, signedAltitude);\r\n }\r\n }\r\n /**\r\n * Pass line segments from a polyline to the clipper. Resolve the fractional clips to simple points for announcement.\r\n * @param clipper clipper to call\r\n * @param points polyline whose segments are passed to the clipper\r\n * @param announce caller's handler for simple point pairs.\r\n */\r\n public static announcePolylineClip(\r\n clipper: Clipper, points: Point3d[], announce: (point0: Point3d, point1: Point3d) => void,\r\n ): void {\r\n for (let i = 0; i + 1 < points.length; i++) {\r\n clipper.announceClippedSegmentIntervals(0, 1, points[i], points[i + 1],\r\n (f0: number, f1: number) => {\r\n announce(points[i].interpolate(f0, points[i + 1]), points[i].interpolate(f1, points[i + 1]));\r\n });\r\n }\r\n }\r\n /**\r\n * Pass line segments from a polyline to the clipper. Sum the lengths of the clipped pieces. Return the sum.\r\n * @param clipper clipper to call\r\n * @param points polyline whose segments are passed to the clipper\r\n */\r\n public static sumPolylineClipLength(clipper: Clipper, points: Point3d[]): number {\r\n let s = 0;\r\n for (let i = 0; i + 1 < points.length; i++) {\r\n const a = points[i].distance(points[i + 1]);\r\n clipper.announceClippedSegmentIntervals(0, 1, points[i], points[i + 1],\r\n (f0: number, f1: number) => { s += Math.abs(f1 - f0) * a; });\r\n }\r\n return s;\r\n }\r\n /**\r\n * Pass polygon `xyz` through a sequence of PolygonClip steps.\r\n * * At the outset, `xyz` is the (only) entry in a set of candidates.\r\n * * For each clipper, each candidate is presented for appendPolygon to inside and outside parts.\r\n * * Each (in,out) result is distributed among (acceptedIn, acceptedOut, candidates) according to\r\n * (inAction, outAction)\r\n * * At the end, all remaining candidates are distributed among (acceptedIn, acceptedOut, finalUnknown)\r\n * according to finalAction\r\n * * Any clipper that does not have an appendPolygonClip method is skipped.\r\n * @param xyz\r\n * @param clippers\r\n * @param acceptedIn\r\n * @param acceptedOut\r\n * @param finalCandidates\r\n * @param inAction\r\n * @param outAction\r\n * @param finalCandidateAction\r\n */\r\n public static doPolygonClipSequence(\r\n xyz: IndexedXYZCollection,\r\n clippers: Clipper[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n finalCandidates: GrowableXYZArray[] | undefined,\r\n inAction: ClipStepAction,\r\n outAction: ClipStepAction,\r\n finalFragmentAction: ClipStepAction,\r\n arrayCache: GrowableXYZArrayCache | undefined,\r\n ) {\r\n if (arrayCache === undefined)\r\n arrayCache = new GrowableXYZArrayCache();\r\n let candidates = [arrayCache.grabAndFill(xyz)];\r\n let nextCandidates: GrowableXYZArray[] = [];\r\n const intermediateIn: GrowableXYZArray[] = [];\r\n const intermediateOut: GrowableXYZArray[] = [];\r\n const oldInsideCount = acceptedIn ? acceptedIn.length : 0;\r\n const oldOutsideCount = acceptedOut ? acceptedOut.length : 0;\r\n let shard;\r\n // At each convex set, carryForwardA is all the fragments that have been outside all previous convex sets.\r\n // Clip each such fragment to the current set, sending the outside parts to carryForwardB, which will got to\r\n // the next clipper. The final surviving carryForward really is out.\r\n for (const c of clippers) {\r\n if (c.appendPolygonClip) {\r\n while (undefined !== (shard = candidates.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(inAction, intermediateIn, acceptedIn, acceptedOut, nextCandidates, arrayCache);\r\n distributeFragments(outAction, intermediateOut, acceptedIn, acceptedOut, nextCandidates, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // candidates is empty !!\r\n const temp = candidates; candidates = nextCandidates; nextCandidates = temp;\r\n }\r\n }\r\n distributeFragments(finalFragmentAction, candidates, acceptedIn, acceptedOut, finalCandidates, arrayCache);\r\n // Note: The following assumes that there were no residual candidates ... need to track if that happened?\r\n // If nothing was out, the inside fragments can be replaced by the original.\r\n if (acceptedOut?.length === oldOutsideCount)\r\n ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedIn, oldInsideCount, xyz, arrayCache);\r\n // If nothing was in, the outside fragments can be replaced by the original.\r\n if (acceptedIn?.length === oldInsideCount)\r\n ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedOut, oldOutsideCount, xyz, arrayCache);\r\n }\r\n /** Pass polygon `xyz` through a sequence of PolygonClip steps with \"parity\" rules */\r\n public static doPolygonClipParitySequence(\r\n xyz: IndexedXYZCollection,\r\n clippers: Clipper[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache | undefined,\r\n ) {\r\n if (arrayCache === undefined)\r\n arrayCache = new GrowableXYZArrayCache();\r\n let candidatesOut = [arrayCache.grabAndFill(xyz)];\r\n let candidatesIn: GrowableXYZArray[] = [];\r\n let nextCandidatesIn: GrowableXYZArray[] = [];\r\n let nextCandidatesOut: GrowableXYZArray[] = [];\r\n const intermediateIn: GrowableXYZArray[] = [];\r\n const intermediateOut: GrowableXYZArray[] = [];\r\n let shard;\r\n // at each step ..\r\n // candidatesIn and candidatesOut are evolved in and out\r\n // nextCandidatesIn and nextCandidatesOut are EMPTY\r\n for (const c of clippers) {\r\n if (c.appendPolygonClip) {\r\n // (IN,OUT) parts of IN parts distribute to (OUT,IN)\r\n while (undefined !== (shard = candidatesIn.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(ClipStepAction.acceptOut, intermediateIn, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n distributeFragments(ClipStepAction.acceptIn, intermediateOut, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // (IN,OUT) parts of IN parts distribute to (OUT,IN)\r\n while (undefined !== (shard = candidatesOut.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(ClipStepAction.acceptIn, intermediateIn, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n distributeFragments(ClipStepAction.acceptOut, intermediateOut, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // reload each candidate step\r\n const tempA = candidatesIn; candidatesIn = nextCandidatesIn; nextCandidatesIn = tempA;\r\n const tempB = candidatesOut; candidatesOut = nextCandidatesOut; nextCandidatesOut = tempB;\r\n }\r\n }\r\n // candidatesIn and candidatesOut are final ....\r\n if (candidatesOut.length === 0)\r\n acceptedIn?.push(arrayCache.grabAndFill(xyz));\r\n else if (candidatesOut.length === 0)\r\n acceptedOut?.push(arrayCache.grabAndFill(xyz));\r\n else {\r\n moveFragments(candidatesIn, acceptedIn, arrayCache);\r\n moveFragments(candidatesOut, acceptedOut, arrayCache);\r\n }\r\n }\r\n /**\r\n * For each plane of clipper, construct a UnionOfConvexClipPlaneSets for an outer (infinite) convex volume that\r\n * abuts the outer volume of the neighbor faces.\r\n */\r\n public static createComplementaryClips(clipper: ConvexClipPlaneSet): UnionOfConvexClipPlaneSets {\r\n const planes = clipper.planes;\r\n const interval = Range1d.createNull();\r\n const n = planes.length;\r\n const newClippers: ConvexClipPlaneSet[] = [];\r\n for (const p of planes) {\r\n const outerSet = ConvexClipPlaneSet.createEmpty();\r\n outerSet.addPlaneToConvexSet(p.cloneNegated());\r\n newClippers.push(outerSet);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n const ray = CurveFactory.planePlaneIntersectionRay(planes[i], planes[j]);\r\n if (ray) {\r\n if (clipper.hasIntersectionWithRay(ray, interval)) {\r\n // the normal-to-normal vector is bisector (or close to bisector?)\r\n const newNormal = planes[j].inwardNormalRef.minus(planes[i].inwardNormalRef);\r\n const plane1 = ClipPlane.createNormalAndPoint(newNormal, ray.origin);\r\n if (plane1) {\r\n const plane2 = plane1.cloneNegated();\r\n newClippers[i].addPlaneToConvexSet(plane1);\r\n newClippers[j].addPlaneToConvexSet(plane2);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return UnionOfConvexClipPlaneSets.createConvexSets(newClippers);\r\n }\r\n}\r\nfunction moveFragments(\r\n fragments: GrowableXYZArray[],\r\n destination: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache,\r\n) {\r\n if (destination === undefined)\r\n arrayCache.dropAllToCache(fragments);\r\n else {\r\n for (const f of fragments)\r\n destination.push(f);\r\n }\r\n fragments.length = 0;\r\n}\r\n/**\r\n * Distribute fragments among acceptedIn, acceptedOut, and passToNextStep as directed by action.\r\n * * If the indicated destination is unknown, drop the fragments to the arrayCache.\r\n * @param action destination selector\r\n * @param fragments fragments to be distributed\r\n * @param acceptedIn destination for \"in\"\r\n * @param acceptedOut destination for \"out\"\r\n * @param passToNextStep destination for fragments to be passed to a later step\r\n * @param arrayCache destination for un-distributed fragments.\r\n */\r\nfunction distributeFragments(\r\n action: ClipStepAction,\r\n fragments: GrowableXYZArray[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n passToNextStep: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache,\r\n) {\r\n let destination;\r\n if (action === ClipStepAction.acceptIn)\r\n destination = acceptedIn;\r\n else if (action === ClipStepAction.acceptOut)\r\n destination = acceptedOut;\r\n else if (action === ClipStepAction.passToNextStep)\r\n destination = passToNextStep;\r\n // remark: if action is other than the enum values, destination is undefined\r\n if (destination === undefined)\r\n arrayCache.dropAllToCache(fragments);\r\n else {\r\n for (const f of fragments)\r\n destination.push(f);\r\n }\r\n fragments.length = 0;\r\n}\r\n"]}
1
+ {"version":3,"file":"ClipUtils.js","sourceRoot":"","sources":["../../../src/clipping/ClipUtils.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAA4D,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGnH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAs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AAmB,CAC1B,MAAsB,EACtB,SAA6B,EAC7B,UAA0C,EAC1C,WAA2C,EAC3C,cAA8C,EAC9C,UAAiC;IAEjC,IAAI,WAAW,CAAC;IAChB,IAAI,MAAM,KAAK,cAAc,CAAC,QAAQ;QACpC,WAAW,GAAG,UAAU,CAAC;SACtB,IAAI,MAAM,KAAK,cAAc,CAAC,SAAS;QAC1C,WAAW,GAAG,WAAW,CAAC;SACvB,IAAI,MAAM,KAAK,cAAc,CAAC,cAAc;QAC/C,WAAW,GAAG,cAAc,CAAC;IAC/B,4EAA4E;IAC5E,IAAI,WAAW,KAAK,SAAS;QAC3B,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;SAClC;QACH,KAAK,MAAM,CAAC,IAAI,SAAS;YACvB,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvB;IACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AACvB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Arc3d } from \"../curve/Arc3d\";\r\nimport { BagOfCurves } from \"../curve/CurveCollection\";\r\nimport { CurveFactory } from \"../curve/CurveFactory\";\r\nimport { AnnounceNumberNumber, AnnounceNumberNumberCurvePrimitive, CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { AnyCurve, AnyRegion } from \"../curve/CurveTypes\";\r\nimport { GeometryQuery } from \"../curve/GeometryQuery\";\r\nimport { LineSegment3d } from \"../curve/LineSegment3d\";\r\nimport { LineString3d } from \"../curve/LineString3d\";\r\nimport { Loop } from \"../curve/Loop\";\r\nimport { Path } from \"../curve/Path\";\r\nimport { RegionBinaryOpType, RegionOps } from \"../curve/RegionOps\";\r\nimport { UnionRegion } from \"../curve/UnionRegion\";\r\nimport { Geometry } from \"../Geometry\";\r\nimport { FrameBuilder } from \"../geometry3d/FrameBuilder\";\r\nimport { GrowableFloat64Array } from \"../geometry3d/GrowableFloat64Array\";\r\nimport { GrowableXYZArray } from \"../geometry3d/GrowableXYZArray\";\r\nimport { IndexedXYZCollection } from \"../geometry3d/IndexedXYZCollection\";\r\nimport { Plane3dByOriginAndUnitNormal } from \"../geometry3d/Plane3dByOriginAndUnitNormal\";\r\nimport { Point3dArrayCarrier } from \"../geometry3d/Point3dArrayCarrier\";\r\nimport { Point3d, Vector3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Range1d, Range3d } from \"../geometry3d/Range\";\r\nimport { GrowableXYZArrayCache } from \"../geometry3d/ReusableObjectCache\";\r\nimport { Transform } from \"../geometry3d/Transform\";\r\nimport { XAndY } from \"../geometry3d/XYZProps\";\r\nimport { PolyfaceBuilder } from \"../polyface/PolyfaceBuilder\";\r\nimport { ClipPlane } from \"./ClipPlane\";\r\nimport { ClipPrimitive } from \"./ClipPrimitive\";\r\nimport { ClipVector } from \"./ClipVector\";\r\nimport { ConvexClipPlaneSet } from \"./ConvexClipPlaneSet\";\r\nimport { LineStringOffsetClipperContext } from \"./internalContexts/LineStringOffsetClipperContext\";\r\nimport { UnionOfConvexClipPlaneSets } from \"./UnionOfConvexClipPlaneSets\";\r\n\r\n/**\r\n * Enumerated type for describing where geometry lies with respect to clipping planes.\r\n * @public\r\n */\r\nexport enum ClipPlaneContainment {\r\n /** All points inside. */\r\n StronglyInside = 1,\r\n /** Inside/outside state unknown. */\r\n Ambiguous = 2,\r\n /** All points outside. */\r\n StronglyOutside = 3,\r\n}\r\n/**\r\n * Enumeration of ways to handle an intermediate fragment from a clipping step.\r\n * @public\r\n */\r\nexport enum ClipStepAction {\r\n /** Pass fragments directly to final accepted \"in\" state. */\r\n acceptIn = 1,\r\n /** Pass fragments directly to final accepted \"out\" state. */\r\n acceptOut = -1,\r\n /** Forward fragments to subsequent steps. */\r\n passToNextStep = 0,\r\n}\r\n\r\n/**\r\n * Enumerated type for describing what must yet be done to clip a piece of geometry.\r\n * @public\r\n */\r\nexport enum ClipStatus {\r\n /** Some geometry may cross the clip boundaries */\r\n ClipRequired,\r\n /** Geometry is clearly outside */\r\n TrivialReject,\r\n /** Geometry is clearly inside */\r\n TrivialAccept,\r\n}\r\n\r\n/**\r\n * An object containing clipping planes that can be used to clip geometry.\r\n * @public\r\n */\r\nexport interface Clipper {\r\n /** Test if `point` is on or inside the Clipper's volume. */\r\n isPointOnOrInside(point: Point3d, tolerance?: number): boolean;\r\n /**\r\n * Find the parts of the line segment (if any) that is within the convex clip volume.\r\n * * The line segment is defined by `pointA` and `pointB`.\r\n * * The input fractional interval from `fraction0` to `fraction1` (increasing) is the active part to consider.\r\n * * To clip to the usual bounded line segment, start with fractions (0,1).\r\n * If the clip volume is unbounded, the line interval may also be unbounded.\r\n * * An unbounded line portion will have fraction coordinates positive or negative `Number.MAX_VALUE`.\r\n * @param f0 fraction that is the initial lower fraction of the active interval (e.g., 0.0 for bounded segment).\r\n * @param f1 fraction that is the initial upper fraction of the active interval (e.g., 1.0 for bounded segment).\r\n * @param pointA segment start (fraction 0)\r\n * @param pointB segment end (fraction 1)\r\n * @param announce function to be called to announce a fraction interval that is within the convex clip volume.\r\n * @returns true if a segment was announced, false if entirely outside.\r\n */\r\n announceClippedSegmentIntervals(\r\n f0: number, f1: number, pointA: Point3d, pointB: Point3d, announce?: AnnounceNumberNumber\r\n ): boolean;\r\n /**\r\n * Find the portion (or portions) of the arc (if any) that are within the convex clip volume.\r\n * @param arc the arc to be clipped.\r\n * @param announce function to be called to announce a fraction intervals that are within the convex clip volume.\r\n * @returns true if one or more arcs portions were announced, false if entirely outside.\r\n */\r\n announceClippedArcIntervals(arc: Arc3d, announce?: AnnounceNumberNumberCurvePrimitive): boolean;\r\n /**\r\n * Optional polygon clip method.\r\n * * This is expected to be implemented by planar clip structures.\r\n * * This is unimplemented for curve clippers (e.g. sphere) for which polygon clip result has curved edges.\r\n * * The input polygon must be convex.\r\n */\r\n appendPolygonClip?: AppendPolygonClipFunction;\r\n}\r\n/**\r\n * Signature of method to execute polygon clip, distributing fragments of xyz among insideFragments and outsideFragments\r\n * @param xyz convex polygon. This is not changed.\r\n * @param insideFragments Array to receive \"inside\" fragments. Each fragment is a GrowableXYZArray grabbed from\r\n * the cache. This is NOT cleared.\r\n * @param outsideFragments Array to receive \"outside\" fragments. Each fragment is a GrowableXYZArray grabbed from\r\n * the cache. This is NOT cleared.\r\n * @param arrayCache cache for reusable GrowableXYZArray.\r\n */\r\ntype AppendPolygonClipFunction = (\r\n xyz: IndexedXYZCollection,\r\n insideFragments: GrowableXYZArray[],\r\n outsideFragments: GrowableXYZArray[],\r\n arrayCache: GrowableXYZArrayCache\r\n) => void;\r\n\r\n/**\r\n * Interface for clipping convex polygons.\r\n * Supported by:\r\n * * AlternatingCCTreeNode\r\n * * ConvexClipPlaneSet\r\n * @public\r\n */\r\nexport interface PolygonClipper {\r\n appendPolygonClip: AppendPolygonClipFunction;\r\n}\r\n/**\r\n * Class whose various static methods are functions for clipping geometry\r\n * @public\r\n */\r\nexport class ClipUtilities {\r\n // on-demand scratch objects for method implementations. If you use one, make sure it isn't already being used in scope.\r\n private static _workTransform?: Transform;\r\n private static _workRange?: Range3d;\r\n private static _workClipper?: ConvexClipPlaneSet;\r\n\r\n private static _selectIntervals01TestPoint = Point3d.create();\r\n /**\r\n * Augment the unsortedFractionsArray with 0 and 1\r\n * * sort\r\n * * test the midpoint of each interval with `clipper.isPointOnOrInside`\r\n * * pass accepted intervals to `announce(f0,f1,curve)`\r\n */\r\n public static selectIntervals01(\r\n curve: CurvePrimitive,\r\n unsortedFractions: GrowableFloat64Array,\r\n clipper: Clipper,\r\n announce?: AnnounceNumberNumberCurvePrimitive,\r\n ): boolean {\r\n unsortedFractions.push(0);\r\n unsortedFractions.push(1);\r\n unsortedFractions.sort();\r\n let f0 = unsortedFractions.atUncheckedIndex(0);\r\n let f1;\r\n let fMid;\r\n const testPoint = ClipUtilities._selectIntervals01TestPoint;\r\n const n = unsortedFractions.length;\r\n for (let i = 1; i < n; i++) {\r\n f1 = unsortedFractions.atUncheckedIndex(i);\r\n if (f1 > f0 + Geometry.smallFraction) {\r\n fMid = 0.5 * (f0 + f1);\r\n if (fMid >= 0.0 && fMid <= 1.0) {\r\n curve.fractionToPoint(fMid, testPoint);\r\n if (clipper.isPointOnOrInside(testPoint)) {\r\n if (announce)\r\n announce(f0, f1, curve);\r\n else\r\n return true;\r\n }\r\n }\r\n f0 = f1;\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Announce triples of (low, high, cp) for each entry in intervals.\r\n * @param intervals source array\r\n * @param cp CurvePrimitive for announcement\r\n * @param announce function to receive data\r\n */\r\n public static announceNNC(\r\n intervals: Range1d[], cp: CurvePrimitive, announce?: AnnounceNumberNumberCurvePrimitive,\r\n ): boolean {\r\n if (announce) {\r\n for (const ab of intervals) {\r\n announce(ab.low, ab.high, cp);\r\n }\r\n }\r\n return intervals.length > 0;\r\n }\r\n /**\r\n * Compute and return portions of the input curve that are within the clipper.\r\n * @param curve input curve, unmodified\r\n * @param clipper used to compute the clipped components\r\n * @return array of clipped curves\r\n */\r\n public static collectClippedCurves(curve: CurvePrimitive, clipper: Clipper): CurvePrimitive[] {\r\n const result: CurvePrimitive[] = [];\r\n curve.announceClipIntervals(\r\n clipper,\r\n (fraction0: number, fraction1: number, curveA: CurvePrimitive) => {\r\n if (fraction1 !== fraction0) {\r\n const partialCurve = curveA.clonePartialCurve(fraction0, fraction1);\r\n if (partialCurve)\r\n result.push(partialCurve);\r\n }\r\n },\r\n );\r\n return result;\r\n }\r\n /**\r\n * Compute and return the portions of the input region that are within the clipper.\r\n * @param region input region, unmodified\r\n * @param clipper used to compute the clipped components\r\n * @return clipped subregion, as a single `AnyRegion`\r\n */\r\n public static clipAnyRegion(region: AnyRegion, clipper: Clipper): AnyRegion | undefined {\r\n let result: UnionRegion | undefined;\r\n // Create \"local region\" which is the result of rotating region to make\r\n // it parallel to the xy-plane and then translating it to the xy-plane.\r\n const localToWorld = ClipUtilities._workTransform = FrameBuilder.createRightHandedFrame(undefined, region, ClipUtilities._workTransform);\r\n if (!localToWorld)\r\n return result;\r\n const worldToLocal = localToWorld?.inverse();\r\n if (!worldToLocal)\r\n return result;\r\n const localRegion = region.cloneTransformed(worldToLocal) as AnyRegion;\r\n if (!localRegion)\r\n return result;\r\n // We can only clip convex polygons with our clipper machinery, but the input region doesn't have to be\r\n // convex or even a polygon. We get around this limitation by using a Boolean operation, which admits\r\n // *any* planar regions, albeit in local coordinates. First, we clip a rectangle that covers the input region\r\n // (in world coordinates), then we intersect the resulting fragments with the input region in local coordinates.\r\n // Finally, we assemble the results into a UnionRegion back in world coordinates.\r\n const localRegionRange = ClipUtilities._workRange = localRegion.range();\r\n const xLength = localRegionRange.xLength();\r\n const yLength = localRegionRange.yLength();\r\n const rectangle = LineString3d.createRectangleXY(localRegionRange.low, xLength, yLength, true);\r\n rectangle.tryTransformInPlace(localToWorld);\r\n // Clip the rectangle to produce fragment(s) which we can Boolean intersect with the input region.\r\n const insideFragments: GrowableXYZArray[] = [];\r\n const outsideFragments: GrowableXYZArray[] = [];\r\n const cache = new GrowableXYZArrayCache();\r\n clipper.appendPolygonClip?.(rectangle.packedPoints, insideFragments, outsideFragments, cache);\r\n if (insideFragments.length === 0)\r\n return result;\r\n // Create the \"clipped region\".\r\n for (const fragment of insideFragments) {\r\n const loop = Loop.createPolygon(fragment);\r\n loop.tryTransformInPlace(worldToLocal);\r\n const clippedLocalRegion = RegionOps.regionBooleanXY(localRegion, loop, RegionBinaryOpType.Intersection);\r\n if (clippedLocalRegion) {\r\n clippedLocalRegion.tryTransformInPlace(localToWorld);\r\n if (!result)\r\n result = (clippedLocalRegion instanceof UnionRegion) ? clippedLocalRegion : UnionRegion.create(clippedLocalRegion);\r\n else if (!result.tryAddChild(clippedLocalRegion))\r\n result.children.push(...(clippedLocalRegion as UnionRegion).children);\r\n }\r\n }\r\n return result;\r\n }\r\n /**\r\n * Compute and return portions of the input curve or region that are within the clipper.\r\n * @param curve input curve or region, unmodified\r\n * @param clipper used to compute the clipped components\r\n * @return array of clipped components of the input curve or region that lie inside the clipper\r\n */\r\n public static clipAnyCurve(curve: AnyCurve, clipper: Clipper): AnyCurve[] {\r\n if (curve instanceof CurvePrimitive)\r\n return ClipUtilities.collectClippedCurves(curve, clipper);\r\n if (curve.isAnyRegion()) {\r\n const ret = ClipUtilities.clipAnyRegion(curve, clipper);\r\n return ret ? [ret] : [];\r\n }\r\n const result: AnyCurve[] = [];\r\n if (curve instanceof Path || curve instanceof BagOfCurves) {\r\n for (const child of curve.children) {\r\n const partialClip = ClipUtilities.clipAnyCurve(child, clipper);\r\n result.push(...partialClip);\r\n }\r\n }\r\n return result;\r\n }\r\n /**\r\n * Clip a polygon down to regions defined by each shape of a ClipShape.\r\n * @return An multidimensional array of points, where each array is the boundary of part of the remaining polygon.\r\n */\r\n public static clipPolygonToClipShape(polygon: Point3d[], clipShape: ClipPrimitive): Point3d[][] {\r\n const outputA = this.clipPolygonToClipShapeReturnGrowableXYZArrays(polygon, clipShape);\r\n const output = [];\r\n for (const g of outputA)\r\n output.push(g.getPoint3dArray());\r\n return output;\r\n }\r\n /**\r\n * Clip a polygon down to regions defined by each shape of a ClipShape.\r\n * @return An multidimensional array of points, where each array is the boundary of part of the remaining polygon.\r\n */\r\n public static clipPolygonToClipShapeReturnGrowableXYZArrays(\r\n polygon: Point3d[], clipShape: ClipPrimitive,\r\n ): GrowableXYZArray[] {\r\n const output: GrowableXYZArray[] = [];\r\n const clipper = clipShape.fetchClipPlanesRef();\r\n // NEEDS WORK -- what if it is a mask !!!!\r\n if (clipper) {\r\n clipper.polygonClip(polygon, output);\r\n }\r\n return output;\r\n }\r\n /**\r\n * Given an array of points, test for trivial containment conditions.\r\n * * ClipStatus.TrivialAccept if all points are in any one of the convexSet's.\r\n * * ClipStatus.ClipRequired if (in any single convexSet) there were points on both sides of any single plane.\r\n * * ClipStatus.TrivialReject if neither of those occurred.\r\n */\r\n public static pointSetSingleClipStatus(\r\n points: GrowableXYZArray, planeSet: UnionOfConvexClipPlaneSets, tolerance: number,\r\n ): ClipStatus {\r\n if (planeSet.convexSets.length === 0)\r\n return ClipStatus.TrivialAccept;\r\n\r\n for (const convexSet of planeSet.convexSets) {\r\n let allOutsideSinglePlane = false, anyOutside = false;\r\n\r\n for (const plane of convexSet.planes) {\r\n let numInside = 0, numOutside = 0;\r\n const planeDistance = plane.distance - tolerance;\r\n\r\n const currPt = Point3d.create();\r\n const currVec = Vector3d.create();\r\n for (let i = 0; i < points.length; i++) {\r\n points.getPoint3dAtUncheckedPointIndex(i, currPt);\r\n currVec.setFrom(currPt);\r\n currVec.dotProduct(plane.inwardNormalRef) > planeDistance ? numInside++ : numOutside++;\r\n }\r\n\r\n anyOutside = (numOutside !== 0) ? true : anyOutside;\r\n if (numInside === 0) {\r\n allOutsideSinglePlane = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!anyOutside) // totally inside this set - no clip required\r\n return ClipStatus.TrivialAccept;\r\n if (!allOutsideSinglePlane)\r\n return ClipStatus.ClipRequired;\r\n }\r\n return ClipStatus.TrivialReject;\r\n }\r\n /**\r\n * Emit point loops for intersection of a convex set with a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static announceLoopsOfConvexClipPlaneSetIntersectRange(\r\n convexSet: ConvexClipPlaneSet | ClipPlane,\r\n range: Range3d,\r\n loopFunction: (loopPoints: GrowableXYZArray) => void,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): void {\r\n const work = new GrowableXYZArray();\r\n if (includeConvexSetFaces) {\r\n // Clip convexSet planes to the range and to the rest of the convexSet . .\r\n if (convexSet instanceof ConvexClipPlaneSet) {\r\n for (const plane of convexSet.planes) {\r\n if (ignoreInvisiblePlanes && plane.invisible)\r\n continue;\r\n const pointsClippedToRange = plane.intersectRange(range, true);\r\n const finalPoints = new GrowableXYZArray();\r\n if (pointsClippedToRange) {\r\n convexSet.polygonClip(pointsClippedToRange, finalPoints, work, plane);\r\n if (finalPoints.length > 0)\r\n loopFunction(finalPoints);\r\n }\r\n }\r\n } else { // `convexSet` is just one plane ...\r\n if (ignoreInvisiblePlanes && convexSet.invisible) {\r\n // skip it !\r\n } else {\r\n const pointsClippedToRange = convexSet.intersectRange(range, true);\r\n if (pointsClippedToRange)\r\n loopFunction(pointsClippedToRange);\r\n }\r\n }\r\n }\r\n\r\n if (includeRangeFaces) {\r\n // clip range faces to the convex set . . .\r\n const corners = range.corners();\r\n for (let i = 0; i < 6; i++) {\r\n const indices = Range3d.faceCornerIndices(i);\r\n const finalPoints = new GrowableXYZArray();\r\n const lineString = LineString3d.createIndexedPoints(corners, indices);\r\n if (convexSet instanceof ConvexClipPlaneSet) {\r\n convexSet.polygonClip(lineString.packedPoints, finalPoints, work);\r\n if (finalPoints.length > 0)\r\n loopFunction(finalPoints);\r\n } else {\r\n convexSet.clipConvexPolygonInPlace(lineString.packedPoints, work);\r\n if (lineString.packedPoints.length > 0)\r\n loopFunction(lineString.packedPoints);\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * Return a (possibly empty) array of geometry (Loops !!) which are facets of the intersection of the convex set\r\n * intersecting a range.\r\n * * Return zero length array for (a) null range or (b) no intersections\r\n * @param allClippers convex or union clipper\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static loopsOfConvexClipPlaneIntersectionWithRange(\r\n allClippers: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPlane,\r\n range: Range3d,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): GeometryQuery[] {\r\n const result: GeometryQuery[] = [];\r\n if (allClippers instanceof UnionOfConvexClipPlaneSets) {\r\n for (const clipper of allClippers.convexSets) {\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(clipper, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.push(Loop.createPolygon(points));\r\n },\r\n includeConvexSetFaces, includeRangeFaces, ignoreInvisiblePlanes);\r\n }\r\n } else if (allClippers instanceof ConvexClipPlaneSet || allClippers instanceof ClipPlane) {\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(allClippers, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.push(Loop.createPolygon(points));\r\n },\r\n includeConvexSetFaces, includeRangeFaces, ignoreInvisiblePlanes);\r\n }\r\n return result;\r\n }\r\n /**\r\n * Return the (possibly null) range of the intersection of the convex set with a range.\r\n * * The convex set is permitted to be unbounded (e.g. a single plane). The range parameter provides bounds.\r\n * @param convexSet convex set for intersection.\r\n * @param range range to intersect\r\n */\r\n public static rangeOfConvexClipPlaneSetIntersectionWithRange(convexSet: ConvexClipPlaneSet, range: Range3d): Range3d {\r\n const result = Range3d.createNull();\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(convexSet, range,\r\n (points: GrowableXYZArray) => {\r\n if (points.length > 0) result.extendArray(points);\r\n },\r\n true, true, false);\r\n return result;\r\n }\r\n /**\r\n * Return the range of various types of clippers\r\n * * `ConvexClipPlaneSet` -- dispatch to `rangeOfConvexClipPlaneSetIntersectionWithRange`\r\n * * `UnionOfConvexClipPlaneSet` -- union of ranges of member `ConvexClipPlaneSet`\r\n * * `ClipPrimitive` -- access its `UnionOfConvexClipPlaneSet`.\r\n * * `ClipVector` -- intersection of the ranges of its `ClipPrimitive`.\r\n * * `undefined` -- entire input range.\r\n * * If `observeInvisibleFlag` is false, the \"invisible\" properties are ignored, and this effectively returns the range of the edge work of the members\r\n * * If `observeInvisibleFlag` is true, the \"invisible\" properties are observed, and \"invisible\" parts do not restrict the range.\r\n * @param clipper\r\n * @param range non-null range.\r\n * @param observeInvisibleFlag indicates how \"invisible\" bit is applied for ClipPrimitive.\r\n */\r\n public static rangeOfClipperIntersectionWithRange(\r\n clipper: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPrimitive | ClipVector | undefined,\r\n range: Range3d,\r\n observeInvisibleFlag: boolean = true,\r\n ): Range3d {\r\n if (clipper === undefined)\r\n return range.clone();\r\n if (clipper instanceof ConvexClipPlaneSet)\r\n return this.rangeOfConvexClipPlaneSetIntersectionWithRange(clipper, range);\r\n if (clipper instanceof UnionOfConvexClipPlaneSets) {\r\n const rangeUnion = Range3d.createNull();\r\n for (const c of clipper.convexSets) {\r\n const rangeC = this.rangeOfConvexClipPlaneSetIntersectionWithRange(c, range);\r\n rangeUnion.extendRange(rangeC);\r\n }\r\n return rangeUnion;\r\n }\r\n if (clipper instanceof ClipPrimitive) {\r\n if (observeInvisibleFlag && clipper.invisible)\r\n return range.clone();\r\n return this.rangeOfClipperIntersectionWithRange(clipper.fetchClipPlanesRef(), range);\r\n }\r\n if (clipper instanceof ClipVector) {\r\n const rangeIntersection = range.clone();\r\n for (const c of clipper.clips) {\r\n if (observeInvisibleFlag && c.invisible) {\r\n // trivial range tests do not expose the effects. Assume the hole allows everything.\r\n } else {\r\n const rangeC = this.rangeOfClipperIntersectionWithRange(c, range, observeInvisibleFlag);\r\n rangeIntersection.intersect(rangeC, rangeIntersection);\r\n }\r\n }\r\n return rangeIntersection;\r\n\r\n }\r\n return range.clone();\r\n }\r\n /**\r\n * Test if various types of clippers have any intersection with a range.\r\n * * This follows the same logic as `rangeOfClipperIntersectionWithRange` but attempts to exit at earliest point of confirmed intersection\r\n * * `ConvexClipPlaneSet` -- dispatch to `doesConvexClipPlaneSetIntersectRange`\r\n * * `UnionOfConvexClipPlaneSet` -- union of ranges of member `ConvexClipPlaneSet`\r\n * * `ClipPrimitive` -- access its `UnionOfConvexClipPlaneSet`.\r\n * * `ClipVector` -- intersection of the ranges of its `ClipPrimitive`.\r\n * * `undefined` -- entire input range.\r\n * * If `observeInvisibleFlag` is false, the \"invisible\" properties are ignored, and holes do not affect the result.\r\n * * If `observeInvisibleFlag` is true, the \"invisible\" properties are observed, and may affect the result.\r\n * @param clipper\r\n * @param range non-null range.\r\n * @param observeInvisibleFlag indicates how \"invisible\" bit is applied for ClipPrimitive.\r\n */\r\n public static doesClipperIntersectRange(\r\n clipper: ConvexClipPlaneSet | UnionOfConvexClipPlaneSets | ClipPrimitive | ClipVector | undefined,\r\n range: Range3d,\r\n observeInvisibleFlag: boolean = true,\r\n ): boolean {\r\n if (clipper === undefined)\r\n return true;\r\n\r\n if (clipper instanceof ConvexClipPlaneSet)\r\n return this.doesConvexClipPlaneSetIntersectRange(clipper, range);\r\n\r\n if (clipper instanceof UnionOfConvexClipPlaneSets) {\r\n for (const c of clipper.convexSets) {\r\n if (this.doesConvexClipPlaneSetIntersectRange(c, range))\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n if (clipper instanceof ClipPrimitive) {\r\n if (observeInvisibleFlag && clipper.invisible) // um is there an easy way to detect range-completely-inside?\r\n return true;\r\n return this.doesClipperIntersectRange(clipper.fetchClipPlanesRef(), range);\r\n }\r\n\r\n if (clipper instanceof ClipVector) {\r\n const rangeIntersection = range.clone();\r\n for (const c of clipper.clips) {\r\n if (observeInvisibleFlag && c.invisible) {\r\n // trivial range tests do not expose the effects. Assume the hole allows everything.\r\n } else {\r\n const rangeC = this.rangeOfClipperIntersectionWithRange(c, range, observeInvisibleFlag);\r\n rangeIntersection.intersect(rangeC, rangeIntersection);\r\n }\r\n }\r\n return !rangeIntersection.isNull;\r\n }\r\n /** If the case statement above is complete for the variant inputs, this is unreachable .. */\r\n return false;\r\n }\r\n /**\r\n * Emit point loops for intersection of a convex set with a range.\r\n * * return zero length array for (a) null range or (b) no intersections\r\n * @param range range to intersect\r\n * @param includeConvexSetFaces if false, do not compute facets originating as convex set planes.\r\n * @param includeRangeFaces if false, do not compute facets originating as range faces\r\n * @param ignoreInvisiblePlanes if true, do NOT compute a facet for convex set faces marked invisible.\r\n */\r\n public static doesConvexClipPlaneSetIntersectRange(\r\n convexSet: ConvexClipPlaneSet,\r\n range: Range3d,\r\n includeConvexSetFaces: boolean = true,\r\n includeRangeFaces: boolean = true,\r\n ignoreInvisiblePlanes = false,\r\n ): boolean {\r\n const work = new GrowableXYZArray();\r\n if (includeConvexSetFaces) {\r\n // Clip convexSet planes to the range and to the rest of the convexSet . .\r\n for (const plane of convexSet.planes) {\r\n if (ignoreInvisiblePlanes && plane.invisible)\r\n continue;\r\n const pointsClippedToRange = plane.intersectRange(range, true);\r\n if (pointsClippedToRange) {\r\n const finalPoints = new GrowableXYZArray();\r\n convexSet.polygonClip(pointsClippedToRange, finalPoints, work, plane);\r\n if (finalPoints.length > 0)\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n if (includeRangeFaces) {\r\n // clip range faces to the convex set . . .\r\n const corners = range.corners();\r\n for (let i = 0; i < 6; i++) {\r\n const indices = Range3d.faceCornerIndices(i);\r\n const finalPoints = new GrowableXYZArray();\r\n const lineString = LineString3d.createIndexedPoints(corners, indices);\r\n convexSet.polygonClip(lineString.packedPoints, finalPoints, work);\r\n if (finalPoints.length > 0)\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Create a clipper from the transformed range.\r\n * @param range input range to create clipper from\r\n * @param transform how to transform the range (NOTE: applied to the range faces without swelling the range volume)\r\n * @param degeneratePoints optionally populated with the 1 or 2 points defining the transformed range if it is degenerate (all points colinear/coincident); otherwise untouched\r\n * @returns newly constructed clipper. If no clip planes could be computed, fill `degeneratePoints` and return undefined.\r\n */\r\n private static createClipperFromTransformedRange3d(range: Range3d, transform: Transform, degeneratePoints?: Point3d[]): ConvexClipPlaneSet | undefined {\r\n if (!transform)\r\n transform = Transform.createIdentity();\r\n const builder = PolyfaceBuilder.create();\r\n builder.addTransformedRangeMesh(transform, range);\r\n const mesh = builder.claimPolyface();\r\n const clipper = this._workClipper = ConvexClipPlaneSet.createConvexPolyface(mesh, this._workClipper).clipper;\r\n if (clipper.planes.length > 0)\r\n return clipper;\r\n // no faces found in the compressed mesh\r\n if (degeneratePoints) {\r\n assert(mesh.data.point.length <= 2);\r\n for (let i = 0; i < 2; ++i) {\r\n const point = mesh.data.point.getPoint3dAtCheckedPointIndex(i);\r\n if (point)\r\n degeneratePoints.push(point);\r\n }\r\n }\r\n return undefined;\r\n }\r\n /**\r\n * Handle pathological cases of range-range intersection, where one of the ranges defines no area or volume (is a line segment or single point).\r\n * @param range local range to intersect with the point/segment\r\n * @param points isolated local point, or local segment's start and end\r\n * @param localToWorld optional transform for output range\r\n * @param intersection optional range of the intersection, in world coordinates, or null range if no intersection.\r\n * @returns whether the point/segment intersects the range\r\n */\r\n private static rangeIntersectPointOrSegment(range: Range3d, points: Point3d[], localToWorld?: Transform, intersection?: Range3d): boolean {\r\n const announceInterval: AnnounceNumberNumberCurvePrimitive | undefined = intersection ?\r\n (f0: number, f1: number, cp: CurvePrimitive) => {\r\n intersection.extendPoint(cp.fractionToPoint(f0), localToWorld);\r\n intersection.extendPoint(cp.fractionToPoint(f1), localToWorld);\r\n } : undefined;\r\n let hasIntersection = false;\r\n if (points.length > 1) {\r\n const segment = LineSegment3d.createCapture(points[0], points[1]);\r\n const clipper = ConvexClipPlaneSet.createRange3dPlanes(range);\r\n hasIntersection = segment.announceClipIntervals(clipper, announceInterval);\r\n } else if (points.length > 0) {\r\n hasIntersection = range.containsPoint(points[0]);\r\n if (hasIntersection && intersection)\r\n intersection.extendPoint(points[0], localToWorld);\r\n }\r\n return hasIntersection;\r\n }\r\n /**\r\n * Test for intersection of two ranges in different local coordinates.\r\n * * Useful for clash detection of elements in iModels, using their stored (tight) local ranges and placement transforms.\r\n * @param range0 first range in local coordinates\r\n * @param local0ToWorld placement transform for first range\r\n * @param range1 second range in local coordinates\r\n * @param local1ToWorld placement transform for second range. Assumed to be invertible.\r\n * @param range1Margin optional signed local distance to expand/contract the second range before intersection. Positive expands.\r\n * @return whether the local ranges are adjacent or intersect. Also returns false if local1ToWorld is singular.\r\n */\r\n public static doLocalRangesIntersect(\r\n range0: Range3d, local0ToWorld: Transform, range1: Range3d, local1ToWorld: Transform, range1Margin?: number,\r\n ): boolean {\r\n const worldToLocal1 = this._workTransform = local1ToWorld.inverse(this._workTransform);\r\n if (!worldToLocal1)\r\n return false;\r\n let myRange1 = range1;\r\n if (range1Margin) {\r\n myRange1 = this._workRange = range1.clone(this._workRange);\r\n myRange1.expandInPlace(range1Margin);\r\n }\r\n const degeneratePoints: Point3d[] = [];\r\n const local0ToLocal1 = worldToLocal1.multiplyTransformTransform(local0ToWorld, worldToLocal1);\r\n // convert range0 into a clipper in local1 coordinates, then intersect with range1\r\n const clipper = this.createClipperFromTransformedRange3d(range0, local0ToLocal1, degeneratePoints);\r\n if (clipper)\r\n return this.doesClipperIntersectRange(clipper, myRange1);\r\n return this.rangeIntersectPointOrSegment(myRange1, degeneratePoints, local1ToWorld);\r\n }\r\n /**\r\n * Compute the range of the intersection between two local (e.g., element-aligned) ranges.\r\n * @param range0 first range in local coordinates\r\n * @param local0ToWorld placement transform for first range\r\n * @param range1 second range in local coordinates\r\n * @param local1ToWorld placement transform for second range. Assumed to be invertible.\r\n * @param result optional pre-allocated range to fill and return\r\n * @return range of the intersection (aligned to world axes). Returns null range if local1ToWorld is singular.\r\n */\r\n public static rangeOfIntersectionOfLocalRanges(range0: Range3d, local0ToWorld: Transform, range1: Range3d, local1ToWorld: Transform, result?: Range3d): Range3d {\r\n const myResult = Range3d.createNull(result);\r\n const worldToLocal1 = this._workTransform = local1ToWorld.inverse(this._workTransform);\r\n if (!worldToLocal1)\r\n return myResult;\r\n const degeneratePoints: Point3d[] = [];\r\n const local0ToLocal1 = worldToLocal1.multiplyTransformTransform(local0ToWorld, worldToLocal1);\r\n // convert range0 into a clipper in local1 coordinates, then intersect with range1\r\n const clipper = this.createClipperFromTransformedRange3d(range0, local0ToLocal1, degeneratePoints);\r\n if (clipper)\r\n this.announceLoopsOfConvexClipPlaneSetIntersectRange(clipper, range1, (loopPoints: GrowableXYZArray) => { loopPoints.extendRange(myResult, local1ToWorld); });\r\n else\r\n this.rangeIntersectPointOrSegment(range1, degeneratePoints, local1ToWorld, myResult);\r\n return myResult;\r\n }\r\n /**\r\n * Test if `obj` is a `Clipper` object.\r\n * * This is implemented by testing for each of the methods in the `Clipper` interface.\r\n */\r\n public static isClipper(obj: any): boolean {\r\n if (obj) {\r\n if (obj.isPointOnOrInside\r\n && obj.announceClippedSegmentIntervals\r\n && obj.announceClippedArcIntervals)\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Specialized logic for replacing clip fragments by an equivalent singleton.\r\n * * If there are baseCount + 1 or fewer fragments, do nothing.\r\n * * If there are more than baseCount+1 fragments:\r\n * * drop them all to the cache\r\n * * push a copy of the singleton.\r\n * * The use case for this is that a multi-step clipper (e.g. UnionOfConvexClipPlaneSets) may produce many fragments,\r\n * and then be able to determine that they really are the original pre-clip polygon unchanged.\r\n * * The baseCount+1 case is the case where the entire original singleton is still a singleton and can be left alone.\r\n * * Calling this replacer shuffles the original back into the fragment array, and drops the fragments.\r\n * * This determination is solely within the logic of the caller.\r\n * @param shards array of fragments\r\n * @param baseCount original count\r\n * @param singleton single array which may be a replacement for multiple fragments\r\n * @param cache cache for array management\r\n */\r\n public static restoreSingletonInPlaceOfMultipleShards(\r\n fragments: GrowableXYZArray[] | undefined, baseCount: number, singleton: IndexedXYZCollection, arrayCache: GrowableXYZArrayCache,\r\n ): void {\r\n if (fragments && fragments.length > baseCount + 1) {\r\n while (fragments.length > baseCount) {\r\n const f = fragments.pop();\r\n arrayCache.dropToCache(f);\r\n }\r\n fragments.push(arrayCache.grabAndFill(singleton));\r\n }\r\n }\r\n /**\r\n * Create a UnionOfConvexClipPlaneSets for a volume defined by a path and offsets.\r\n * @param points points along the path.\r\n * @param positiveOffsetLeft offset to left. 0 is clip on the path.\r\n * @param positiveOffsetRight offset to the right. 0 is clip on the path.\r\n * @param z0 z for lower clipping plane. If undefined, unbounded in positive z\r\n * @param z1 z for upper clipping plane. If undefined, unbounded in negative z.\r\n * @alpha\r\n */\r\n public static createXYOffsetClipFromLineString(\r\n points: Point3d[] | IndexedXYZCollection, leftOffset: number, rightOffset: number, z0: number, z1: number,\r\n ): UnionOfConvexClipPlaneSets {\r\n if (Array.isArray(points)) {\r\n return LineStringOffsetClipperContext.createClipBetweenOffsets(\r\n new Point3dArrayCarrier(points), leftOffset, rightOffset, z0, z1);\r\n }\r\n return LineStringOffsetClipperContext.createClipBetweenOffsets(points, leftOffset, rightOffset, z0, z1);\r\n }\r\n /** If data.length >= minLength threshold, push it to destination; if smaller drop it back to the cache. */\r\n public static captureOrDrop(\r\n data: GrowableXYZArray, minLength: number, destination: GrowableXYZArray[], cache: GrowableXYZArrayCache,\r\n ): void {\r\n if (data.length >= minLength)\r\n destination.push(data);\r\n else\r\n cache.dropToCache(data);\r\n }\r\n /**\r\n * Find the portion of a line within a half-plane clip.\r\n * * The half-plane clip is to the left of the line from clipA to clipB.\r\n * * The original clipped segment has fractions 0 and 1 at respective segment points.\r\n * * Caller initializes the interval\r\n * * This method reduces the interval size.\r\n * * See clipSegmentToCCWTriangleXY for typical use.\r\n * @param linePointA First point of clip line\r\n * @param linePointB Second point of clip line\r\n * @param segmentPoint0 First point of clipped segment\r\n * @param segmentPoint1 Second point of clipped segment\r\n * @param interval Live interval.\r\n * @param absoluteTolerance absolute tolerance for both cross product values to indicate \"on\" the line\r\n */\r\n public static clipSegmentToLLeftOfLineXY(\r\n linePointA: XAndY, linePointB: XAndY, segmentPoint0: XAndY, segmentPoint1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n const ux = linePointB.x - linePointA.x;\r\n const uy = linePointB.y - linePointA.y;\r\n // negative is in positive is out ...\r\n const h0 = -(ux * (segmentPoint0.y - linePointA.y) - uy * (segmentPoint0.x - linePointA.x));\r\n const h1 = -(ux * (segmentPoint1.y - linePointA.y) - uy * (segmentPoint1.x - linePointA.x));\r\n if (h0 < absoluteTolerance && h1 < absoluteTolerance) {\r\n // The entire segment is in .....\r\n return;\r\n }\r\n if (h0 * h1 > 0.0) {\r\n if (h0 > 0.0)\r\n interval.setNull();\r\n } else if (h0 * h1 < 0.0) {\r\n // strict crossing with safe fraction . . .\r\n const fraction = -h0 / (h1 - h0);\r\n if (h0 < 0.0) {\r\n return interval.intersectRangeXXInPlace(0.0, fraction);\r\n } else {\r\n return interval.intersectRangeXXInPlace(fraction, 1.0);\r\n }\r\n } else {\r\n // There is an exact hit at one end, possibly non-zero at the other ... the sign of either determines which side is in play\r\n // A zero and a zero or negative is entirely in, which does not alter the prior clip.\r\n if (h0 > 0.0) {\r\n interval.intersectRangeXXInPlace(1.0, 1.0);\r\n } else if (h1 > 0.0) {\r\n interval.intersectRangeXXInPlace(0.0, 0.0);\r\n }\r\n }\r\n }\r\n /**\r\n * Clip an interval of a line segment to a triangle.\r\n * * Triangle is assumed CCW\r\n * @param pointA point of triangle.\r\n * @param pointB point of triangle.\r\n * @param pointC point of triangle.\r\n * @param segment0 start of segment\r\n * @param segment1 end of segment\r\n * @param interval Pre-initialized interval of live part of segment\r\n * @param absoluteTolerance absolute tolerance for begin \"on a line\"\r\n */\r\n public static clipSegmentToCCWTriangleXY(\r\n pointA: XAndY, pointB: XAndY, pointC: XAndY, segment0: XAndY, segment1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointA, pointB, segment0, segment1, interval, absoluteTolerance);\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointB, pointC, segment0, segment1, interval, absoluteTolerance);\r\n if (!interval.isNull) {\r\n this.clipSegmentToLLeftOfLineXY(pointC, pointA, segment0, segment1, interval, absoluteTolerance);\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * Find the portion of a line within a half-plane clip.\r\n * * The half-plane clip is to the left of the line from clipA to clipB.\r\n * * The original clipped segment has fractions 0 and 1 at respective segment points.\r\n * * Caller initializes the interval\r\n * * This method reduces the interval size.\r\n * * See clipSegmentToCCWTriangleXY for typical use.\r\n * @param linePointA First point of clip line\r\n * @param linePointB Second point of clip line\r\n * @param segmentPoint0 First point of clipped segment\r\n * @param segmentPoint1 Second point of clipped segment\r\n * @param interval Live interval.\r\n * @param absoluteTolerance absolute tolerance for both cross product values to indicate \"on\" the line\r\n */\r\n public static clipSegmentBelowPlaneXY(\r\n plane: Plane3dByOriginAndUnitNormal, segmentPoint0: XAndY, segmentPoint1: XAndY, interval: Range1d, absoluteTolerance: number = 1.0e-14,\r\n ): void {\r\n // negative is in positive is out ...\r\n const h0 = plane.altitudeXY(segmentPoint0.x, segmentPoint0.y);\r\n const h1 = plane.altitudeXY(segmentPoint1.x, segmentPoint1.y);\r\n if (h0 < absoluteTolerance && h1 < absoluteTolerance) {\r\n // The entire segment is in ..... the interval is unaffected.\r\n return;\r\n }\r\n if (h0 * h1 > 0.0) {\r\n if (h0 > 0.0)\r\n interval.setNull();\r\n } else if (h0 * h1 < 0.0) {\r\n // strict crossing with safe fraction . . .\r\n const fraction = -h0 / (h1 - h0);\r\n if (h0 < 0.0) {\r\n return interval.intersectRangeXXInPlace(0.0, fraction);\r\n } else {\r\n return interval.intersectRangeXXInPlace(fraction, 1.0);\r\n }\r\n } else {\r\n // There is an exact hit at one end, possibly non-zero at the other ... the sign of either determines which side is in play\r\n // A zero and a zero or negative is entirely in, which does not alter the prior clip.\r\n if (h0 > 0.0) {\r\n interval.intersectRangeXXInPlace(1.0, 1.0);\r\n } else if (h1 > 0.0) {\r\n interval.intersectRangeXXInPlace(0.0, 0.0);\r\n }\r\n }\r\n }\r\n /**\r\n * Clip an interval of a line segment to an array of planes\r\n * * plane normals assumed OUTWARD\r\n * * planeAltitude is typically a tolerance a tolerance distance.\r\n * * positive altitude makes tha plane move in the direction of the unit normal.\r\n * @param planes array of planes\r\n * @param segment0 start of segment\r\n * @param segment1 end of segment\r\n * @param interval Pre-initialized interval of live part of segment\r\n * @param absoluteTolerance absolute tolerance for begin \"on a line\"\r\n */\r\n public static clipSegmentBelowPlanesXY(\r\n planes: Plane3dByOriginAndUnitNormal[], segment0: XAndY, segment1: XAndY, interval: Range1d, signedAltitude: number = 1.0e-14,\r\n ): void {\r\n const numPlanes = planes.length;\r\n for (let i = 0; (!interval.isNull) && i < numPlanes; i++) {\r\n this.clipSegmentBelowPlaneXY(planes[i], segment0, segment1, interval, signedAltitude);\r\n }\r\n }\r\n /**\r\n * Pass line segments from a polyline to the clipper. Resolve the fractional clips to simple points for announcement.\r\n * @param clipper clipper to call\r\n * @param points polyline whose segments are passed to the clipper\r\n * @param announce caller's handler for simple point pairs.\r\n */\r\n public static announcePolylineClip(\r\n clipper: Clipper, points: Point3d[], announce: (point0: Point3d, point1: Point3d) => void,\r\n ): void {\r\n for (let i = 0; i + 1 < points.length; i++) {\r\n clipper.announceClippedSegmentIntervals(0, 1, points[i], points[i + 1],\r\n (f0: number, f1: number) => {\r\n announce(points[i].interpolate(f0, points[i + 1]), points[i].interpolate(f1, points[i + 1]));\r\n });\r\n }\r\n }\r\n /**\r\n * Pass line segments from a polyline to the clipper. Sum the lengths of the clipped pieces. Return the sum.\r\n * @param clipper clipper to call\r\n * @param points polyline whose segments are passed to the clipper\r\n */\r\n public static sumPolylineClipLength(clipper: Clipper, points: Point3d[]): number {\r\n let s = 0;\r\n for (let i = 0; i + 1 < points.length; i++) {\r\n const a = points[i].distance(points[i + 1]);\r\n clipper.announceClippedSegmentIntervals(0, 1, points[i], points[i + 1],\r\n (f0: number, f1: number) => { s += Math.abs(f1 - f0) * a; });\r\n }\r\n return s;\r\n }\r\n /**\r\n * Pass polygon `xyz` through a sequence of PolygonClip steps.\r\n * * At the outset, `xyz` is the (only) entry in a set of candidates.\r\n * * For each clipper, each candidate is presented for appendPolygon to inside and outside parts.\r\n * * Each (in,out) result is distributed among (acceptedIn, acceptedOut, candidates) according to\r\n * (inAction, outAction)\r\n * * At the end, all remaining candidates are distributed among (acceptedIn, acceptedOut, finalUnknown)\r\n * according to finalAction\r\n * * Any clipper that does not have an appendPolygonClip method is skipped.\r\n * @param xyz\r\n * @param clippers\r\n * @param acceptedIn\r\n * @param acceptedOut\r\n * @param finalCandidates\r\n * @param inAction\r\n * @param outAction\r\n * @param finalCandidateAction\r\n */\r\n public static doPolygonClipSequence(\r\n xyz: IndexedXYZCollection,\r\n clippers: Clipper[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n finalCandidates: GrowableXYZArray[] | undefined,\r\n inAction: ClipStepAction,\r\n outAction: ClipStepAction,\r\n finalFragmentAction: ClipStepAction,\r\n arrayCache: GrowableXYZArrayCache | undefined,\r\n ) {\r\n if (arrayCache === undefined)\r\n arrayCache = new GrowableXYZArrayCache();\r\n let candidates = [arrayCache.grabAndFill(xyz)];\r\n let nextCandidates: GrowableXYZArray[] = [];\r\n const intermediateIn: GrowableXYZArray[] = [];\r\n const intermediateOut: GrowableXYZArray[] = [];\r\n const oldInsideCount = acceptedIn ? acceptedIn.length : 0;\r\n const oldOutsideCount = acceptedOut ? acceptedOut.length : 0;\r\n let shard;\r\n // At each convex set, carryForwardA is all the fragments that have been outside all previous convex sets.\r\n // Clip each such fragment to the current set, sending the outside parts to carryForwardB, which will got to\r\n // the next clipper. The final surviving carryForward really is out.\r\n for (const c of clippers) {\r\n if (c.appendPolygonClip) {\r\n while (undefined !== (shard = candidates.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(inAction, intermediateIn, acceptedIn, acceptedOut, nextCandidates, arrayCache);\r\n distributeFragments(outAction, intermediateOut, acceptedIn, acceptedOut, nextCandidates, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // candidates is empty !!\r\n const temp = candidates; candidates = nextCandidates; nextCandidates = temp;\r\n }\r\n }\r\n distributeFragments(finalFragmentAction, candidates, acceptedIn, acceptedOut, finalCandidates, arrayCache);\r\n // Note: The following assumes that there were no residual candidates ... need to track if that happened?\r\n // If nothing was out, the inside fragments can be replaced by the original.\r\n if (acceptedOut?.length === oldOutsideCount)\r\n ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedIn, oldInsideCount, xyz, arrayCache);\r\n // If nothing was in, the outside fragments can be replaced by the original.\r\n if (acceptedIn?.length === oldInsideCount)\r\n ClipUtilities.restoreSingletonInPlaceOfMultipleShards(acceptedOut, oldOutsideCount, xyz, arrayCache);\r\n }\r\n /** Pass polygon `xyz` through a sequence of PolygonClip steps with \"parity\" rules */\r\n public static doPolygonClipParitySequence(\r\n xyz: IndexedXYZCollection,\r\n clippers: Clipper[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache | undefined,\r\n ) {\r\n if (arrayCache === undefined)\r\n arrayCache = new GrowableXYZArrayCache();\r\n let candidatesOut = [arrayCache.grabAndFill(xyz)];\r\n let candidatesIn: GrowableXYZArray[] = [];\r\n let nextCandidatesIn: GrowableXYZArray[] = [];\r\n let nextCandidatesOut: GrowableXYZArray[] = [];\r\n const intermediateIn: GrowableXYZArray[] = [];\r\n const intermediateOut: GrowableXYZArray[] = [];\r\n let shard;\r\n // at each step ..\r\n // candidatesIn and candidatesOut are evolved in and out\r\n // nextCandidatesIn and nextCandidatesOut are EMPTY\r\n for (const c of clippers) {\r\n if (c.appendPolygonClip) {\r\n // (IN,OUT) parts of IN parts distribute to (OUT,IN)\r\n while (undefined !== (shard = candidatesIn.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(ClipStepAction.acceptOut, intermediateIn, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n distributeFragments(ClipStepAction.acceptIn, intermediateOut, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // (IN,OUT) parts of IN parts distribute to (OUT,IN)\r\n while (undefined !== (shard = candidatesOut.pop())) {\r\n c.appendPolygonClip(shard, intermediateIn, intermediateOut, arrayCache);\r\n distributeFragments(ClipStepAction.acceptIn, intermediateIn, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n distributeFragments(ClipStepAction.acceptOut, intermediateOut, nextCandidatesIn, nextCandidatesOut, undefined, arrayCache);\r\n arrayCache.dropToCache(shard);\r\n }\r\n // reload each candidate step\r\n const tempA = candidatesIn; candidatesIn = nextCandidatesIn; nextCandidatesIn = tempA;\r\n const tempB = candidatesOut; candidatesOut = nextCandidatesOut; nextCandidatesOut = tempB;\r\n }\r\n }\r\n // candidatesIn and candidatesOut are final ....\r\n if (candidatesOut.length === 0)\r\n acceptedIn?.push(arrayCache.grabAndFill(xyz));\r\n else if (candidatesOut.length === 0)\r\n acceptedOut?.push(arrayCache.grabAndFill(xyz));\r\n else {\r\n moveFragments(candidatesIn, acceptedIn, arrayCache);\r\n moveFragments(candidatesOut, acceptedOut, arrayCache);\r\n }\r\n }\r\n /**\r\n * For each plane of clipper, construct a UnionOfConvexClipPlaneSets for an outer (infinite) convex volume that\r\n * abuts the outer volume of the neighbor faces.\r\n */\r\n public static createComplementaryClips(clipper: ConvexClipPlaneSet): UnionOfConvexClipPlaneSets {\r\n const planes = clipper.planes;\r\n const interval = Range1d.createNull();\r\n const n = planes.length;\r\n const newClippers: ConvexClipPlaneSet[] = [];\r\n for (const p of planes) {\r\n const outerSet = ConvexClipPlaneSet.createEmpty();\r\n outerSet.addPlaneToConvexSet(p.cloneNegated());\r\n newClippers.push(outerSet);\r\n }\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n const ray = CurveFactory.planePlaneIntersectionRay(planes[i], planes[j]);\r\n if (ray) {\r\n if (clipper.hasIntersectionWithRay(ray, interval)) {\r\n // the normal-to-normal vector is bisector (or close to bisector?)\r\n const newNormal = planes[j].inwardNormalRef.minus(planes[i].inwardNormalRef);\r\n const plane1 = ClipPlane.createNormalAndPoint(newNormal, ray.origin);\r\n if (plane1) {\r\n const plane2 = plane1.cloneNegated();\r\n newClippers[i].addPlaneToConvexSet(plane1);\r\n newClippers[j].addPlaneToConvexSet(plane2);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return UnionOfConvexClipPlaneSets.createConvexSets(newClippers);\r\n }\r\n}\r\nfunction moveFragments(\r\n fragments: GrowableXYZArray[],\r\n destination: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache,\r\n) {\r\n if (destination === undefined)\r\n arrayCache.dropAllToCache(fragments);\r\n else {\r\n for (const f of fragments)\r\n destination.push(f);\r\n }\r\n fragments.length = 0;\r\n}\r\n/**\r\n * Distribute fragments among acceptedIn, acceptedOut, and passToNextStep as directed by action.\r\n * * If the indicated destination is unknown, drop the fragments to the arrayCache.\r\n * @param action destination selector\r\n * @param fragments fragments to be distributed\r\n * @param acceptedIn destination for \"in\"\r\n * @param acceptedOut destination for \"out\"\r\n * @param passToNextStep destination for fragments to be passed to a later step\r\n * @param arrayCache destination for un-distributed fragments.\r\n */\r\nfunction distributeFragments(\r\n action: ClipStepAction,\r\n fragments: GrowableXYZArray[],\r\n acceptedIn: GrowableXYZArray[] | undefined,\r\n acceptedOut: GrowableXYZArray[] | undefined,\r\n passToNextStep: GrowableXYZArray[] | undefined,\r\n arrayCache: GrowableXYZArrayCache,\r\n) {\r\n let destination;\r\n if (action === ClipStepAction.acceptIn)\r\n destination = acceptedIn;\r\n else if (action === ClipStepAction.acceptOut)\r\n destination = acceptedOut;\r\n else if (action === ClipStepAction.passToNextStep)\r\n destination = passToNextStep;\r\n // remark: if action is other than the enum values, destination is undefined\r\n if (destination === undefined)\r\n arrayCache.dropAllToCache(fragments);\r\n else {\r\n for (const f of fragments)\r\n destination.push(f);\r\n }\r\n fragments.length = 0;\r\n}\r\n"]}
@@ -247,7 +247,8 @@ export class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {
247
247
  computeStep() {
248
248
  if (this._func.evaluate(this._currentUV.x, this._currentUV.y)) {
249
249
  const fA = this._func.currentF;
250
- if (SmallSystem.linearSystem2d(fA.vectorU.x, fA.vectorV.x, fA.vectorU.y, fA.vectorV.y, fA.origin.x, fA.origin.y, this._currentStep))
250
+ if ( // Given X_{n+1} = X_n - dX = X_n - JInv(X_n) F(X_n), we solve J(X_n) dX = F(X_n) for dX:
251
+ SmallSystem.linearSystem2d(fA.vectorU.x, fA.vectorV.x, fA.vectorU.y, fA.vectorV.y, fA.origin.x, fA.origin.y, this._currentStep))
251
252
  return true;
252
253
  }
253
254
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"Newton.js","sourceRoot":"","sources":["../../../src/numerics/Newton.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,0BAA0B;AAE1B;;;;GAIG;AACH,MAAM,OAAgB,sBAAsB;IAa1C;;;;;;;;;;;OAWG;IACH,YACE,oBAA4B,OAAO,EACnC,8BAAsC,CAAC,EACvC,gBAAwB,EAAE;QAM5B,sEAAsE;QAC5D,iBAAY,GAAW,CAAC,CAAC;QAOnC,uDAAuD;QAChD,kBAAa,GAAW,CAAC,CAAC;QAb/B,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAC5C,IAAI,CAAC,4BAA4B,GAAG,2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SAAS,GAAG,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;gBACrD,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE;oBAC5B,YAAY,EAAE,CAAC;oBACf,IAAI,EAAE,KAAK,GAAG,IAAI,YAAY,GAAG,CAAC,EAAI,wCAAwC;wBAC5E,OAAO,CAAC,CAAC;iBACZ;qBAAM;oBACL,YAAY,GAAG,CAAC,CAAC;iBAClB;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,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 { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point2d, Vector2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { SmallSystem } from \"./Polynomials\";\r\n\r\n// cspell:word currentdFdX\r\n\r\n/**\r\n * Base class for Newton iterations in various dimensions.\r\n * Dimension-specific classes carry all dimension-related data and answer generalized queries from this base class.\r\n * @internal\r\n */\r\nexport abstract class AbstractNewtonIterator {\r\n /** Compute a step. The current x and function values must be retained for use in later method calls. */\r\n public abstract computeStep(): boolean;\r\n /**\r\n * Return the current step size, scaled for use in tolerance tests.\r\n * * This is a single number, typically the max of various per-dimension `dx/(1+x)` for the x and dx of that dimension.\r\n */\r\n public abstract currentStepSize(): number;\r\n /**\r\n * Apply the current step (in all dimensions).\r\n * @param isFinalStep true if this is a final step.\r\n */\r\n public abstract applyCurrentStep(isFinalStep: boolean): boolean;\r\n /**\r\n * The constructor.\r\n * @param stepSizeTarget tolerance to consider a single step converged.\r\n * This number should be \"moderately\" strict. Because 2 successive convergences are required,\r\n * it is expected that a first \"accept\" for (say) 10 to 14 digit step will be followed by another\r\n * iteration. A well behaved newton would then hypothetically double the number of digits to\r\n * 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will\r\n * typically achieve full precision.\r\n * @param successiveConvergenceTarget number of successive convergences required for acceptance.\r\n * @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations.\r\n * Allow 15 to 20 to catch difficult cases.\r\n */\r\n protected constructor(\r\n stepSizeTolerance: number = 1.0e-11,\r\n successiveConvergenceTarget: number = 2,\r\n maxIterations: number = 15,\r\n ) {\r\n this._stepSizeTolerance = stepSizeTolerance;\r\n this._successiveConvergenceTarget = successiveConvergenceTarget;\r\n this._maxIterations = maxIterations;\r\n }\r\n /** Number of consecutive steps which passed convergence condition. */\r\n protected _numAccepted: number = 0;\r\n /** Target number of successive convergences. */\r\n protected _successiveConvergenceTarget: number;\r\n /** Convergence target (the implementation-specific currentStepSize is compared to this). */\r\n protected _stepSizeTolerance: number;\r\n /** Max iterations allowed. */\r\n protected _maxIterations: number;\r\n /** Number of iterations (incremented at each step). */\r\n public numIterations: number = 0;\r\n /**\r\n * Test if a step is converged.\r\n * * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance)\r\n * occur in succession.\r\n * @param delta step size as reported by currentStepSize.\r\n */\r\n public testConvergence(delta: number): boolean {\r\n if (Math.abs(delta) < this._stepSizeTolerance) {\r\n this._numAccepted++;\r\n return this._numAccepted >= this._successiveConvergenceTarget;\r\n }\r\n this._numAccepted = 0;\r\n return false;\r\n }\r\n /**\r\n * Run iterations, calling various methods from base and derived classes:\r\n * * computeStep -- typically evaluate derivatives and solve linear system.\r\n * * currentStepSize -- return numeric measure of the step just computed by computeStep.\r\n * * testConvergence -- test if the step from currentStepSize (along with recent steps) is converged.\r\n * * applyCurrentStep -- apply the step to the independent variables.\r\n */\r\n public runIterations(): boolean {\r\n this._numAccepted = 0;\r\n this.numIterations = 0;\r\n while (this.numIterations++ < this._maxIterations && this.computeStep()) {\r\n if (this.testConvergence(this.currentStepSize()) && this.applyCurrentStep(true)) {\r\n return true;\r\n }\r\n this.applyCurrentStep(false);\r\n }\r\n return false;\r\n }\r\n}\r\n/**\r\n * Object to evaluate a newton function. The object must retain most-recent function and derivative\r\n * values for immediate query.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRtoRD {\r\n /** Evaluate the function and its derivative at x. */\r\n public abstract evaluate(x: number): boolean;\r\n /** Most recent function value, i.e., f(x_n). */\r\n public currentF!: number;\r\n /** Most recent evaluated derivative, i.e., f'(x_n). */\r\n public currentdFdX!: number;\r\n}\r\n/**\r\n * Newton iterator for use when both function and derivative can be evaluated.\r\n * To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`.\r\n * To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is\r\n * `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`.\r\n * @internal\r\n */\r\nexport class Newton1dUnbounded extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRtoRD;\r\n /** Current step is dx. */\r\n private _currentStep!: number;\r\n /** Current X is x_n. */\r\n private _currentX!: number;\r\n /** The target */\r\n private _target!: number;\r\n /**\r\n * Constructor for 1D newton iteration with derivatives.\r\n * @param func function that returns both function value and derivative.\r\n */\r\n public constructor(func: NewtonEvaluatorRtoRD) {\r\n super();\r\n this._func = func;\r\n this.setTarget(0);\r\n }\r\n /** Set the independent variable, i.e., x_n. */\r\n public setX(x: number): boolean {\r\n this._currentX = x;\r\n return true;\r\n }\r\n /** Get the independent variable, i.e., x_n. */\r\n public getX(): number {\r\n return this._currentX;\r\n }\r\n /** Set the target function value. */\r\n public setTarget(y: number): void {\r\n this._target = y;\r\n }\r\n /** Move the current X by the just-computed step, i.e., `x_n - dx`. */\r\n public applyCurrentStep(): boolean {\r\n // console.log(this._currentX - this._currentStep); // print approximations for debug\r\n return this.setX(this._currentX - this._currentStep);\r\n }\r\n /** Compute the univariate newton step. */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentX)) {\r\n const dx = Geometry.conditionalDivideFraction(this._func.currentF - this._target, this._func.currentdFdX);\r\n if (dx !== undefined) {\r\n this._currentStep = dx;\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */\r\n public currentStepSize(): number {\r\n return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));\r\n }\r\n}\r\n\r\n/**\r\n * Object to evaluate a newton function (without derivative). The object must retain most-recent function value.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRtoR {\r\n /** Evaluate function value into member currentF */\r\n public abstract evaluate(x: number): boolean;\r\n /** Most recent function evaluation, i.e., f(x_n). */\r\n public currentF!: number;\r\n}\r\n\r\n/**\r\n * Newton iteration for a univariate function, using approximate derivatives.\r\n * To approximate the derivatives we use a small step `h`, i.e., `f'(x_n) = (f(x_n + h) - f(x_n)) / h`.\r\n * Therefore, to solve `f(x) = 0`, the iteration is\r\n * `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n) = x_n - f(x_n) * h / (f(x_n + h) - f(x_n))`.\r\n * @internal\r\n */\r\nexport class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRtoR;\r\n /** Current step is dx. */\r\n private _currentStep!: number;\r\n /** Current X is x_n. */\r\n private _currentX!: number;\r\n /**\r\n * Step size for approximate derivative for the iteration.\r\n * * Initialized to 1e-8, which is appropriate for iteration in fraction space.\r\n * * Should be larger for iteration with real distance as x.\r\n */\r\n public derivativeH: number; // h\r\n\r\n /**\r\n * Constructor for 1D newton iteration with approximate derivatives.\r\n * @param func function that only returns function value (and not derivative).\r\n */\r\n public constructor(func: NewtonEvaluatorRtoR) {\r\n super();\r\n this._func = func;\r\n this.derivativeH = 1.0e-8;\r\n }\r\n /** Set the independent variable, i.e., x_n. */\r\n public setX(x: number): boolean {\r\n this._currentX = x;\r\n return true;\r\n }\r\n /** Get the independent variable, i.e., x_n. */\r\n public getX(): number {\r\n return this._currentX;\r\n }\r\n /** Move the current X by the just-computed step, i.e., `x_n - dx`. */\r\n public applyCurrentStep(): boolean {\r\n // console.log(this._currentX - this._currentStep); // print approximations for debug\r\n return this.setX(this._currentX - this._currentStep);\r\n }\r\n /** Univariate newton step computed with approximate derivative. */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentX)) {\r\n const fA = this._func.currentF; // f(x_n)\r\n if (this._func.evaluate(this._currentX + this.derivativeH)) {\r\n const fB = this._func.currentF; // f(x_n + h)\r\n const dx = Geometry.conditionalDivideFraction(fA, (fB - fA) / this.derivativeH);\r\n if (dx !== undefined) {\r\n this._currentStep = dx;\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */\r\n public currentStepSize(): number {\r\n return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));\r\n }\r\n}\r\n\r\n/**\r\n * Object to evaluate a 2-parameter newton function with derivatives.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRRtoRRD {\r\n /**\r\n * Iteration controller calls this to ask for evaluation of the function and its two partial derivatives.\r\n * * The implementation returns true, it must set the currentF object.\r\n */\r\n public abstract evaluate(x: number, y: number): boolean;\r\n /**\r\n * Most recent function evaluation as parts of the plane.\r\n * * See doc of [[Newton2dUnboundedWithDerivative]] class for info on 2d newton method.\r\n * * For current value (u,v) of the independent variable, and `F(u,v) := (x(u,v), y(u,v)), the returned plane has:\r\n * * `origin.x` = x(u,v)\r\n * * `origin.y` = y(u,v)\r\n * * `vectorU.x` = dx/du\r\n * * `vectorU.y` = dy/du\r\n * * `vectorV.x` = dx/dv\r\n * * `vectorV.y` = dy/dv\r\n * * In other words, the plane stores the columns of the Jacobian matrix J of F: `vectorU` stores the partials\r\n * of F with respect to u (the first column of J), and `vectorV` stores the partials of F with respect to v\r\n * (the second column of J):\r\n *\r\n * `[vectorU.x vectorV.x]`\r\n *\r\n * `[vectorU.y vectorV.y]`\r\n */\r\n public currentF!: Plane3dByOriginAndVectors;\r\n /**\r\n * Constructor.\r\n * * This creates a currentF object to (repeatedly) receive function and derivatives.\r\n */\r\n public constructor() {\r\n this.currentF = Plane3dByOriginAndVectors.createXYPlane();\r\n }\r\n}\r\n\r\n/**\r\n * Implement evaluation steps for newton iteration in 2 dimensions, using caller supplied NewtonEvaluatorRRtoRRD object.\r\n * * Suppose we want to find the roots of `F(u,v) := (x(u,v), y(u,v))`. Writing `X := (u,v)` and `F(X)` as column vectors,\r\n * the 2D Newton's iteration to find a root of `F` is given by:\r\n * `X_{n+1} = X_n - dX = X_n - JInv(X_n)F(X_n)`, where `JInv` is the inverse of the Jacobian matrix `J`, and `J` is\r\n * defined as:\r\n *\r\n * `[dx/du dx/dv]`\r\n *\r\n * `[dy/du dy/dv]`\r\n * @internal\r\n */\r\nexport class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRRtoRRD;\r\n /** Current step, or dX = (du, dv). */\r\n private _currentStep: Vector2d;\r\n /** Current uv parameters, or X_n = (u_n, v_n). */\r\n private _currentUV: Point2d;\r\n /**\r\n * Constructor for 2D newton iteration with derivatives.\r\n * @param func function that returns both function value and derivative.\r\n */\r\n public constructor(func: NewtonEvaluatorRRtoRRD) {\r\n super();\r\n this._func = func;\r\n this._currentStep = Vector2d.createZero();\r\n this._currentUV = Point2d.createZero();\r\n }\r\n /** Set the current uv parameters, i.e., `X_n = (u_n, v_n)`. */\r\n public setUV(u: number, v: number): boolean {\r\n this._currentUV.set(u, v);\r\n return true;\r\n }\r\n /** Get the current u parameter of X_n, i.e., u_n. */\r\n public getU(): number {\r\n return this._currentUV.x;\r\n }\r\n /** Get the current v parameter of X_n, i.e., v_n. */\r\n public getV(): number {\r\n return this._currentUV.y;\r\n }\r\n /** Update the current uv parameter by currentStep, i.e., compute `X_{n+1} := X_n - dX = (u_n - du, v_n - dv)`. */\r\n public applyCurrentStep(): boolean {\r\n // print approximations for debug\r\n // console.log(\"(\" + (this._currentUV.x - this._currentStep.x) + \",\" + (this._currentUV.y - this._currentStep.y) + \")\");\r\n return this.setUV(this._currentUV.x - this._currentStep.x, this._currentUV.y - this._currentStep.y);\r\n }\r\n /**\r\n * Evaluate the functions and derivatives at `X_n = (u_n, v_n)`, and solve the Jacobian matrix equation to\r\n * compute `dX = (du, dv)`.\r\n */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentUV.x, this._currentUV.y)) {\r\n const fA = this._func.currentF;\r\n if (\r\n SmallSystem.linearSystem2d(\r\n fA.vectorU.x, fA.vectorV.x,\r\n fA.vectorU.y, fA.vectorV.y,\r\n fA.origin.x, fA.origin.y,\r\n this._currentStep,\r\n )\r\n )\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Return the current relative step size, i.e., the larger absolute component of `dX / (1 + |X_n|)`\r\n */\r\n public currentStepSize(): number {\r\n return Geometry.maxAbsXY(\r\n this._currentStep.x / (1.0 + Math.abs(this._currentUV.x)),\r\n this._currentStep.y / (1.0 + Math.abs(this._currentUV.y)),\r\n );\r\n }\r\n}\r\n/**\r\n * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments\r\n * (not function object).\r\n * @internal\r\n */\r\nexport class SimpleNewton {\r\n /**\r\n * Run a one-dimensional newton iteration with separate functions for function and derivative.\r\n * * Completion is at 2 (TWO) successive passes at `absoluteTolerance + relTol * abs(x)`, where relTol is\r\n * chosen internally.\r\n * * `absoluteTolerance` is usually aggressively tight -- should come into play only for x near zero.\r\n * * The `relTol` is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after\r\n * first success normally moves to full machine precision.\r\n * * This is an open-loop newton -- it just runs, and returns undefined if anything bad happens.\r\n */\r\n public static runNewton1D(\r\n x: number,\r\n func: (x: number) => number | undefined,\r\n derivative: (x: number) => number | undefined,\r\n absoluteTolerance: number = Geometry.smallFloatingPoint,\r\n ): number | undefined {\r\n let numConverged = 0;\r\n let tolerance: number;\r\n const relTol = 1.0e-11;\r\n for (let iteration = 0; iteration < 20; iteration++) {\r\n const f = func(x);\r\n const df = derivative(x);\r\n if (f !== undefined && df !== undefined) {\r\n const dx = Geometry.conditionalDivideCoordinate(f, df);\r\n if (dx === undefined)\r\n return undefined;\r\n x -= dx;\r\n // console.log(x); // print approximations for debug\r\n tolerance = absoluteTolerance + Math.abs(x) * relTol;\r\n if (Math.abs(dx) < tolerance) {\r\n numConverged++;\r\n if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx\r\n return x;\r\n } else {\r\n numConverged = 0;\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Newton.js","sourceRoot":"","sources":["../../../src/numerics/Newton.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,0BAA0B;AAE1B;;;;GAIG;AACH,MAAM,OAAgB,sBAAsB;IAa1C;;;;;;;;;;;OAWG;IACH,YACE,oBAA4B,OAAO,EACnC,8BAAsC,CAAC,EACvC,gBAAwB,EAAE;QAM5B,sEAAsE;QAC5D,iBAAY,GAAW,CAAC,CAAC;QAOnC,uDAAuD;QAChD,kBAAa,GAAW,CAAC,CAAC;QAb/B,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAC5C,IAAI,CAAC,4BAA4B,GAAG,2BAA2B,CAAC;QAChE,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAWD;;;;;O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GAAG,MAAM,CAAC;gBACrD,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE;oBAC5B,YAAY,EAAE,CAAC;oBACf,IAAI,EAAE,KAAK,GAAG,IAAI,YAAY,GAAG,CAAC,EAAI,wCAAwC;wBAC5E,OAAO,CAAC,CAAC;iBACZ;qBAAM;oBACL,YAAY,GAAG,CAAC,CAAC;iBAClB;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,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 { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point2d, Vector2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { SmallSystem } from \"./Polynomials\";\r\n\r\n// cspell:word currentdFdX\r\n\r\n/**\r\n * Base class for Newton iterations in various dimensions.\r\n * Dimension-specific classes carry all dimension-related data and answer generalized queries from this base class.\r\n * @internal\r\n */\r\nexport abstract class AbstractNewtonIterator {\r\n /** Compute a step. The current x and function values must be retained for use in later method calls. */\r\n public abstract computeStep(): boolean;\r\n /**\r\n * Return the current step size, scaled for use in tolerance tests.\r\n * * This is a single number, typically the max of various per-dimension `dx/(1+x)` for the x and dx of that dimension.\r\n */\r\n public abstract currentStepSize(): number;\r\n /**\r\n * Apply the current step (in all dimensions).\r\n * @param isFinalStep true if this is a final step.\r\n */\r\n public abstract applyCurrentStep(isFinalStep: boolean): boolean;\r\n /**\r\n * The constructor.\r\n * @param stepSizeTarget tolerance to consider a single step converged.\r\n * This number should be \"moderately\" strict. Because 2 successive convergences are required,\r\n * it is expected that a first \"accept\" for (say) 10 to 14 digit step will be followed by another\r\n * iteration. A well behaved newton would then hypothetically double the number of digits to\r\n * 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will\r\n * typically achieve full precision.\r\n * @param successiveConvergenceTarget number of successive convergences required for acceptance.\r\n * @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations.\r\n * Allow 15 to 20 to catch difficult cases.\r\n */\r\n protected constructor(\r\n stepSizeTolerance: number = 1.0e-11,\r\n successiveConvergenceTarget: number = 2,\r\n maxIterations: number = 15,\r\n ) {\r\n this._stepSizeTolerance = stepSizeTolerance;\r\n this._successiveConvergenceTarget = successiveConvergenceTarget;\r\n this._maxIterations = maxIterations;\r\n }\r\n /** Number of consecutive steps which passed convergence condition. */\r\n protected _numAccepted: number = 0;\r\n /** Target number of successive convergences. */\r\n protected _successiveConvergenceTarget: number;\r\n /** Convergence target (the implementation-specific currentStepSize is compared to this). */\r\n protected _stepSizeTolerance: number;\r\n /** Max iterations allowed. */\r\n protected _maxIterations: number;\r\n /** Number of iterations (incremented at each step). */\r\n public numIterations: number = 0;\r\n /**\r\n * Test if a step is converged.\r\n * * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance)\r\n * occur in succession.\r\n * @param delta step size as reported by currentStepSize.\r\n */\r\n public testConvergence(delta: number): boolean {\r\n if (Math.abs(delta) < this._stepSizeTolerance) {\r\n this._numAccepted++;\r\n return this._numAccepted >= this._successiveConvergenceTarget;\r\n }\r\n this._numAccepted = 0;\r\n return false;\r\n }\r\n /**\r\n * Run iterations, calling various methods from base and derived classes:\r\n * * computeStep -- typically evaluate derivatives and solve linear system.\r\n * * currentStepSize -- return numeric measure of the step just computed by computeStep.\r\n * * testConvergence -- test if the step from currentStepSize (along with recent steps) is converged.\r\n * * applyCurrentStep -- apply the step to the independent variables.\r\n */\r\n public runIterations(): boolean {\r\n this._numAccepted = 0;\r\n this.numIterations = 0;\r\n while (this.numIterations++ < this._maxIterations && this.computeStep()) {\r\n if (this.testConvergence(this.currentStepSize()) && this.applyCurrentStep(true)) {\r\n return true;\r\n }\r\n this.applyCurrentStep(false);\r\n }\r\n return false;\r\n }\r\n}\r\n/**\r\n * Object to evaluate a newton function. The object must retain most-recent function and derivative\r\n * values for immediate query.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRtoRD {\r\n /** Evaluate the function and its derivative at x. */\r\n public abstract evaluate(x: number): boolean;\r\n /** Most recent function value, i.e., f(x_n). */\r\n public currentF!: number;\r\n /** Most recent evaluated derivative, i.e., f'(x_n). */\r\n public currentdFdX!: number;\r\n}\r\n/**\r\n * Newton iterator for use when both function and derivative can be evaluated.\r\n * To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`.\r\n * To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is\r\n * `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`.\r\n * @internal\r\n */\r\nexport class Newton1dUnbounded extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRtoRD;\r\n /** Current step is dx. */\r\n private _currentStep!: number;\r\n /** Current X is x_n. */\r\n private _currentX!: number;\r\n /** The target */\r\n private _target!: number;\r\n /**\r\n * Constructor for 1D newton iteration with derivatives.\r\n * @param func function that returns both function value and derivative.\r\n */\r\n public constructor(func: NewtonEvaluatorRtoRD) {\r\n super();\r\n this._func = func;\r\n this.setTarget(0);\r\n }\r\n /** Set the independent variable, i.e., x_n. */\r\n public setX(x: number): boolean {\r\n this._currentX = x;\r\n return true;\r\n }\r\n /** Get the independent variable, i.e., x_n. */\r\n public getX(): number {\r\n return this._currentX;\r\n }\r\n /** Set the target function value. */\r\n public setTarget(y: number): void {\r\n this._target = y;\r\n }\r\n /** Move the current X by the just-computed step, i.e., `x_n - dx`. */\r\n public applyCurrentStep(): boolean {\r\n // console.log(this._currentX - this._currentStep); // print approximations for debug\r\n return this.setX(this._currentX - this._currentStep);\r\n }\r\n /** Compute the univariate newton step. */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentX)) {\r\n const dx = Geometry.conditionalDivideFraction(this._func.currentF - this._target, this._func.currentdFdX);\r\n if (dx !== undefined) {\r\n this._currentStep = dx;\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */\r\n public currentStepSize(): number {\r\n return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));\r\n }\r\n}\r\n\r\n/**\r\n * Object to evaluate a newton function (without derivative). The object must retain most-recent function value.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRtoR {\r\n /** Evaluate function value into member currentF */\r\n public abstract evaluate(x: number): boolean;\r\n /** Most recent function evaluation, i.e., f(x_n). */\r\n public currentF!: number;\r\n}\r\n\r\n/**\r\n * Newton iteration for a univariate function, using approximate derivatives.\r\n * To approximate the derivatives we use a small step `h`, i.e., `f'(x_n) = (f(x_n + h) - f(x_n)) / h`.\r\n * Therefore, to solve `f(x) = 0`, the iteration is\r\n * `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n) = x_n - f(x_n) * h / (f(x_n + h) - f(x_n))`.\r\n * @internal\r\n */\r\nexport class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRtoR;\r\n /** Current step is dx. */\r\n private _currentStep!: number;\r\n /** Current X is x_n. */\r\n private _currentX!: number;\r\n /**\r\n * Step size for approximate derivative for the iteration.\r\n * * Initialized to 1e-8, which is appropriate for iteration in fraction space.\r\n * * Should be larger for iteration with real distance as x.\r\n */\r\n public derivativeH: number; // h\r\n\r\n /**\r\n * Constructor for 1D newton iteration with approximate derivatives.\r\n * @param func function that only returns function value (and not derivative).\r\n */\r\n public constructor(func: NewtonEvaluatorRtoR) {\r\n super();\r\n this._func = func;\r\n this.derivativeH = 1.0e-8;\r\n }\r\n /** Set the independent variable, i.e., x_n. */\r\n public setX(x: number): boolean {\r\n this._currentX = x;\r\n return true;\r\n }\r\n /** Get the independent variable, i.e., x_n. */\r\n public getX(): number {\r\n return this._currentX;\r\n }\r\n /** Move the current X by the just-computed step, i.e., `x_n - dx`. */\r\n public applyCurrentStep(): boolean {\r\n // console.log(this._currentX - this._currentStep); // print approximations for debug\r\n return this.setX(this._currentX - this._currentStep);\r\n }\r\n /** Univariate newton step computed with approximate derivative. */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentX)) {\r\n const fA = this._func.currentF; // f(x_n)\r\n if (this._func.evaluate(this._currentX + this.derivativeH)) {\r\n const fB = this._func.currentF; // f(x_n + h)\r\n const dx = Geometry.conditionalDivideFraction(fA, (fB - fA) / this.derivativeH);\r\n if (dx !== undefined) {\r\n this._currentStep = dx;\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */\r\n public currentStepSize(): number {\r\n return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));\r\n }\r\n}\r\n\r\n/**\r\n * Object to evaluate a 2-parameter newton function with derivatives.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRRtoRRD {\r\n /**\r\n * Iteration controller calls this to ask for evaluation of the function and its two partial derivatives.\r\n * * The implementation returns true, it must set the currentF object.\r\n */\r\n public abstract evaluate(x: number, y: number): boolean;\r\n /**\r\n * Most recent function evaluation as parts of the plane.\r\n * * See doc of [[Newton2dUnboundedWithDerivative]] class for info on 2d newton method.\r\n * * For current value (u,v) of the independent variable, and `F(u,v) := (x(u,v), y(u,v)), the returned plane has:\r\n * * `origin.x` = x(u,v)\r\n * * `origin.y` = y(u,v)\r\n * * `vectorU.x` = dx/du\r\n * * `vectorU.y` = dy/du\r\n * * `vectorV.x` = dx/dv\r\n * * `vectorV.y` = dy/dv\r\n * * In other words, the plane stores the columns of the Jacobian matrix J of F: `vectorU` stores the partials\r\n * of F with respect to u (the first column of J), and `vectorV` stores the partials of F with respect to v\r\n * (the second column of J):\r\n *\r\n * `[vectorU.x vectorV.x]`\r\n *\r\n * `[vectorU.y vectorV.y]`\r\n */\r\n public currentF!: Plane3dByOriginAndVectors;\r\n /**\r\n * Constructor.\r\n * * This creates a currentF object to (repeatedly) receive function and derivatives.\r\n */\r\n public constructor() {\r\n this.currentF = Plane3dByOriginAndVectors.createXYPlane();\r\n }\r\n}\r\n\r\n/**\r\n * Implement evaluation steps for newton iteration in 2 dimensions, using caller supplied NewtonEvaluatorRRtoRRD object.\r\n * * Suppose we want to find the roots of `F(u,v) := (x(u,v), y(u,v))`. Writing `X := (u,v)` and `F(X)` as column vectors,\r\n * the 2D Newton's iteration to find a root of `F` is given by:\r\n * `X_{n+1} = X_n - dX = X_n - JInv(X_n)F(X_n)`, where `JInv` is the inverse of the Jacobian matrix `J`, and `J` is\r\n * defined as:\r\n *\r\n * `[dx/du dx/dv]`\r\n *\r\n * `[dy/du dy/dv]`\r\n * @internal\r\n */\r\nexport class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRRtoRRD;\r\n /** Current step, or dX = (du, dv). */\r\n private _currentStep: Vector2d;\r\n /** Current uv parameters, or X_n = (u_n, v_n). */\r\n private _currentUV: Point2d;\r\n /**\r\n * Constructor for 2D newton iteration with derivatives.\r\n * @param func function that returns both function value and derivative.\r\n */\r\n public constructor(func: NewtonEvaluatorRRtoRRD) {\r\n super();\r\n this._func = func;\r\n this._currentStep = Vector2d.createZero();\r\n this._currentUV = Point2d.createZero();\r\n }\r\n /** Set the current uv parameters, i.e., `X_n = (u_n, v_n)`. */\r\n public setUV(u: number, v: number): boolean {\r\n this._currentUV.set(u, v);\r\n return true;\r\n }\r\n /** Get the current u parameter of X_n, i.e., u_n. */\r\n public getU(): number {\r\n return this._currentUV.x;\r\n }\r\n /** Get the current v parameter of X_n, i.e., v_n. */\r\n public getV(): number {\r\n return this._currentUV.y;\r\n }\r\n /** Update the current uv parameter by currentStep, i.e., compute `X_{n+1} := X_n - dX = (u_n - du, v_n - dv)`. */\r\n public applyCurrentStep(): boolean {\r\n // print approximations for debug\r\n // console.log(\"(\" + (this._currentUV.x - this._currentStep.x) + \",\" + (this._currentUV.y - this._currentStep.y) + \")\");\r\n return this.setUV(this._currentUV.x - this._currentStep.x, this._currentUV.y - this._currentStep.y);\r\n }\r\n /**\r\n * Evaluate the functions and derivatives at `X_n = (u_n, v_n)`, and solve the Jacobian matrix equation to\r\n * compute `dX = (du, dv)`.\r\n */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentUV.x, this._currentUV.y)) {\r\n const fA = this._func.currentF;\r\n if ( // Given X_{n+1} = X_n - dX = X_n - JInv(X_n) F(X_n), we solve J(X_n) dX = F(X_n) for dX:\r\n SmallSystem.linearSystem2d(\r\n fA.vectorU.x, fA.vectorV.x,\r\n fA.vectorU.y, fA.vectorV.y,\r\n fA.origin.x, fA.origin.y,\r\n this._currentStep,\r\n )\r\n )\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Return the current relative step size, i.e., the larger absolute component of `dX / (1 + |X_n|)`\r\n */\r\n public currentStepSize(): number {\r\n return Geometry.maxAbsXY(\r\n this._currentStep.x / (1.0 + Math.abs(this._currentUV.x)),\r\n this._currentStep.y / (1.0 + Math.abs(this._currentUV.y)),\r\n );\r\n }\r\n}\r\n/**\r\n * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments\r\n * (not function object).\r\n * @internal\r\n */\r\nexport class SimpleNewton {\r\n /**\r\n * Run a one-dimensional newton iteration with separate functions for function and derivative.\r\n * * Completion is at 2 (TWO) successive passes at `absoluteTolerance + relTol * abs(x)`, where relTol is\r\n * chosen internally.\r\n * * `absoluteTolerance` is usually aggressively tight -- should come into play only for x near zero.\r\n * * The `relTol` is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after\r\n * first success normally moves to full machine precision.\r\n * * This is an open-loop newton -- it just runs, and returns undefined if anything bad happens.\r\n */\r\n public static runNewton1D(\r\n x: number,\r\n func: (x: number) => number | undefined,\r\n derivative: (x: number) => number | undefined,\r\n absoluteTolerance: number = Geometry.smallFloatingPoint,\r\n ): number | undefined {\r\n let numConverged = 0;\r\n let tolerance: number;\r\n const relTol = 1.0e-11;\r\n for (let iteration = 0; iteration < 20; iteration++) {\r\n const f = func(x);\r\n const df = derivative(x);\r\n if (f !== undefined && df !== undefined) {\r\n const dx = Geometry.conditionalDivideCoordinate(f, df);\r\n if (dx === undefined)\r\n return undefined;\r\n x -= dx;\r\n // console.log(x); // print approximations for debug\r\n tolerance = absoluteTolerance + Math.abs(x) * relTol;\r\n if (Math.abs(dx) < tolerance) {\r\n numConverged++;\r\n if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx\r\n return x;\r\n } else {\r\n numConverged = 0;\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
@@ -99,6 +99,7 @@ export declare class PolyfaceBuilder extends NullGeometryHandler {
99
99
  /** add facets for a transformed unit box. */
100
100
  addTransformedUnitBox(transform: Transform): void;
101
101
  /** Add facets for a transformed range box.
102
+ * * For best results, the transformed range corners should define a nonzero volume or area.
102
103
  * @param transform applied to the range points before adding to the polyface
103
104
  * @param range sides become 6 quad polyface facets
104
105
  * @param faceSelector for each face in the order of BoxTopology.cornerIndexCCW, faceSelector[i]===false skips that facet.
@@ -1 +1 @@
1
- {"version":3,"file":"PolyfaceBuilder.d.ts","sourceRoot":"","sources":["../../../src/polyface/PolyfaceBuilder.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,e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EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,SAAS;IAiHvG;;;OAGG;WACW,4BAA4B,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,eAAe,GAAG,SAAS;IAMnH;;;;;;;;;OASG;IACI,wCAAwC,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,YAAY,GAAG,oBAAoB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,YAAY,GAAG,oBAAoB;IAUlK,OAAO,CAAC,yBAAyB;IAuBjC;;;;;;;;OAQG;IACI,eAAe,CAAC,UAAU,EAAE,oBAAoB,GAAG,OAAO,EAAE,GAAG,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,cAAc,GAAE,MAAW;IAgBtJ,sGAAsG;IACtG,OAAO,CAAC,cAAc;IAWtB;;MAEE;IACF,OAAO,CAAC,YAAY;IAyCpB;;;;;;OAMG;IACI,uBAAuB,CAAC,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,GAAE,OAAe,GAAG,OAAO;CA0C3H"}
@@ -206,6 +206,7 @@ class PolyfaceBuilder extends NullGeometryHandler {
206
206
  this.addTransformedRangeMesh(transform, Range3d.createXYZXYZ(0, 0, 0, 1, 1, 1));
207
207
  }
208
208
  /** Add facets for a transformed range box.
209
+ * * For best results, the transformed range corners should define a nonzero volume or area.
209
210
  * @param transform applied to the range points before adding to the polyface
210
211
  * @param range sides become 6 quad polyface facets
211
212
  * @param faceSelector for each face in the order of BoxTopology.cornerIndexCCW, faceSelector[i]===false skips that facet.