brepjs 18.6.0 → 18.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/{sketching/sketcher2d.d.ts → 2d/blueprints/baseSketcher2d.d.ts} +4 -91
- package/dist/2d/blueprints/blueprint.d.ts +0 -1
- package/dist/2d/blueprints/blueprintApproximations.d.ts +0 -1
- package/dist/2d/blueprints/blueprintCustomCorners.d.ts +0 -1
- package/dist/2d/blueprints/blueprintFns.d.ts +0 -1
- package/dist/2d/blueprints/blueprintOffset.d.ts +0 -1
- package/dist/2d/blueprints/blueprintSketcher.d.ts +29 -0
- package/dist/2d/blueprints/blueprints.d.ts +0 -1
- package/dist/2d/blueprints/boolean2D.d.ts +0 -1
- package/dist/2d/blueprints/booleanHelpers.d.ts +0 -1
- package/dist/2d/blueprints/booleanOperations.d.ts +0 -1
- package/dist/2d/blueprints/cannedBlueprints.d.ts +0 -1
- package/dist/2d/blueprints/compoundBlueprint.d.ts +0 -1
- package/dist/{sketching → 2d/blueprints}/ellipseUtils.d.ts +19 -2
- package/dist/{sketching/sketcherlib.d.ts → 2d/blueprints/genericSketcher.d.ts} +1 -20
- package/dist/2d/blueprints/index.d.ts +0 -1
- package/dist/2d/blueprints/intersectionSegments.d.ts +0 -1
- package/dist/2d/blueprints/lib.d.ts +0 -1
- package/dist/2d/blueprints/segmentAssembly.d.ts +0 -1
- package/dist/2d/blueprints/svg.d.ts +0 -1
- package/dist/2d/curve2dGeometryFns.d.ts +0 -1
- package/dist/2d/curves.d.ts +0 -1
- package/dist/2d/lib/approximations.d.ts +0 -1
- package/dist/2d/lib/boundingBox2d.d.ts +0 -1
- package/dist/2d/lib/curve2D.d.ts +0 -1
- package/dist/2d/lib/curve2dFns.d.ts +0 -1
- package/dist/2d/lib/customCorners.d.ts +0 -1
- package/dist/2d/lib/definitions.d.ts +0 -1
- package/dist/2d/lib/index.d.ts +0 -1
- package/dist/2d/lib/intersections.d.ts +0 -1
- package/dist/2d/lib/makeCurves.d.ts +0 -1
- package/dist/2d/lib/offset.d.ts +0 -1
- package/dist/2d/lib/precision.d.ts +0 -1
- package/dist/2d/lib/stitching.d.ts +0 -1
- package/dist/2d/lib/svgPath.d.ts +0 -1
- package/dist/2d/lib/utils.d.ts +0 -1
- package/dist/2d/lib/vectorOperations.d.ts +0 -1
- package/dist/2d.cjs +20 -19
- package/dist/2d.d.ts +0 -1
- package/dist/2d.js +7 -6
- package/dist/{blueprint-CscZ0-wr.cjs → blueprint-B8ogGJiQ.cjs} +16 -15
- package/dist/{blueprint-BCoJbaQN.js → blueprint-Dv45Evnu.js} +16 -15
- package/dist/{blueprintFns-DQP4KQHE.cjs → blueprintFns-BK3FYYjO.cjs} +4 -4
- package/dist/{blueprintFns-BZlx6BjG.js → blueprintFns-a9C2g8_E.js} +3 -3
- package/dist/{boolean2D-k1AJmCMp.cjs → blueprintSketcher-Bei866Bt.cjs} +65 -1383
- package/dist/{boolean2D-JvgjbESt.js → blueprintSketcher-xDsl9GXO.js} +70 -1316
- package/dist/boolean2D-DGuiEJHA.cjs +902 -0
- package/dist/boolean2D-Z7P0c012.js +855 -0
- package/dist/{booleanFns-D13Pb-NO.js → booleanFns-CRa80qMX.js} +9 -9
- package/dist/{booleanFns-DQW4lt7H.cjs → booleanFns-qmgMQyDl.cjs} +12 -12
- package/dist/brepjs.cjs +772 -112
- package/dist/brepjs.js +692 -42
- package/dist/cameraFns-1y1NyACI.cjs +315 -0
- package/dist/cameraFns-CUzI5RKS.js +274 -0
- package/dist/core/constants.d.ts +0 -1
- package/dist/core/curve2dHandle.d.ts +0 -1
- package/dist/core/dimensionTypes.d.ts +0 -1
- package/dist/core/disposal.d.ts +0 -1
- package/dist/core/errors.d.ts +0 -1
- package/dist/core/kernelBoundary.d.ts +0 -1
- package/dist/core/kernelCall.d.ts +0 -1
- package/dist/core/kernelErrorTranslation.d.ts +0 -1
- package/dist/core/planeOps.d.ts +0 -1
- package/dist/core/planeTypes.d.ts +0 -1
- package/dist/core/result.d.ts +0 -1
- package/dist/core/shapeTypeCache.d.ts +0 -1
- package/dist/core/shapeTypes.d.ts +0 -1
- package/dist/core/typeDiscriminants.d.ts +0 -1
- package/dist/core/types.d.ts +0 -1
- package/dist/core/validityTypes.d.ts +0 -1
- package/dist/core/vecOps.d.ts +0 -1
- package/dist/core.cjs +6 -6
- package/dist/core.d.ts +0 -1
- package/dist/core.js +6 -6
- package/dist/{cornerFinder-5BYE2cbd.cjs → cornerFinder-CC8EBRCR.cjs} +3 -3
- package/dist/{cornerFinder-Zg7pf2s0.js → cornerFinder-Dix2ghke.js} +3 -3
- package/dist/{curveFns-DhqUp0EI.js → curveFns-B4tWuinR.js} +2 -2
- package/dist/{curveFns-DrT54cm8.cjs → curveFns-CD20-4fM.cjs} +2 -2
- package/dist/{drawFns-lUXjhTYL.js → drawFns-BsarLfUN.js} +163 -769
- package/dist/{drawFns-DmP2o1oF.cjs → drawFns-LlOZoFyp.cjs} +203 -985
- package/dist/{errors-DboJwVCf.js → errors-0fYW_YnO.js} +2 -1
- package/dist/{errors-CXRNVCec.cjs → errors-Dv6pfNct.cjs} +2 -1
- package/dist/{extrudeFns-B9bVCt3C.js → extrudeFns-7pE8dIWz.js} +3 -3
- package/dist/{extrudeFns-BtblHdaJ.cjs → extrudeFns-DD36mWKv.cjs} +3 -3
- package/dist/faceFns-BFWz17_E.js +218 -0
- package/dist/faceFns-DP7i60yJ.cjs +343 -0
- package/dist/gear/gearFns.d.ts +129 -0
- package/dist/gear/gearMath.d.ts +88 -0
- package/dist/gear/gearProfile.d.ts +16 -0
- package/dist/gear/index.d.ts +3 -0
- package/dist/{helpers-BpXNcxuJ.cjs → helpers-Cyj6gaqy.cjs} +14 -13
- package/dist/{helpers-S_Ht6gwX.js → helpers-vV2ONZwD.js} +9 -8
- package/dist/{historyFns-B01hrkcJ.js → historyFns-DGb61ETW.js} +6 -6
- package/dist/{historyFns-RHO-QvEZ.cjs → historyFns-DfyrPjnK.cjs} +6 -6
- package/dist/{importFns-CG49lyTm.cjs → importFns-C-p0vl_h.cjs} +11 -19
- package/dist/{importFns-C0tUyeiW.js → importFns-Ci-L2iB3.js} +11 -19
- package/dist/index.d.ts +16 -8
- package/dist/io/dxfExportFns.d.ts +0 -1
- package/dist/io/dxfImportFns.d.ts +0 -1
- package/dist/io/gltfExportFns.d.ts +0 -1
- package/dist/io/gltfImportFns.d.ts +0 -1
- package/dist/io/importFns.d.ts +0 -1
- package/dist/io/ioUtils.d.ts +0 -1
- package/dist/io/objExportFns.d.ts +0 -1
- package/dist/io/objImportFns.d.ts +0 -1
- package/dist/io/stepConfigFns.d.ts +0 -1
- package/dist/io/svgImportFns.d.ts +0 -1
- package/dist/io/threemfExportFns.d.ts +0 -1
- package/dist/io/threemfImportFns.d.ts +0 -1
- package/dist/io.cjs +2 -2
- package/dist/io.d.ts +0 -1
- package/dist/io.js +2 -2
- package/dist/kernel/brepkit/booleanOps.d.ts +23 -1
- package/dist/kernel/brepkit/brepkitAdapter.d.ts +21 -408
- package/dist/kernel/brepkit/brepkitWasmTypes.d.ts +0 -1
- package/dist/kernel/brepkit/constructionOps.d.ts +51 -1
- package/dist/kernel/brepkit/evolutionOps.d.ts +34 -3
- package/dist/kernel/brepkit/geometryOps.d.ts +63 -2
- package/dist/kernel/brepkit/helpers.d.ts +6 -1
- package/dist/kernel/brepkit/internalOps.d.ts +0 -1
- package/dist/kernel/brepkit/ioOps.d.ts +47 -9
- package/dist/kernel/brepkit/kernel2dOps.d.ts +113 -1
- package/dist/kernel/brepkit/measureOps.d.ts +39 -1
- package/dist/kernel/brepkit/meshOps.d.ts +7 -1
- package/dist/kernel/brepkit/modifierOps.d.ts +15 -1
- package/dist/kernel/brepkit/repairOps.d.ts +14 -1
- package/dist/kernel/brepkit/sketchOps.d.ts +3 -1
- package/dist/kernel/brepkit/sweepOps.d.ts +37 -1
- package/dist/kernel/brepkit/topologyOps.d.ts +16 -1
- package/dist/kernel/brepkit/transformOps.d.ts +18 -1
- package/dist/kernel/geometry2d.d.ts +0 -1
- package/dist/kernel/index.d.ts +0 -1
- package/dist/kernel/interfaces/booleanOps.d.ts +0 -1
- package/dist/kernel/interfaces/builderOps.d.ts +0 -1
- package/dist/kernel/interfaces/core.d.ts +0 -1
- package/dist/kernel/interfaces/curveOps.d.ts +0 -1
- package/dist/kernel/interfaces/evolutionOps.d.ts +0 -1
- package/dist/kernel/interfaces/index.d.ts +0 -1
- package/dist/kernel/interfaces/ioOps.d.ts +0 -1
- package/dist/kernel/interfaces/measureOps.d.ts +0 -1
- package/dist/kernel/interfaces/meshOps.d.ts +0 -1
- package/dist/kernel/interfaces/modifierOps.d.ts +0 -1
- package/dist/kernel/interfaces/primitiveOps.d.ts +0 -1
- package/dist/kernel/interfaces/repairOps.d.ts +0 -1
- package/dist/kernel/interfaces/surfaceOps.d.ts +0 -1
- package/dist/kernel/interfaces/sweepOps.d.ts +0 -1
- package/dist/kernel/interfaces/topologyOps.d.ts +0 -1
- package/dist/kernel/interfaces/transformOps.d.ts +0 -1
- package/dist/kernel/kernel2dTypes.d.ts +0 -1
- package/dist/kernel/occt/advancedOps.d.ts +126 -24
- package/dist/kernel/occt/booleanBatchOps.d.ts +0 -1
- package/dist/kernel/occt/booleanOps.d.ts +11 -1
- package/dist/kernel/occt/booleanPipelineOps.d.ts +10 -1
- package/dist/kernel/occt/constructorOps.d.ts +14 -1
- package/dist/kernel/occt/curveOps.d.ts +13 -1
- package/dist/kernel/occt/defaultAdapter.d.ts +10 -441
- package/dist/kernel/occt/evolutionOps.d.ts +0 -1
- package/dist/kernel/occt/extendedConstructorOps.d.ts +31 -1
- package/dist/kernel/occt/geometryQueryOps.d.ts +40 -1
- package/dist/kernel/occt/healingOps.d.ts +6 -1
- package/dist/kernel/occt/historyOps.d.ts +17 -1
- package/dist/kernel/occt/hullOps.d.ts +14 -1
- package/dist/kernel/occt/ioOps.d.ts +9 -1
- package/dist/kernel/occt/kernel2dOps.d.ts +113 -1
- package/dist/kernel/occt/measureOps.d.ts +19 -1
- package/dist/kernel/occt/meshOps.d.ts +5 -1
- package/dist/kernel/occt/modifierOps.d.ts +24 -1
- package/dist/kernel/occt/nurbsQueryOps.d.ts +5 -1
- package/dist/kernel/occt/sweepOps.d.ts +23 -1
- package/dist/kernel/occt/topologyOps.d.ts +10 -1
- package/dist/kernel/occt/transformOps.d.ts +14 -4
- package/dist/kernel/occt/wasmTypes/externals.d.ts +0 -1
- package/dist/kernel/occt/wasmTypes/index.d.ts +0 -1
- package/dist/kernel/occt/wasmTypes/occtBuilders.d.ts +0 -1
- package/dist/kernel/occtWasm/adapterShims.d.ts +4 -0
- package/dist/kernel/occtWasm/booleanOps.d.ts +11 -0
- package/dist/kernel/occtWasm/constructionOps.d.ts +36 -0
- package/dist/kernel/occtWasm/curveOps.d.ts +23 -0
- package/dist/kernel/occtWasm/evolutionOps.d.ts +17 -0
- package/dist/kernel/occtWasm/helpers.d.ts +31 -0
- package/dist/kernel/occtWasm/hullOps.d.ts +12 -0
- package/dist/kernel/occtWasm/ioOps.d.ts +52 -0
- package/dist/kernel/occtWasm/kernel2dOps.d.ts +90 -0
- package/dist/kernel/occtWasm/measureOps.d.ts +31 -0
- package/dist/kernel/occtWasm/meshOps.d.ts +6 -0
- package/dist/kernel/occtWasm/modifierOps.d.ts +14 -0
- package/dist/kernel/occtWasm/occtWasmAdapter.cjs +1 -1
- package/dist/kernel/occtWasm/occtWasmAdapter.d.ts +30 -31
- package/dist/kernel/occtWasm/occtWasmAdapter.js +1 -1
- package/dist/kernel/occtWasm/occtWasmTypes.d.ts +0 -1
- package/dist/kernel/occtWasm/primitiveOps.d.ts +10 -0
- package/dist/kernel/occtWasm/repairOps.d.ts +10 -0
- package/dist/kernel/occtWasm/surfaceOps.d.ts +28 -0
- package/dist/kernel/occtWasm/sweepOps.d.ts +38 -0
- package/dist/kernel/occtWasm/topologyOps.d.ts +14 -0
- package/dist/kernel/occtWasm/transformOps.d.ts +27 -0
- package/dist/kernel/perfStats.d.ts +0 -1
- package/dist/kernel/solverAdapter.d.ts +0 -1
- package/dist/kernel/types.d.ts +0 -1
- package/dist/{measureFns-C751QGI1.cjs → measureFns-6ifSQfJt.cjs} +6 -5
- package/dist/{measureFns-B8C85hbT.js → measureFns-Io2nHE1k.js} +4 -3
- package/dist/measurement/interferenceFns.d.ts +0 -1
- package/dist/measurement/measureCache.d.ts +0 -1
- package/dist/measurement/measureFns.d.ts +0 -1
- package/dist/measurement/measureTypes.d.ts +0 -1
- package/dist/measurement.cjs +1 -1
- package/dist/measurement.d.ts +0 -1
- package/dist/measurement.js +1 -1
- package/dist/{meshFns-Cdhtbrhm.cjs → meshFns-BCRVZgPi.cjs} +3 -3
- package/dist/{meshFns-BgvsA-xA.js → meshFns-DSdkRFWq.js} +3 -3
- package/dist/ns/booleans.d.ts +0 -1
- package/dist/ns/construction.d.ts +0 -1
- package/dist/ns/ioNs.d.ts +0 -1
- package/dist/ns/measurement.d.ts +0 -1
- package/dist/ns/modifiers.d.ts +0 -1
- package/dist/ns/patterns.d.ts +0 -1
- package/dist/ns/primitives.d.ts +0 -1
- package/dist/ns/query.d.ts +0 -1
- package/dist/ns/transforms.d.ts +0 -1
- package/dist/occtWasmAdapter--TZGP9DX.js +4606 -0
- package/dist/occtWasmAdapter-C2VW-uYg.cjs +4719 -0
- package/dist/operations/api.d.ts +0 -1
- package/dist/operations/assemblyFns.d.ts +0 -1
- package/dist/operations/compoundOpsFns.d.ts +0 -1
- package/dist/operations/convexHullFns.d.ts +0 -1
- package/dist/operations/exporterFns.d.ts +0 -1
- package/dist/operations/exporterUtils.d.ts +0 -1
- package/dist/operations/exporters.d.ts +0 -1
- package/dist/operations/extrudeFns.d.ts +0 -1
- package/dist/operations/extrudeUtils.d.ts +0 -1
- package/dist/operations/guidedSweepFns.d.ts +0 -1
- package/dist/operations/historyFns.d.ts +0 -1
- package/dist/operations/loftFns.d.ts +0 -1
- package/dist/operations/mateFns.d.ts +0 -1
- package/dist/operations/multiSweepFns.d.ts +0 -1
- package/dist/operations/patternFns.d.ts +0 -1
- package/dist/operations/roofFns.d.ts +0 -1
- package/dist/operations/straightSkeleton.d.ts +0 -1
- package/dist/operations/sweepFns.d.ts +0 -1
- package/dist/operations.cjs +2 -2
- package/dist/operations.d.ts +0 -1
- package/dist/operations.js +2 -2
- package/dist/{planeOps-sTrM3dcQ.js → planeOps-4i2qEraD.js} +4 -4
- package/dist/{planeOps-BJOIbn4K.cjs → planeOps-CH4ruLuj.cjs} +4 -4
- package/dist/{primitiveFns-BLxaJ40A.cjs → primitiveFns-BH-JQPzh.cjs} +20 -19
- package/dist/{primitiveFns-fR9sWOEb.js → primitiveFns-C1p92ZcD.js} +8 -7
- package/dist/projection/cameraFns.d.ts +0 -1
- package/dist/projection/makeProjectedEdges.d.ts +0 -1
- package/dist/projection/projectionPlanes.d.ts +0 -1
- package/dist/projection.cjs +9 -0
- package/dist/projection.d.ts +11 -0
- package/dist/projection.js +2 -0
- package/dist/query/cornerFinder.d.ts +0 -1
- package/dist/query/directionUtils.d.ts +0 -1
- package/dist/query/edgeFinder.d.ts +0 -1
- package/dist/query/faceFinder.d.ts +0 -1
- package/dist/query/finderCore.d.ts +0 -1
- package/dist/query/finderFns.d.ts +0 -1
- package/dist/query/helpers.d.ts +0 -1
- package/dist/query/shapeDistanceFilter.d.ts +0 -1
- package/dist/query/shapeFinders.d.ts +0 -1
- package/dist/query/vertexFinder.d.ts +0 -1
- package/dist/query/wireFinder.d.ts +0 -1
- package/dist/query.cjs +2 -2
- package/dist/query.d.ts +0 -1
- package/dist/query.js +2 -2
- package/dist/result.cjs +1 -1
- package/dist/result.d.ts +0 -1
- package/dist/result.js +1 -1
- package/dist/{shapeFns-183zCtMc.cjs → shapeFns-B7x82K11.cjs} +17 -17
- package/dist/{shapeFns-2X3VOi1a.js → shapeFns-BhZ9weSI.js} +4 -4
- package/dist/shapeRef.cjs +1 -1
- package/dist/shapeRef.d.ts +0 -1
- package/dist/shapeRef.js +1 -1
- package/dist/{shapeRefFns-CU1Jwq9C.js → shapeRefFns-B9PsEqWf.js} +6 -4
- package/dist/{shapeRefFns-CFyv5cdW.cjs → shapeRefFns-wDY88A8u.cjs} +8 -6
- package/dist/{shapeTypes-C0MDggKf.cjs → shapeTypes-BTt_LLbk.cjs} +6922 -7884
- package/dist/{shapeTypes-CN0GUoHr.js → shapeTypes-C--1jaT1.js} +6900 -7862
- package/dist/sketching/cannedSketches.d.ts +0 -1
- package/dist/sketching/compoundSketch.d.ts +8 -7
- package/dist/sketching/draw3d.d.ts +1 -2
- package/dist/sketching/drawFns.d.ts +4 -3
- package/dist/sketching/{draw.d.ts → drawing.d.ts} +2 -127
- package/dist/sketching/drawingFactories.d.ts +94 -0
- package/dist/sketching/drawingPen.d.ts +34 -0
- package/dist/sketching/faceSketcher.d.ts +52 -0
- package/dist/sketching/shortcuts.d.ts +0 -1
- package/dist/sketching/sketch.d.ts +64 -10
- package/dist/sketching/sketchFns.d.ts +42 -95
- package/dist/sketching/sketcher.d.ts +2 -3
- package/dist/sketching/sketches.d.ts +5 -6
- package/dist/sketching.cjs +19 -18
- package/dist/sketching.d.ts +8 -5
- package/dist/sketching.js +3 -2
- package/dist/{solidBuilders-DACzFqvX.cjs → solidBuilders-CX_197Xm.cjs} +3 -3
- package/dist/{solidBuilders-BuS5ByIl.js → solidBuilders-Xs7VDMGD.js} +3 -3
- package/dist/{surfaceBuilders-CbH4FIW5.cjs → surfaceBuilders-CYeTNW33.cjs} +25 -3
- package/dist/{surfaceBuilders-BVH2SL-z.js → surfaceBuilders-CinmHCbZ.js} +20 -4
- package/dist/text/fontRegistry.d.ts +22 -0
- package/dist/text/sketchText.d.ts +30 -0
- package/dist/text/textBlueprints.d.ts +0 -91
- package/dist/text/textMetrics.d.ts +39 -0
- package/dist/text.cjs +9 -0
- package/dist/text.d.ts +12 -0
- package/dist/text.js +3 -0
- package/dist/textBlueprints-Do6xNsLt.js +643 -0
- package/dist/textBlueprints-oWhiABaY.cjs +800 -0
- package/dist/textMetrics-BjJ8sn_e.js +69 -0
- package/dist/textMetrics-CUvtglQE.cjs +86 -0
- package/dist/topology/adjacencyFns.d.ts +0 -1
- package/dist/topology/api.d.ts +0 -1
- package/dist/topology/apiTypes.d.ts +0 -1
- package/dist/topology/booleanDiagnosticFns.d.ts +0 -1
- package/dist/topology/booleanFns.d.ts +0 -1
- package/dist/topology/cast.d.ts +0 -1
- package/dist/topology/chamferAngleFns.d.ts +0 -1
- package/dist/topology/compoundOpsFns.d.ts +0 -1
- package/dist/topology/curveBuilders.d.ts +12 -1
- package/dist/topology/curveFns.d.ts +0 -1
- package/dist/topology/evolutionFns.d.ts +0 -1
- package/dist/topology/faceFns.d.ts +0 -1
- package/dist/topology/healingFns.d.ts +0 -1
- package/dist/topology/hullFns.d.ts +0 -1
- package/dist/topology/index.d.ts +0 -1
- package/dist/topology/meshCache.d.ts +0 -1
- package/dist/topology/meshFns.d.ts +0 -1
- package/dist/topology/metadata/colorFns.d.ts +0 -1
- package/dist/topology/metadata/faceTagFns.d.ts +0 -1
- package/dist/topology/metadata/metadataPropagation.d.ts +0 -1
- package/dist/topology/metadata/originTrackingFns.d.ts +0 -1
- package/dist/topology/minkowskiFns.d.ts +0 -1
- package/dist/topology/modifierFns.d.ts +0 -1
- package/dist/topology/nurbsFns.d.ts +0 -1
- package/dist/topology/polyhedronFns.d.ts +0 -1
- package/dist/topology/positionFns.d.ts +0 -1
- package/dist/topology/primitiveFns.d.ts +0 -1
- package/dist/topology/shapeBooleans.d.ts +0 -1
- package/dist/topology/shapeFns.d.ts +0 -1
- package/dist/topology/shapeHelpers.d.ts +0 -1
- package/dist/topology/shapeModifiers.d.ts +0 -1
- package/dist/topology/shapeRef/index.d.ts +0 -1
- package/dist/topology/shapeRef/scoring.d.ts +0 -1
- package/dist/topology/shapeRef/shapeRefFns.d.ts +0 -1
- package/dist/topology/shapeRef/shapeRefTypes.d.ts +0 -1
- package/dist/topology/shapeUtils.d.ts +0 -1
- package/dist/topology/solidBuilders.d.ts +0 -1
- package/dist/topology/surfaceBuilders.d.ts +0 -1
- package/dist/topology/surfaceFns.d.ts +0 -1
- package/dist/topology/threeHelpers.d.ts +0 -1
- package/dist/topology/topologyQueryFns.d.ts +0 -1
- package/dist/topology/transformFns.d.ts +0 -1
- package/dist/topology/wrapperFns.d.ts +0 -1
- package/dist/topology.cjs +18 -17
- package/dist/topology.d.ts +0 -1
- package/dist/topology.js +7 -6
- package/dist/{faceFns-22idS-ht.cjs → topologyQueryFns-BU0qdNJP.cjs} +2 -342
- package/dist/{faceFns-NbWd8-iR.js → topologyQueryFns-Dhf85ZBK.js} +3 -217
- package/dist/utils/arrayAccess.d.ts +0 -1
- package/dist/utils/bug.d.ts +0 -1
- package/dist/utils/ioFilename.d.ts +0 -1
- package/dist/utils/precisionRound.d.ts +0 -1
- package/dist/utils/range.d.ts +0 -1
- package/dist/utils/uuid.d.ts +0 -1
- package/dist/utils/vec2d.d.ts +0 -1
- package/dist/utils/vec3.d.ts +8 -1
- package/dist/utils/zip.d.ts +0 -1
- package/dist/vec3-BRj3eI54.js +25 -0
- package/dist/vec3-S4Oh59IX.cjs +36 -0
- package/dist/vectors.cjs +4 -4
- package/dist/vectors.d.ts +0 -1
- package/dist/vectors.js +4 -4
- package/dist/worker/index.d.ts +0 -1
- package/dist/worker/protocol.d.ts +0 -1
- package/dist/worker/taskQueue.d.ts +0 -1
- package/dist/worker/workerClient.d.ts +0 -1
- package/dist/worker/workerHandler.d.ts +0 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.ts +0 -1
- package/dist/worker.js +1 -1
- package/package.json +35 -14
- package/dist/2d/blueprints/blueprint.d.ts.map +0 -1
- package/dist/2d/blueprints/blueprintApproximations.d.ts.map +0 -1
- package/dist/2d/blueprints/blueprintCustomCorners.d.ts.map +0 -1
- package/dist/2d/blueprints/blueprintFns.d.ts.map +0 -1
- package/dist/2d/blueprints/blueprintOffset.d.ts.map +0 -1
- package/dist/2d/blueprints/blueprints.d.ts.map +0 -1
- package/dist/2d/blueprints/boolean2D.d.ts.map +0 -1
- package/dist/2d/blueprints/booleanHelpers.d.ts.map +0 -1
- package/dist/2d/blueprints/booleanOperations.d.ts.map +0 -1
- package/dist/2d/blueprints/cannedBlueprints.d.ts.map +0 -1
- package/dist/2d/blueprints/compoundBlueprint.d.ts.map +0 -1
- package/dist/2d/blueprints/index.d.ts.map +0 -1
- package/dist/2d/blueprints/intersectionSegments.d.ts.map +0 -1
- package/dist/2d/blueprints/lib.d.ts.map +0 -1
- package/dist/2d/blueprints/segmentAssembly.d.ts.map +0 -1
- package/dist/2d/blueprints/svg.d.ts.map +0 -1
- package/dist/2d/curve2dGeometryFns.d.ts.map +0 -1
- package/dist/2d/curves.d.ts.map +0 -1
- package/dist/2d/lib/approximations.d.ts.map +0 -1
- package/dist/2d/lib/boundingBox2d.d.ts.map +0 -1
- package/dist/2d/lib/curve2D.d.ts.map +0 -1
- package/dist/2d/lib/curve2dFns.d.ts.map +0 -1
- package/dist/2d/lib/customCorners.d.ts.map +0 -1
- package/dist/2d/lib/definitions.d.ts.map +0 -1
- package/dist/2d/lib/index.d.ts.map +0 -1
- package/dist/2d/lib/intersections.d.ts.map +0 -1
- package/dist/2d/lib/makeCurves.d.ts.map +0 -1
- package/dist/2d/lib/offset.d.ts.map +0 -1
- package/dist/2d/lib/precision.d.ts.map +0 -1
- package/dist/2d/lib/stitching.d.ts.map +0 -1
- package/dist/2d/lib/svgPath.d.ts.map +0 -1
- package/dist/2d/lib/utils.d.ts.map +0 -1
- package/dist/2d/lib/vectorOperations.d.ts.map +0 -1
- package/dist/2d.d.ts.map +0 -1
- package/dist/core/constants.d.ts.map +0 -1
- package/dist/core/curve2dHandle.d.ts.map +0 -1
- package/dist/core/dimensionTypes.d.ts.map +0 -1
- package/dist/core/disposal.d.ts.map +0 -1
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/kernelBoundary.d.ts.map +0 -1
- package/dist/core/kernelCall.d.ts.map +0 -1
- package/dist/core/kernelErrorTranslation.d.ts.map +0 -1
- package/dist/core/planeOps.d.ts.map +0 -1
- package/dist/core/planeTypes.d.ts.map +0 -1
- package/dist/core/result.d.ts.map +0 -1
- package/dist/core/shapeTypeCache.d.ts.map +0 -1
- package/dist/core/shapeTypes.d.ts.map +0 -1
- package/dist/core/typeDiscriminants.d.ts.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/validityTypes.d.ts.map +0 -1
- package/dist/core/vecOps.d.ts.map +0 -1
- package/dist/core.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/io/dxfExportFns.d.ts.map +0 -1
- package/dist/io/dxfImportFns.d.ts.map +0 -1
- package/dist/io/gltfExportFns.d.ts.map +0 -1
- package/dist/io/gltfImportFns.d.ts.map +0 -1
- package/dist/io/importFns.d.ts.map +0 -1
- package/dist/io/ioUtils.d.ts.map +0 -1
- package/dist/io/objExportFns.d.ts.map +0 -1
- package/dist/io/objImportFns.d.ts.map +0 -1
- package/dist/io/stepConfigFns.d.ts.map +0 -1
- package/dist/io/svgImportFns.d.ts.map +0 -1
- package/dist/io/threemfExportFns.d.ts.map +0 -1
- package/dist/io/threemfImportFns.d.ts.map +0 -1
- package/dist/io.d.ts.map +0 -1
- package/dist/kernel/brepkit/booleanOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/brepkitAdapter.d.ts.map +0 -1
- package/dist/kernel/brepkit/brepkitWasmTypes.d.ts.map +0 -1
- package/dist/kernel/brepkit/constructionOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/evolutionOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/geometryOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/helpers.d.ts.map +0 -1
- package/dist/kernel/brepkit/internalOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/ioOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/kernel2dOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/measureOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/meshOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/modifierOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/repairOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/sketchOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/sweepOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/topologyOps.d.ts.map +0 -1
- package/dist/kernel/brepkit/transformOps.d.ts.map +0 -1
- package/dist/kernel/geometry2d.d.ts.map +0 -1
- package/dist/kernel/index.d.ts.map +0 -1
- package/dist/kernel/interfaces/booleanOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/builderOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/core.d.ts.map +0 -1
- package/dist/kernel/interfaces/curveOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/evolutionOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/index.d.ts.map +0 -1
- package/dist/kernel/interfaces/ioOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/measureOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/meshOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/modifierOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/primitiveOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/repairOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/surfaceOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/sweepOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/topologyOps.d.ts.map +0 -1
- package/dist/kernel/interfaces/transformOps.d.ts.map +0 -1
- package/dist/kernel/kernel2dTypes.d.ts.map +0 -1
- package/dist/kernel/occt/advancedOps.d.ts.map +0 -1
- package/dist/kernel/occt/booleanBatchOps.d.ts.map +0 -1
- package/dist/kernel/occt/booleanOps.d.ts.map +0 -1
- package/dist/kernel/occt/booleanPipelineOps.d.ts.map +0 -1
- package/dist/kernel/occt/constructorOps.d.ts.map +0 -1
- package/dist/kernel/occt/curveOps.d.ts.map +0 -1
- package/dist/kernel/occt/defaultAdapter.d.ts.map +0 -1
- package/dist/kernel/occt/evolutionOps.d.ts.map +0 -1
- package/dist/kernel/occt/extendedConstructorOps.d.ts.map +0 -1
- package/dist/kernel/occt/geometryQueryOps.d.ts.map +0 -1
- package/dist/kernel/occt/healingOps.d.ts.map +0 -1
- package/dist/kernel/occt/historyOps.d.ts.map +0 -1
- package/dist/kernel/occt/hullOps.d.ts.map +0 -1
- package/dist/kernel/occt/ioOps.d.ts.map +0 -1
- package/dist/kernel/occt/kernel2dOps.d.ts.map +0 -1
- package/dist/kernel/occt/measureOps.d.ts.map +0 -1
- package/dist/kernel/occt/meshOps.d.ts.map +0 -1
- package/dist/kernel/occt/modifierOps.d.ts.map +0 -1
- package/dist/kernel/occt/nurbsQueryOps.d.ts.map +0 -1
- package/dist/kernel/occt/sweepOps.d.ts.map +0 -1
- package/dist/kernel/occt/topologyOps.d.ts.map +0 -1
- package/dist/kernel/occt/transformOps.d.ts.map +0 -1
- package/dist/kernel/occt/wasmTypes/externals.d.ts.map +0 -1
- package/dist/kernel/occt/wasmTypes/index.d.ts.map +0 -1
- package/dist/kernel/occt/wasmTypes/occtBuilders.d.ts.map +0 -1
- package/dist/kernel/occtWasm/occtWasmAdapter.d.ts.map +0 -1
- package/dist/kernel/occtWasm/occtWasmTypes.d.ts.map +0 -1
- package/dist/kernel/perfStats.d.ts.map +0 -1
- package/dist/kernel/solverAdapter.d.ts.map +0 -1
- package/dist/kernel/types.d.ts.map +0 -1
- package/dist/measurement/interferenceFns.d.ts.map +0 -1
- package/dist/measurement/measureCache.d.ts.map +0 -1
- package/dist/measurement/measureFns.d.ts.map +0 -1
- package/dist/measurement/measureTypes.d.ts.map +0 -1
- package/dist/measurement.d.ts.map +0 -1
- package/dist/ns/booleans.d.ts.map +0 -1
- package/dist/ns/construction.d.ts.map +0 -1
- package/dist/ns/ioNs.d.ts.map +0 -1
- package/dist/ns/measurement.d.ts.map +0 -1
- package/dist/ns/modifiers.d.ts.map +0 -1
- package/dist/ns/patterns.d.ts.map +0 -1
- package/dist/ns/primitives.d.ts.map +0 -1
- package/dist/ns/query.d.ts.map +0 -1
- package/dist/ns/transforms.d.ts.map +0 -1
- package/dist/occtWasmAdapter-CuZRRioz.cjs +0 -3947
- package/dist/occtWasmAdapter-DIhUXubY.js +0 -3834
- package/dist/operations/api.d.ts.map +0 -1
- package/dist/operations/assemblyFns.d.ts.map +0 -1
- package/dist/operations/compoundOpsFns.d.ts.map +0 -1
- package/dist/operations/convexHullFns.d.ts.map +0 -1
- package/dist/operations/exporterFns.d.ts.map +0 -1
- package/dist/operations/exporterUtils.d.ts.map +0 -1
- package/dist/operations/exporters.d.ts.map +0 -1
- package/dist/operations/extrudeFns.d.ts.map +0 -1
- package/dist/operations/extrudeUtils.d.ts.map +0 -1
- package/dist/operations/guidedSweepFns.d.ts.map +0 -1
- package/dist/operations/historyFns.d.ts.map +0 -1
- package/dist/operations/loftFns.d.ts.map +0 -1
- package/dist/operations/mateFns.d.ts.map +0 -1
- package/dist/operations/multiSweepFns.d.ts.map +0 -1
- package/dist/operations/patternFns.d.ts.map +0 -1
- package/dist/operations/roofFns.d.ts.map +0 -1
- package/dist/operations/straightSkeleton.d.ts.map +0 -1
- package/dist/operations/sweepFns.d.ts.map +0 -1
- package/dist/operations.d.ts.map +0 -1
- package/dist/projection/cameraFns.d.ts.map +0 -1
- package/dist/projection/makeProjectedEdges.d.ts.map +0 -1
- package/dist/projection/projectionPlanes.d.ts.map +0 -1
- package/dist/query/cornerFinder.d.ts.map +0 -1
- package/dist/query/directionUtils.d.ts.map +0 -1
- package/dist/query/edgeFinder.d.ts.map +0 -1
- package/dist/query/faceFinder.d.ts.map +0 -1
- package/dist/query/finderCore.d.ts.map +0 -1
- package/dist/query/finderFns.d.ts.map +0 -1
- package/dist/query/helpers.d.ts.map +0 -1
- package/dist/query/shapeDistanceFilter.d.ts.map +0 -1
- package/dist/query/shapeFinders.d.ts.map +0 -1
- package/dist/query/vertexFinder.d.ts.map +0 -1
- package/dist/query/wireFinder.d.ts.map +0 -1
- package/dist/query.d.ts.map +0 -1
- package/dist/quick.d.ts.map +0 -1
- package/dist/result.d.ts.map +0 -1
- package/dist/shapeRef.d.ts.map +0 -1
- package/dist/sketching/cannedSketches.d.ts.map +0 -1
- package/dist/sketching/compoundSketch.d.ts.map +0 -1
- package/dist/sketching/draw.d.ts.map +0 -1
- package/dist/sketching/draw3d.d.ts.map +0 -1
- package/dist/sketching/drawFns.d.ts.map +0 -1
- package/dist/sketching/ellipseUtils.d.ts.map +0 -1
- package/dist/sketching/shortcuts.d.ts.map +0 -1
- package/dist/sketching/sketch.d.ts.map +0 -1
- package/dist/sketching/sketchFns.d.ts.map +0 -1
- package/dist/sketching/sketchLib.d.ts +0 -47
- package/dist/sketching/sketchLib.d.ts.map +0 -1
- package/dist/sketching/sketchUtils.d.ts +0 -8
- package/dist/sketching/sketchUtils.d.ts.map +0 -1
- package/dist/sketching/sketcher.d.ts.map +0 -1
- package/dist/sketching/sketcher2d.d.ts.map +0 -1
- package/dist/sketching/sketcherlib.d.ts.map +0 -1
- package/dist/sketching/sketches.d.ts.map +0 -1
- package/dist/sketching.d.ts.map +0 -1
- package/dist/text/textBlueprints.d.ts.map +0 -1
- package/dist/topology/adjacencyFns.d.ts.map +0 -1
- package/dist/topology/api.d.ts.map +0 -1
- package/dist/topology/apiTypes.d.ts.map +0 -1
- package/dist/topology/booleanDiagnosticFns.d.ts.map +0 -1
- package/dist/topology/booleanFns.d.ts.map +0 -1
- package/dist/topology/cast.d.ts.map +0 -1
- package/dist/topology/chamferAngleFns.d.ts.map +0 -1
- package/dist/topology/compoundOpsFns.d.ts.map +0 -1
- package/dist/topology/curveBuilders.d.ts.map +0 -1
- package/dist/topology/curveFns.d.ts.map +0 -1
- package/dist/topology/evolutionFns.d.ts.map +0 -1
- package/dist/topology/faceFns.d.ts.map +0 -1
- package/dist/topology/healingFns.d.ts.map +0 -1
- package/dist/topology/hullFns.d.ts.map +0 -1
- package/dist/topology/index.d.ts.map +0 -1
- package/dist/topology/meshCache.d.ts.map +0 -1
- package/dist/topology/meshFns.d.ts.map +0 -1
- package/dist/topology/metadata/colorFns.d.ts.map +0 -1
- package/dist/topology/metadata/faceTagFns.d.ts.map +0 -1
- package/dist/topology/metadata/metadataPropagation.d.ts.map +0 -1
- package/dist/topology/metadata/originTrackingFns.d.ts.map +0 -1
- package/dist/topology/minkowskiFns.d.ts.map +0 -1
- package/dist/topology/modifierFns.d.ts.map +0 -1
- package/dist/topology/nurbsFns.d.ts.map +0 -1
- package/dist/topology/polyhedronFns.d.ts.map +0 -1
- package/dist/topology/positionFns.d.ts.map +0 -1
- package/dist/topology/primitiveFns.d.ts.map +0 -1
- package/dist/topology/shapeBooleans.d.ts.map +0 -1
- package/dist/topology/shapeFns.d.ts.map +0 -1
- package/dist/topology/shapeHelpers.d.ts.map +0 -1
- package/dist/topology/shapeModifiers.d.ts.map +0 -1
- package/dist/topology/shapeRef/index.d.ts.map +0 -1
- package/dist/topology/shapeRef/scoring.d.ts.map +0 -1
- package/dist/topology/shapeRef/shapeRefFns.d.ts.map +0 -1
- package/dist/topology/shapeRef/shapeRefTypes.d.ts.map +0 -1
- package/dist/topology/shapeUtils.d.ts.map +0 -1
- package/dist/topology/solidBuilders.d.ts.map +0 -1
- package/dist/topology/surfaceBuilders.d.ts.map +0 -1
- package/dist/topology/surfaceFns.d.ts.map +0 -1
- package/dist/topology/threeHelpers.d.ts.map +0 -1
- package/dist/topology/topologyQueryFns.d.ts.map +0 -1
- package/dist/topology/transformFns.d.ts.map +0 -1
- package/dist/topology/wrapperFns.d.ts.map +0 -1
- package/dist/topology.d.ts.map +0 -1
- package/dist/utils/arrayAccess.d.ts.map +0 -1
- package/dist/utils/bug.d.ts.map +0 -1
- package/dist/utils/ioFilename.d.ts.map +0 -1
- package/dist/utils/precisionRound.d.ts.map +0 -1
- package/dist/utils/range.d.ts.map +0 -1
- package/dist/utils/uuid.d.ts.map +0 -1
- package/dist/utils/vec2d.d.ts.map +0 -1
- package/dist/utils/vec3.d.ts.map +0 -1
- package/dist/utils/zip.d.ts.map +0 -1
- package/dist/vectors.d.ts.map +0 -1
- package/dist/worker/index.d.ts.map +0 -1
- package/dist/worker/protocol.d.ts.map +0 -1
- package/dist/worker/taskQueue.d.ts.map +0 -1
- package/dist/worker/workerClient.d.ts.map +0 -1
- package/dist/worker/workerHandler.d.ts.map +0 -1
- package/dist/worker.d.ts.map +0 -1
- /package/dist/{arrayAccess-DsnQpdSD.cjs → arrayAccess-7pTWqkJu.cjs} +0 -0
- /package/dist/{arrayAccess-tCIbjLs5.js → arrayAccess-C5IWcxs9.js} +0 -0
- /package/dist/{constants-csSEYddm.js → constants-Ci5CA3aZ.js} +0 -0
- /package/dist/{constants-BNP_xnBN.cjs → constants-DTorLmes.cjs} +0 -0
- /package/dist/{types--GD-LVc6.js → types-BIdk_GJY.js} +0 -0
- /package/dist/{types-gLi9wL0N.cjs → types-CDkxah-M.cjs} +0 -0
- /package/dist/{vecOps-CODplJp3.cjs → vecOps-D7xplSx8.cjs} +0 -0
- /package/dist/{vecOps-B-PCHgyB.js → vecOps-DVROrqTV.js} +0 -0
- /package/dist/{workerHandler-C-3cFcsQ.cjs → workerHandler-C7seK7H-.cjs} +0 -0
- /package/dist/{workerHandler-Dm0_0F8Z.js → workerHandler-DaulgMax.js} +0 -0
|
@@ -1,3947 +0,0 @@
|
|
|
1
|
-
//#region src/kernel/geometry2d.ts
|
|
2
|
-
function evaluateCurve2d(c, t) {
|
|
3
|
-
switch (c.__bk2d) {
|
|
4
|
-
case "line": return [c.ox + c.dx * t, c.oy + c.dy * t];
|
|
5
|
-
case "circle": {
|
|
6
|
-
const angle = c.sense ? t : -t;
|
|
7
|
-
return [c.cx + c.radius * Math.cos(angle), c.cy + c.radius * Math.sin(angle)];
|
|
8
|
-
}
|
|
9
|
-
case "ellipse": {
|
|
10
|
-
const angle = c.sense ? t : -t;
|
|
11
|
-
const cos = Math.cos(c.xDirAngle);
|
|
12
|
-
const sin = Math.sin(c.xDirAngle);
|
|
13
|
-
const x = c.majorRadius * Math.cos(angle);
|
|
14
|
-
const y = c.minorRadius * Math.sin(angle);
|
|
15
|
-
return [c.cx + x * cos - y * sin, c.cy + x * sin + y * cos];
|
|
16
|
-
}
|
|
17
|
-
case "bezier": return evaluateBezier(c.poles, t);
|
|
18
|
-
case "bspline": return evaluateBSpline2d(c, t);
|
|
19
|
-
case "trimmed": {
|
|
20
|
-
const mapped = c.tStart + t * (c.tEnd - c.tStart);
|
|
21
|
-
return evaluateCurve2d(c.basis, mapped);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function tangentCurve2d(c, t) {
|
|
26
|
-
switch (c.__bk2d) {
|
|
27
|
-
case "line": return [c.dx, c.dy];
|
|
28
|
-
case "circle": {
|
|
29
|
-
const angle = c.sense ? t : -t;
|
|
30
|
-
const sign = c.sense ? 1 : -1;
|
|
31
|
-
return [-c.radius * Math.sin(angle) * sign, c.radius * Math.cos(angle) * sign];
|
|
32
|
-
}
|
|
33
|
-
case "ellipse": {
|
|
34
|
-
const angle = c.sense ? t : -t;
|
|
35
|
-
const sign = c.sense ? 1 : -1;
|
|
36
|
-
const cos = Math.cos(c.xDirAngle);
|
|
37
|
-
const sin = Math.sin(c.xDirAngle);
|
|
38
|
-
const dx = -c.majorRadius * Math.sin(angle) * sign;
|
|
39
|
-
const dy = c.minorRadius * Math.cos(angle) * sign;
|
|
40
|
-
return [dx * cos - dy * sin, dx * sin + dy * cos];
|
|
41
|
-
}
|
|
42
|
-
case "bezier": {
|
|
43
|
-
const h = 1e-8;
|
|
44
|
-
const p0 = evaluateBezier(c.poles, Math.max(0, t - h));
|
|
45
|
-
const p1 = evaluateBezier(c.poles, Math.min(1, t + h));
|
|
46
|
-
const dt = Math.min(1, t + h) - Math.max(0, t - h);
|
|
47
|
-
return [(p1[0] - p0[0]) / dt, (p1[1] - p0[1]) / dt];
|
|
48
|
-
}
|
|
49
|
-
case "bspline": {
|
|
50
|
-
const h = 1e-8;
|
|
51
|
-
const kFirst = c.knots[0];
|
|
52
|
-
const kLast = c.knots[c.knots.length - 1];
|
|
53
|
-
const p0 = evaluateBSpline2d(c, Math.max(kFirst, t - h));
|
|
54
|
-
const p1 = evaluateBSpline2d(c, Math.min(kLast, t + h));
|
|
55
|
-
const dt = Math.min(kLast, t + h) - Math.max(kFirst, t - h);
|
|
56
|
-
return [(p1[0] - p0[0]) / dt, (p1[1] - p0[1]) / dt];
|
|
57
|
-
}
|
|
58
|
-
case "trimmed": {
|
|
59
|
-
const mapped = c.tStart + t * (c.tEnd - c.tStart);
|
|
60
|
-
const tan = tangentCurve2d(c.basis, mapped);
|
|
61
|
-
const scale = c.tEnd - c.tStart;
|
|
62
|
-
return [tan[0] * scale, tan[1] * scale];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function curveBounds(c) {
|
|
67
|
-
switch (c.__bk2d) {
|
|
68
|
-
case "line": return {
|
|
69
|
-
first: 0,
|
|
70
|
-
last: c.len
|
|
71
|
-
};
|
|
72
|
-
case "circle":
|
|
73
|
-
case "ellipse": return {
|
|
74
|
-
first: 0,
|
|
75
|
-
last: 2 * Math.PI
|
|
76
|
-
};
|
|
77
|
-
case "bezier": return {
|
|
78
|
-
first: 0,
|
|
79
|
-
last: 1
|
|
80
|
-
};
|
|
81
|
-
case "bspline": return {
|
|
82
|
-
first: c.knots[0],
|
|
83
|
-
last: c.knots[c.knots.length - 1]
|
|
84
|
-
};
|
|
85
|
-
case "trimmed": return {
|
|
86
|
-
first: 0,
|
|
87
|
-
last: 1
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function curveTypeName(c) {
|
|
92
|
-
switch (c.__bk2d) {
|
|
93
|
-
case "line": return "LINE";
|
|
94
|
-
case "circle": return "CIRCLE";
|
|
95
|
-
case "ellipse": return "ELLIPSE";
|
|
96
|
-
case "bezier": return "BEZIER_CURVE";
|
|
97
|
-
case "bspline": return "BSPLINE_CURVE";
|
|
98
|
-
case "trimmed": return "TRIMMED_" + curveTypeName(c.basis);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function makeLine2d(x1, y1, x2, y2) {
|
|
102
|
-
const dx = x2 - x1;
|
|
103
|
-
const dy = y2 - y1;
|
|
104
|
-
const len = Math.sqrt(dx * dx + dy * dy);
|
|
105
|
-
return {
|
|
106
|
-
__bk2d: "line",
|
|
107
|
-
ox: x1,
|
|
108
|
-
oy: y1,
|
|
109
|
-
dx: len > 0 ? dx / len : 1,
|
|
110
|
-
dy: len > 0 ? dy / len : 0,
|
|
111
|
-
len
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function makeCircle2d(cx, cy, radius, sense = true) {
|
|
115
|
-
return {
|
|
116
|
-
__bk2d: "circle",
|
|
117
|
-
cx,
|
|
118
|
-
cy,
|
|
119
|
-
radius,
|
|
120
|
-
sense
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function makeEllipse2d(cx, cy, majorRadius, minorRadius, xDirX = 1, xDirY = 0, sense = true) {
|
|
124
|
-
return {
|
|
125
|
-
__bk2d: "ellipse",
|
|
126
|
-
cx,
|
|
127
|
-
cy,
|
|
128
|
-
majorRadius,
|
|
129
|
-
minorRadius,
|
|
130
|
-
xDirAngle: Math.atan2(xDirY, xDirX),
|
|
131
|
-
sense
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
function makeBezier2d(poles) {
|
|
135
|
-
return {
|
|
136
|
-
__bk2d: "bezier",
|
|
137
|
-
poles: [...poles]
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
function translateCurve2d(c, dx, dy) {
|
|
141
|
-
switch (c.__bk2d) {
|
|
142
|
-
case "line": return {
|
|
143
|
-
...c,
|
|
144
|
-
ox: c.ox + dx,
|
|
145
|
-
oy: c.oy + dy
|
|
146
|
-
};
|
|
147
|
-
case "circle": return {
|
|
148
|
-
...c,
|
|
149
|
-
cx: c.cx + dx,
|
|
150
|
-
cy: c.cy + dy
|
|
151
|
-
};
|
|
152
|
-
case "ellipse": return {
|
|
153
|
-
...c,
|
|
154
|
-
cx: c.cx + dx,
|
|
155
|
-
cy: c.cy + dy
|
|
156
|
-
};
|
|
157
|
-
case "bezier": return {
|
|
158
|
-
...c,
|
|
159
|
-
poles: c.poles.map(([x, y]) => [x + dx, y + dy])
|
|
160
|
-
};
|
|
161
|
-
case "bspline": return {
|
|
162
|
-
...c,
|
|
163
|
-
poles: c.poles.map(([x, y]) => [x + dx, y + dy])
|
|
164
|
-
};
|
|
165
|
-
case "trimmed": return {
|
|
166
|
-
...c,
|
|
167
|
-
basis: translateCurve2d(c.basis, dx, dy)
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function rotateCurve2d(c, angle, cx, cy) {
|
|
172
|
-
const cos = Math.cos(angle);
|
|
173
|
-
const sin = Math.sin(angle);
|
|
174
|
-
const rotatePoint = (x, y) => {
|
|
175
|
-
const rx = x - cx;
|
|
176
|
-
const ry = y - cy;
|
|
177
|
-
return [cx + rx * cos - ry * sin, cy + rx * sin + ry * cos];
|
|
178
|
-
};
|
|
179
|
-
switch (c.__bk2d) {
|
|
180
|
-
case "line": {
|
|
181
|
-
const [ox, oy] = rotatePoint(c.ox, c.oy);
|
|
182
|
-
const ndx = c.dx * cos - c.dy * sin;
|
|
183
|
-
const ndy = c.dx * sin + c.dy * cos;
|
|
184
|
-
return {
|
|
185
|
-
...c,
|
|
186
|
-
ox,
|
|
187
|
-
oy,
|
|
188
|
-
dx: ndx,
|
|
189
|
-
dy: ndy
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
case "circle": {
|
|
193
|
-
const [ncx, ncy] = rotatePoint(c.cx, c.cy);
|
|
194
|
-
return {
|
|
195
|
-
...c,
|
|
196
|
-
cx: ncx,
|
|
197
|
-
cy: ncy
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
case "ellipse": {
|
|
201
|
-
const [ncx, ncy] = rotatePoint(c.cx, c.cy);
|
|
202
|
-
return {
|
|
203
|
-
...c,
|
|
204
|
-
cx: ncx,
|
|
205
|
-
cy: ncy,
|
|
206
|
-
xDirAngle: c.xDirAngle + angle
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
case "bezier": return {
|
|
210
|
-
...c,
|
|
211
|
-
poles: c.poles.map(([x, y]) => rotatePoint(x, y))
|
|
212
|
-
};
|
|
213
|
-
case "bspline": return {
|
|
214
|
-
...c,
|
|
215
|
-
poles: c.poles.map(([x, y]) => rotatePoint(x, y))
|
|
216
|
-
};
|
|
217
|
-
case "trimmed": return {
|
|
218
|
-
...c,
|
|
219
|
-
basis: rotateCurve2d(c.basis, angle, cx, cy)
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
function scaleCurve2d(c, factor, cx, cy) {
|
|
224
|
-
const scalePoint = (x, y) => [cx + (x - cx) * factor, cy + (y - cy) * factor];
|
|
225
|
-
switch (c.__bk2d) {
|
|
226
|
-
case "line": {
|
|
227
|
-
const [ox, oy] = scalePoint(c.ox, c.oy);
|
|
228
|
-
return {
|
|
229
|
-
...c,
|
|
230
|
-
ox,
|
|
231
|
-
oy
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
case "circle": {
|
|
235
|
-
const [ncx, ncy] = scalePoint(c.cx, c.cy);
|
|
236
|
-
return {
|
|
237
|
-
...c,
|
|
238
|
-
cx: ncx,
|
|
239
|
-
cy: ncy,
|
|
240
|
-
radius: c.radius * Math.abs(factor)
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
case "ellipse": {
|
|
244
|
-
const [ncx, ncy] = scalePoint(c.cx, c.cy);
|
|
245
|
-
return {
|
|
246
|
-
...c,
|
|
247
|
-
cx: ncx,
|
|
248
|
-
cy: ncy,
|
|
249
|
-
majorRadius: c.majorRadius * Math.abs(factor),
|
|
250
|
-
minorRadius: c.minorRadius * Math.abs(factor)
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
case "bezier": return {
|
|
254
|
-
...c,
|
|
255
|
-
poles: c.poles.map(([x, y]) => scalePoint(x, y))
|
|
256
|
-
};
|
|
257
|
-
case "bspline": return {
|
|
258
|
-
...c,
|
|
259
|
-
poles: c.poles.map(([x, y]) => scalePoint(x, y))
|
|
260
|
-
};
|
|
261
|
-
case "trimmed": return {
|
|
262
|
-
...c,
|
|
263
|
-
basis: scaleCurve2d(c.basis, factor, cx, cy)
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
function mirrorAtPoint(c, cx, cy) {
|
|
268
|
-
return scaleCurve2d(c, -1, cx, cy);
|
|
269
|
-
}
|
|
270
|
-
function mirrorAcrossAxis(c, ox, oy, dx, dy) {
|
|
271
|
-
const len = Math.sqrt(dx * dx + dy * dy);
|
|
272
|
-
const nx = dx / len;
|
|
273
|
-
const ny = dy / len;
|
|
274
|
-
const reflectPoint = (x, y) => {
|
|
275
|
-
const rx = x - ox;
|
|
276
|
-
const ry = y - oy;
|
|
277
|
-
const dot = rx * nx + ry * ny;
|
|
278
|
-
return [ox + 2 * dot * nx - rx, oy + 2 * dot * ny - ry];
|
|
279
|
-
};
|
|
280
|
-
switch (c.__bk2d) {
|
|
281
|
-
case "line": {
|
|
282
|
-
const [nox, noy] = reflectPoint(c.ox, c.oy);
|
|
283
|
-
const ndx = 2 * (c.dx * nx + c.dy * ny) * nx - c.dx;
|
|
284
|
-
const ndy = 2 * (c.dx * nx + c.dy * ny) * ny - c.dy;
|
|
285
|
-
return {
|
|
286
|
-
...c,
|
|
287
|
-
ox: nox,
|
|
288
|
-
oy: noy,
|
|
289
|
-
dx: ndx,
|
|
290
|
-
dy: ndy
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
case "circle": {
|
|
294
|
-
const [ncx, ncy] = reflectPoint(c.cx, c.cy);
|
|
295
|
-
return {
|
|
296
|
-
...c,
|
|
297
|
-
cx: ncx,
|
|
298
|
-
cy: ncy,
|
|
299
|
-
sense: !c.sense
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
case "ellipse": {
|
|
303
|
-
const [ncx, ncy] = reflectPoint(c.cx, c.cy);
|
|
304
|
-
const cos2 = nx * nx - ny * ny;
|
|
305
|
-
const sin2 = 2 * nx * ny;
|
|
306
|
-
const newAngle = Math.atan2(sin2 * Math.cos(c.xDirAngle) - cos2 * Math.sin(c.xDirAngle), cos2 * Math.cos(c.xDirAngle) + sin2 * Math.sin(c.xDirAngle));
|
|
307
|
-
return {
|
|
308
|
-
...c,
|
|
309
|
-
cx: ncx,
|
|
310
|
-
cy: ncy,
|
|
311
|
-
xDirAngle: newAngle,
|
|
312
|
-
sense: !c.sense
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
case "bezier": return {
|
|
316
|
-
...c,
|
|
317
|
-
poles: c.poles.map(([x, y]) => reflectPoint(x, y))
|
|
318
|
-
};
|
|
319
|
-
case "bspline": return {
|
|
320
|
-
...c,
|
|
321
|
-
poles: c.poles.map(([x, y]) => reflectPoint(x, y))
|
|
322
|
-
};
|
|
323
|
-
case "trimmed": return {
|
|
324
|
-
...c,
|
|
325
|
-
basis: mirrorAcrossAxis(c.basis, ox, oy, dx, dy)
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Compute intersection points (and overlapping segments) between two 2D curves.
|
|
331
|
-
* Handles analytic cases (line-line, line-circle, circle-circle) and falls back
|
|
332
|
-
* to numerical sampling + Newton refinement for general curves.
|
|
333
|
-
*/
|
|
334
|
-
function intersectCurves2dFn(c1, c2, tolerance) {
|
|
335
|
-
const b1 = unwrapCurve(c1);
|
|
336
|
-
const b2 = unwrapCurve(c2);
|
|
337
|
-
if (b1.__bk2d === "line" && b2.__bk2d === "line") return intersectLineLine(c1, b1, c2, b2, tolerance);
|
|
338
|
-
if (b1.__bk2d === "line" && b2.__bk2d === "circle") return {
|
|
339
|
-
points: intersectLineCircle(c1, b1, c2, b2, tolerance),
|
|
340
|
-
segments: []
|
|
341
|
-
};
|
|
342
|
-
if (b1.__bk2d === "circle" && b2.__bk2d === "line") return {
|
|
343
|
-
points: intersectLineCircle(c2, b2, c1, b1, tolerance),
|
|
344
|
-
segments: []
|
|
345
|
-
};
|
|
346
|
-
if (b1.__bk2d === "circle" && b2.__bk2d === "circle") return {
|
|
347
|
-
points: intersectCircleCircle(c1, b1, c2, b2, tolerance),
|
|
348
|
-
segments: []
|
|
349
|
-
};
|
|
350
|
-
return numericalIntersect(c1, c2, tolerance, c1 === c2);
|
|
351
|
-
}
|
|
352
|
-
/** Unwrap trimmed wrappers to get the basis curve type. */
|
|
353
|
-
function unwrapCurve(c) {
|
|
354
|
-
let cur = c;
|
|
355
|
-
while (cur.__bk2d === "trimmed") cur = cur.basis;
|
|
356
|
-
return cur;
|
|
357
|
-
}
|
|
358
|
-
/** Check if parameter t is within the curve's domain. */
|
|
359
|
-
function inDomain(c, t, tol) {
|
|
360
|
-
const b = curveBounds(c);
|
|
361
|
-
return t >= b.first - tol && t <= b.last + tol;
|
|
362
|
-
}
|
|
363
|
-
/** Find the parameter on curve c closest to point (px, py), searching near tGuess. */
|
|
364
|
-
function refineParam(c, px, py) {
|
|
365
|
-
const bounds = curveBounds(c);
|
|
366
|
-
if (!isFinite(bounds.first) || !isFinite(bounds.last)) return null;
|
|
367
|
-
const N = 80;
|
|
368
|
-
const dt = (bounds.last - bounds.first) / N;
|
|
369
|
-
let bestT = bounds.first;
|
|
370
|
-
let bestD = Infinity;
|
|
371
|
-
for (let i = 0; i <= N; i++) {
|
|
372
|
-
const t = bounds.first + i * dt;
|
|
373
|
-
const [ex, ey] = evaluateCurve2d(c, t);
|
|
374
|
-
const d = (ex - px) ** 2 + (ey - py) ** 2;
|
|
375
|
-
if (d < bestD) {
|
|
376
|
-
bestD = d;
|
|
377
|
-
bestT = t;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
const [sx, sy] = evaluateCurve2d(c, bounds.first);
|
|
381
|
-
const [ex, ey] = evaluateCurve2d(c, bounds.last);
|
|
382
|
-
const [mx, my] = evaluateCurve2d(c, (bounds.first + bounds.last) / 2);
|
|
383
|
-
const maxDist = Math.max(Math.sqrt((ex - sx) ** 2 + (ey - sy) ** 2), Math.sqrt((mx - sx) ** 2 + (my - sy) ** 2), 1e-6) * .1;
|
|
384
|
-
return bestD < maxDist * maxDist ? bestT : null;
|
|
385
|
-
}
|
|
386
|
-
function intersectLineLine(c1, l1, c2, l2, tol) {
|
|
387
|
-
const det = l1.dx * l2.dy - l1.dy * l2.dx;
|
|
388
|
-
if (Math.abs(det) >= 1e-14) {
|
|
389
|
-
const ex = l2.ox - l1.ox;
|
|
390
|
-
const ey = l2.oy - l1.oy;
|
|
391
|
-
const t1 = (ex * l2.dy - ey * l2.dx) / det;
|
|
392
|
-
const t2 = (ex * l1.dy - ey * l1.dx) / det;
|
|
393
|
-
if (!inDomain(c1, t1, tol) || !inDomain(c2, t2, tol)) return {
|
|
394
|
-
points: [],
|
|
395
|
-
segments: []
|
|
396
|
-
};
|
|
397
|
-
return {
|
|
398
|
-
points: [[l1.ox + t1 * l1.dx, l1.oy + t1 * l1.dy]],
|
|
399
|
-
segments: []
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
const ex = l2.ox - l1.ox;
|
|
403
|
-
const ey = l2.oy - l1.oy;
|
|
404
|
-
const cross = ex * l1.dy - ey * l1.dx;
|
|
405
|
-
if (Math.abs(cross) > tol) return {
|
|
406
|
-
points: [],
|
|
407
|
-
segments: []
|
|
408
|
-
};
|
|
409
|
-
const b1 = curveBounds(c1);
|
|
410
|
-
const b2 = curveBounds(c2);
|
|
411
|
-
const p2s = evaluateCurve2d(c2, b2.first);
|
|
412
|
-
const p2e = evaluateCurve2d(c2, b2.last);
|
|
413
|
-
const t2sOn1 = (p2s[0] - l1.ox) * l1.dx + (p2s[1] - l1.oy) * l1.dy;
|
|
414
|
-
const t2eOn1 = (p2e[0] - l1.ox) * l1.dx + (p2e[1] - l1.oy) * l1.dy;
|
|
415
|
-
const overlapStart = Math.max(b1.first, Math.min(t2sOn1, t2eOn1));
|
|
416
|
-
const overlapEnd = Math.min(b1.last, Math.max(t2sOn1, t2eOn1));
|
|
417
|
-
if (overlapEnd - overlapStart < tol) return {
|
|
418
|
-
points: [],
|
|
419
|
-
segments: []
|
|
420
|
-
};
|
|
421
|
-
return {
|
|
422
|
-
points: [],
|
|
423
|
-
segments: [makeLine2d(l1.ox + overlapStart * l1.dx, l1.oy + overlapStart * l1.dy, l1.ox + overlapEnd * l1.dx, l1.oy + overlapEnd * l1.dy)]
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
function intersectLineCircle(cLine, line, cCirc, circ, tol) {
|
|
427
|
-
const fx = line.ox - circ.cx;
|
|
428
|
-
const fy = line.oy - circ.cy;
|
|
429
|
-
const a = line.dx * line.dx + line.dy * line.dy;
|
|
430
|
-
const b = 2 * (fx * line.dx + fy * line.dy);
|
|
431
|
-
const c = fx * fx + fy * fy - circ.radius * circ.radius;
|
|
432
|
-
const disc = b * b - 4 * a * c;
|
|
433
|
-
if (disc < -tol) return [];
|
|
434
|
-
const results = [];
|
|
435
|
-
const sqrtDisc = Math.sqrt(Math.max(0, disc));
|
|
436
|
-
const t1 = (-b - sqrtDisc) / (2 * a);
|
|
437
|
-
const t2 = (-b + sqrtDisc) / (2 * a);
|
|
438
|
-
for (const tLine of disc < tol * tol ? [t1] : [t1, t2]) {
|
|
439
|
-
if (!inDomain(cLine, tLine, tol)) continue;
|
|
440
|
-
const px = line.ox + tLine * line.dx;
|
|
441
|
-
const py = line.oy + tLine * line.dy;
|
|
442
|
-
const tCirc = refineParam(cCirc, px, py);
|
|
443
|
-
if (tCirc === null) continue;
|
|
444
|
-
const [cx2, cy2] = evaluateCurve2d(cCirc, tCirc);
|
|
445
|
-
if ((cx2 - px) ** 2 + (cy2 - py) ** 2 > tol * tol * 1e6) continue;
|
|
446
|
-
results.push([px, py]);
|
|
447
|
-
}
|
|
448
|
-
return results;
|
|
449
|
-
}
|
|
450
|
-
function intersectConcentricArcs(c1, c2, tol) {
|
|
451
|
-
const b1 = curveBounds(c1);
|
|
452
|
-
const b2 = curveBounds(c2);
|
|
453
|
-
const isFullCircle1 = Math.abs(b1.last - b1.first - 2 * Math.PI) < 1e-10;
|
|
454
|
-
const isFullCircle2 = Math.abs(b2.last - b2.first - 2 * Math.PI) < 1e-10;
|
|
455
|
-
if (isFullCircle1 && isFullCircle2) return [];
|
|
456
|
-
if (isFullCircle1) return [evaluateCurve2d(c2, b2.first), evaluateCurve2d(c2, b2.last)];
|
|
457
|
-
if (isFullCircle2) return [evaluateCurve2d(c1, b1.first), evaluateCurve2d(c1, b1.last)];
|
|
458
|
-
const pts = [];
|
|
459
|
-
const checks = [
|
|
460
|
-
[c2, evaluateCurve2d(c1, b1.first)],
|
|
461
|
-
[c2, evaluateCurve2d(c1, b1.last)],
|
|
462
|
-
[c1, evaluateCurve2d(c2, b2.first)],
|
|
463
|
-
[c1, evaluateCurve2d(c2, b2.last)]
|
|
464
|
-
];
|
|
465
|
-
for (const [target, pt] of checks) {
|
|
466
|
-
const t = refineParam(target, pt[0], pt[1]);
|
|
467
|
-
if (t !== null) {
|
|
468
|
-
const [ex, ey] = evaluateCurve2d(target, t);
|
|
469
|
-
if ((ex - pt[0]) ** 2 + (ey - pt[1]) ** 2 < tol * tol * 100) pts.push(pt);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
const deduped = [];
|
|
473
|
-
for (const p of pts) if (!deduped.some(([ddx, ddy]) => (ddx - p[0]) ** 2 + (ddy - p[1]) ** 2 < tol * tol * 100)) deduped.push(p);
|
|
474
|
-
return deduped;
|
|
475
|
-
}
|
|
476
|
-
function intersectCircleCircle(c1, circ1, c2, circ2, tol) {
|
|
477
|
-
const dx = circ2.cx - circ1.cx;
|
|
478
|
-
const dy = circ2.cy - circ1.cy;
|
|
479
|
-
const d = Math.sqrt(dx * dx + dy * dy);
|
|
480
|
-
if (d > circ1.radius + circ2.radius + tol) return [];
|
|
481
|
-
if (d < Math.abs(circ1.radius - circ2.radius) - tol) return [];
|
|
482
|
-
if (d < 1e-14) {
|
|
483
|
-
if (Math.abs(circ1.radius - circ2.radius) > tol) return [];
|
|
484
|
-
return intersectConcentricArcs(c1, c2, tol);
|
|
485
|
-
}
|
|
486
|
-
const a = (circ1.radius * circ1.radius - circ2.radius * circ2.radius + d * d) / (2 * d);
|
|
487
|
-
const h2 = circ1.radius * circ1.radius - a * a;
|
|
488
|
-
const h = Math.sqrt(Math.max(0, h2));
|
|
489
|
-
const mx = circ1.cx + a * dx / d;
|
|
490
|
-
const my = circ1.cy + a * dy / d;
|
|
491
|
-
const candidates = h < tol ? [[mx, my]] : [[mx + h * dy / d, my - h * dx / d], [mx - h * dy / d, my + h * dx / d]];
|
|
492
|
-
const results = [];
|
|
493
|
-
for (const [px, py] of candidates) {
|
|
494
|
-
const t1 = refineParam(c1, px, py);
|
|
495
|
-
const t2 = refineParam(c2, px, py);
|
|
496
|
-
if (t1 === null || t2 === null) continue;
|
|
497
|
-
const [x1, y1] = evaluateCurve2d(c1, t1);
|
|
498
|
-
const [x2, y2] = evaluateCurve2d(c2, t2);
|
|
499
|
-
const tolSq = (tol * 10) ** 2;
|
|
500
|
-
if ((x1 - px) ** 2 + (y1 - py) ** 2 > tolSq) continue;
|
|
501
|
-
if ((x2 - px) ** 2 + (y2 - py) ** 2 > tolSq) continue;
|
|
502
|
-
results.push([px, py]);
|
|
503
|
-
}
|
|
504
|
-
return results;
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Numerical intersection via sampling + Newton refinement.
|
|
508
|
-
* Samples both curves densely, finds close point pairs, refines with Newton.
|
|
509
|
-
*/
|
|
510
|
-
function numericalIntersect(c1, c2, tolerance, isSelf = false) {
|
|
511
|
-
const b1 = curveBounds(c1);
|
|
512
|
-
const b2 = curveBounds(c2);
|
|
513
|
-
if (!isFinite(b1.first) || !isFinite(b1.last) || !isFinite(b2.first) || !isFinite(b2.last)) return {
|
|
514
|
-
points: [],
|
|
515
|
-
segments: []
|
|
516
|
-
};
|
|
517
|
-
const N = 100;
|
|
518
|
-
const pts1 = [];
|
|
519
|
-
const pts2 = [];
|
|
520
|
-
for (let i = 0; i <= N; i++) {
|
|
521
|
-
const t1 = b1.first + (b1.last - b1.first) * i / N;
|
|
522
|
-
const [x1, y1] = evaluateCurve2d(c1, t1);
|
|
523
|
-
pts1.push({
|
|
524
|
-
t: t1,
|
|
525
|
-
x: x1,
|
|
526
|
-
y: y1
|
|
527
|
-
});
|
|
528
|
-
const t2 = b2.first + (b2.last - b2.first) * i / N;
|
|
529
|
-
const [x2, y2] = evaluateCurve2d(c2, t2);
|
|
530
|
-
pts2.push({
|
|
531
|
-
t: t2,
|
|
532
|
-
x: x2,
|
|
533
|
-
y: y2
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
const crossTol = Math.max(tolerance * 100, .5);
|
|
537
|
-
const seg2Bounds = new Float64Array(N * 6);
|
|
538
|
-
for (let j = 0; j < N; j++) {
|
|
539
|
-
const a = pts2[j], b = pts2[j + 1];
|
|
540
|
-
const off = j * 6;
|
|
541
|
-
seg2Bounds[off] = Math.min(a.x, b.x);
|
|
542
|
-
seg2Bounds[off + 1] = Math.max(a.x, b.x);
|
|
543
|
-
seg2Bounds[off + 2] = Math.min(a.y, b.y);
|
|
544
|
-
seg2Bounds[off + 3] = Math.max(a.y, b.y);
|
|
545
|
-
seg2Bounds[off + 4] = (a.t + b.t) / 2;
|
|
546
|
-
}
|
|
547
|
-
const candidates = [];
|
|
548
|
-
const selfMinSep = (b1.last - b1.first) / 5;
|
|
549
|
-
for (let i = 0; i < N; i++) {
|
|
550
|
-
const p1a = pts1[i];
|
|
551
|
-
const p1b = pts1[i + 1];
|
|
552
|
-
const x1min = Math.min(p1a.x, p1b.x) - crossTol;
|
|
553
|
-
const x1max = Math.max(p1a.x, p1b.x) + crossTol;
|
|
554
|
-
const y1min = Math.min(p1a.y, p1b.y) - crossTol;
|
|
555
|
-
const y1max = Math.max(p1a.y, p1b.y) + crossTol;
|
|
556
|
-
const t1mid = (p1a.t + p1b.t) / 2;
|
|
557
|
-
for (let j = 0; j < N; j++) {
|
|
558
|
-
const off = j * 6;
|
|
559
|
-
if (x1max < seg2Bounds[off] || seg2Bounds[off + 1] < x1min) continue;
|
|
560
|
-
if (y1max < seg2Bounds[off + 2] || seg2Bounds[off + 3] < y1min) continue;
|
|
561
|
-
const t2mid = seg2Bounds[off + 4];
|
|
562
|
-
if (isSelf && Math.abs(t1mid - t2mid) < selfMinSep) continue;
|
|
563
|
-
candidates.push({
|
|
564
|
-
t1: t1mid,
|
|
565
|
-
t2: t2mid
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
const tol2 = tolerance * tolerance;
|
|
570
|
-
const found = [];
|
|
571
|
-
for (const { t1: t1Init, t2: t2Init } of candidates) {
|
|
572
|
-
let t1 = t1Init;
|
|
573
|
-
let t2 = t2Init;
|
|
574
|
-
for (let iter = 0; iter < 20; iter++) {
|
|
575
|
-
const [x1, y1] = evaluateCurve2d(c1, t1);
|
|
576
|
-
const [x2, y2] = evaluateCurve2d(c2, t2);
|
|
577
|
-
const dx = x1 - x2;
|
|
578
|
-
const dy = y1 - y2;
|
|
579
|
-
if (dx * dx + dy * dy < tol2) break;
|
|
580
|
-
const d1 = tangentCurve2d(c1, t1);
|
|
581
|
-
const d2 = tangentCurve2d(c2, t2);
|
|
582
|
-
const det = d1[0] * -d2[1] - -d2[0] * d1[1];
|
|
583
|
-
if (Math.abs(det) < 1e-14) break;
|
|
584
|
-
const dt1 = (-dx * -d2[1] - -dy * -d2[0]) / det;
|
|
585
|
-
const dt2 = (d1[0] * -dy - d1[1] * -dx) / det;
|
|
586
|
-
t1 += dt1;
|
|
587
|
-
t2 += dt2;
|
|
588
|
-
t1 = Math.max(b1.first, Math.min(b1.last, t1));
|
|
589
|
-
t2 = Math.max(b2.first, Math.min(b2.last, t2));
|
|
590
|
-
}
|
|
591
|
-
const [x1, y1] = evaluateCurve2d(c1, t1);
|
|
592
|
-
const [x2, y2] = evaluateCurve2d(c2, t2);
|
|
593
|
-
if (isSelf && Math.abs(t1 - t2) < (b1.last - b1.first) * .05) continue;
|
|
594
|
-
if ((x1 - x2) ** 2 + (y1 - y2) ** 2 < tolerance * tolerance * 1e6) {
|
|
595
|
-
const px = (x1 + x2) / 2;
|
|
596
|
-
const py = (y1 + y2) / 2;
|
|
597
|
-
let dup = false;
|
|
598
|
-
for (const [fx, fy] of found) if ((fx - px) ** 2 + (fy - py) ** 2 < tolerance * tolerance * 1e4) {
|
|
599
|
-
dup = true;
|
|
600
|
-
break;
|
|
601
|
-
}
|
|
602
|
-
if (!dup) found.push([px, py]);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
return {
|
|
606
|
-
points: found,
|
|
607
|
-
segments: []
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
function serializeCurve2d(c) {
|
|
611
|
-
return JSON.stringify(c);
|
|
612
|
-
}
|
|
613
|
-
function deserializeCurve2d(data) {
|
|
614
|
-
return JSON.parse(data);
|
|
615
|
-
}
|
|
616
|
-
function createBBox2d() {
|
|
617
|
-
return {
|
|
618
|
-
__bk2d_bbox: true,
|
|
619
|
-
xMin: Infinity,
|
|
620
|
-
yMin: Infinity,
|
|
621
|
-
xMax: -Infinity,
|
|
622
|
-
yMax: -Infinity
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
function addCurveToBBox(bbox, c, _tol) {
|
|
626
|
-
const basis = c.__bk2d === "trimmed" ? c.basis : c;
|
|
627
|
-
if (basis.__bk2d === "line") {
|
|
628
|
-
const bounds = curveBounds(c);
|
|
629
|
-
if (!isFinite(bounds.first) || !isFinite(bounds.last)) return;
|
|
630
|
-
const [x0, y0] = evaluateCurve2d(c, bounds.first);
|
|
631
|
-
const [x1, y1] = evaluateCurve2d(c, bounds.last);
|
|
632
|
-
bbox.xMin = Math.min(bbox.xMin, x0, x1);
|
|
633
|
-
bbox.yMin = Math.min(bbox.yMin, y0, y1);
|
|
634
|
-
bbox.xMax = Math.max(bbox.xMax, x0, x1);
|
|
635
|
-
bbox.yMax = Math.max(bbox.yMax, y0, y1);
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
|
-
if (basis.__bk2d === "circle") {
|
|
639
|
-
const bounds = curveBounds(c);
|
|
640
|
-
if (!isFinite(bounds.first) || !isFinite(bounds.last)) return;
|
|
641
|
-
const { cx, cy, radius, sense } = basis;
|
|
642
|
-
const [x0, y0] = evaluateCurve2d(c, bounds.first);
|
|
643
|
-
const [x1, y1] = evaluateCurve2d(c, bounds.last);
|
|
644
|
-
let xMin = Math.min(x0, x1), xMax = Math.max(x0, x1);
|
|
645
|
-
let yMin = Math.min(y0, y1), yMax = Math.max(y0, y1);
|
|
646
|
-
const tStart = c.__bk2d === "trimmed" ? c.tStart : bounds.first;
|
|
647
|
-
const tEnd = c.__bk2d === "trimmed" ? c.tEnd : bounds.last;
|
|
648
|
-
for (let k = 0; k < 4; k++) {
|
|
649
|
-
const angle = k * Math.PI / 2;
|
|
650
|
-
const t = sense ? angle : -angle;
|
|
651
|
-
for (let wrap = 0; wrap <= 1; wrap++) {
|
|
652
|
-
const tt = t + wrap * 2 * Math.PI;
|
|
653
|
-
if (tt >= tStart - 1e-10 && tt <= tEnd + 1e-10) {
|
|
654
|
-
const ex = cx + radius * Math.cos(angle);
|
|
655
|
-
const ey = cy + radius * Math.sin(angle);
|
|
656
|
-
xMin = Math.min(xMin, ex);
|
|
657
|
-
xMax = Math.max(xMax, ex);
|
|
658
|
-
yMin = Math.min(yMin, ey);
|
|
659
|
-
yMax = Math.max(yMax, ey);
|
|
660
|
-
break;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
bbox.xMin = Math.min(bbox.xMin, xMin);
|
|
665
|
-
bbox.yMin = Math.min(bbox.yMin, yMin);
|
|
666
|
-
bbox.xMax = Math.max(bbox.xMax, xMax);
|
|
667
|
-
bbox.yMax = Math.max(bbox.yMax, yMax);
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
const bounds = curveBounds(c);
|
|
671
|
-
if (!isFinite(bounds.first) || !isFinite(bounds.last)) return;
|
|
672
|
-
const nSamples = 20;
|
|
673
|
-
const dt = (bounds.last - bounds.first) / nSamples;
|
|
674
|
-
for (let i = 0; i <= nSamples; i++) {
|
|
675
|
-
const [x, y] = evaluateCurve2d(c, bounds.first + i * dt);
|
|
676
|
-
if (x < bbox.xMin) bbox.xMin = x;
|
|
677
|
-
if (y < bbox.yMin) bbox.yMin = y;
|
|
678
|
-
if (x > bbox.xMax) bbox.xMax = x;
|
|
679
|
-
if (y > bbox.yMax) bbox.yMax = y;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
function evaluateBezier(poles, t) {
|
|
683
|
-
const n = poles.length;
|
|
684
|
-
const work = poles.map(([x, y]) => [x, y]);
|
|
685
|
-
for (let r = 1; r < n; r++) for (let i = 0; i < n - r; i++) {
|
|
686
|
-
const wi = work[i];
|
|
687
|
-
const wi1 = work[i + 1];
|
|
688
|
-
wi[0] = (1 - t) * wi[0] + t * wi1[0];
|
|
689
|
-
wi[1] = (1 - t) * wi[1] + t * wi1[1];
|
|
690
|
-
}
|
|
691
|
-
return work[0];
|
|
692
|
-
}
|
|
693
|
-
function evaluateBSpline2d(c, t) {
|
|
694
|
-
const fullKnots = [];
|
|
695
|
-
for (let i = 0; i < c.knots.length; i++) {
|
|
696
|
-
const mult = c.multiplicities[i] ?? 1;
|
|
697
|
-
for (let j = 0; j < mult; j++) fullKnots.push(c.knots[i]);
|
|
698
|
-
}
|
|
699
|
-
const p = c.degree;
|
|
700
|
-
const n = c.poles.length;
|
|
701
|
-
const k = fullKnots.length;
|
|
702
|
-
const tClamped = Math.max(fullKnots[p], Math.min(fullKnots[k - p - 1], t));
|
|
703
|
-
let span = p;
|
|
704
|
-
for (let i = p; i < k - p - 1; i++) if (tClamped >= fullKnots[i] && tClamped < fullKnots[i + 1]) {
|
|
705
|
-
span = i;
|
|
706
|
-
break;
|
|
707
|
-
}
|
|
708
|
-
if (tClamped >= fullKnots[k - p - 1]) span = k - p - 2;
|
|
709
|
-
const d = [];
|
|
710
|
-
for (let j = 0; j <= p; j++) {
|
|
711
|
-
const idx = Math.min(span - p + j, n - 1);
|
|
712
|
-
const pole = c.poles[Math.max(0, idx)];
|
|
713
|
-
d.push([pole[0], pole[1]]);
|
|
714
|
-
}
|
|
715
|
-
for (let r = 1; r <= p; r++) for (let j = p; j >= r; j--) {
|
|
716
|
-
const i = span - p + j;
|
|
717
|
-
const left = fullKnots[i] ?? 0;
|
|
718
|
-
const denom = (fullKnots[i + p - r + 1] ?? 1) - left;
|
|
719
|
-
const alpha = denom > 1e-15 ? (tClamped - left) / denom : 0;
|
|
720
|
-
const dj = d[j];
|
|
721
|
-
const djPrev = d[j - 1];
|
|
722
|
-
dj[0] = (1 - alpha) * djPrev[0] + alpha * dj[0];
|
|
723
|
-
dj[1] = (1 - alpha) * djPrev[1] + alpha * dj[1];
|
|
724
|
-
}
|
|
725
|
-
return d[p];
|
|
726
|
-
}
|
|
727
|
-
//#endregion
|
|
728
|
-
//#region src/kernel/occtWasm/occtWasmAdapter.ts
|
|
729
|
-
var noop = () => {};
|
|
730
|
-
function handle(type, id) {
|
|
731
|
-
return {
|
|
732
|
-
__occtWasm: true,
|
|
733
|
-
type,
|
|
734
|
-
id,
|
|
735
|
-
delete: noop,
|
|
736
|
-
HashCode(upperBound) {
|
|
737
|
-
return id % upperBound;
|
|
738
|
-
},
|
|
739
|
-
IsNull() {
|
|
740
|
-
return false;
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
function isOcctWasmHandle(shape) {
|
|
745
|
-
return typeof shape === "object" && shape !== null && shape.__occtWasm;
|
|
746
|
-
}
|
|
747
|
-
/** Extract the u32 id from a handle. */
|
|
748
|
-
function unwrap(shape) {
|
|
749
|
-
if (isOcctWasmHandle(shape)) return shape.id;
|
|
750
|
-
if (typeof shape === "number") return shape;
|
|
751
|
-
throw new Error("occt-wasm: expected an OcctWasmHandle or number, got " + typeof shape);
|
|
752
|
-
}
|
|
753
|
-
/** Map a WASM shape type string to our ShapeType enum. */
|
|
754
|
-
function mapShapeType(wasmType) {
|
|
755
|
-
switch (wasmType.toLowerCase()) {
|
|
756
|
-
case "vertex": return "vertex";
|
|
757
|
-
case "edge": return "edge";
|
|
758
|
-
case "wire": return "wire";
|
|
759
|
-
case "face": return "face";
|
|
760
|
-
case "shell": return "shell";
|
|
761
|
-
case "solid": return "solid";
|
|
762
|
-
case "compsolid": return "compsolid";
|
|
763
|
-
case "compound": return "compound";
|
|
764
|
-
default: return "compound";
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
/** Wrap a WASM u32 result as a typed handle, querying the kernel for type. */
|
|
768
|
-
function wrapResult(kernel, id) {
|
|
769
|
-
return handle(mapShapeType(kernel.getShapeType(id)), id);
|
|
770
|
-
}
|
|
771
|
-
function makeVecU32(Module, values) {
|
|
772
|
-
const vec = new Module.VectorUint32();
|
|
773
|
-
for (const v of values) vec.push_back(v);
|
|
774
|
-
return vec;
|
|
775
|
-
}
|
|
776
|
-
function makeVecInt(Module, values) {
|
|
777
|
-
const vec = new Module.VectorInt();
|
|
778
|
-
for (const v of values) vec.push_back(v);
|
|
779
|
-
return vec;
|
|
780
|
-
}
|
|
781
|
-
function makeVecDouble(Module, values) {
|
|
782
|
-
const vec = new Module.VectorDouble();
|
|
783
|
-
for (const v of values) vec.push_back(v);
|
|
784
|
-
return vec;
|
|
785
|
-
}
|
|
786
|
-
function readVecInt(vec) {
|
|
787
|
-
const result = [];
|
|
788
|
-
const n = vec.size();
|
|
789
|
-
for (let i = 0; i < n; i++) result.push(vec.get(i));
|
|
790
|
-
return result;
|
|
791
|
-
}
|
|
792
|
-
/**
|
|
793
|
-
* Parse an EvolutionData result from the WASM kernel into a ShapeEvolution.
|
|
794
|
-
*
|
|
795
|
-
* The C++ facade returns flat vectors of [inputHash, outputHash, inputHash, outputHash, ...]
|
|
796
|
-
* for modified and generated, and a flat vector of deleted input hashes.
|
|
797
|
-
*/
|
|
798
|
-
function parseEvolution(evo) {
|
|
799
|
-
try {
|
|
800
|
-
const modifiedRaw = readVecInt(evo.modified);
|
|
801
|
-
const generatedRaw = readVecInt(evo.generated);
|
|
802
|
-
const deletedRaw = readVecInt(evo.deleted);
|
|
803
|
-
const parseMap = (raw) => {
|
|
804
|
-
const map = /* @__PURE__ */ new Map();
|
|
805
|
-
let i = 0;
|
|
806
|
-
while (i + 1 < raw.length) {
|
|
807
|
-
const inputHash = raw[i] ?? 0;
|
|
808
|
-
const count = raw[i + 1] ?? 0;
|
|
809
|
-
i += 2;
|
|
810
|
-
const outputs = [];
|
|
811
|
-
for (let j = 0; j < count && i < raw.length; j++, i++) outputs.push(raw[i] ?? 0);
|
|
812
|
-
map.set(inputHash, outputs);
|
|
813
|
-
}
|
|
814
|
-
return map;
|
|
815
|
-
};
|
|
816
|
-
const modified = parseMap(modifiedRaw);
|
|
817
|
-
const generated = parseMap(generatedRaw);
|
|
818
|
-
const deleted = new Set(deletedRaw);
|
|
819
|
-
return {
|
|
820
|
-
id: evo.resultId,
|
|
821
|
-
evolution: {
|
|
822
|
-
modified,
|
|
823
|
-
generated,
|
|
824
|
-
deleted
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
} finally {
|
|
828
|
-
evo.delete();
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
function notImplemented(method) {
|
|
832
|
-
throw new Error(`occt-wasm: ${method} is not yet implemented`);
|
|
833
|
-
}
|
|
834
|
-
function computePositionBounds(positions, vCount) {
|
|
835
|
-
if (vCount === 0) return {
|
|
836
|
-
min: [
|
|
837
|
-
0,
|
|
838
|
-
0,
|
|
839
|
-
0
|
|
840
|
-
],
|
|
841
|
-
max: [
|
|
842
|
-
0,
|
|
843
|
-
0,
|
|
844
|
-
0
|
|
845
|
-
]
|
|
846
|
-
};
|
|
847
|
-
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
|
848
|
-
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
849
|
-
for (let i = 0; i < vCount; i++) {
|
|
850
|
-
const o = i * 3;
|
|
851
|
-
const x = positions[o] ?? 0;
|
|
852
|
-
const y = positions[o + 1] ?? 0;
|
|
853
|
-
const z = positions[o + 2] ?? 0;
|
|
854
|
-
if (x < minX) minX = x;
|
|
855
|
-
if (y < minY) minY = y;
|
|
856
|
-
if (z < minZ) minZ = z;
|
|
857
|
-
if (x > maxX) maxX = x;
|
|
858
|
-
if (y > maxY) maxY = y;
|
|
859
|
-
if (z > maxZ) maxZ = z;
|
|
860
|
-
}
|
|
861
|
-
return {
|
|
862
|
-
min: [
|
|
863
|
-
minX,
|
|
864
|
-
minY,
|
|
865
|
-
minZ
|
|
866
|
-
],
|
|
867
|
-
max: [
|
|
868
|
-
maxX,
|
|
869
|
-
maxY,
|
|
870
|
-
maxZ
|
|
871
|
-
]
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
function buildGltfManifest(vCount, nCount, iCount, posBytes, nrmBytes, idxBytes, bufferLength, bounds) {
|
|
875
|
-
return {
|
|
876
|
-
asset: {
|
|
877
|
-
version: "2.0",
|
|
878
|
-
generator: "brepjs occt-wasm"
|
|
879
|
-
},
|
|
880
|
-
scene: 0,
|
|
881
|
-
scenes: [{ nodes: [0] }],
|
|
882
|
-
nodes: [{ mesh: 0 }],
|
|
883
|
-
meshes: [{ primitives: [{
|
|
884
|
-
attributes: {
|
|
885
|
-
POSITION: 0,
|
|
886
|
-
NORMAL: 1
|
|
887
|
-
},
|
|
888
|
-
indices: 2,
|
|
889
|
-
mode: 4
|
|
890
|
-
}] }],
|
|
891
|
-
buffers: [{ byteLength: bufferLength }],
|
|
892
|
-
bufferViews: [
|
|
893
|
-
{
|
|
894
|
-
buffer: 0,
|
|
895
|
-
byteOffset: 0,
|
|
896
|
-
byteLength: posBytes,
|
|
897
|
-
target: 34962
|
|
898
|
-
},
|
|
899
|
-
{
|
|
900
|
-
buffer: 0,
|
|
901
|
-
byteOffset: posBytes,
|
|
902
|
-
byteLength: nrmBytes,
|
|
903
|
-
target: 34962
|
|
904
|
-
},
|
|
905
|
-
{
|
|
906
|
-
buffer: 0,
|
|
907
|
-
byteOffset: posBytes + nrmBytes,
|
|
908
|
-
byteLength: idxBytes,
|
|
909
|
-
target: 34963
|
|
910
|
-
}
|
|
911
|
-
],
|
|
912
|
-
accessors: [
|
|
913
|
-
{
|
|
914
|
-
bufferView: 0,
|
|
915
|
-
componentType: 5126,
|
|
916
|
-
count: vCount,
|
|
917
|
-
type: "VEC3",
|
|
918
|
-
min: bounds.min,
|
|
919
|
-
max: bounds.max
|
|
920
|
-
},
|
|
921
|
-
{
|
|
922
|
-
bufferView: 1,
|
|
923
|
-
componentType: 5126,
|
|
924
|
-
count: nCount,
|
|
925
|
-
type: "VEC3"
|
|
926
|
-
},
|
|
927
|
-
{
|
|
928
|
-
bufferView: 2,
|
|
929
|
-
componentType: 5125,
|
|
930
|
-
count: iCount,
|
|
931
|
-
type: "SCALAR"
|
|
932
|
-
}
|
|
933
|
-
]
|
|
934
|
-
};
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* Wrap an OcctKernelWasm instance so that every method call converts
|
|
938
|
-
* C++ exceptions (WebAssembly.Exception) into readable JS Errors.
|
|
939
|
-
*/
|
|
940
|
-
function wrapKernelExceptions(kernel, mod) {
|
|
941
|
-
return new Proxy(kernel, { get(target, prop, receiver) {
|
|
942
|
-
const val = Reflect.get(target, prop, receiver);
|
|
943
|
-
if (typeof val !== "function") return val;
|
|
944
|
-
return function(...args) {
|
|
945
|
-
try {
|
|
946
|
-
return val.apply(target, args);
|
|
947
|
-
} catch (ex) {
|
|
948
|
-
const WasmException = WebAssembly.Exception;
|
|
949
|
-
if (WasmException && ex instanceof WasmException) try {
|
|
950
|
-
const [, msg] = mod.getExceptionMessage(ex);
|
|
951
|
-
throw new Error(msg, { cause: ex });
|
|
952
|
-
} catch (inner) {
|
|
953
|
-
if (inner instanceof Error && !(inner instanceof WasmException)) throw inner;
|
|
954
|
-
}
|
|
955
|
-
throw ex;
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
} });
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Resolve a callback-style radius/distance to a uniform number.
|
|
962
|
-
* occt-wasm only supports uniform fillet/chamfer per call.
|
|
963
|
-
*/
|
|
964
|
-
function resolveUniformRadius(edges, radius) {
|
|
965
|
-
if (typeof radius === "number") return radius;
|
|
966
|
-
if (Array.isArray(radius)) return radius[0];
|
|
967
|
-
if (edges.length === 0) throw new Error("occt-wasm: no edges provided");
|
|
968
|
-
const val = radius(edges[0]);
|
|
969
|
-
return typeof val === "number" ? val : val[0];
|
|
970
|
-
}
|
|
971
|
-
/** Rotate a shape from Z-axis to an arbitrary direction. */
|
|
972
|
-
function rotateZToDirection(k, shapeId, dir) {
|
|
973
|
-
const [dx, dy, dz] = dir;
|
|
974
|
-
const len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
975
|
-
if (len < 1e-10) return shapeId;
|
|
976
|
-
const nx = dx / len, ny = dy / len, nz = dz / len;
|
|
977
|
-
if (Math.abs(nz - 1) < 1e-10) return shapeId;
|
|
978
|
-
if (Math.abs(nz + 1) < 1e-10) return k.rotate(shapeId, 0, 0, 0, 1, 0, 0, Math.PI);
|
|
979
|
-
const ax = -ny, ay = nx;
|
|
980
|
-
const axLen = Math.sqrt(ax * ax + ay * ay);
|
|
981
|
-
if (axLen < 1e-10) return shapeId;
|
|
982
|
-
const angle = Math.acos(Math.max(-1, Math.min(1, nz)));
|
|
983
|
-
return k.rotate(shapeId, 0, 0, 0, ax / axLen, ay / axLen, 0, angle);
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* Collect 3D sample points from a shape for nearest-pair queries: every
|
|
987
|
-
* topological vertex, plus tessellation vertices when the shape carries
|
|
988
|
-
* surfaces. Used by distance() to approximate witness points.
|
|
989
|
-
*/
|
|
990
|
-
function collectDistanceSamples(k, mod, shapeId) {
|
|
991
|
-
const out = [];
|
|
992
|
-
const verts = k.getSubShapes(shapeId, "vertex");
|
|
993
|
-
try {
|
|
994
|
-
const n = verts.size();
|
|
995
|
-
for (let i = 0; i < n; i++) {
|
|
996
|
-
const p = k.vertexPosition(verts.get(i));
|
|
997
|
-
out.push([
|
|
998
|
-
p.get(0),
|
|
999
|
-
p.get(1),
|
|
1000
|
-
p.get(2)
|
|
1001
|
-
]);
|
|
1002
|
-
p.delete();
|
|
1003
|
-
}
|
|
1004
|
-
} finally {
|
|
1005
|
-
verts.delete();
|
|
1006
|
-
}
|
|
1007
|
-
const bb = k.getBoundingBox(shapeId, true);
|
|
1008
|
-
const diag = Math.sqrt((bb.xmax - bb.xmin) ** 2 + (bb.ymax - bb.ymin) ** 2 + (bb.zmax - bb.zmin) ** 2);
|
|
1009
|
-
const linDef = Math.max(diag * .01, 1e-4);
|
|
1010
|
-
let mesh;
|
|
1011
|
-
try {
|
|
1012
|
-
mesh = k.tessellate(shapeId, linDef, .5);
|
|
1013
|
-
} catch {
|
|
1014
|
-
return out;
|
|
1015
|
-
}
|
|
1016
|
-
try {
|
|
1017
|
-
const posCount = mesh.positionCount;
|
|
1018
|
-
if (posCount > 0) {
|
|
1019
|
-
const ptr = mesh.getPositionsPtr() >> 2;
|
|
1020
|
-
const heap = mod.HEAPF32;
|
|
1021
|
-
const MAX_MESH_SAMPLES = 256;
|
|
1022
|
-
const vertexCount = Math.floor(posCount / 3);
|
|
1023
|
-
const step = (vertexCount > MAX_MESH_SAMPLES ? Math.ceil(vertexCount / MAX_MESH_SAMPLES) : 1) * 3;
|
|
1024
|
-
for (let i = 0; i < posCount; i += step) out.push([
|
|
1025
|
-
heap[ptr + i] ?? 0,
|
|
1026
|
-
heap[ptr + i + 1] ?? 0,
|
|
1027
|
-
heap[ptr + i + 2] ?? 0
|
|
1028
|
-
]);
|
|
1029
|
-
}
|
|
1030
|
-
} finally {
|
|
1031
|
-
mesh.delete();
|
|
1032
|
-
}
|
|
1033
|
-
return out;
|
|
1034
|
-
}
|
|
1035
|
-
/** Read a 3D point on a surface via the WASM facade. */
|
|
1036
|
-
function pointAt(k, faceId, u, v) {
|
|
1037
|
-
const p = k.pointOnSurface(faceId, u, v);
|
|
1038
|
-
const r = [
|
|
1039
|
-
p.get(0),
|
|
1040
|
-
p.get(1),
|
|
1041
|
-
p.get(2)
|
|
1042
|
-
];
|
|
1043
|
-
p.delete();
|
|
1044
|
-
return r;
|
|
1045
|
-
}
|
|
1046
|
-
/**
|
|
1047
|
-
* Compute principal curvature directions at (u, v) via finite-difference
|
|
1048
|
-
* fundamental forms. The C++ facade exposes only k1 and k2 as scalars; this
|
|
1049
|
-
* helper recovers the corresponding tangent directions in 3D space.
|
|
1050
|
-
*
|
|
1051
|
-
* Step sizes are clamped so all sample points stay inside the parametric
|
|
1052
|
-
* domain, with a one-sided fallback near the boundary. For elementary
|
|
1053
|
-
* surfaces (plane, sphere) where curvature is direction-degenerate, returns
|
|
1054
|
-
* any orthonormal pair tangent to the surface.
|
|
1055
|
-
*/
|
|
1056
|
-
function computePrincipalDirections(k, faceId, u, v, maxK, minK) {
|
|
1057
|
-
const { Pu, Pv, Puu, Pvv, Puv } = surfaceDerivatives(k, faceId, u, v);
|
|
1058
|
-
const nx = Pu[1] * Pv[2] - Pu[2] * Pv[1];
|
|
1059
|
-
const ny = Pu[2] * Pv[0] - Pu[0] * Pv[2];
|
|
1060
|
-
const nz = Pu[0] * Pv[1] - Pu[1] * Pv[0];
|
|
1061
|
-
const nlen = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
1062
|
-
const E = Pu[0] * Pu[0] + Pu[1] * Pu[1] + Pu[2] * Pu[2];
|
|
1063
|
-
const F = Pu[0] * Pv[0] + Pu[1] * Pv[1] + Pu[2] * Pv[2];
|
|
1064
|
-
const G = Pv[0] * Pv[0] + Pv[1] * Pv[1] + Pv[2] * Pv[2];
|
|
1065
|
-
if (nlen < 1e-12 || E * G - F * F < 1e-24) return degenerateOrthoFrame(Pu, Pv);
|
|
1066
|
-
const e = (Puu[0] * nx + Puu[1] * ny + Puu[2] * nz) / nlen;
|
|
1067
|
-
const f = (Puv[0] * nx + Puv[1] * ny + Puv[2] * nz) / nlen;
|
|
1068
|
-
const g = (Pvv[0] * nx + Pvv[1] * ny + Pvv[2] * nz) / nlen;
|
|
1069
|
-
const det = E * G - F * F;
|
|
1070
|
-
const w11 = (e * G - f * F) / det;
|
|
1071
|
-
const w12 = (f * G - g * F) / det;
|
|
1072
|
-
const w21 = (f * E - e * F) / det;
|
|
1073
|
-
const w22 = (g * E - f * F) / det;
|
|
1074
|
-
if (Math.abs(maxK - minK) < 1e-9 * (Math.abs(maxK) + Math.abs(minK) + 1)) return degenerateOrthoFrame(Pu, Pv);
|
|
1075
|
-
const dirMax2D = eigenvector2x2(w11 - maxK, w12, w21, w22 - maxK);
|
|
1076
|
-
const dirMin2D = eigenvector2x2(w11 - minK, w12, w21, w22 - minK);
|
|
1077
|
-
return {
|
|
1078
|
-
maxDirection: liftAndNormalize(dirMax2D, Pu, Pv),
|
|
1079
|
-
minDirection: liftAndNormalize(dirMin2D, Pu, Pv)
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
/**
|
|
1083
|
-
* Sample a 9-point stencil around (u, v) and return central-difference
|
|
1084
|
-
* partial derivatives Pu, Pv, Puu, Pvv, Puv. Step size is 1e-3 of the
|
|
1085
|
-
* parametric range (clamped at 1e-6) — the sweet spot between truncation
|
|
1086
|
-
* error and float-eval noise. Near the boundary the stencil shifts inward
|
|
1087
|
-
* so all sample points stay in the domain.
|
|
1088
|
-
*/
|
|
1089
|
-
function surfaceDerivatives(k, faceId, u, v) {
|
|
1090
|
-
const bounds = k.uvBounds(faceId);
|
|
1091
|
-
const uMin = bounds.get(0);
|
|
1092
|
-
const uMax = bounds.get(1);
|
|
1093
|
-
const vMin = bounds.get(2);
|
|
1094
|
-
const vMax = bounds.get(3);
|
|
1095
|
-
bounds.delete();
|
|
1096
|
-
const hu = Math.max(Math.max(uMax - uMin, 1e-12) * .001, 1e-6);
|
|
1097
|
-
const hv = Math.max(Math.max(vMax - vMin, 1e-12) * .001, 1e-6);
|
|
1098
|
-
const uc = Math.min(Math.max(u, uMin + hu), uMax - hu);
|
|
1099
|
-
const vc = Math.min(Math.max(v, vMin + hv), vMax - hv);
|
|
1100
|
-
const P = pointAt(k, faceId, uc, vc);
|
|
1101
|
-
const Pup = pointAt(k, faceId, uc + hu, vc);
|
|
1102
|
-
const Pum = pointAt(k, faceId, uc - hu, vc);
|
|
1103
|
-
const Pvp = pointAt(k, faceId, uc, vc + hv);
|
|
1104
|
-
const Pvm = pointAt(k, faceId, uc, vc - hv);
|
|
1105
|
-
const Ppp = pointAt(k, faceId, uc + hu, vc + hv);
|
|
1106
|
-
const Ppm = pointAt(k, faceId, uc + hu, vc - hv);
|
|
1107
|
-
const Pmp = pointAt(k, faceId, uc - hu, vc + hv);
|
|
1108
|
-
const Pmm = pointAt(k, faceId, uc - hu, vc - hv);
|
|
1109
|
-
const huu = hu * hu;
|
|
1110
|
-
const hvv = hv * hv;
|
|
1111
|
-
const huv4 = 4 * hu * hv;
|
|
1112
|
-
return {
|
|
1113
|
-
Pu: [
|
|
1114
|
-
(Pup[0] - Pum[0]) / (2 * hu),
|
|
1115
|
-
(Pup[1] - Pum[1]) / (2 * hu),
|
|
1116
|
-
(Pup[2] - Pum[2]) / (2 * hu)
|
|
1117
|
-
],
|
|
1118
|
-
Pv: [
|
|
1119
|
-
(Pvp[0] - Pvm[0]) / (2 * hv),
|
|
1120
|
-
(Pvp[1] - Pvm[1]) / (2 * hv),
|
|
1121
|
-
(Pvp[2] - Pvm[2]) / (2 * hv)
|
|
1122
|
-
],
|
|
1123
|
-
Puu: [
|
|
1124
|
-
(Pup[0] - 2 * P[0] + Pum[0]) / huu,
|
|
1125
|
-
(Pup[1] - 2 * P[1] + Pum[1]) / huu,
|
|
1126
|
-
(Pup[2] - 2 * P[2] + Pum[2]) / huu
|
|
1127
|
-
],
|
|
1128
|
-
Pvv: [
|
|
1129
|
-
(Pvp[0] - 2 * P[0] + Pvm[0]) / hvv,
|
|
1130
|
-
(Pvp[1] - 2 * P[1] + Pvm[1]) / hvv,
|
|
1131
|
-
(Pvp[2] - 2 * P[2] + Pvm[2]) / hvv
|
|
1132
|
-
],
|
|
1133
|
-
Puv: [
|
|
1134
|
-
(Ppp[0] - Ppm[0] - Pmp[0] + Pmm[0]) / huv4,
|
|
1135
|
-
(Ppp[1] - Ppm[1] - Pmp[1] + Pmm[1]) / huv4,
|
|
1136
|
-
(Ppp[2] - Ppm[2] - Pmp[2] + Pmm[2]) / huv4
|
|
1137
|
-
]
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
/**
|
|
1141
|
-
* Return a non-zero eigenvector of the singular matrix [[a,b],[c,d]] (whose
|
|
1142
|
-
* eigenvalue is implicit — caller has already subtracted λ from the diagonal).
|
|
1143
|
-
* Picks the row with the larger magnitude for numerical stability.
|
|
1144
|
-
*/
|
|
1145
|
-
function eigenvector2x2(a, b, c, d) {
|
|
1146
|
-
if (Math.abs(a) + Math.abs(b) >= Math.abs(c) + Math.abs(d)) {
|
|
1147
|
-
if (Math.abs(a) + Math.abs(b) < 1e-12) return [1, 0];
|
|
1148
|
-
return [-b, a];
|
|
1149
|
-
}
|
|
1150
|
-
if (Math.abs(c) + Math.abs(d) < 1e-12) return [0, 1];
|
|
1151
|
-
return [-d, c];
|
|
1152
|
-
}
|
|
1153
|
-
/** Map a 2D tangent vector (a·Pu + b·Pv) to a unit 3D direction. */
|
|
1154
|
-
function liftAndNormalize(ab, Pu, Pv) {
|
|
1155
|
-
const x = ab[0] * Pu[0] + ab[1] * Pv[0];
|
|
1156
|
-
const y = ab[0] * Pu[1] + ab[1] * Pv[1];
|
|
1157
|
-
const z = ab[0] * Pu[2] + ab[1] * Pv[2];
|
|
1158
|
-
const len = Math.sqrt(x * x + y * y + z * z);
|
|
1159
|
-
if (len < 1e-12) return [
|
|
1160
|
-
1,
|
|
1161
|
-
0,
|
|
1162
|
-
0
|
|
1163
|
-
];
|
|
1164
|
-
return [
|
|
1165
|
-
x / len,
|
|
1166
|
-
y / len,
|
|
1167
|
-
z / len
|
|
1168
|
-
];
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
* Fallback when curvature is direction-degenerate: return an orthonormal
|
|
1172
|
-
* tangent frame derived from Pu and the Gram-Schmidt-corrected Pv.
|
|
1173
|
-
*/
|
|
1174
|
-
function degenerateOrthoFrame(Pu, Pv) {
|
|
1175
|
-
const uLen = Math.sqrt(Pu[0] * Pu[0] + Pu[1] * Pu[1] + Pu[2] * Pu[2]);
|
|
1176
|
-
if (uLen < 1e-12) return {
|
|
1177
|
-
maxDirection: [
|
|
1178
|
-
1,
|
|
1179
|
-
0,
|
|
1180
|
-
0
|
|
1181
|
-
],
|
|
1182
|
-
minDirection: [
|
|
1183
|
-
0,
|
|
1184
|
-
1,
|
|
1185
|
-
0
|
|
1186
|
-
]
|
|
1187
|
-
};
|
|
1188
|
-
const ux = Pu[0] / uLen, uy = Pu[1] / uLen, uz = Pu[2] / uLen;
|
|
1189
|
-
const dot = ux * Pv[0] + uy * Pv[1] + uz * Pv[2];
|
|
1190
|
-
const vx = Pv[0] - dot * ux;
|
|
1191
|
-
const vy = Pv[1] - dot * uy;
|
|
1192
|
-
const vz = Pv[2] - dot * uz;
|
|
1193
|
-
const vLen = Math.sqrt(vx * vx + vy * vy + vz * vz);
|
|
1194
|
-
if (vLen < 1e-12) {
|
|
1195
|
-
const ax = Math.abs(ux) < .9 ? [
|
|
1196
|
-
1,
|
|
1197
|
-
0,
|
|
1198
|
-
0
|
|
1199
|
-
] : [
|
|
1200
|
-
0,
|
|
1201
|
-
1,
|
|
1202
|
-
0
|
|
1203
|
-
];
|
|
1204
|
-
const ox = uy * ax[2] - uz * ax[1];
|
|
1205
|
-
const oy = uz * ax[0] - ux * ax[2];
|
|
1206
|
-
const oz = ux * ax[1] - uy * ax[0];
|
|
1207
|
-
const oLen = Math.sqrt(ox * ox + oy * oy + oz * oz) || 1;
|
|
1208
|
-
return {
|
|
1209
|
-
maxDirection: [
|
|
1210
|
-
ux,
|
|
1211
|
-
uy,
|
|
1212
|
-
uz
|
|
1213
|
-
],
|
|
1214
|
-
minDirection: [
|
|
1215
|
-
ox / oLen,
|
|
1216
|
-
oy / oLen,
|
|
1217
|
-
oz / oLen
|
|
1218
|
-
]
|
|
1219
|
-
};
|
|
1220
|
-
}
|
|
1221
|
-
return {
|
|
1222
|
-
maxDirection: [
|
|
1223
|
-
ux,
|
|
1224
|
-
uy,
|
|
1225
|
-
uz
|
|
1226
|
-
],
|
|
1227
|
-
minDirection: [
|
|
1228
|
-
vx / vLen,
|
|
1229
|
-
vy / vLen,
|
|
1230
|
-
vz / vLen
|
|
1231
|
-
]
|
|
1232
|
-
};
|
|
1233
|
-
}
|
|
1234
|
-
var OcctWasmAdapter = class {
|
|
1235
|
-
oc;
|
|
1236
|
-
kernelId = "occt-wasm";
|
|
1237
|
-
Module;
|
|
1238
|
-
k;
|
|
1239
|
-
constructor(module, kernel) {
|
|
1240
|
-
this.Module = module;
|
|
1241
|
-
this.k = wrapKernelExceptions(kernel, module);
|
|
1242
|
-
const k = this.k;
|
|
1243
|
-
const makeNull = () => handle("compound", k.makeNullShape());
|
|
1244
|
-
this.oc = Object.assign(Object.create(module), {
|
|
1245
|
-
TopoDS_Solid: function() {
|
|
1246
|
-
return makeNull();
|
|
1247
|
-
},
|
|
1248
|
-
TopoDS_Face: function() {
|
|
1249
|
-
return makeNull();
|
|
1250
|
-
},
|
|
1251
|
-
TopoDS_Shape: function() {
|
|
1252
|
-
return makeNull();
|
|
1253
|
-
},
|
|
1254
|
-
TopoDS_Wire: function() {
|
|
1255
|
-
return makeNull();
|
|
1256
|
-
},
|
|
1257
|
-
TopoDS_Edge: function() {
|
|
1258
|
-
return makeNull();
|
|
1259
|
-
},
|
|
1260
|
-
TopoDS_Vertex: function() {
|
|
1261
|
-
return makeNull();
|
|
1262
|
-
},
|
|
1263
|
-
TopoDS_Shell: function() {
|
|
1264
|
-
return makeNull();
|
|
1265
|
-
},
|
|
1266
|
-
TopoDS_Compound: function() {
|
|
1267
|
-
return makeNull();
|
|
1268
|
-
},
|
|
1269
|
-
gp_Pnt_3: function(x, y, z) {
|
|
1270
|
-
return handle("vertex", k.makeVertex(x, y, z));
|
|
1271
|
-
},
|
|
1272
|
-
BRepBuilderAPI_MakeEdge_3: function(p1, p2) {
|
|
1273
|
-
const v1 = p1;
|
|
1274
|
-
const v2 = p2;
|
|
1275
|
-
const pos1 = k.vertexPosition(v1.id);
|
|
1276
|
-
const pos2 = k.vertexPosition(v2.id);
|
|
1277
|
-
const edgeId = k.makeLineEdge(pos1.get(0), pos1.get(1), pos1.get(2), pos2.get(0), pos2.get(1), pos2.get(2));
|
|
1278
|
-
pos1.delete();
|
|
1279
|
-
pos2.delete();
|
|
1280
|
-
return {
|
|
1281
|
-
Edge: () => handle("edge", edgeId),
|
|
1282
|
-
delete() {}
|
|
1283
|
-
};
|
|
1284
|
-
}
|
|
1285
|
-
});
|
|
1286
|
-
}
|
|
1287
|
-
dispose(h) {
|
|
1288
|
-
if (isOcctWasmHandle(h)) this.k.release(h.id);
|
|
1289
|
-
else if (typeof h.delete === "function") h.delete();
|
|
1290
|
-
}
|
|
1291
|
-
executeBatch(_json) {
|
|
1292
|
-
notImplemented("executeBatch");
|
|
1293
|
-
}
|
|
1294
|
-
checkpoint() {
|
|
1295
|
-
notImplemented("checkpoint");
|
|
1296
|
-
}
|
|
1297
|
-
checkpointCount() {
|
|
1298
|
-
notImplemented("checkpointCount");
|
|
1299
|
-
}
|
|
1300
|
-
restoreCheckpoint(_cp) {
|
|
1301
|
-
notImplemented("restoreCheckpoint");
|
|
1302
|
-
}
|
|
1303
|
-
discardCheckpoint(_cp) {
|
|
1304
|
-
notImplemented("discardCheckpoint");
|
|
1305
|
-
}
|
|
1306
|
-
makeBox(width, height, depth) {
|
|
1307
|
-
return handle("solid", this.k.makeBox(width, height, depth));
|
|
1308
|
-
}
|
|
1309
|
-
makeCylinder(radius, height, center, direction) {
|
|
1310
|
-
let id = this.k.makeCylinder(radius, height);
|
|
1311
|
-
if (direction) id = rotateZToDirection(this.k, id, direction);
|
|
1312
|
-
if (center && (center[0] !== 0 || center[1] !== 0 || center[2] !== 0)) id = this.k.translate(id, center[0], center[1], center[2]);
|
|
1313
|
-
return handle("solid", id);
|
|
1314
|
-
}
|
|
1315
|
-
makeSphere(radius, center) {
|
|
1316
|
-
let id = this.k.makeSphere(radius);
|
|
1317
|
-
if (center && (center[0] !== 0 || center[1] !== 0 || center[2] !== 0)) id = this.k.translate(id, center[0], center[1], center[2]);
|
|
1318
|
-
return handle("solid", id);
|
|
1319
|
-
}
|
|
1320
|
-
makeCone(radius1, radius2, height, center, direction) {
|
|
1321
|
-
let id = this.k.makeCone(radius1, radius2, height);
|
|
1322
|
-
if (direction) id = rotateZToDirection(this.k, id, direction);
|
|
1323
|
-
if (center && (center[0] !== 0 || center[1] !== 0 || center[2] !== 0)) id = this.k.translate(id, center[0], center[1], center[2]);
|
|
1324
|
-
return handle("solid", id);
|
|
1325
|
-
}
|
|
1326
|
-
makeTorus(majorRadius, minorRadius, center, direction) {
|
|
1327
|
-
let id = this.k.makeTorus(majorRadius, minorRadius);
|
|
1328
|
-
if (direction) id = rotateZToDirection(this.k, id, direction);
|
|
1329
|
-
if (center && (center[0] !== 0 || center[1] !== 0 || center[2] !== 0)) id = this.k.translate(id, center[0], center[1], center[2]);
|
|
1330
|
-
return handle("solid", id);
|
|
1331
|
-
}
|
|
1332
|
-
makeEllipsoid(aLength, bLength, cLength) {
|
|
1333
|
-
return handle("solid", this.k.makeEllipsoid(aLength, bLength, cLength));
|
|
1334
|
-
}
|
|
1335
|
-
makeBoxFromCorners(p1, p2) {
|
|
1336
|
-
return handle("solid", this.k.makeBoxFromCorners(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]));
|
|
1337
|
-
}
|
|
1338
|
-
makeRectangle(width, height) {
|
|
1339
|
-
return handle("face", this.k.makeRectangle(width, height));
|
|
1340
|
-
}
|
|
1341
|
-
fuse(shape, tool, _options) {
|
|
1342
|
-
return wrapResult(this.k, this.k.fuse(unwrap(shape), unwrap(tool)));
|
|
1343
|
-
}
|
|
1344
|
-
cut(shape, tool, _options) {
|
|
1345
|
-
return wrapResult(this.k, this.k.cut(unwrap(shape), unwrap(tool)));
|
|
1346
|
-
}
|
|
1347
|
-
intersect(shape, tool, _options) {
|
|
1348
|
-
return wrapResult(this.k, this.k.intersect(unwrap(shape), unwrap(tool)));
|
|
1349
|
-
}
|
|
1350
|
-
section(shape, plane, _approximation) {
|
|
1351
|
-
return wrapResult(this.k, this.k.section(unwrap(shape), unwrap(plane)));
|
|
1352
|
-
}
|
|
1353
|
-
fuseAll(shapes, _options) {
|
|
1354
|
-
const vec = makeVecU32(this.Module, shapes.map(unwrap));
|
|
1355
|
-
try {
|
|
1356
|
-
return wrapResult(this.k, this.k.fuseAll(vec));
|
|
1357
|
-
} finally {
|
|
1358
|
-
vec.delete();
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
cutAll(shape, tools, _options) {
|
|
1362
|
-
const vec = makeVecU32(this.Module, tools.map(unwrap));
|
|
1363
|
-
try {
|
|
1364
|
-
return wrapResult(this.k, this.k.cutAll(unwrap(shape), vec));
|
|
1365
|
-
} finally {
|
|
1366
|
-
vec.delete();
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
split(shape, tools) {
|
|
1370
|
-
const vec = makeVecU32(this.Module, tools.map(unwrap));
|
|
1371
|
-
try {
|
|
1372
|
-
return wrapResult(this.k, this.k.split(unwrap(shape), vec));
|
|
1373
|
-
} finally {
|
|
1374
|
-
vec.delete();
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
checkBoolean(shape, tool, _op) {
|
|
1378
|
-
const issues = [];
|
|
1379
|
-
if (this.k.isNull(unwrap(shape))) issues.push({
|
|
1380
|
-
operand: "base",
|
|
1381
|
-
issue: "null-shape",
|
|
1382
|
-
message: "Base shape is null"
|
|
1383
|
-
});
|
|
1384
|
-
if (this.k.isNull(unwrap(tool))) issues.push({
|
|
1385
|
-
operand: "tool",
|
|
1386
|
-
issue: "null-shape",
|
|
1387
|
-
message: "Tool shape is null"
|
|
1388
|
-
});
|
|
1389
|
-
if (issues.length === 0 && !this.k.isValid(unwrap(shape))) issues.push({
|
|
1390
|
-
operand: "base",
|
|
1391
|
-
issue: "not-valid",
|
|
1392
|
-
message: "Base shape is not valid"
|
|
1393
|
-
});
|
|
1394
|
-
if (issues.length === 0 && !this.k.isValid(unwrap(tool))) issues.push({
|
|
1395
|
-
operand: "tool",
|
|
1396
|
-
issue: "not-valid",
|
|
1397
|
-
message: "Tool shape is not valid"
|
|
1398
|
-
});
|
|
1399
|
-
return {
|
|
1400
|
-
valid: issues.length === 0,
|
|
1401
|
-
issues
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
|
-
meshBoolean(_positionsA, _indicesA, _positionsB, _indicesB, _op, _tolerance) {
|
|
1405
|
-
throw new Error("occt-wasm: meshBoolean is not supported (use brepkit for mesh booleans)");
|
|
1406
|
-
}
|
|
1407
|
-
makeVertex(x, y, z) {
|
|
1408
|
-
return handle("vertex", this.k.makeVertex(x, y, z));
|
|
1409
|
-
}
|
|
1410
|
-
makeEdge(curve, _start, _end) {
|
|
1411
|
-
if (isOcctWasmHandle(curve)) notImplemented("makeEdge from curve handle");
|
|
1412
|
-
notImplemented("makeEdge");
|
|
1413
|
-
}
|
|
1414
|
-
makeWire(edges) {
|
|
1415
|
-
const vec = makeVecU32(this.Module, edges.map(unwrap));
|
|
1416
|
-
try {
|
|
1417
|
-
return handle("wire", this.k.makeWire(vec));
|
|
1418
|
-
} finally {
|
|
1419
|
-
vec.delete();
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
makeFace(wire, _planar) {
|
|
1423
|
-
return handle("face", this.k.makeFace(unwrap(wire)));
|
|
1424
|
-
}
|
|
1425
|
-
makeLineEdge(p1, p2) {
|
|
1426
|
-
return handle("edge", this.k.makeLineEdge(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]));
|
|
1427
|
-
}
|
|
1428
|
-
makeCircleEdge(center, normal, radius) {
|
|
1429
|
-
return handle("edge", this.k.makeCircleEdge(center[0], center[1], center[2], normal[0], normal[1], normal[2], radius));
|
|
1430
|
-
}
|
|
1431
|
-
makeCircleArc(center, normal, radius, startAngle, endAngle) {
|
|
1432
|
-
return handle("edge", this.k.makeCircleArc(center[0], center[1], center[2], normal[0], normal[1], normal[2], radius, startAngle, endAngle));
|
|
1433
|
-
}
|
|
1434
|
-
makeArcEdge(p1, p2, p3) {
|
|
1435
|
-
return handle("edge", this.k.makeArcEdge(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2], p3[0], p3[1], p3[2]));
|
|
1436
|
-
}
|
|
1437
|
-
makeEllipseEdge(center, normal, majorRadius, minorRadius, _xDir) {
|
|
1438
|
-
return handle("edge", this.k.makeEllipseEdge(center[0], center[1], center[2], normal[0], normal[1], normal[2], majorRadius, minorRadius));
|
|
1439
|
-
}
|
|
1440
|
-
makeEllipseArc(center, normal, majorRadius, minorRadius, startAngle, endAngle, _xDir) {
|
|
1441
|
-
return handle("edge", this.k.makeEllipseArc(center[0], center[1], center[2], normal[0], normal[1], normal[2], majorRadius, minorRadius, startAngle, endAngle));
|
|
1442
|
-
}
|
|
1443
|
-
makeBezierEdge(points) {
|
|
1444
|
-
const flat = [];
|
|
1445
|
-
for (const p of points) flat.push(p[0], p[1], p[2]);
|
|
1446
|
-
const vec = makeVecDouble(this.Module, flat);
|
|
1447
|
-
try {
|
|
1448
|
-
return handle("edge", this.k.makeBezierEdge(vec));
|
|
1449
|
-
} finally {
|
|
1450
|
-
vec.delete();
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
makeTangentArc(startPoint, startTangent, endPoint) {
|
|
1454
|
-
const [x1, y1, z1] = startPoint;
|
|
1455
|
-
const [tx, ty, tz] = startTangent;
|
|
1456
|
-
const [x2, y2, z2] = endPoint;
|
|
1457
|
-
return handle("edge", this.k.makeTangentArc(x1, y1, z1, tx, ty, tz, x2, y2, z2));
|
|
1458
|
-
}
|
|
1459
|
-
makeHelixWire(pitch, height, radius, center, direction, _leftHanded) {
|
|
1460
|
-
const px = center ? center[0] : 0;
|
|
1461
|
-
const py = center ? center[1] : 0;
|
|
1462
|
-
const pz = center ? center[2] : 0;
|
|
1463
|
-
const dx = direction ? direction[0] : 0;
|
|
1464
|
-
const dy = direction ? direction[1] : 0;
|
|
1465
|
-
const dz = direction ? direction[2] : 1;
|
|
1466
|
-
return handle("wire", this.k.makeHelixWire(px, py, pz, dx, dy, dz, pitch, height, radius));
|
|
1467
|
-
}
|
|
1468
|
-
makeWireFromMixed(items) {
|
|
1469
|
-
return this.makeWire(items);
|
|
1470
|
-
}
|
|
1471
|
-
makeCompound(shapes) {
|
|
1472
|
-
const vec = makeVecU32(this.Module, shapes.map(unwrap));
|
|
1473
|
-
try {
|
|
1474
|
-
return handle("compound", this.k.makeCompound(vec));
|
|
1475
|
-
} finally {
|
|
1476
|
-
vec.delete();
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
solidFromShell(shell) {
|
|
1480
|
-
return handle("solid", this.k.solidFromShell(unwrap(shell)));
|
|
1481
|
-
}
|
|
1482
|
-
hull(_shapes, _tolerance) {
|
|
1483
|
-
notImplemented("hull");
|
|
1484
|
-
}
|
|
1485
|
-
hullFromPoints(points, tolerance) {
|
|
1486
|
-
if (points.length < 4) throw new Error("hullFromPoints: need at least 4 points");
|
|
1487
|
-
const faces = computeConvexHullFaces(points);
|
|
1488
|
-
return this.buildSolidFromFaces(points, faces, tolerance);
|
|
1489
|
-
}
|
|
1490
|
-
buildSolidFromFaces(points, faces, tolerance) {
|
|
1491
|
-
const faceIds = [];
|
|
1492
|
-
for (const [i0, i1, i2] of faces) {
|
|
1493
|
-
const p0 = points[i0];
|
|
1494
|
-
const p1 = points[i1];
|
|
1495
|
-
const p2 = points[i2];
|
|
1496
|
-
if (!p0 || !p1 || !p2) continue;
|
|
1497
|
-
faceIds.push(this.k.buildTriFace(p0.x, p0.y, p0.z, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z));
|
|
1498
|
-
}
|
|
1499
|
-
const vec = makeVecU32(this.Module, faceIds);
|
|
1500
|
-
try {
|
|
1501
|
-
let sewn = this.k.sewAndSolidify(vec, tolerance);
|
|
1502
|
-
sewn = this.k.fixFaceOrientations(sewn);
|
|
1503
|
-
return wrapResult(this.k, sewn);
|
|
1504
|
-
} finally {
|
|
1505
|
-
vec.delete();
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
makeNonPlanarFace(wire) {
|
|
1509
|
-
return handle("face", this.k.makeNonPlanarFace(unwrap(wire)));
|
|
1510
|
-
}
|
|
1511
|
-
addHolesInFace(face, holeWires) {
|
|
1512
|
-
const vec = makeVecU32(this.Module, holeWires.map(unwrap));
|
|
1513
|
-
try {
|
|
1514
|
-
return handle("face", this.k.addHolesInFace(unwrap(face), vec));
|
|
1515
|
-
} finally {
|
|
1516
|
-
vec.delete();
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
removeHolesFromFace(face) {
|
|
1520
|
-
const allWires = this.k.getSubShapes(unwrap(face), "wire");
|
|
1521
|
-
const holeCount = allWires.size() - 1;
|
|
1522
|
-
allWires.delete();
|
|
1523
|
-
const indices = [];
|
|
1524
|
-
for (let i = 0; i < holeCount; i++) indices.push(i);
|
|
1525
|
-
const vec = makeVecInt(this.Module, indices);
|
|
1526
|
-
try {
|
|
1527
|
-
return handle("face", this.k.removeHolesFromFace(unwrap(face), vec));
|
|
1528
|
-
} finally {
|
|
1529
|
-
vec.delete();
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
makeFaceOnSurface(surface, wire) {
|
|
1533
|
-
const faceId = unwrap(surface);
|
|
1534
|
-
return handle("face", this.k.makeFaceOnSurface(faceId, unwrap(wire)));
|
|
1535
|
-
}
|
|
1536
|
-
bsplineSurface(points, rows, cols) {
|
|
1537
|
-
const vec = new this.Module.VectorDouble();
|
|
1538
|
-
for (const [x, y, z] of points) {
|
|
1539
|
-
vec.push_back(x);
|
|
1540
|
-
vec.push_back(y);
|
|
1541
|
-
vec.push_back(z);
|
|
1542
|
-
}
|
|
1543
|
-
try {
|
|
1544
|
-
return handle("face", this.k.bsplineSurface(vec, rows, cols));
|
|
1545
|
-
} finally {
|
|
1546
|
-
vec.delete();
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
triangulatedSurface(points, rows, cols) {
|
|
1550
|
-
const faceIds = [];
|
|
1551
|
-
for (let r = 0; r < rows - 1; r++) for (let c = 0; c < cols - 1; c++) {
|
|
1552
|
-
const i00 = r * cols + c;
|
|
1553
|
-
const i10 = (r + 1) * cols + c;
|
|
1554
|
-
const i01 = r * cols + (c + 1);
|
|
1555
|
-
const i11 = (r + 1) * cols + (c + 1);
|
|
1556
|
-
const p00 = points[i00];
|
|
1557
|
-
const p10 = points[i10];
|
|
1558
|
-
const p01 = points[i01];
|
|
1559
|
-
const p11 = points[i11];
|
|
1560
|
-
if (p00 && p10 && p01) faceIds.push(this.k.buildTriFace(p00[0], p00[1], p00[2], p10[0], p10[1], p10[2], p01[0], p01[1], p01[2]));
|
|
1561
|
-
if (p10 && p11 && p01) faceIds.push(this.k.buildTriFace(p10[0], p10[1], p10[2], p11[0], p11[1], p11[2], p01[0], p01[1], p01[2]));
|
|
1562
|
-
}
|
|
1563
|
-
const vec = makeVecU32(this.Module, faceIds);
|
|
1564
|
-
try {
|
|
1565
|
-
return wrapResult(this.k, this.k.sewAndSolidify(vec, .001));
|
|
1566
|
-
} finally {
|
|
1567
|
-
vec.delete();
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
buildTriFace(a, b, c) {
|
|
1571
|
-
const id = this.k.buildTriFace(a[0], a[1], a[2], b[0], b[1], b[2], c[0], c[1], c[2]);
|
|
1572
|
-
if (id === 0) return null;
|
|
1573
|
-
return handle("face", id);
|
|
1574
|
-
}
|
|
1575
|
-
sewAndSolidify(faces, tolerance) {
|
|
1576
|
-
const vec = makeVecU32(this.Module, faces.map(unwrap));
|
|
1577
|
-
try {
|
|
1578
|
-
let sewn = this.k.sewAndSolidify(vec, tolerance);
|
|
1579
|
-
sewn = this.k.fixFaceOrientations(sewn);
|
|
1580
|
-
return handle("solid", sewn);
|
|
1581
|
-
} finally {
|
|
1582
|
-
vec.delete();
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
createPoint3d(_x, _y, _z) {
|
|
1586
|
-
return {
|
|
1587
|
-
x: _x,
|
|
1588
|
-
y: _y,
|
|
1589
|
-
z: _z,
|
|
1590
|
-
__type: "point3d",
|
|
1591
|
-
delete: noop
|
|
1592
|
-
};
|
|
1593
|
-
}
|
|
1594
|
-
createDirection3d(x, y, z) {
|
|
1595
|
-
return {
|
|
1596
|
-
x,
|
|
1597
|
-
y,
|
|
1598
|
-
z,
|
|
1599
|
-
__type: "direction3d",
|
|
1600
|
-
delete: noop
|
|
1601
|
-
};
|
|
1602
|
-
}
|
|
1603
|
-
createVector3d(x, y, z) {
|
|
1604
|
-
return {
|
|
1605
|
-
x,
|
|
1606
|
-
y,
|
|
1607
|
-
z,
|
|
1608
|
-
__type: "vector3d",
|
|
1609
|
-
delete: noop
|
|
1610
|
-
};
|
|
1611
|
-
}
|
|
1612
|
-
createAxis1(cx, cy, cz, dx, dy, dz) {
|
|
1613
|
-
return {
|
|
1614
|
-
origin: {
|
|
1615
|
-
x: cx,
|
|
1616
|
-
y: cy,
|
|
1617
|
-
z: cz
|
|
1618
|
-
},
|
|
1619
|
-
direction: {
|
|
1620
|
-
x: dx,
|
|
1621
|
-
y: dy,
|
|
1622
|
-
z: dz
|
|
1623
|
-
},
|
|
1624
|
-
__type: "axis1",
|
|
1625
|
-
delete: noop
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
|
-
createAxis2(ox, oy, oz, zx, zy, zz, xx, xy, xz) {
|
|
1629
|
-
return {
|
|
1630
|
-
origin: {
|
|
1631
|
-
x: ox,
|
|
1632
|
-
y: oy,
|
|
1633
|
-
z: oz
|
|
1634
|
-
},
|
|
1635
|
-
zDir: {
|
|
1636
|
-
x: zx,
|
|
1637
|
-
y: zy,
|
|
1638
|
-
z: zz
|
|
1639
|
-
},
|
|
1640
|
-
xDir: xx !== void 0 ? {
|
|
1641
|
-
x: xx,
|
|
1642
|
-
y: xy,
|
|
1643
|
-
z: xz
|
|
1644
|
-
} : void 0,
|
|
1645
|
-
__type: "axis2",
|
|
1646
|
-
delete: noop
|
|
1647
|
-
};
|
|
1648
|
-
}
|
|
1649
|
-
createAxis3(ox, oy, oz, zx, zy, zz, xx, xy, xz) {
|
|
1650
|
-
return {
|
|
1651
|
-
origin: {
|
|
1652
|
-
x: ox,
|
|
1653
|
-
y: oy,
|
|
1654
|
-
z: oz
|
|
1655
|
-
},
|
|
1656
|
-
zDir: {
|
|
1657
|
-
x: zx,
|
|
1658
|
-
y: zy,
|
|
1659
|
-
z: zz
|
|
1660
|
-
},
|
|
1661
|
-
xDir: xx !== void 0 ? {
|
|
1662
|
-
x: xx,
|
|
1663
|
-
y: xy,
|
|
1664
|
-
z: xz
|
|
1665
|
-
} : void 0,
|
|
1666
|
-
__type: "axis3",
|
|
1667
|
-
delete: noop
|
|
1668
|
-
};
|
|
1669
|
-
}
|
|
1670
|
-
extrude(face, direction, length) {
|
|
1671
|
-
const dx = direction[0] * length;
|
|
1672
|
-
const dy = direction[1] * length;
|
|
1673
|
-
const dz = direction[2] * length;
|
|
1674
|
-
return wrapResult(this.k, this.k.extrude(unwrap(face), dx, dy, dz));
|
|
1675
|
-
}
|
|
1676
|
-
revolve(shape, axis, angle) {
|
|
1677
|
-
const o = axis.origin;
|
|
1678
|
-
const d = axis.direction;
|
|
1679
|
-
return wrapResult(this.k, this.k.revolve(unwrap(shape), o.x, o.y, o.z, d.x, d.y, d.z, angle));
|
|
1680
|
-
}
|
|
1681
|
-
loft(wires, ruled, _startShape, _endShape) {
|
|
1682
|
-
const vec = makeVecU32(this.Module, wires.map(unwrap));
|
|
1683
|
-
try {
|
|
1684
|
-
return wrapResult(this.k, this.k.loft(vec, true, ruled ?? false));
|
|
1685
|
-
} finally {
|
|
1686
|
-
vec.delete();
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
sweep(wire, spine, options) {
|
|
1690
|
-
const mode = options?.transitionMode ?? 0;
|
|
1691
|
-
return wrapResult(this.k, this.k.sweep(unwrap(wire), unwrap(spine), mode));
|
|
1692
|
-
}
|
|
1693
|
-
simplePipe(profile, spine) {
|
|
1694
|
-
return wrapResult(this.k, this.k.simplePipe(unwrap(profile), unwrap(spine)));
|
|
1695
|
-
}
|
|
1696
|
-
helicalSweep(_profile, _axisOrigin, _axisDirection, _radius, _pitch, _turns) {
|
|
1697
|
-
throw new Error("helicalSweep on occt-wasm requires profile positioning+orientation logic not yet implemented; brepkit has a native implementation");
|
|
1698
|
-
}
|
|
1699
|
-
sweepWithOptions(_profile, _pathEdge, _contactMode, _scaleValues, _segments) {
|
|
1700
|
-
notImplemented("sweepWithOptions");
|
|
1701
|
-
}
|
|
1702
|
-
sweepPipeShell(profile, spine, options) {
|
|
1703
|
-
const freenet = options?.frenet ?? false;
|
|
1704
|
-
const smooth = options?.transitionMode === "round";
|
|
1705
|
-
const shellMode = options?.shellMode ?? false;
|
|
1706
|
-
const result = wrapResult(this.k, this.k.sweepPipeShell(unwrap(profile), unwrap(spine), freenet, smooth));
|
|
1707
|
-
if (shellMode) {
|
|
1708
|
-
const edges = this.k.getSubShapes(unwrap(result), "wire");
|
|
1709
|
-
try {
|
|
1710
|
-
return {
|
|
1711
|
-
shape: result,
|
|
1712
|
-
firstShape: edges.size() > 0 ? wrapResult(this.k, edges.get(0)) : result,
|
|
1713
|
-
lastShape: edges.size() > 1 ? wrapResult(this.k, edges.get(edges.size() - 1)) : result
|
|
1714
|
-
};
|
|
1715
|
-
} finally {
|
|
1716
|
-
edges.delete();
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
return result;
|
|
1720
|
-
}
|
|
1721
|
-
loftAdvanced(wires, options) {
|
|
1722
|
-
const isSolid = options?.solid ?? true;
|
|
1723
|
-
const ruled = options?.ruled ?? false;
|
|
1724
|
-
const startV = options?.startVertex ? unwrap(options.startVertex) : 0;
|
|
1725
|
-
const endV = options?.endVertex ? unwrap(options.endVertex) : 0;
|
|
1726
|
-
const vec = makeVecU32(this.Module, wires.map(unwrap));
|
|
1727
|
-
try {
|
|
1728
|
-
if (startV || endV) return wrapResult(this.k, this.k.loftWithVertices(vec, isSolid, ruled, startV, endV));
|
|
1729
|
-
return wrapResult(this.k, this.k.loft(vec, isSolid, ruled));
|
|
1730
|
-
} finally {
|
|
1731
|
-
vec.delete();
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
buildExtrusionLaw(profile, length, endFactor) {
|
|
1735
|
-
const law = {
|
|
1736
|
-
__occtWasmLaw: true,
|
|
1737
|
-
profile,
|
|
1738
|
-
length,
|
|
1739
|
-
endFactor,
|
|
1740
|
-
Trim(first, last, _tol) {
|
|
1741
|
-
return {
|
|
1742
|
-
...law,
|
|
1743
|
-
trimFirst: first,
|
|
1744
|
-
trimLast: last
|
|
1745
|
-
};
|
|
1746
|
-
},
|
|
1747
|
-
delete() {}
|
|
1748
|
-
};
|
|
1749
|
-
return law;
|
|
1750
|
-
}
|
|
1751
|
-
revolveVec(shape, center, direction, angle) {
|
|
1752
|
-
return wrapResult(this.k, this.k.revolveVec(unwrap(shape), center[0], center[1], center[2], direction[0], direction[1], direction[2], angle));
|
|
1753
|
-
}
|
|
1754
|
-
draftPrism(shape, _face, _baseFace, height, angleDeg, _fuse) {
|
|
1755
|
-
const h = height ?? 10;
|
|
1756
|
-
return wrapResult(this.k, this.k.draftPrism(unwrap(shape), 0, 0, h, angleDeg));
|
|
1757
|
-
}
|
|
1758
|
-
fillet(shape, edges, radius) {
|
|
1759
|
-
const r = resolveUniformRadius(edges, radius);
|
|
1760
|
-
const vec = makeVecU32(this.Module, edges.map(unwrap));
|
|
1761
|
-
try {
|
|
1762
|
-
return wrapResult(this.k, this.k.fillet(unwrap(shape), vec, r));
|
|
1763
|
-
} finally {
|
|
1764
|
-
vec.delete();
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
chamfer(shape, edges, distance) {
|
|
1768
|
-
const d = resolveUniformRadius(edges, distance);
|
|
1769
|
-
const vec = makeVecU32(this.Module, edges.map(unwrap));
|
|
1770
|
-
try {
|
|
1771
|
-
return wrapResult(this.k, this.k.chamfer(unwrap(shape), vec, d));
|
|
1772
|
-
} finally {
|
|
1773
|
-
vec.delete();
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
chamferDistAngle(shape, edges, distance, angleDeg) {
|
|
1777
|
-
const vec = makeVecU32(this.Module, edges.map(unwrap));
|
|
1778
|
-
try {
|
|
1779
|
-
return wrapResult(this.k, this.k.chamferDistAngle(unwrap(shape), vec, distance, angleDeg));
|
|
1780
|
-
} finally {
|
|
1781
|
-
vec.delete();
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
shell(shape, faces, thickness, tolerance) {
|
|
1785
|
-
const vec = makeVecU32(this.Module, faces.map(unwrap));
|
|
1786
|
-
try {
|
|
1787
|
-
return wrapResult(this.k, this.k.shell(unwrap(shape), vec, thickness, tolerance ?? .001));
|
|
1788
|
-
} finally {
|
|
1789
|
-
vec.delete();
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
thicken(shape, thickness) {
|
|
1793
|
-
return wrapResult(this.k, this.k.thicken(unwrap(shape), thickness, .001));
|
|
1794
|
-
}
|
|
1795
|
-
offset(shape, distance, tolerance) {
|
|
1796
|
-
return wrapResult(this.k, this.k.offset(unwrap(shape), distance, tolerance ?? 1e-6));
|
|
1797
|
-
}
|
|
1798
|
-
filletVariable(shape, spec) {
|
|
1799
|
-
const parsed = JSON.parse(spec);
|
|
1800
|
-
if (parsed.edgeId !== void 0 && parsed.startRadius !== void 0 && parsed.endRadius !== void 0) return wrapResult(this.k, this.k.filletVariable(unwrap(shape), parsed.edgeId, parsed.startRadius, parsed.endRadius));
|
|
1801
|
-
notImplemented("filletVariable (complex spec)");
|
|
1802
|
-
}
|
|
1803
|
-
draft(shape, faces, pullDirection, _neutralPlane, angleDeg) {
|
|
1804
|
-
let currentId = unwrap(shape);
|
|
1805
|
-
for (const face of faces) {
|
|
1806
|
-
const angleRad = (typeof angleDeg === "function" ? angleDeg(face) : angleDeg) * Math.PI / 180;
|
|
1807
|
-
currentId = this.k.draft(currentId, unwrap(face), angleRad, pullDirection[0], pullDirection[1], pullDirection[2]);
|
|
1808
|
-
}
|
|
1809
|
-
return wrapResult(this.k, currentId);
|
|
1810
|
-
}
|
|
1811
|
-
defeature(shape, faces) {
|
|
1812
|
-
const vec = makeVecU32(this.Module, faces.map(unwrap));
|
|
1813
|
-
try {
|
|
1814
|
-
return wrapResult(this.k, this.k.defeature(unwrap(shape), vec, .001));
|
|
1815
|
-
} finally {
|
|
1816
|
-
vec.delete();
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
offsetWire2D(wire, offset, joinType) {
|
|
1820
|
-
let jt = 0;
|
|
1821
|
-
if (joinType === "intersection" || joinType === 1) jt = 1;
|
|
1822
|
-
else if (joinType === "tangent" || joinType === 2) jt = 2;
|
|
1823
|
-
else if (typeof joinType === "number") jt = joinType;
|
|
1824
|
-
return wrapResult(this.k, this.k.offsetWire2D(unwrap(wire), offset, jt));
|
|
1825
|
-
}
|
|
1826
|
-
simplify(shape) {
|
|
1827
|
-
return wrapResult(this.k, this.k.simplify(unwrap(shape)));
|
|
1828
|
-
}
|
|
1829
|
-
reverseShape(shape) {
|
|
1830
|
-
return wrapResult(this.k, this.k.reverseShape(unwrap(shape)));
|
|
1831
|
-
}
|
|
1832
|
-
composeTransform(ops) {
|
|
1833
|
-
let matrix = [
|
|
1834
|
-
1,
|
|
1835
|
-
0,
|
|
1836
|
-
0,
|
|
1837
|
-
0,
|
|
1838
|
-
0,
|
|
1839
|
-
1,
|
|
1840
|
-
0,
|
|
1841
|
-
0,
|
|
1842
|
-
0,
|
|
1843
|
-
0,
|
|
1844
|
-
1,
|
|
1845
|
-
0,
|
|
1846
|
-
0,
|
|
1847
|
-
0,
|
|
1848
|
-
0,
|
|
1849
|
-
1
|
|
1850
|
-
];
|
|
1851
|
-
for (const op of ops) if (op.type === "translate") matrix = multiplyMatrices4x4([
|
|
1852
|
-
1,
|
|
1853
|
-
0,
|
|
1854
|
-
0,
|
|
1855
|
-
op.x,
|
|
1856
|
-
0,
|
|
1857
|
-
1,
|
|
1858
|
-
0,
|
|
1859
|
-
op.y,
|
|
1860
|
-
0,
|
|
1861
|
-
0,
|
|
1862
|
-
1,
|
|
1863
|
-
op.z,
|
|
1864
|
-
0,
|
|
1865
|
-
0,
|
|
1866
|
-
0,
|
|
1867
|
-
1
|
|
1868
|
-
], matrix);
|
|
1869
|
-
else {
|
|
1870
|
-
const ax = op.axis ?? [
|
|
1871
|
-
0,
|
|
1872
|
-
0,
|
|
1873
|
-
1
|
|
1874
|
-
];
|
|
1875
|
-
const cn = op.center ?? [
|
|
1876
|
-
0,
|
|
1877
|
-
0,
|
|
1878
|
-
0
|
|
1879
|
-
];
|
|
1880
|
-
const rad = op.angle * Math.PI / 180;
|
|
1881
|
-
const c = Math.cos(rad);
|
|
1882
|
-
const s = Math.sin(rad);
|
|
1883
|
-
const t = 1 - c;
|
|
1884
|
-
const len = Math.sqrt(ax[0] ** 2 + ax[1] ** 2 + ax[2] ** 2);
|
|
1885
|
-
const [ux, uy, uz] = [
|
|
1886
|
-
ax[0] / len,
|
|
1887
|
-
ax[1] / len,
|
|
1888
|
-
ax[2] / len
|
|
1889
|
-
];
|
|
1890
|
-
const r00 = t * ux * ux + c;
|
|
1891
|
-
const r01 = t * ux * uy - s * uz;
|
|
1892
|
-
const r02 = t * ux * uz + s * uy;
|
|
1893
|
-
const r10 = t * uy * ux + s * uz;
|
|
1894
|
-
const r11 = t * uy * uy + c;
|
|
1895
|
-
const r12 = t * uy * uz - s * ux;
|
|
1896
|
-
const r20 = t * uz * ux - s * uy;
|
|
1897
|
-
const r21 = t * uz * uy + s * ux;
|
|
1898
|
-
const r22 = t * uz * uz + c;
|
|
1899
|
-
matrix = multiplyMatrices4x4([
|
|
1900
|
-
r00,
|
|
1901
|
-
r01,
|
|
1902
|
-
r02,
|
|
1903
|
-
cn[0] - (r00 * cn[0] + r01 * cn[1] + r02 * cn[2]),
|
|
1904
|
-
r10,
|
|
1905
|
-
r11,
|
|
1906
|
-
r12,
|
|
1907
|
-
cn[1] - (r10 * cn[0] + r11 * cn[1] + r12 * cn[2]),
|
|
1908
|
-
r20,
|
|
1909
|
-
r21,
|
|
1910
|
-
r22,
|
|
1911
|
-
cn[2] - (r20 * cn[0] + r21 * cn[1] + r22 * cn[2]),
|
|
1912
|
-
0,
|
|
1913
|
-
0,
|
|
1914
|
-
0,
|
|
1915
|
-
1
|
|
1916
|
-
], matrix);
|
|
1917
|
-
}
|
|
1918
|
-
return {
|
|
1919
|
-
handle: {
|
|
1920
|
-
__type: "transform_matrix",
|
|
1921
|
-
matrix,
|
|
1922
|
-
delete: noop
|
|
1923
|
-
},
|
|
1924
|
-
dispose: noop
|
|
1925
|
-
};
|
|
1926
|
-
}
|
|
1927
|
-
transform(shape, trsf) {
|
|
1928
|
-
const t = trsf;
|
|
1929
|
-
let matrix;
|
|
1930
|
-
if (Array.isArray(t)) matrix = t;
|
|
1931
|
-
else if (typeof t === "object") {
|
|
1932
|
-
if (Array.isArray(t["matrix"])) {
|
|
1933
|
-
matrix = t["matrix"];
|
|
1934
|
-
if (matrix.length === 16) matrix = matrix.slice(0, 12);
|
|
1935
|
-
} else if (Array.isArray(t["elements"])) matrix = t["elements"];
|
|
1936
|
-
}
|
|
1937
|
-
if (matrix) {
|
|
1938
|
-
if (matrix.length === 16) matrix = matrix.slice(0, 12);
|
|
1939
|
-
if (matrix.length >= 12) {
|
|
1940
|
-
const vec = makeVecDouble(this.Module, matrix);
|
|
1941
|
-
try {
|
|
1942
|
-
return wrapResult(this.k, this.k.transform(unwrap(shape), vec));
|
|
1943
|
-
} finally {
|
|
1944
|
-
vec.delete();
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
return handle(this.k.getShapeType(unwrap(shape)), this.k.copy(unwrap(shape)));
|
|
1949
|
-
}
|
|
1950
|
-
translate(shape, x, y, z) {
|
|
1951
|
-
return wrapResult(this.k, this.k.translate(unwrap(shape), x, y, z));
|
|
1952
|
-
}
|
|
1953
|
-
rotate(shape, angle, axis, center) {
|
|
1954
|
-
const ax = axis ?? [
|
|
1955
|
-
0,
|
|
1956
|
-
0,
|
|
1957
|
-
1
|
|
1958
|
-
];
|
|
1959
|
-
const cn = center ?? [
|
|
1960
|
-
0,
|
|
1961
|
-
0,
|
|
1962
|
-
0
|
|
1963
|
-
];
|
|
1964
|
-
return wrapResult(this.k, this.k.rotate(unwrap(shape), cn[0], cn[1], cn[2], ax[0], ax[1], ax[2], angle));
|
|
1965
|
-
}
|
|
1966
|
-
mirror(shape, origin, normal) {
|
|
1967
|
-
return wrapResult(this.k, this.k.mirror(unwrap(shape), origin[0], origin[1], origin[2], normal[0], normal[1], normal[2]));
|
|
1968
|
-
}
|
|
1969
|
-
scale(shape, center, factor) {
|
|
1970
|
-
return wrapResult(this.k, this.k.scale(unwrap(shape), center[0], center[1], center[2], factor));
|
|
1971
|
-
}
|
|
1972
|
-
generalTransform(shape, linear, translation, _isOrthogonal) {
|
|
1973
|
-
const matrix = [
|
|
1974
|
-
linear[0],
|
|
1975
|
-
linear[1],
|
|
1976
|
-
linear[2],
|
|
1977
|
-
translation[0],
|
|
1978
|
-
linear[3],
|
|
1979
|
-
linear[4],
|
|
1980
|
-
linear[5],
|
|
1981
|
-
translation[1],
|
|
1982
|
-
linear[6],
|
|
1983
|
-
linear[7],
|
|
1984
|
-
linear[8],
|
|
1985
|
-
translation[2]
|
|
1986
|
-
];
|
|
1987
|
-
const vec = makeVecDouble(this.Module, matrix);
|
|
1988
|
-
try {
|
|
1989
|
-
return wrapResult(this.k, this.k.generalTransform(unwrap(shape), vec));
|
|
1990
|
-
} finally {
|
|
1991
|
-
vec.delete();
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
generalTransformNonOrthogonal(shape, linear, translation) {
|
|
1995
|
-
return this.generalTransform(shape, linear, translation, false);
|
|
1996
|
-
}
|
|
1997
|
-
positionOnCurve(shape, spine, param) {
|
|
1998
|
-
const ptVec = this.k.curvePointAtParam(unwrap(spine), param);
|
|
1999
|
-
const tgVec = this.k.curveTangent(unwrap(spine), param);
|
|
2000
|
-
const px = ptVec.get(0), py = ptVec.get(1), pz = ptVec.get(2);
|
|
2001
|
-
const tx = tgVec.get(0), ty = tgVec.get(1), tz = tgVec.get(2);
|
|
2002
|
-
ptVec.delete();
|
|
2003
|
-
tgVec.delete();
|
|
2004
|
-
let ux, uy, uz;
|
|
2005
|
-
if (Math.abs(tx) < .9) {
|
|
2006
|
-
ux = 0;
|
|
2007
|
-
uy = tz;
|
|
2008
|
-
uz = -ty;
|
|
2009
|
-
} else {
|
|
2010
|
-
ux = -tz;
|
|
2011
|
-
uy = 0;
|
|
2012
|
-
uz = tx;
|
|
2013
|
-
}
|
|
2014
|
-
const uLen = Math.sqrt(ux * ux + uy * uy + uz * uz);
|
|
2015
|
-
ux /= uLen;
|
|
2016
|
-
uy /= uLen;
|
|
2017
|
-
uz /= uLen;
|
|
2018
|
-
const vx = ty * uz - tz * uy;
|
|
2019
|
-
const vy = tz * ux - tx * uz;
|
|
2020
|
-
const vz = tx * uy - ty * ux;
|
|
2021
|
-
const mat = new this.Module.VectorDouble();
|
|
2022
|
-
mat.push_back(ux);
|
|
2023
|
-
mat.push_back(vx);
|
|
2024
|
-
mat.push_back(tx);
|
|
2025
|
-
mat.push_back(px);
|
|
2026
|
-
mat.push_back(uy);
|
|
2027
|
-
mat.push_back(vy);
|
|
2028
|
-
mat.push_back(ty);
|
|
2029
|
-
mat.push_back(py);
|
|
2030
|
-
mat.push_back(uz);
|
|
2031
|
-
mat.push_back(vz);
|
|
2032
|
-
mat.push_back(tz);
|
|
2033
|
-
mat.push_back(pz);
|
|
2034
|
-
try {
|
|
2035
|
-
return wrapResult(this.k, this.k.transform(unwrap(shape), mat));
|
|
2036
|
-
} finally {
|
|
2037
|
-
mat.delete();
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
|
-
linearPattern(shape, direction, spacing, count) {
|
|
2041
|
-
const compoundId = this.k.linearPattern(unwrap(shape), direction[0], direction[1], direction[2], spacing, count);
|
|
2042
|
-
const subVec = this.k.getSubShapes(compoundId, "solid");
|
|
2043
|
-
const results = [];
|
|
2044
|
-
const n = subVec.size();
|
|
2045
|
-
for (let i = 0; i < n; i++) results.push(handle("solid", subVec.get(i)));
|
|
2046
|
-
subVec.delete();
|
|
2047
|
-
if (results.length === 0) {
|
|
2048
|
-
const iter = this.k.iterShapes(compoundId);
|
|
2049
|
-
const n2 = iter.size();
|
|
2050
|
-
for (let i = 0; i < n2; i++) results.push(wrapResult(this.k, iter.get(i)));
|
|
2051
|
-
iter.delete();
|
|
2052
|
-
}
|
|
2053
|
-
return results;
|
|
2054
|
-
}
|
|
2055
|
-
circularPattern(shape, center, axis, angleStep, count) {
|
|
2056
|
-
const compoundId = this.k.circularPattern(unwrap(shape), center[0], center[1], center[2], axis[0], axis[1], axis[2], angleStep, count);
|
|
2057
|
-
const subVec = this.k.getSubShapes(compoundId, "solid");
|
|
2058
|
-
const results = [];
|
|
2059
|
-
try {
|
|
2060
|
-
const n = subVec.size();
|
|
2061
|
-
for (let i = 0; i < n; i++) results.push(handle("solid", subVec.get(i)));
|
|
2062
|
-
} finally {
|
|
2063
|
-
subVec.delete();
|
|
2064
|
-
}
|
|
2065
|
-
if (results.length === 0) {
|
|
2066
|
-
const iter = this.k.iterShapes(compoundId);
|
|
2067
|
-
try {
|
|
2068
|
-
const n2 = iter.size();
|
|
2069
|
-
for (let i = 0; i < n2; i++) results.push(wrapResult(this.k, iter.get(i)));
|
|
2070
|
-
} finally {
|
|
2071
|
-
iter.delete();
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
return results;
|
|
2075
|
-
}
|
|
2076
|
-
transformBatch(entries) {
|
|
2077
|
-
return entries.map((entry) => {
|
|
2078
|
-
switch (entry.type) {
|
|
2079
|
-
case "translate": return this.translate(entry.shape, entry.x, entry.y, entry.z);
|
|
2080
|
-
case "rotate": return this.rotate(entry.shape, entry.angle, entry.axis, entry.center);
|
|
2081
|
-
case "scale": return this.scale(entry.shape, entry.center, entry.factor);
|
|
2082
|
-
case "mirror": return this.mirror(entry.shape, entry.origin, entry.normal);
|
|
2083
|
-
default: notImplemented("transformBatch unknown type");
|
|
2084
|
-
}
|
|
2085
|
-
});
|
|
2086
|
-
}
|
|
2087
|
-
translateWithHistory(shape, x, y, z, inputFaceHashes, hashUpperBound) {
|
|
2088
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2089
|
-
try {
|
|
2090
|
-
const { id, evolution } = parseEvolution(this.k.translateWithHistory(unwrap(shape), x, y, z, hashVec, hashUpperBound));
|
|
2091
|
-
return {
|
|
2092
|
-
shape: wrapResult(this.k, id),
|
|
2093
|
-
evolution
|
|
2094
|
-
};
|
|
2095
|
-
} finally {
|
|
2096
|
-
hashVec.delete();
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
rotateWithHistory(shape, angle, inputFaceHashes, hashUpperBound, axis, center) {
|
|
2100
|
-
const ax = axis ?? [
|
|
2101
|
-
0,
|
|
2102
|
-
0,
|
|
2103
|
-
1
|
|
2104
|
-
];
|
|
2105
|
-
const cn = center ?? [
|
|
2106
|
-
0,
|
|
2107
|
-
0,
|
|
2108
|
-
0
|
|
2109
|
-
];
|
|
2110
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2111
|
-
try {
|
|
2112
|
-
const { id, evolution } = parseEvolution(this.k.rotateWithHistory(unwrap(shape), cn[0], cn[1], cn[2], ax[0], ax[1], ax[2], angle, hashVec, hashUpperBound));
|
|
2113
|
-
return {
|
|
2114
|
-
shape: wrapResult(this.k, id),
|
|
2115
|
-
evolution
|
|
2116
|
-
};
|
|
2117
|
-
} finally {
|
|
2118
|
-
hashVec.delete();
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
mirrorWithHistory(shape, origin, normal, inputFaceHashes, hashUpperBound) {
|
|
2122
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2123
|
-
try {
|
|
2124
|
-
const { id, evolution } = parseEvolution(this.k.mirrorWithHistory(unwrap(shape), origin[0], origin[1], origin[2], normal[0], normal[1], normal[2], hashVec, hashUpperBound));
|
|
2125
|
-
return {
|
|
2126
|
-
shape: wrapResult(this.k, id),
|
|
2127
|
-
evolution
|
|
2128
|
-
};
|
|
2129
|
-
} finally {
|
|
2130
|
-
hashVec.delete();
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
scaleWithHistory(shape, center, factor, inputFaceHashes, hashUpperBound) {
|
|
2134
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2135
|
-
try {
|
|
2136
|
-
const { id, evolution } = parseEvolution(this.k.scaleWithHistory(unwrap(shape), center[0], center[1], center[2], factor, hashVec, hashUpperBound));
|
|
2137
|
-
return {
|
|
2138
|
-
shape: wrapResult(this.k, id),
|
|
2139
|
-
evolution
|
|
2140
|
-
};
|
|
2141
|
-
} finally {
|
|
2142
|
-
hashVec.delete();
|
|
2143
|
-
}
|
|
2144
|
-
}
|
|
2145
|
-
generalTransformWithHistory(shape, linear, translation, _isOrthogonal, inputFaceHashes, _hashUpperBound) {
|
|
2146
|
-
const result = this.generalTransform(shape, linear, translation, _isOrthogonal);
|
|
2147
|
-
const modified = /* @__PURE__ */ new Map();
|
|
2148
|
-
for (const h of inputFaceHashes) modified.set(h, [h]);
|
|
2149
|
-
return {
|
|
2150
|
-
shape: result,
|
|
2151
|
-
evolution: {
|
|
2152
|
-
modified,
|
|
2153
|
-
generated: /* @__PURE__ */ new Map(),
|
|
2154
|
-
deleted: /* @__PURE__ */ new Set()
|
|
2155
|
-
}
|
|
2156
|
-
};
|
|
2157
|
-
}
|
|
2158
|
-
fuseWithHistory(shape, tool, inputFaceHashes, hashUpperBound, _options) {
|
|
2159
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2160
|
-
try {
|
|
2161
|
-
const { id, evolution } = parseEvolution(this.k.fuseWithHistory(unwrap(shape), unwrap(tool), hashVec, hashUpperBound));
|
|
2162
|
-
return {
|
|
2163
|
-
shape: wrapResult(this.k, id),
|
|
2164
|
-
evolution,
|
|
2165
|
-
diagnostics: {
|
|
2166
|
-
hasErrors: false,
|
|
2167
|
-
hasWarnings: false,
|
|
2168
|
-
messages: []
|
|
2169
|
-
}
|
|
2170
|
-
};
|
|
2171
|
-
} finally {
|
|
2172
|
-
hashVec.delete();
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
cutWithHistory(shape, tool, inputFaceHashes, hashUpperBound, _options) {
|
|
2176
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2177
|
-
try {
|
|
2178
|
-
const { id, evolution } = parseEvolution(this.k.cutWithHistory(unwrap(shape), unwrap(tool), hashVec, hashUpperBound));
|
|
2179
|
-
return {
|
|
2180
|
-
shape: wrapResult(this.k, id),
|
|
2181
|
-
evolution,
|
|
2182
|
-
diagnostics: {
|
|
2183
|
-
hasErrors: false,
|
|
2184
|
-
hasWarnings: false,
|
|
2185
|
-
messages: []
|
|
2186
|
-
}
|
|
2187
|
-
};
|
|
2188
|
-
} finally {
|
|
2189
|
-
hashVec.delete();
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
intersectWithHistory(shape, tool, inputFaceHashes, hashUpperBound, _options) {
|
|
2193
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2194
|
-
try {
|
|
2195
|
-
const { id, evolution } = parseEvolution(this.k.intersectWithHistory(unwrap(shape), unwrap(tool), hashVec, hashUpperBound));
|
|
2196
|
-
return {
|
|
2197
|
-
shape: wrapResult(this.k, id),
|
|
2198
|
-
evolution,
|
|
2199
|
-
diagnostics: {
|
|
2200
|
-
hasErrors: false,
|
|
2201
|
-
hasWarnings: false,
|
|
2202
|
-
messages: []
|
|
2203
|
-
}
|
|
2204
|
-
};
|
|
2205
|
-
} finally {
|
|
2206
|
-
hashVec.delete();
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
filletWithHistory(shape, edges, radius, inputFaceHashes, hashUpperBound) {
|
|
2210
|
-
const r = resolveUniformRadius(edges, radius);
|
|
2211
|
-
const edgeVec = makeVecU32(this.Module, edges.map(unwrap));
|
|
2212
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2213
|
-
try {
|
|
2214
|
-
const { id, evolution } = parseEvolution(this.k.filletWithHistory(unwrap(shape), edgeVec, r, hashVec, hashUpperBound));
|
|
2215
|
-
return {
|
|
2216
|
-
shape: wrapResult(this.k, id),
|
|
2217
|
-
evolution
|
|
2218
|
-
};
|
|
2219
|
-
} finally {
|
|
2220
|
-
edgeVec.delete();
|
|
2221
|
-
hashVec.delete();
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
chamferWithHistory(shape, edges, distance, inputFaceHashes, hashUpperBound) {
|
|
2225
|
-
const d = resolveUniformRadius(edges, distance);
|
|
2226
|
-
const edgeVec = makeVecU32(this.Module, edges.map(unwrap));
|
|
2227
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2228
|
-
try {
|
|
2229
|
-
const { id, evolution } = parseEvolution(this.k.chamferWithHistory(unwrap(shape), edgeVec, d, hashVec, hashUpperBound));
|
|
2230
|
-
return {
|
|
2231
|
-
shape: wrapResult(this.k, id),
|
|
2232
|
-
evolution
|
|
2233
|
-
};
|
|
2234
|
-
} finally {
|
|
2235
|
-
edgeVec.delete();
|
|
2236
|
-
hashVec.delete();
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
shellWithHistory(shape, faces, thickness, inputFaceHashes, hashUpperBound, tolerance) {
|
|
2240
|
-
const faceVec = makeVecU32(this.Module, faces.map(unwrap));
|
|
2241
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2242
|
-
try {
|
|
2243
|
-
const { id, evolution } = parseEvolution(this.k.shellWithHistory(unwrap(shape), faceVec, thickness, tolerance ?? .001, hashVec, hashUpperBound));
|
|
2244
|
-
return {
|
|
2245
|
-
shape: wrapResult(this.k, id),
|
|
2246
|
-
evolution
|
|
2247
|
-
};
|
|
2248
|
-
} finally {
|
|
2249
|
-
faceVec.delete();
|
|
2250
|
-
hashVec.delete();
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
thickenWithHistory(shape, thickness, inputFaceHashes, hashUpperBound) {
|
|
2254
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2255
|
-
try {
|
|
2256
|
-
const { id, evolution } = parseEvolution(this.k.thickenWithHistory(unwrap(shape), thickness, .001, hashVec, hashUpperBound));
|
|
2257
|
-
return {
|
|
2258
|
-
shape: wrapResult(this.k, id),
|
|
2259
|
-
evolution
|
|
2260
|
-
};
|
|
2261
|
-
} finally {
|
|
2262
|
-
hashVec.delete();
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
offsetWithHistory(shape, distance, inputFaceHashes, hashUpperBound, tolerance) {
|
|
2266
|
-
const hashVec = makeVecInt(this.Module, inputFaceHashes);
|
|
2267
|
-
try {
|
|
2268
|
-
const { id, evolution } = parseEvolution(this.k.offsetWithHistory(unwrap(shape), distance, tolerance ?? 1e-6, hashVec, hashUpperBound));
|
|
2269
|
-
return {
|
|
2270
|
-
shape: wrapResult(this.k, id),
|
|
2271
|
-
evolution
|
|
2272
|
-
};
|
|
2273
|
-
} finally {
|
|
2274
|
-
hashVec.delete();
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
draftWithHistory(shape, faces, pullDirection, _neutralPlane, angleDeg, _inputFaceHashes, _hashUpperBound) {
|
|
2278
|
-
const [dx, dy, dz] = pullDirection;
|
|
2279
|
-
let currentId = unwrap(shape);
|
|
2280
|
-
for (const face of faces) {
|
|
2281
|
-
const angleRad = (typeof angleDeg === "number" ? angleDeg : angleDeg(face)) * Math.PI / 180;
|
|
2282
|
-
currentId = this.k.draft(currentId, unwrap(face), angleRad, dx, dy, dz);
|
|
2283
|
-
}
|
|
2284
|
-
return {
|
|
2285
|
-
shape: wrapResult(this.k, currentId),
|
|
2286
|
-
evolution: {
|
|
2287
|
-
modified: /* @__PURE__ */ new Map(),
|
|
2288
|
-
generated: /* @__PURE__ */ new Map(),
|
|
2289
|
-
deleted: /* @__PURE__ */ new Set()
|
|
2290
|
-
}
|
|
2291
|
-
};
|
|
2292
|
-
}
|
|
2293
|
-
applyComposedTransformWithHistory(shape, transformHandle, inputFaceHashes, hashUpperBound) {
|
|
2294
|
-
const result = this.transform(shape, transformHandle);
|
|
2295
|
-
const outFaces = this.iterShapes(result, "face");
|
|
2296
|
-
const modified = /* @__PURE__ */ new Map();
|
|
2297
|
-
const limit = Math.min(inputFaceHashes.length, outFaces.length);
|
|
2298
|
-
for (let i = 0; i < limit; i++) {
|
|
2299
|
-
const outFace = outFaces[i];
|
|
2300
|
-
const inHash = inputFaceHashes[i];
|
|
2301
|
-
if (outFace !== void 0 && inHash !== void 0) modified.set(inHash, [this.hashCode(outFace, hashUpperBound)]);
|
|
2302
|
-
}
|
|
2303
|
-
return {
|
|
2304
|
-
shape: result,
|
|
2305
|
-
evolution: {
|
|
2306
|
-
modified,
|
|
2307
|
-
generated: /* @__PURE__ */ new Map(),
|
|
2308
|
-
deleted: /* @__PURE__ */ new Set()
|
|
2309
|
-
}
|
|
2310
|
-
};
|
|
2311
|
-
}
|
|
2312
|
-
mesh(shape, options) {
|
|
2313
|
-
const meshData = this.k.tessellate(unwrap(shape), options.tolerance, options.angularTolerance);
|
|
2314
|
-
const posCount = meshData.positionCount;
|
|
2315
|
-
const normCount = meshData.normalCount;
|
|
2316
|
-
const idxCount = meshData.indexCount;
|
|
2317
|
-
const posPtr = meshData.getPositionsPtr() >> 2;
|
|
2318
|
-
const normPtr = meshData.getNormalsPtr() >> 2;
|
|
2319
|
-
const idxPtr = meshData.getIndicesPtr() >> 2;
|
|
2320
|
-
const vertices = new Float32Array(posCount);
|
|
2321
|
-
for (let i = 0; i < posCount; i++) vertices[i] = this.Module.HEAPF32[posPtr + i] ?? 0;
|
|
2322
|
-
const normals = new Float32Array(normCount);
|
|
2323
|
-
if (!options.skipNormals) for (let i = 0; i < normCount; i++) normals[i] = this.Module.HEAPF32[normPtr + i] ?? 0;
|
|
2324
|
-
const triangles = new Uint32Array(idxCount);
|
|
2325
|
-
for (let i = 0; i < idxCount; i++) triangles[i] = this.Module.HEAPU32[idxPtr + i] ?? 0;
|
|
2326
|
-
const faceGroups = [];
|
|
2327
|
-
const fgCount = meshData.faceGroupCount;
|
|
2328
|
-
if (fgCount > 0) {
|
|
2329
|
-
const fgPtr = meshData.getFaceGroupsPtr() >> 2;
|
|
2330
|
-
for (let i = 0; i < fgCount; i += 3) faceGroups.push({
|
|
2331
|
-
start: this.Module.HEAP32[fgPtr + i] ?? 0,
|
|
2332
|
-
count: this.Module.HEAP32[fgPtr + i + 1] ?? 0,
|
|
2333
|
-
faceHash: this.Module.HEAP32[fgPtr + i + 2] ?? 0
|
|
2334
|
-
});
|
|
2335
|
-
}
|
|
2336
|
-
meshData.delete();
|
|
2337
|
-
return {
|
|
2338
|
-
vertices,
|
|
2339
|
-
normals: options.skipNormals ? new Float32Array(0) : normals,
|
|
2340
|
-
triangles,
|
|
2341
|
-
uvs: new Float32Array(0),
|
|
2342
|
-
faceGroups
|
|
2343
|
-
};
|
|
2344
|
-
}
|
|
2345
|
-
meshEdges(shape, tolerance, _angularTolerance) {
|
|
2346
|
-
const edgeData = this.k.wireframe(unwrap(shape), tolerance);
|
|
2347
|
-
const pointCount = edgeData.pointCount;
|
|
2348
|
-
const ptr = edgeData.getPointsPtr() >> 2;
|
|
2349
|
-
const lines = new Float32Array(pointCount);
|
|
2350
|
-
for (let i = 0; i < pointCount; i++) lines[i] = this.Module.HEAPF32[ptr + i] ?? 0;
|
|
2351
|
-
const edgeGroups = [];
|
|
2352
|
-
const egCount = edgeData.edgeGroupCount;
|
|
2353
|
-
if (egCount > 0) {
|
|
2354
|
-
const egPtr = edgeData.getEdgeGroupsPtr() >> 2;
|
|
2355
|
-
for (let i = 0; i < egCount; i += 3) edgeGroups.push({
|
|
2356
|
-
start: this.Module.HEAP32[egPtr + i] ?? 0,
|
|
2357
|
-
count: this.Module.HEAP32[egPtr + i + 1] ?? 0,
|
|
2358
|
-
edgeHash: this.Module.HEAP32[egPtr + i + 2] ?? 0
|
|
2359
|
-
});
|
|
2360
|
-
}
|
|
2361
|
-
edgeData.delete();
|
|
2362
|
-
return {
|
|
2363
|
-
lines,
|
|
2364
|
-
edgeGroups
|
|
2365
|
-
};
|
|
2366
|
-
}
|
|
2367
|
-
hasTriangulation(shape) {
|
|
2368
|
-
return this.k.hasTriangulation(unwrap(shape));
|
|
2369
|
-
}
|
|
2370
|
-
meshShape(shape, tolerance, angularTolerance) {
|
|
2371
|
-
this.k.meshShape(unwrap(shape), tolerance, angularTolerance).delete();
|
|
2372
|
-
}
|
|
2373
|
-
exportSTEP(shapes) {
|
|
2374
|
-
if (shapes.length === 1) return this.k.exportStep(unwrap(shapes[0]));
|
|
2375
|
-
const compound = this.makeCompound(shapes);
|
|
2376
|
-
return this.k.exportStep(unwrap(compound));
|
|
2377
|
-
}
|
|
2378
|
-
exportSTL(shape, binary) {
|
|
2379
|
-
const ascii = !binary;
|
|
2380
|
-
const result = this.k.exportStl(unwrap(shape), .1, ascii);
|
|
2381
|
-
if (binary) {
|
|
2382
|
-
const buf = new ArrayBuffer(result.length);
|
|
2383
|
-
const view = new Uint8Array(buf);
|
|
2384
|
-
for (let i = 0; i < result.length; i++) view[i] = result.charCodeAt(i);
|
|
2385
|
-
return buf;
|
|
2386
|
-
}
|
|
2387
|
-
return result;
|
|
2388
|
-
}
|
|
2389
|
-
importSTEP(data) {
|
|
2390
|
-
const str = typeof data === "string" ? data : new TextDecoder().decode(data);
|
|
2391
|
-
const id = this.k.importStep(str);
|
|
2392
|
-
return [wrapResult(this.k, id)];
|
|
2393
|
-
}
|
|
2394
|
-
importSTL(data) {
|
|
2395
|
-
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : new Uint8Array(data);
|
|
2396
|
-
const mod = this.Module;
|
|
2397
|
-
if (mod.FS) mod.FS.writeFile("/tmp/import.stl", bytes);
|
|
2398
|
-
else {
|
|
2399
|
-
const str = Array.from(bytes, (b) => String.fromCharCode(b)).join("");
|
|
2400
|
-
const id = this.k.importStl(str);
|
|
2401
|
-
return wrapResult(this.k, id);
|
|
2402
|
-
}
|
|
2403
|
-
const id = this.k.importStl("");
|
|
2404
|
-
return wrapResult(this.k, id);
|
|
2405
|
-
}
|
|
2406
|
-
exportIGES(shapes) {
|
|
2407
|
-
if (shapes.length === 1) return this.k.exportIges(unwrap(shapes[0]));
|
|
2408
|
-
const compound = this.makeCompound(shapes);
|
|
2409
|
-
return this.k.exportIges(unwrap(compound));
|
|
2410
|
-
}
|
|
2411
|
-
importIGES(data) {
|
|
2412
|
-
const str = typeof data === "string" ? data : new TextDecoder().decode(data);
|
|
2413
|
-
const id = this.k.importIges(str);
|
|
2414
|
-
return [wrapResult(this.k, id)];
|
|
2415
|
-
}
|
|
2416
|
-
exportSTEPAssembly(parts, _options) {
|
|
2417
|
-
if (parts.length === 0) return "";
|
|
2418
|
-
const doc = this.createXCAFDocument(parts);
|
|
2419
|
-
try {
|
|
2420
|
-
return this.writeXCAFToSTEP(doc);
|
|
2421
|
-
} finally {
|
|
2422
|
-
doc.delete();
|
|
2423
|
-
}
|
|
2424
|
-
}
|
|
2425
|
-
export3MF(_shape, _tolerance) {
|
|
2426
|
-
throw new Error("export3MF is only available with the brepkit kernel");
|
|
2427
|
-
}
|
|
2428
|
-
exportGLB(shape, tolerance) {
|
|
2429
|
-
const result = this.mesh(shape, {
|
|
2430
|
-
tolerance,
|
|
2431
|
-
angularTolerance: .5,
|
|
2432
|
-
skipNormals: false
|
|
2433
|
-
});
|
|
2434
|
-
const positions = result.vertices;
|
|
2435
|
-
const normals = result.normals;
|
|
2436
|
-
const indices = result.triangles;
|
|
2437
|
-
const vCount = positions.length / 3;
|
|
2438
|
-
const nCount = normals.length / 3;
|
|
2439
|
-
const iCount = indices.length;
|
|
2440
|
-
const posBytes = positions.byteLength;
|
|
2441
|
-
const nrmBytes = normals.byteLength;
|
|
2442
|
-
const idxBytes = indices.byteLength;
|
|
2443
|
-
const binLength = posBytes + nrmBytes + idxBytes;
|
|
2444
|
-
const paddedBinLength = binLength + (4 - binLength % 4) % 4;
|
|
2445
|
-
const manifest = buildGltfManifest(vCount, nCount, iCount, posBytes, nrmBytes, idxBytes, paddedBinLength, computePositionBounds(positions, vCount));
|
|
2446
|
-
const jsonBytes = new TextEncoder().encode(JSON.stringify(manifest));
|
|
2447
|
-
const paddedJsonLength = jsonBytes.byteLength + (4 - jsonBytes.byteLength % 4) % 4;
|
|
2448
|
-
const totalLength = 20 + paddedJsonLength + 8 + paddedBinLength;
|
|
2449
|
-
const glb = new ArrayBuffer(totalLength);
|
|
2450
|
-
const view = new DataView(glb);
|
|
2451
|
-
view.setUint32(0, 1179937895, true);
|
|
2452
|
-
view.setUint32(4, 2, true);
|
|
2453
|
-
view.setUint32(8, totalLength, true);
|
|
2454
|
-
view.setUint32(12, paddedJsonLength, true);
|
|
2455
|
-
view.setUint32(16, 1313821514, true);
|
|
2456
|
-
const jsonDst = new Uint8Array(glb, 20, paddedJsonLength);
|
|
2457
|
-
jsonDst.set(jsonBytes);
|
|
2458
|
-
for (let i = jsonBytes.byteLength; i < paddedJsonLength; i++) jsonDst[i] = 32;
|
|
2459
|
-
const binHeaderOffset = 20 + paddedJsonLength;
|
|
2460
|
-
view.setUint32(binHeaderOffset, paddedBinLength, true);
|
|
2461
|
-
view.setUint32(binHeaderOffset + 4, 5130562, true);
|
|
2462
|
-
const binDataOffset = binHeaderOffset + 8;
|
|
2463
|
-
new Uint8Array(glb, binDataOffset, posBytes).set(new Uint8Array(positions.buffer, positions.byteOffset, posBytes));
|
|
2464
|
-
new Uint8Array(glb, binDataOffset + posBytes, nrmBytes).set(new Uint8Array(normals.buffer, normals.byteOffset, nrmBytes));
|
|
2465
|
-
new Uint8Array(glb, binDataOffset + posBytes + nrmBytes, idxBytes).set(new Uint8Array(indices.buffer, indices.byteOffset, idxBytes));
|
|
2466
|
-
return glb;
|
|
2467
|
-
}
|
|
2468
|
-
exportOBJ(shape, tolerance) {
|
|
2469
|
-
const result = this.mesh(shape, {
|
|
2470
|
-
tolerance,
|
|
2471
|
-
angularTolerance: .5,
|
|
2472
|
-
skipNormals: false
|
|
2473
|
-
});
|
|
2474
|
-
const v = result.vertices;
|
|
2475
|
-
const n = result.normals;
|
|
2476
|
-
const t = result.triangles;
|
|
2477
|
-
const lines = ["# brepjs OBJ export"];
|
|
2478
|
-
const vCount = v.length / 3;
|
|
2479
|
-
for (let i = 0; i < vCount; i++) {
|
|
2480
|
-
const o = i * 3;
|
|
2481
|
-
lines.push(`v ${v[o] ?? 0} ${v[o + 1] ?? 0} ${v[o + 2] ?? 0}`);
|
|
2482
|
-
}
|
|
2483
|
-
const nCount = n.length / 3;
|
|
2484
|
-
for (let i = 0; i < nCount; i++) {
|
|
2485
|
-
const o = i * 3;
|
|
2486
|
-
lines.push(`vn ${n[o] ?? 0} ${n[o + 1] ?? 0} ${n[o + 2] ?? 0}`);
|
|
2487
|
-
}
|
|
2488
|
-
const pushTri = (offset) => {
|
|
2489
|
-
const a = (t[offset] ?? 0) + 1;
|
|
2490
|
-
const b = (t[offset + 1] ?? 0) + 1;
|
|
2491
|
-
const c = (t[offset + 2] ?? 0) + 1;
|
|
2492
|
-
lines.push(`f ${a}//${a} ${b}//${b} ${c}//${c}`);
|
|
2493
|
-
};
|
|
2494
|
-
if (result.faceGroups.length > 0) for (const group of result.faceGroups) {
|
|
2495
|
-
lines.push(`g face_${group.faceHash}`);
|
|
2496
|
-
const count = group.count / 3;
|
|
2497
|
-
for (let i = 0; i < count; i++) pushTri(group.start + i * 3);
|
|
2498
|
-
}
|
|
2499
|
-
else {
|
|
2500
|
-
const triCount = t.length / 3;
|
|
2501
|
-
for (let i = 0; i < triCount; i++) pushTri(i * 3);
|
|
2502
|
-
}
|
|
2503
|
-
return new TextEncoder().encode(lines.join("\n") + "\n").buffer;
|
|
2504
|
-
}
|
|
2505
|
-
exportPLY(shape, tolerance) {
|
|
2506
|
-
const result = this.mesh(shape, {
|
|
2507
|
-
tolerance,
|
|
2508
|
-
angularTolerance: .5,
|
|
2509
|
-
skipNormals: false
|
|
2510
|
-
});
|
|
2511
|
-
const v = result.vertices;
|
|
2512
|
-
const n = result.normals;
|
|
2513
|
-
const t = result.triangles;
|
|
2514
|
-
const vCount = v.length / 3;
|
|
2515
|
-
const triCount = t.length / 3;
|
|
2516
|
-
const hasNormals = n.length === v.length;
|
|
2517
|
-
const lines = [
|
|
2518
|
-
"ply",
|
|
2519
|
-
"format ascii 1.0",
|
|
2520
|
-
"comment brepjs PLY export",
|
|
2521
|
-
`element vertex ${vCount}`,
|
|
2522
|
-
"property float x",
|
|
2523
|
-
"property float y",
|
|
2524
|
-
"property float z"
|
|
2525
|
-
];
|
|
2526
|
-
if (hasNormals) lines.push("property float nx", "property float ny", "property float nz");
|
|
2527
|
-
lines.push(`element face ${triCount}`, "property list uchar int vertex_index", "end_header");
|
|
2528
|
-
for (let i = 0; i < vCount; i++) {
|
|
2529
|
-
const o = i * 3;
|
|
2530
|
-
const x = v[o] ?? 0;
|
|
2531
|
-
const y = v[o + 1] ?? 0;
|
|
2532
|
-
const z = v[o + 2] ?? 0;
|
|
2533
|
-
if (hasNormals) {
|
|
2534
|
-
const nx = n[o] ?? 0;
|
|
2535
|
-
const ny = n[o + 1] ?? 0;
|
|
2536
|
-
const nz = n[o + 2] ?? 0;
|
|
2537
|
-
lines.push(`${x} ${y} ${z} ${nx} ${ny} ${nz}`);
|
|
2538
|
-
} else lines.push(`${x} ${y} ${z}`);
|
|
2539
|
-
}
|
|
2540
|
-
for (let i = 0; i < triCount; i++) {
|
|
2541
|
-
const a = t[i * 3] ?? 0;
|
|
2542
|
-
const b = t[i * 3 + 1] ?? 0;
|
|
2543
|
-
const c = t[i * 3 + 2] ?? 0;
|
|
2544
|
-
lines.push(`3 ${a} ${b} ${c}`);
|
|
2545
|
-
}
|
|
2546
|
-
return new TextEncoder().encode(lines.join("\n") + "\n").buffer;
|
|
2547
|
-
}
|
|
2548
|
-
import3MF(_data) {
|
|
2549
|
-
throw new Error("import3MF is only available with the brepkit kernel");
|
|
2550
|
-
}
|
|
2551
|
-
importOBJ(_data) {
|
|
2552
|
-
throw new Error("importOBJ is only available with the brepkit kernel");
|
|
2553
|
-
}
|
|
2554
|
-
importGLB(_data) {
|
|
2555
|
-
throw new Error("importGLB is only available with the brepkit kernel");
|
|
2556
|
-
}
|
|
2557
|
-
toBREP(shape) {
|
|
2558
|
-
return this.k.toBREP(unwrap(shape));
|
|
2559
|
-
}
|
|
2560
|
-
fromBREP(data) {
|
|
2561
|
-
return wrapResult(this.k, this.k.fromBREP(data));
|
|
2562
|
-
}
|
|
2563
|
-
createXCAFDocument(shapes) {
|
|
2564
|
-
const ids = new this.Module.VectorUint32();
|
|
2565
|
-
const nameParts = [];
|
|
2566
|
-
const colors = new this.Module.VectorDouble();
|
|
2567
|
-
for (const entry of shapes) {
|
|
2568
|
-
ids.push_back(unwrap(entry.shape));
|
|
2569
|
-
nameParts.push(entry.name);
|
|
2570
|
-
const [r, g, b, a] = entry.color ?? [
|
|
2571
|
-
.5,
|
|
2572
|
-
.5,
|
|
2573
|
-
.5,
|
|
2574
|
-
1
|
|
2575
|
-
];
|
|
2576
|
-
colors.push_back(r);
|
|
2577
|
-
colors.push_back(g);
|
|
2578
|
-
colors.push_back(b);
|
|
2579
|
-
colors.push_back(a);
|
|
2580
|
-
}
|
|
2581
|
-
try {
|
|
2582
|
-
const joinedNames = nameParts.join("\0");
|
|
2583
|
-
return handle("compound", this.k.createXCAFDocument(ids, joinedNames, colors));
|
|
2584
|
-
} finally {
|
|
2585
|
-
ids.delete();
|
|
2586
|
-
colors.delete();
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
writeXCAFToSTEP(doc, _options) {
|
|
2590
|
-
const id = unwrap(doc);
|
|
2591
|
-
const subs = this.k.getSubShapes(id, "solid");
|
|
2592
|
-
const hasSolids = subs.size() > 0;
|
|
2593
|
-
subs.delete();
|
|
2594
|
-
if (!hasSolids) {
|
|
2595
|
-
const faces = this.k.getSubShapes(id, "face");
|
|
2596
|
-
const hasFaces = faces.size() > 0;
|
|
2597
|
-
faces.delete();
|
|
2598
|
-
if (!hasFaces) return "";
|
|
2599
|
-
}
|
|
2600
|
-
return this.k.writeXCAFToSTEP(id);
|
|
2601
|
-
}
|
|
2602
|
-
exportSTEPConfigured(shapes, _options) {
|
|
2603
|
-
if (shapes.length === 0) return "";
|
|
2604
|
-
const named = shapes.map((s) => ({
|
|
2605
|
-
shape: s.shape,
|
|
2606
|
-
name: s.name ?? "",
|
|
2607
|
-
color: s.color
|
|
2608
|
-
}));
|
|
2609
|
-
const doc = this.createXCAFDocument(named);
|
|
2610
|
-
try {
|
|
2611
|
-
return this.writeXCAFToSTEP(doc);
|
|
2612
|
-
} finally {
|
|
2613
|
-
doc.delete();
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
volume(shape) {
|
|
2617
|
-
return this.k.getVolume(unwrap(shape));
|
|
2618
|
-
}
|
|
2619
|
-
area(shape) {
|
|
2620
|
-
return this.k.getSurfaceArea(unwrap(shape));
|
|
2621
|
-
}
|
|
2622
|
-
length(shape) {
|
|
2623
|
-
return this.k.getLength(unwrap(shape));
|
|
2624
|
-
}
|
|
2625
|
-
centerOfMass(shape) {
|
|
2626
|
-
const vec = this.k.getCenterOfMass(unwrap(shape));
|
|
2627
|
-
const result = [
|
|
2628
|
-
vec.get(0),
|
|
2629
|
-
vec.get(1),
|
|
2630
|
-
vec.get(2)
|
|
2631
|
-
];
|
|
2632
|
-
vec.delete();
|
|
2633
|
-
return result;
|
|
2634
|
-
}
|
|
2635
|
-
linearCenterOfMass(shape) {
|
|
2636
|
-
const vec = this.k.getLinearCenterOfMass(unwrap(shape));
|
|
2637
|
-
const result = [
|
|
2638
|
-
vec.get(0),
|
|
2639
|
-
vec.get(1),
|
|
2640
|
-
vec.get(2)
|
|
2641
|
-
];
|
|
2642
|
-
vec.delete();
|
|
2643
|
-
return result;
|
|
2644
|
-
}
|
|
2645
|
-
boundingBox(shape) {
|
|
2646
|
-
const bb = this.k.getBoundingBox(unwrap(shape), true);
|
|
2647
|
-
return {
|
|
2648
|
-
min: [
|
|
2649
|
-
bb.xmin,
|
|
2650
|
-
bb.ymin,
|
|
2651
|
-
bb.zmin
|
|
2652
|
-
],
|
|
2653
|
-
max: [
|
|
2654
|
-
bb.xmax,
|
|
2655
|
-
bb.ymax,
|
|
2656
|
-
bb.zmax
|
|
2657
|
-
]
|
|
2658
|
-
};
|
|
2659
|
-
}
|
|
2660
|
-
distance(shape1, shape2) {
|
|
2661
|
-
const id1 = unwrap(shape1);
|
|
2662
|
-
const id2 = unwrap(shape2);
|
|
2663
|
-
const value = this.k.distanceBetween(id1, id2);
|
|
2664
|
-
const samples1 = collectDistanceSamples(this.k, this.Module, id1);
|
|
2665
|
-
const samples2 = collectDistanceSamples(this.k, this.Module, id2);
|
|
2666
|
-
if (samples1.length === 0 || samples2.length === 0) return {
|
|
2667
|
-
value,
|
|
2668
|
-
point1: [
|
|
2669
|
-
0,
|
|
2670
|
-
0,
|
|
2671
|
-
0
|
|
2672
|
-
],
|
|
2673
|
-
point2: [
|
|
2674
|
-
0,
|
|
2675
|
-
0,
|
|
2676
|
-
0
|
|
2677
|
-
]
|
|
2678
|
-
};
|
|
2679
|
-
let bestD2 = Infinity;
|
|
2680
|
-
let bestP1 = samples1[0] ?? [
|
|
2681
|
-
0,
|
|
2682
|
-
0,
|
|
2683
|
-
0
|
|
2684
|
-
];
|
|
2685
|
-
let bestP2 = samples2[0] ?? [
|
|
2686
|
-
0,
|
|
2687
|
-
0,
|
|
2688
|
-
0
|
|
2689
|
-
];
|
|
2690
|
-
for (const p1 of samples1) for (const p2 of samples2) {
|
|
2691
|
-
const dx = p2[0] - p1[0];
|
|
2692
|
-
const dy = p2[1] - p1[1];
|
|
2693
|
-
const dz = p2[2] - p1[2];
|
|
2694
|
-
const d2 = dx * dx + dy * dy + dz * dz;
|
|
2695
|
-
if (d2 < bestD2) {
|
|
2696
|
-
bestD2 = d2;
|
|
2697
|
-
bestP1 = p1;
|
|
2698
|
-
bestP2 = p2;
|
|
2699
|
-
}
|
|
2700
|
-
}
|
|
2701
|
-
return {
|
|
2702
|
-
value,
|
|
2703
|
-
point1: bestP1,
|
|
2704
|
-
point2: bestP2
|
|
2705
|
-
};
|
|
2706
|
-
}
|
|
2707
|
-
surfaceCurvature(face, u, v) {
|
|
2708
|
-
const faceId = unwrap(face);
|
|
2709
|
-
const vec = this.k.surfaceCurvature(faceId, u, v);
|
|
2710
|
-
const mean = vec.get(0);
|
|
2711
|
-
const gaussian = vec.get(1);
|
|
2712
|
-
const maxK = vec.get(2);
|
|
2713
|
-
const minK = vec.get(3);
|
|
2714
|
-
vec.delete();
|
|
2715
|
-
const { maxDirection, minDirection } = computePrincipalDirections(this.k, faceId, u, v, maxK, minK);
|
|
2716
|
-
return {
|
|
2717
|
-
gaussian,
|
|
2718
|
-
mean,
|
|
2719
|
-
max: maxK,
|
|
2720
|
-
min: minK,
|
|
2721
|
-
maxDirection,
|
|
2722
|
-
minDirection
|
|
2723
|
-
};
|
|
2724
|
-
}
|
|
2725
|
-
surfaceCenterOfMass(face) {
|
|
2726
|
-
try {
|
|
2727
|
-
const v = this.k.getSurfaceCenterOfMass(unwrap(face));
|
|
2728
|
-
const result = [
|
|
2729
|
-
v.get(0),
|
|
2730
|
-
v.get(1),
|
|
2731
|
-
v.get(2)
|
|
2732
|
-
];
|
|
2733
|
-
v.delete();
|
|
2734
|
-
return result;
|
|
2735
|
-
} catch {
|
|
2736
|
-
return [
|
|
2737
|
-
0,
|
|
2738
|
-
0,
|
|
2739
|
-
0
|
|
2740
|
-
];
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
measureBulk(shape, includeLinear) {
|
|
2744
|
-
const bb = this.boundingBox(shape);
|
|
2745
|
-
return {
|
|
2746
|
-
volume: this.volume(shape),
|
|
2747
|
-
area: this.area(shape),
|
|
2748
|
-
length: includeLinear ? this.length(shape) : 0,
|
|
2749
|
-
centerOfMass: this.centerOfMass(shape),
|
|
2750
|
-
boundingBox: bb
|
|
2751
|
-
};
|
|
2752
|
-
}
|
|
2753
|
-
createDistanceQuery(referenceShape) {
|
|
2754
|
-
const refId = unwrap(referenceShape);
|
|
2755
|
-
const k = this.k;
|
|
2756
|
-
return {
|
|
2757
|
-
distanceTo(shape) {
|
|
2758
|
-
return {
|
|
2759
|
-
value: k.distanceBetween(refId, unwrap(shape)),
|
|
2760
|
-
point1: [
|
|
2761
|
-
0,
|
|
2762
|
-
0,
|
|
2763
|
-
0
|
|
2764
|
-
],
|
|
2765
|
-
point2: [
|
|
2766
|
-
0,
|
|
2767
|
-
0,
|
|
2768
|
-
0
|
|
2769
|
-
]
|
|
2770
|
-
};
|
|
2771
|
-
},
|
|
2772
|
-
dispose: noop
|
|
2773
|
-
};
|
|
2774
|
-
}
|
|
2775
|
-
iterShapes(shape, type) {
|
|
2776
|
-
const vec = this.k.getSubShapes(unwrap(shape), type);
|
|
2777
|
-
const results = [];
|
|
2778
|
-
const n = vec.size();
|
|
2779
|
-
for (let i = 0; i < n; i++) results.push(handle(type, vec.get(i)));
|
|
2780
|
-
vec.delete();
|
|
2781
|
-
return results;
|
|
2782
|
-
}
|
|
2783
|
-
iterShapeList(_list, _callback) {
|
|
2784
|
-
throw new Error("iterShapeList is not applicable to occt-wasm: the arena model has no TopTools_ListOfShape handles");
|
|
2785
|
-
}
|
|
2786
|
-
shapeType(shape) {
|
|
2787
|
-
if (isOcctWasmHandle(shape)) return shape.type;
|
|
2788
|
-
return mapShapeType(this.k.getShapeType(unwrap(shape)));
|
|
2789
|
-
}
|
|
2790
|
-
isSame(a, b) {
|
|
2791
|
-
return this.k.isSame(unwrap(a), unwrap(b));
|
|
2792
|
-
}
|
|
2793
|
-
isEqual(a, b) {
|
|
2794
|
-
return this.k.isEqual(unwrap(a), unwrap(b));
|
|
2795
|
-
}
|
|
2796
|
-
downcast(shape, type) {
|
|
2797
|
-
if (type) return handle(type, this.k.downcast(unwrap(shape), type));
|
|
2798
|
-
return shape;
|
|
2799
|
-
}
|
|
2800
|
-
hashCode(shape, upperBound) {
|
|
2801
|
-
return this.k.hashCode(unwrap(shape), upperBound);
|
|
2802
|
-
}
|
|
2803
|
-
isNull(shape) {
|
|
2804
|
-
return this.k.isNull(unwrap(shape));
|
|
2805
|
-
}
|
|
2806
|
-
shapeOrientation(shape) {
|
|
2807
|
-
return this.k.shapeOrientation(unwrap(shape)).toLowerCase();
|
|
2808
|
-
}
|
|
2809
|
-
edgeToFaceMap(shape) {
|
|
2810
|
-
const vec = this.k.edgeToFaceMap(unwrap(shape), 1e6);
|
|
2811
|
-
const data = readVecInt(vec);
|
|
2812
|
-
vec.delete();
|
|
2813
|
-
const map = {};
|
|
2814
|
-
for (let i = 0; i + 1 < data.length; i += 2) {
|
|
2815
|
-
const edgeHash = data[i];
|
|
2816
|
-
const faceHash = data[i + 1];
|
|
2817
|
-
if (!map[edgeHash]) map[edgeHash] = [];
|
|
2818
|
-
map[edgeHash].push(faceHash);
|
|
2819
|
-
}
|
|
2820
|
-
return JSON.stringify(map);
|
|
2821
|
-
}
|
|
2822
|
-
sharedEdges(faceA, faceB) {
|
|
2823
|
-
const vec = this.k.sharedEdges(unwrap(faceA), unwrap(faceB));
|
|
2824
|
-
const results = [];
|
|
2825
|
-
const n = vec.size();
|
|
2826
|
-
for (let i = 0; i < n; i++) results.push(handle("edge", vec.get(i)));
|
|
2827
|
-
vec.delete();
|
|
2828
|
-
return results;
|
|
2829
|
-
}
|
|
2830
|
-
adjacentFaces(shape, face) {
|
|
2831
|
-
const vec = this.k.adjacentFaces(unwrap(shape), unwrap(face));
|
|
2832
|
-
const results = [];
|
|
2833
|
-
const n = vec.size();
|
|
2834
|
-
for (let i = 0; i < n; i++) results.push(handle("face", vec.get(i)));
|
|
2835
|
-
vec.delete();
|
|
2836
|
-
return results;
|
|
2837
|
-
}
|
|
2838
|
-
sew(shapes, tolerance) {
|
|
2839
|
-
const vec = makeVecU32(this.Module, shapes.map(unwrap));
|
|
2840
|
-
try {
|
|
2841
|
-
return wrapResult(this.k, this.k.sew(vec, tolerance ?? 1e-6));
|
|
2842
|
-
} finally {
|
|
2843
|
-
vec.delete();
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
curveType(shape) {
|
|
2847
|
-
const t = this.k.curveType(unwrap(shape));
|
|
2848
|
-
return {
|
|
2849
|
-
line: "LINE",
|
|
2850
|
-
circle: "CIRCLE",
|
|
2851
|
-
ellipse: "ELLIPSE",
|
|
2852
|
-
hyperbola: "HYPERBOLA",
|
|
2853
|
-
parabola: "PARABOLA",
|
|
2854
|
-
bezier: "BEZIER_CURVE",
|
|
2855
|
-
bspline: "BSPLINE_CURVE",
|
|
2856
|
-
offset: "OFFSET_CURVE",
|
|
2857
|
-
other: "OTHER_CURVE"
|
|
2858
|
-
}[t] ?? t.toUpperCase();
|
|
2859
|
-
}
|
|
2860
|
-
curveParameters(shape) {
|
|
2861
|
-
const vec = this.k.curveParameters(unwrap(shape));
|
|
2862
|
-
const result = [vec.get(0), vec.get(1)];
|
|
2863
|
-
vec.delete();
|
|
2864
|
-
return result;
|
|
2865
|
-
}
|
|
2866
|
-
curvePointAtParam(shape, param) {
|
|
2867
|
-
const vec = this.k.curvePointAtParam(unwrap(shape), param);
|
|
2868
|
-
const result = [
|
|
2869
|
-
vec.get(0),
|
|
2870
|
-
vec.get(1),
|
|
2871
|
-
vec.get(2)
|
|
2872
|
-
];
|
|
2873
|
-
vec.delete();
|
|
2874
|
-
return result;
|
|
2875
|
-
}
|
|
2876
|
-
curveTangent(shape, param) {
|
|
2877
|
-
const tvec = this.k.curveTangent(unwrap(shape), param);
|
|
2878
|
-
const pvec = this.k.curvePointAtParam(unwrap(shape), param);
|
|
2879
|
-
const result = {
|
|
2880
|
-
point: [
|
|
2881
|
-
pvec.get(0),
|
|
2882
|
-
pvec.get(1),
|
|
2883
|
-
pvec.get(2)
|
|
2884
|
-
],
|
|
2885
|
-
tangent: [
|
|
2886
|
-
tvec.get(0),
|
|
2887
|
-
tvec.get(1),
|
|
2888
|
-
tvec.get(2)
|
|
2889
|
-
]
|
|
2890
|
-
};
|
|
2891
|
-
tvec.delete();
|
|
2892
|
-
pvec.delete();
|
|
2893
|
-
return result;
|
|
2894
|
-
}
|
|
2895
|
-
curveIsClosed(shape) {
|
|
2896
|
-
return this.k.curveIsClosed(unwrap(shape));
|
|
2897
|
-
}
|
|
2898
|
-
curveIsPeriodic(shape) {
|
|
2899
|
-
return this.k.curveIsPeriodic(unwrap(shape));
|
|
2900
|
-
}
|
|
2901
|
-
curvePeriod(_shape) {
|
|
2902
|
-
return 2 * Math.PI;
|
|
2903
|
-
}
|
|
2904
|
-
interpolatePoints(points, options) {
|
|
2905
|
-
const flat = [];
|
|
2906
|
-
for (const p of points) flat.push(p[0], p[1], p[2]);
|
|
2907
|
-
const vec = makeVecDouble(this.Module, flat);
|
|
2908
|
-
try {
|
|
2909
|
-
return handle("edge", this.k.interpolatePoints(vec, options?.periodic ?? false));
|
|
2910
|
-
} finally {
|
|
2911
|
-
vec.delete();
|
|
2912
|
-
}
|
|
2913
|
-
}
|
|
2914
|
-
approximatePoints(points, options) {
|
|
2915
|
-
const flat = [];
|
|
2916
|
-
for (const p of points) flat.push(p[0], p[1], p[2]);
|
|
2917
|
-
const vec = makeVecDouble(this.Module, flat);
|
|
2918
|
-
try {
|
|
2919
|
-
return handle("edge", this.k.approximatePoints(vec, options?.tolerance ?? .001));
|
|
2920
|
-
} finally {
|
|
2921
|
-
vec.delete();
|
|
2922
|
-
}
|
|
2923
|
-
}
|
|
2924
|
-
curveDegreeElevate(_edge, _elevateBy) {
|
|
2925
|
-
notImplemented("curveDegreeElevate");
|
|
2926
|
-
}
|
|
2927
|
-
curveKnotInsert(_edge, _knot, _times) {
|
|
2928
|
-
notImplemented("curveKnotInsert");
|
|
2929
|
-
}
|
|
2930
|
-
curveKnotRemove(_edge, _knot, _tolerance) {
|
|
2931
|
-
notImplemented("curveKnotRemove");
|
|
2932
|
-
}
|
|
2933
|
-
curveSplit(_edge, _param) {
|
|
2934
|
-
notImplemented("curveSplit");
|
|
2935
|
-
}
|
|
2936
|
-
createCurveAdaptor(_shape) {
|
|
2937
|
-
notImplemented("createCurveAdaptor");
|
|
2938
|
-
}
|
|
2939
|
-
getBezierPenultimatePole(_edge) {
|
|
2940
|
-
notImplemented("getBezierPenultimatePole");
|
|
2941
|
-
}
|
|
2942
|
-
vertexPosition(vertex) {
|
|
2943
|
-
const vec = this.k.vertexPosition(unwrap(vertex));
|
|
2944
|
-
const result = [
|
|
2945
|
-
vec.get(0),
|
|
2946
|
-
vec.get(1),
|
|
2947
|
-
vec.get(2)
|
|
2948
|
-
];
|
|
2949
|
-
vec.delete();
|
|
2950
|
-
return result;
|
|
2951
|
-
}
|
|
2952
|
-
surfaceType(face) {
|
|
2953
|
-
return this.k.surfaceType(unwrap(face)).toLowerCase();
|
|
2954
|
-
}
|
|
2955
|
-
uvBounds(face) {
|
|
2956
|
-
const vec = this.k.uvBounds(unwrap(face));
|
|
2957
|
-
const result = {
|
|
2958
|
-
uMin: vec.get(0),
|
|
2959
|
-
uMax: vec.get(1),
|
|
2960
|
-
vMin: vec.get(2),
|
|
2961
|
-
vMax: vec.get(3)
|
|
2962
|
-
};
|
|
2963
|
-
vec.delete();
|
|
2964
|
-
return result;
|
|
2965
|
-
}
|
|
2966
|
-
outerWire(face) {
|
|
2967
|
-
return handle("wire", this.k.outerWire(unwrap(face)));
|
|
2968
|
-
}
|
|
2969
|
-
surfaceNormal(face, u, v) {
|
|
2970
|
-
const vec = this.k.surfaceNormal(unwrap(face), u, v);
|
|
2971
|
-
const result = [
|
|
2972
|
-
vec.get(0),
|
|
2973
|
-
vec.get(1),
|
|
2974
|
-
vec.get(2)
|
|
2975
|
-
];
|
|
2976
|
-
vec.delete();
|
|
2977
|
-
return result;
|
|
2978
|
-
}
|
|
2979
|
-
pointOnSurface(face, u, v) {
|
|
2980
|
-
const vec = this.k.pointOnSurface(unwrap(face), u, v);
|
|
2981
|
-
const result = [
|
|
2982
|
-
vec.get(0),
|
|
2983
|
-
vec.get(1),
|
|
2984
|
-
vec.get(2)
|
|
2985
|
-
];
|
|
2986
|
-
vec.delete();
|
|
2987
|
-
return result;
|
|
2988
|
-
}
|
|
2989
|
-
uvFromPoint(face, point) {
|
|
2990
|
-
const vec = this.k.uvFromPoint(unwrap(face), point[0], point[1], point[2]);
|
|
2991
|
-
if (vec.size() < 2) {
|
|
2992
|
-
vec.delete();
|
|
2993
|
-
return null;
|
|
2994
|
-
}
|
|
2995
|
-
const result = [vec.get(0), vec.get(1)];
|
|
2996
|
-
vec.delete();
|
|
2997
|
-
return result;
|
|
2998
|
-
}
|
|
2999
|
-
projectPointOnFace(face, point) {
|
|
3000
|
-
const vec = this.k.projectPointOnFace(unwrap(face), point[0], point[1], point[2]);
|
|
3001
|
-
const result = [
|
|
3002
|
-
vec.get(0),
|
|
3003
|
-
vec.get(1),
|
|
3004
|
-
vec.get(2)
|
|
3005
|
-
];
|
|
3006
|
-
vec.delete();
|
|
3007
|
-
return result;
|
|
3008
|
-
}
|
|
3009
|
-
classifyPointOnFace(face, u, v, _tolerance) {
|
|
3010
|
-
return this.k.classifyPointOnFace(unwrap(face), u, v).toLowerCase();
|
|
3011
|
-
}
|
|
3012
|
-
classifyPointRobust(_shape, _point, _tolerance) {
|
|
3013
|
-
notImplemented("classifyPointRobust");
|
|
3014
|
-
}
|
|
3015
|
-
classifyPointWinding(_shape, _point, _tolerance) {
|
|
3016
|
-
notImplemented("classifyPointWinding");
|
|
3017
|
-
}
|
|
3018
|
-
approximateSurfaceLspia(_coords, _rows, _cols, _degreeU, _degreeV, _numCpsU, _numCpsV, _tolerance, _maxIterations) {
|
|
3019
|
-
notImplemented("approximateSurfaceLspia");
|
|
3020
|
-
}
|
|
3021
|
-
untrimFace(_face, _samplesPerCurve, _interiorSamples) {
|
|
3022
|
-
notImplemented("untrimFace");
|
|
3023
|
-
}
|
|
3024
|
-
getSurfaceCylinderData(_surface) {
|
|
3025
|
-
notImplemented("getSurfaceCylinderData");
|
|
3026
|
-
}
|
|
3027
|
-
reverseSurfaceU(_surface) {
|
|
3028
|
-
notImplemented("reverseSurfaceU");
|
|
3029
|
-
}
|
|
3030
|
-
detectSmallFeatures(_shape, _areaThreshold, _tolerance) {
|
|
3031
|
-
notImplemented("detectSmallFeatures");
|
|
3032
|
-
}
|
|
3033
|
-
recognizeFeatures(_shape, _tolerance) {
|
|
3034
|
-
notImplemented("recognizeFeatures");
|
|
3035
|
-
}
|
|
3036
|
-
projectEdges(shape, cameraOrigin, cameraDirection, cameraXAxis) {
|
|
3037
|
-
const [ox, oy, oz] = cameraOrigin;
|
|
3038
|
-
const [dx, dy, dz] = cameraDirection;
|
|
3039
|
-
const hasXAxis = !!cameraXAxis;
|
|
3040
|
-
const [xx, xy, xz] = cameraXAxis ?? [
|
|
3041
|
-
1,
|
|
3042
|
-
0,
|
|
3043
|
-
0
|
|
3044
|
-
];
|
|
3045
|
-
const proj = this.k.projectEdges(unwrap(shape), ox, oy, oz, dx, dy, dz, xx, xy, xz, hasXAxis);
|
|
3046
|
-
const wrapOrNull = (id) => id === 0 ? handle("compound", this.k.makeCompound(new this.Module.VectorUint32())) : handle("compound", id);
|
|
3047
|
-
return {
|
|
3048
|
-
visible: {
|
|
3049
|
-
outline: wrapOrNull(proj.visibleOutline),
|
|
3050
|
-
smooth: wrapOrNull(proj.visibleSmooth),
|
|
3051
|
-
sharp: wrapOrNull(proj.visibleSharp)
|
|
3052
|
-
},
|
|
3053
|
-
hidden: {
|
|
3054
|
-
outline: wrapOrNull(proj.hiddenOutline),
|
|
3055
|
-
smooth: wrapOrNull(proj.hiddenSmooth),
|
|
3056
|
-
sharp: wrapOrNull(proj.hiddenSharp)
|
|
3057
|
-
}
|
|
3058
|
-
};
|
|
3059
|
-
}
|
|
3060
|
-
isValid(shape) {
|
|
3061
|
-
return this.k.isValid(unwrap(shape));
|
|
3062
|
-
}
|
|
3063
|
-
healSolid(shape) {
|
|
3064
|
-
const id = this.k.healSolid(unwrap(shape), 1e-6);
|
|
3065
|
-
if (id === 0) return null;
|
|
3066
|
-
return wrapResult(this.k, id);
|
|
3067
|
-
}
|
|
3068
|
-
healFace(shape) {
|
|
3069
|
-
return wrapResult(this.k, this.k.healFace(unwrap(shape), 1e-6));
|
|
3070
|
-
}
|
|
3071
|
-
healWire(wire, _face) {
|
|
3072
|
-
return wrapResult(this.k, this.k.healWire(unwrap(wire), 1e-6));
|
|
3073
|
-
}
|
|
3074
|
-
mergeCoincidentVertices(_shape, _tolerance) {
|
|
3075
|
-
return 0;
|
|
3076
|
-
}
|
|
3077
|
-
removeDegenerateEdges(shape, _tolerance) {
|
|
3078
|
-
this.k.removeDegenerateEdges(unwrap(shape));
|
|
3079
|
-
return 0;
|
|
3080
|
-
}
|
|
3081
|
-
fixFaceOrientations(shape) {
|
|
3082
|
-
this.k.fixFaceOrientations(unwrap(shape));
|
|
3083
|
-
return 0;
|
|
3084
|
-
}
|
|
3085
|
-
fixShape(shape) {
|
|
3086
|
-
return wrapResult(this.k, this.k.fixShape(unwrap(shape)));
|
|
3087
|
-
}
|
|
3088
|
-
fixSelfIntersection(_wire) {
|
|
3089
|
-
notImplemented("fixSelfIntersection");
|
|
3090
|
-
}
|
|
3091
|
-
createPoint2d(x, y) {
|
|
3092
|
-
return {
|
|
3093
|
-
x,
|
|
3094
|
-
y
|
|
3095
|
-
};
|
|
3096
|
-
}
|
|
3097
|
-
createDirection2d(x, y) {
|
|
3098
|
-
const l = Math.sqrt(x * x + y * y);
|
|
3099
|
-
if (l < 1e-15) throw new Error("occt-wasm: createDirection2d called with zero-length vector");
|
|
3100
|
-
return {
|
|
3101
|
-
x: x / l,
|
|
3102
|
-
y: y / l
|
|
3103
|
-
};
|
|
3104
|
-
}
|
|
3105
|
-
createVector2d(x, y) {
|
|
3106
|
-
return {
|
|
3107
|
-
x,
|
|
3108
|
-
y
|
|
3109
|
-
};
|
|
3110
|
-
}
|
|
3111
|
-
createAxis2d(px, py, dx, dy) {
|
|
3112
|
-
return {
|
|
3113
|
-
px,
|
|
3114
|
-
py,
|
|
3115
|
-
dx,
|
|
3116
|
-
dy,
|
|
3117
|
-
delete() {}
|
|
3118
|
-
};
|
|
3119
|
-
}
|
|
3120
|
-
wrapCurve2dHandle(handle) {
|
|
3121
|
-
return handle;
|
|
3122
|
-
}
|
|
3123
|
-
createCurve2dAdaptor(_handle) {
|
|
3124
|
-
notImplemented("createCurve2dAdaptor");
|
|
3125
|
-
}
|
|
3126
|
-
makeLine2d(x1, y1, x2, y2) {
|
|
3127
|
-
return c2dWrap(makeLine2d(x1, y1, x2, y2));
|
|
3128
|
-
}
|
|
3129
|
-
makeCircle2d(cx, cy, radius, sense) {
|
|
3130
|
-
return c2dWrap(makeCircle2d(cx, cy, radius, sense));
|
|
3131
|
-
}
|
|
3132
|
-
makeArc2dThreePoints(x1, y1, xm, ym, x2, y2) {
|
|
3133
|
-
const d = 2 * (x1 * (ym - y2) + xm * (y2 - y1) + x2 * (y1 - ym));
|
|
3134
|
-
if (Math.abs(d) < 1e-12) return c2dWrap(makeLine2d(x1, y1, x2, y2));
|
|
3135
|
-
const cx = ((x1 * x1 + y1 * y1) * (ym - y2) + (xm * xm + ym * ym) * (y2 - y1) + (x2 * x2 + y2 * y2) * (y1 - ym)) / d;
|
|
3136
|
-
const cy = ((x1 * x1 + y1 * y1) * (x2 - xm) + (xm * xm + ym * ym) * (x1 - x2) + (x2 * x2 + y2 * y2) * (xm - x1)) / d;
|
|
3137
|
-
const radius = Math.sqrt((x1 - cx) ** 2 + (y1 - cy) ** 2);
|
|
3138
|
-
const a1 = Math.atan2(y1 - cy, x1 - cx);
|
|
3139
|
-
const am = Math.atan2(ym - cy, xm - cx);
|
|
3140
|
-
const a2 = Math.atan2(y2 - cy, x2 - cx);
|
|
3141
|
-
let da1m = am - a1;
|
|
3142
|
-
if (da1m < 0) da1m += 2 * Math.PI;
|
|
3143
|
-
let da12 = a2 - a1;
|
|
3144
|
-
if (da12 < 0) da12 += 2 * Math.PI;
|
|
3145
|
-
const sense = da1m < da12;
|
|
3146
|
-
const circle = makeCircle2d(cx, cy, radius, sense);
|
|
3147
|
-
if (!sense) {
|
|
3148
|
-
const tStart = -a1;
|
|
3149
|
-
let tEnd = -a2;
|
|
3150
|
-
if (tEnd < tStart - 1e-9) tEnd += 2 * Math.PI;
|
|
3151
|
-
return c2dWrap({
|
|
3152
|
-
__bk2d: "trimmed",
|
|
3153
|
-
basis: circle,
|
|
3154
|
-
tStart,
|
|
3155
|
-
tEnd
|
|
3156
|
-
});
|
|
3157
|
-
}
|
|
3158
|
-
let tEnd = a2;
|
|
3159
|
-
if (tEnd < a1 - 1e-9) tEnd += 2 * Math.PI;
|
|
3160
|
-
return c2dWrap({
|
|
3161
|
-
__bk2d: "trimmed",
|
|
3162
|
-
basis: circle,
|
|
3163
|
-
tStart: a1,
|
|
3164
|
-
tEnd
|
|
3165
|
-
});
|
|
3166
|
-
}
|
|
3167
|
-
makeArc2dTangent(startX, startY, tangentX, tangentY, endX, endY) {
|
|
3168
|
-
const len = Math.sqrt(tangentX * tangentX + tangentY * tangentY);
|
|
3169
|
-
const ntx = len > 0 ? tangentX / len : 0;
|
|
3170
|
-
const nty = len > 0 ? tangentY / len : 0;
|
|
3171
|
-
const dx = startX - endX;
|
|
3172
|
-
const dy = startY - endY;
|
|
3173
|
-
const denom = 2 * (dy * ntx - dx * nty);
|
|
3174
|
-
if (Math.abs(denom) < 1e-12) return c2dWrap(makeLine2d(startX, startY, endX, endY));
|
|
3175
|
-
const t = -(dx * dx + dy * dy) / denom;
|
|
3176
|
-
const cx = startX - t * nty;
|
|
3177
|
-
const cy = startY + t * ntx;
|
|
3178
|
-
const radius = Math.abs(t);
|
|
3179
|
-
const a1 = Math.atan2(startY - cy, startX - cx);
|
|
3180
|
-
const a2 = Math.atan2(endY - cy, endX - cx);
|
|
3181
|
-
const ccwTanX = -(startY - cy) / radius;
|
|
3182
|
-
const ccwTanY = (startX - cx) / radius;
|
|
3183
|
-
const sense = ccwTanX * ntx + ccwTanY * nty > 0;
|
|
3184
|
-
const circle = makeCircle2d(cx, cy, radius, sense);
|
|
3185
|
-
if (!sense) {
|
|
3186
|
-
const tStart = -a1;
|
|
3187
|
-
let tEnd = -a2;
|
|
3188
|
-
if (tEnd < tStart - 1e-9) tEnd += 2 * Math.PI;
|
|
3189
|
-
return c2dWrap({
|
|
3190
|
-
__bk2d: "trimmed",
|
|
3191
|
-
basis: circle,
|
|
3192
|
-
tStart,
|
|
3193
|
-
tEnd
|
|
3194
|
-
});
|
|
3195
|
-
}
|
|
3196
|
-
let tEnd = a2;
|
|
3197
|
-
if (tEnd < a1 - 1e-9) tEnd += 2 * Math.PI;
|
|
3198
|
-
return c2dWrap({
|
|
3199
|
-
__bk2d: "trimmed",
|
|
3200
|
-
basis: circle,
|
|
3201
|
-
tStart: a1,
|
|
3202
|
-
tEnd
|
|
3203
|
-
});
|
|
3204
|
-
}
|
|
3205
|
-
makeEllipse2d(cx, cy, majorRadius, minorRadius, xDirX, xDirY, sense) {
|
|
3206
|
-
return c2dWrap(makeEllipse2d(cx, cy, majorRadius, minorRadius, xDirX ?? 1, xDirY ?? 0, sense ?? true));
|
|
3207
|
-
}
|
|
3208
|
-
makeEllipseArc2d(cx, cy, majorRadius, minorRadius, startAngle, endAngle, xDirX, xDirY, sense) {
|
|
3209
|
-
return c2dWrap({
|
|
3210
|
-
...makeEllipse2d(cx, cy, majorRadius, minorRadius, xDirX ?? 1, xDirY ?? 0, sense ?? true),
|
|
3211
|
-
__bk2d: "ellipse",
|
|
3212
|
-
startAngle,
|
|
3213
|
-
endAngle
|
|
3214
|
-
});
|
|
3215
|
-
}
|
|
3216
|
-
makeBezier2d(points) {
|
|
3217
|
-
return c2dWrap(makeBezier2d(points));
|
|
3218
|
-
}
|
|
3219
|
-
makeBSpline2d(points, _options) {
|
|
3220
|
-
if (points.length <= 25) return c2dWrap(makeBezier2d(points));
|
|
3221
|
-
const step = Math.max(1, Math.floor(points.length / 24));
|
|
3222
|
-
return c2dWrap(makeBezier2d(points.filter((_, i) => i % step === 0 || i === points.length - 1)));
|
|
3223
|
-
}
|
|
3224
|
-
evaluateCurve2d(curve, param) {
|
|
3225
|
-
return evaluateCurve2d(c2d(curve), param);
|
|
3226
|
-
}
|
|
3227
|
-
evaluateCurve2dD1(curve, param) {
|
|
3228
|
-
return {
|
|
3229
|
-
point: evaluateCurve2d(c2d(curve), param),
|
|
3230
|
-
tangent: tangentCurve2d(c2d(curve), param)
|
|
3231
|
-
};
|
|
3232
|
-
}
|
|
3233
|
-
getCurve2dBounds(curve) {
|
|
3234
|
-
return curveBounds(c2d(curve));
|
|
3235
|
-
}
|
|
3236
|
-
getCurve2dType(curve) {
|
|
3237
|
-
let cu = c2d(curve);
|
|
3238
|
-
while (cu.__bk2d === "trimmed" && cu.basis) cu = cu.basis;
|
|
3239
|
-
return curveTypeName(cu);
|
|
3240
|
-
}
|
|
3241
|
-
trimCurve2d(curve, start, end) {
|
|
3242
|
-
return c2dWrap({
|
|
3243
|
-
__bk2d: "trimmed",
|
|
3244
|
-
basis: c2d(curve),
|
|
3245
|
-
tStart: start,
|
|
3246
|
-
tEnd: end
|
|
3247
|
-
});
|
|
3248
|
-
}
|
|
3249
|
-
reverseCurve2d(_curve) {}
|
|
3250
|
-
copyCurve2d(curve) {
|
|
3251
|
-
return c2dWrap(JSON.parse(JSON.stringify(c2d(curve))));
|
|
3252
|
-
}
|
|
3253
|
-
offsetCurve2d(curve, offset) {
|
|
3254
|
-
const c = c2d(curve);
|
|
3255
|
-
const bounds = curveBounds(c);
|
|
3256
|
-
const pts = [];
|
|
3257
|
-
for (let i = 0; i <= 20; i++) {
|
|
3258
|
-
const t = bounds.first + (bounds.last - bounds.first) * i / 20;
|
|
3259
|
-
const [px, py] = evaluateCurve2d(c, t);
|
|
3260
|
-
const [tx, ty] = tangentCurve2d(c, t);
|
|
3261
|
-
const len = Math.sqrt(tx * tx + ty * ty) || 1;
|
|
3262
|
-
pts.push([px - ty / len * offset, py + tx / len * offset]);
|
|
3263
|
-
}
|
|
3264
|
-
return c2dWrap(makeBezier2d(pts.length <= 25 ? pts : pts.filter((_, i) => i % 2 === 0 || i === pts.length - 1)));
|
|
3265
|
-
}
|
|
3266
|
-
translateCurve2d(curve, dx, dy) {
|
|
3267
|
-
return c2dWrap(translateCurve2d(c2d(curve), dx, dy));
|
|
3268
|
-
}
|
|
3269
|
-
rotateCurve2d(curve, angle, cx, cy) {
|
|
3270
|
-
return c2dWrap(rotateCurve2d(c2d(curve), angle, cx, cy));
|
|
3271
|
-
}
|
|
3272
|
-
scaleCurve2d(curve, factor, cx, cy) {
|
|
3273
|
-
const result = scaleCurve2d(c2d(curve), factor, cx, cy);
|
|
3274
|
-
const r = result;
|
|
3275
|
-
if (r.__bk2d === "line" && typeof r.len === "number") r.len = r.len * Math.abs(factor);
|
|
3276
|
-
return c2dWrap(result);
|
|
3277
|
-
}
|
|
3278
|
-
mirrorCurve2dAtPoint(curve, cx, cy) {
|
|
3279
|
-
return c2dWrap(mirrorAtPoint(c2d(curve), cx, cy));
|
|
3280
|
-
}
|
|
3281
|
-
mirrorCurve2dAcrossAxis(curve, originX, originY, dirX, dirY) {
|
|
3282
|
-
return c2dWrap(mirrorAcrossAxis(c2d(curve), originX, originY, dirX, dirY));
|
|
3283
|
-
}
|
|
3284
|
-
affinityTransform2d(_curve, _axisOriginX, _axisOriginY, _axisDirX, _axisDirY, _ratio) {
|
|
3285
|
-
return _curve;
|
|
3286
|
-
}
|
|
3287
|
-
createIdentityGTrsf2d() {
|
|
3288
|
-
return {
|
|
3289
|
-
type: "identity2d",
|
|
3290
|
-
delete() {}
|
|
3291
|
-
};
|
|
3292
|
-
}
|
|
3293
|
-
createAffinityGTrsf2d(originX, originY, dirX, dirY, ratio) {
|
|
3294
|
-
return {
|
|
3295
|
-
type: "affinity2d",
|
|
3296
|
-
axOriginX: originX,
|
|
3297
|
-
axOriginY: originY,
|
|
3298
|
-
axDirX: dirX,
|
|
3299
|
-
axDirY: dirY,
|
|
3300
|
-
ratio,
|
|
3301
|
-
delete() {}
|
|
3302
|
-
};
|
|
3303
|
-
}
|
|
3304
|
-
createTranslationGTrsf2d(dx, dy) {
|
|
3305
|
-
return {
|
|
3306
|
-
type: "translate2d",
|
|
3307
|
-
dx,
|
|
3308
|
-
dy,
|
|
3309
|
-
delete() {}
|
|
3310
|
-
};
|
|
3311
|
-
}
|
|
3312
|
-
createMirrorGTrsf2d(cx, cy, mode, originX, originY, dirX, dirY) {
|
|
3313
|
-
return {
|
|
3314
|
-
type: "mirror2d",
|
|
3315
|
-
cx,
|
|
3316
|
-
cy,
|
|
3317
|
-
mode,
|
|
3318
|
-
originX,
|
|
3319
|
-
originY,
|
|
3320
|
-
dirX,
|
|
3321
|
-
dirY,
|
|
3322
|
-
delete() {}
|
|
3323
|
-
};
|
|
3324
|
-
}
|
|
3325
|
-
createRotationGTrsf2d(angle, cx, cy) {
|
|
3326
|
-
return {
|
|
3327
|
-
type: "rotate2d",
|
|
3328
|
-
angle,
|
|
3329
|
-
cx,
|
|
3330
|
-
cy,
|
|
3331
|
-
delete() {}
|
|
3332
|
-
};
|
|
3333
|
-
}
|
|
3334
|
-
createScaleGTrsf2d(factor, cx, cy) {
|
|
3335
|
-
return {
|
|
3336
|
-
type: "scale2d",
|
|
3337
|
-
sx: factor,
|
|
3338
|
-
sy: factor,
|
|
3339
|
-
cx,
|
|
3340
|
-
cy,
|
|
3341
|
-
delete() {}
|
|
3342
|
-
};
|
|
3343
|
-
}
|
|
3344
|
-
setGTrsf2dTranslationPart(gtrsf, dx, dy) {
|
|
3345
|
-
const t = gtrsf;
|
|
3346
|
-
t["dx"] = (Number(t["dx"]) || 0) + dx;
|
|
3347
|
-
t["dy"] = (Number(t["dy"]) || 0) + dy;
|
|
3348
|
-
}
|
|
3349
|
-
multiplyGTrsf2d(base, other) {
|
|
3350
|
-
const b = base;
|
|
3351
|
-
const o = other;
|
|
3352
|
-
b["dx"] = (Number(b["dx"]) || 0) + (Number(o["dx"]) || 0);
|
|
3353
|
-
b["dy"] = (Number(b["dy"]) || 0) + (Number(o["dy"]) || 0);
|
|
3354
|
-
if (o["type"] === "scale2d") {
|
|
3355
|
-
b["type"] = "scale2d";
|
|
3356
|
-
b["sx"] = o["sx"];
|
|
3357
|
-
b["sy"] = o["sy"];
|
|
3358
|
-
}
|
|
3359
|
-
}
|
|
3360
|
-
transformCurve2dGeneral(curve, gtrsf) {
|
|
3361
|
-
const t = gtrsf;
|
|
3362
|
-
if (t["type"] === "translate2d") return this.translateCurve2d(curve, t["dx"] ?? 0, t["dy"] ?? 0);
|
|
3363
|
-
if (t["type"] === "rotate2d") return this.rotateCurve2d(curve, t["angle"] ?? 0, t["cx"] ?? 0, t["cy"] ?? 0);
|
|
3364
|
-
if (t["type"] === "scale2d") return this.scaleCurve2d(curve, t["sx"] ?? 1, t["cx"] ?? 0, t["cy"] ?? 0);
|
|
3365
|
-
if (t["type"] === "mirror2d") return this.mirrorCurve2dAtPoint(curve, t["ox"] ?? 0, t["oy"] ?? 0);
|
|
3366
|
-
if (t["type"] === "affinity2d") return this.scaleCurve2d(curve, Number(t["ratio"]) || 1, Number(t["axOriginX"]) || 0, Number(t["axOriginY"]) || 0);
|
|
3367
|
-
if (Number(t["dx"]) || Number(t["dy"])) return this.translateCurve2d(curve, Number(t["dx"]) || 0, Number(t["dy"]) || 0);
|
|
3368
|
-
return curve;
|
|
3369
|
-
}
|
|
3370
|
-
intersectCurves2d(c1, c2, tolerance) {
|
|
3371
|
-
const result = intersectCurves2dFn(c2d(c1), c2d(c2), tolerance);
|
|
3372
|
-
return {
|
|
3373
|
-
points: result.points,
|
|
3374
|
-
segments: result.segments.map((s) => c2dWrap(s))
|
|
3375
|
-
};
|
|
3376
|
-
}
|
|
3377
|
-
projectPointOnCurve2d(curve, x, y) {
|
|
3378
|
-
const c = c2d(curve);
|
|
3379
|
-
const bounds = curveBounds(c);
|
|
3380
|
-
const projectOnBasis = (basis, bFirst, bLast) => {
|
|
3381
|
-
if (basis.__bk2d === "line") {
|
|
3382
|
-
const rawT = (x - basis.ox) * basis.dx + (y - basis.oy) * basis.dy;
|
|
3383
|
-
const t = Math.max(bFirst, Math.min(bLast, rawT));
|
|
3384
|
-
const [px, py] = evaluateCurve2d(basis, t);
|
|
3385
|
-
return {
|
|
3386
|
-
param: t,
|
|
3387
|
-
distance: Math.sqrt((px - x) ** 2 + (py - y) ** 2)
|
|
3388
|
-
};
|
|
3389
|
-
}
|
|
3390
|
-
const N = 200;
|
|
3391
|
-
let bestT = bFirst;
|
|
3392
|
-
let bestDist = Infinity;
|
|
3393
|
-
for (let i = 0; i <= N; i++) {
|
|
3394
|
-
const t = bFirst + (bLast - bFirst) * i / N;
|
|
3395
|
-
const [px, py] = evaluateCurve2d(basis, t);
|
|
3396
|
-
const d = (px - x) ** 2 + (py - y) ** 2;
|
|
3397
|
-
if (d < bestDist) {
|
|
3398
|
-
bestDist = d;
|
|
3399
|
-
bestT = t;
|
|
3400
|
-
}
|
|
3401
|
-
}
|
|
3402
|
-
return {
|
|
3403
|
-
param: bestT,
|
|
3404
|
-
distance: Math.sqrt(bestDist)
|
|
3405
|
-
};
|
|
3406
|
-
};
|
|
3407
|
-
if (c.__bk2d === "trimmed" && c.basis) {
|
|
3408
|
-
const tStart = c.tStart;
|
|
3409
|
-
const tEnd = c.tEnd;
|
|
3410
|
-
const basisResult = projectOnBasis(c.basis, tStart, tEnd);
|
|
3411
|
-
if (!basisResult) return null;
|
|
3412
|
-
const range = tEnd - tStart;
|
|
3413
|
-
const trimmedT = range > 1e-15 ? (basisResult.param - tStart) / range : 0;
|
|
3414
|
-
return {
|
|
3415
|
-
param: Math.max(0, Math.min(1, trimmedT)),
|
|
3416
|
-
distance: basisResult.distance
|
|
3417
|
-
};
|
|
3418
|
-
}
|
|
3419
|
-
return projectOnBasis(c, bounds.first, bounds.last);
|
|
3420
|
-
}
|
|
3421
|
-
distanceBetweenCurves2d(c1, c2, p1Start, p1End, p2Start, p2End) {
|
|
3422
|
-
const n = 20;
|
|
3423
|
-
let minDist = Infinity;
|
|
3424
|
-
for (let i = 0; i <= n; i++) {
|
|
3425
|
-
const t1 = p1Start + (p1End - p1Start) * (i / n);
|
|
3426
|
-
const [x1, y1] = evaluateCurve2d(c2d(c1), t1);
|
|
3427
|
-
for (let j = 0; j <= n; j++) {
|
|
3428
|
-
const t2 = p2Start + (p2End - p2Start) * (j / n);
|
|
3429
|
-
const [x2, y2] = evaluateCurve2d(c2d(c2), t2);
|
|
3430
|
-
const d = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
|
|
3431
|
-
if (d < minDist) minDist = d;
|
|
3432
|
-
}
|
|
3433
|
-
}
|
|
3434
|
-
return minDist;
|
|
3435
|
-
}
|
|
3436
|
-
approximateCurve2dAsBSpline(curve, _tolerance, _continuity, maxSegments) {
|
|
3437
|
-
const cu = c2d(curve);
|
|
3438
|
-
const bounds = curveBounds(cu);
|
|
3439
|
-
const nPts = Math.min(Math.max(maxSegments + 1, 10), 100);
|
|
3440
|
-
const poles = [];
|
|
3441
|
-
for (let i = 0; i < nPts; i++) {
|
|
3442
|
-
const t = bounds.first + (bounds.last - bounds.first) * i / (nPts - 1);
|
|
3443
|
-
poles.push(evaluateCurve2d(cu, t));
|
|
3444
|
-
}
|
|
3445
|
-
const degree = Math.min(3, nPts - 1);
|
|
3446
|
-
const n = poles.length;
|
|
3447
|
-
const knots = [];
|
|
3448
|
-
const mults = [];
|
|
3449
|
-
const nInternalKnots = n - degree - 1;
|
|
3450
|
-
knots.push(0);
|
|
3451
|
-
mults.push(degree + 1);
|
|
3452
|
-
for (let i = 1; i <= nInternalKnots; i++) {
|
|
3453
|
-
knots.push(i / (nInternalKnots + 1));
|
|
3454
|
-
mults.push(1);
|
|
3455
|
-
}
|
|
3456
|
-
knots.push(1);
|
|
3457
|
-
mults.push(degree + 1);
|
|
3458
|
-
return c2dWrap({
|
|
3459
|
-
__bk2d: "bspline",
|
|
3460
|
-
poles,
|
|
3461
|
-
knots,
|
|
3462
|
-
multiplicities: mults,
|
|
3463
|
-
degree,
|
|
3464
|
-
isPeriodic: false
|
|
3465
|
-
});
|
|
3466
|
-
}
|
|
3467
|
-
decomposeBSpline2dToBeziers(curve) {
|
|
3468
|
-
const knots = c2d(curve).knots ?? [];
|
|
3469
|
-
if (knots.length < 2) return [curve];
|
|
3470
|
-
const result = [];
|
|
3471
|
-
for (let i = 0; i < knots.length - 1; i++) {
|
|
3472
|
-
const k0 = knots[i];
|
|
3473
|
-
const k1 = knots[i + 1];
|
|
3474
|
-
if (Math.abs(k1 - k0) < 1e-15) continue;
|
|
3475
|
-
result.push(this.trimCurve2d(curve, k0, k1));
|
|
3476
|
-
}
|
|
3477
|
-
return result.length > 0 ? result : [curve];
|
|
3478
|
-
}
|
|
3479
|
-
createBoundingBox2d() {
|
|
3480
|
-
return createBBox2d();
|
|
3481
|
-
}
|
|
3482
|
-
addCurveToBBox2d(bbox, curve, tolerance) {
|
|
3483
|
-
addCurveToBBox(bbox, c2d(curve), tolerance);
|
|
3484
|
-
}
|
|
3485
|
-
getBBox2dBounds(bbox) {
|
|
3486
|
-
const b = bbox;
|
|
3487
|
-
return {
|
|
3488
|
-
xMin: b.xMin,
|
|
3489
|
-
yMin: b.yMin,
|
|
3490
|
-
xMax: b.xMax,
|
|
3491
|
-
yMax: b.yMax
|
|
3492
|
-
};
|
|
3493
|
-
}
|
|
3494
|
-
mergeBBox2d(target, other) {
|
|
3495
|
-
const t = target;
|
|
3496
|
-
const o = other;
|
|
3497
|
-
t.xMin = Math.min(t.xMin, o.xMin);
|
|
3498
|
-
t.yMin = Math.min(t.yMin, o.yMin);
|
|
3499
|
-
t.xMax = Math.max(t.xMax, o.xMax);
|
|
3500
|
-
t.yMax = Math.max(t.yMax, o.yMax);
|
|
3501
|
-
}
|
|
3502
|
-
isBBox2dOut(a, b) {
|
|
3503
|
-
const ba = a;
|
|
3504
|
-
const bb = b;
|
|
3505
|
-
return ba.xMax < bb.xMin || ba.xMin > bb.xMax || ba.yMax < bb.yMin || ba.yMin > bb.yMax;
|
|
3506
|
-
}
|
|
3507
|
-
isBBox2dOutPoint(bbox, x, y) {
|
|
3508
|
-
const b = bbox;
|
|
3509
|
-
return x < b.xMin || x > b.xMax || y < b.yMin || y > b.yMax;
|
|
3510
|
-
}
|
|
3511
|
-
getCurve2dCircleData(curve) {
|
|
3512
|
-
let c = c2d(curve);
|
|
3513
|
-
while (c.__bk2d === "trimmed" && c.basis) c = c.basis;
|
|
3514
|
-
if (c.__bk2d === "circle") return {
|
|
3515
|
-
cx: c.cx,
|
|
3516
|
-
cy: c.cy,
|
|
3517
|
-
radius: c.radius,
|
|
3518
|
-
isDirect: c.sense !== false
|
|
3519
|
-
};
|
|
3520
|
-
return null;
|
|
3521
|
-
}
|
|
3522
|
-
getCurve2dEllipseData(curve) {
|
|
3523
|
-
let c = c2d(curve);
|
|
3524
|
-
while (c.__bk2d === "trimmed" && c.basis) c = c.basis;
|
|
3525
|
-
if (c.__bk2d === "ellipse") return {
|
|
3526
|
-
majorRadius: c.majorRadius,
|
|
3527
|
-
minorRadius: c.minorRadius,
|
|
3528
|
-
xAxisAngle: c.xDirAngle ?? 0,
|
|
3529
|
-
isDirect: c.sense !== false
|
|
3530
|
-
};
|
|
3531
|
-
return null;
|
|
3532
|
-
}
|
|
3533
|
-
getCurve2dBezierPoles(curve) {
|
|
3534
|
-
let c = c2d(curve);
|
|
3535
|
-
while (c.__bk2d === "trimmed" && c.basis) c = c.basis;
|
|
3536
|
-
if (c.__bk2d === "bezier" && Array.isArray(c.poles)) return c.poles;
|
|
3537
|
-
return null;
|
|
3538
|
-
}
|
|
3539
|
-
getCurve2dBezierDegree(curve) {
|
|
3540
|
-
let c = c2d(curve);
|
|
3541
|
-
while (c.__bk2d === "trimmed" && c.basis) c = c.basis;
|
|
3542
|
-
if (c["__bk2d"] === "bezier" && Array.isArray(c["poles"])) return c["poles"].length - 1;
|
|
3543
|
-
return null;
|
|
3544
|
-
}
|
|
3545
|
-
getCurve2dBSplineData(_curve) {
|
|
3546
|
-
notImplemented("getCurve2dBSplineData");
|
|
3547
|
-
}
|
|
3548
|
-
serializeCurve2d(curve) {
|
|
3549
|
-
return serializeCurve2d(c2d(curve));
|
|
3550
|
-
}
|
|
3551
|
-
deserializeCurve2d(data) {
|
|
3552
|
-
return c2dWrap(deserializeCurve2d(data));
|
|
3553
|
-
}
|
|
3554
|
-
splitCurve2d(curve, params) {
|
|
3555
|
-
const bounds = curveBounds(c2d(curve));
|
|
3556
|
-
const sorted = [
|
|
3557
|
-
bounds.first,
|
|
3558
|
-
...params.sort((a, b) => a - b),
|
|
3559
|
-
bounds.last
|
|
3560
|
-
];
|
|
3561
|
-
const result = [];
|
|
3562
|
-
for (let i = 0; i < sorted.length - 1; i++) {
|
|
3563
|
-
const start = sorted[i] ?? bounds.first;
|
|
3564
|
-
const end = sorted[i + 1] ?? bounds.last;
|
|
3565
|
-
result.push(this.trimCurve2d(curve, start, end));
|
|
3566
|
-
}
|
|
3567
|
-
return result;
|
|
3568
|
-
}
|
|
3569
|
-
liftCurve2dToPlane(curve, planeOrigin, planeZ, planeX) {
|
|
3570
|
-
const cu = c2d(curve);
|
|
3571
|
-
const [ox, oy, oz] = planeOrigin;
|
|
3572
|
-
const [zx, zy, zz] = planeZ;
|
|
3573
|
-
const [xx, xy, xz] = planeX;
|
|
3574
|
-
const yx = zy * xz - zz * xy, yy = zz * xx - zx * xz, yz = zx * xy - zy * xx;
|
|
3575
|
-
const lift = (u, v) => [
|
|
3576
|
-
ox + u * xx + v * yx,
|
|
3577
|
-
oy + u * xy + v * yy,
|
|
3578
|
-
oz + u * xz + v * yz
|
|
3579
|
-
];
|
|
3580
|
-
const bk2dType = cu.__bk2d;
|
|
3581
|
-
if (bk2dType === "line") {
|
|
3582
|
-
const bounds = curveBounds(cu);
|
|
3583
|
-
const [u1, v1] = evaluateCurve2d(cu, bounds.first);
|
|
3584
|
-
const [u2, v2] = evaluateCurve2d(cu, bounds.last);
|
|
3585
|
-
const p1 = lift(u1, v1);
|
|
3586
|
-
const p2 = lift(u2, v2);
|
|
3587
|
-
return handle("edge", this.k.makeLineEdge(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]));
|
|
3588
|
-
}
|
|
3589
|
-
if (bk2dType === "trimmed") {
|
|
3590
|
-
const trimmed = cu;
|
|
3591
|
-
if (trimmed.basis && trimmed.basis.__bk2d === "line") {
|
|
3592
|
-
const [u1, v1] = evaluateCurve2d(cu, 0);
|
|
3593
|
-
const [u2, v2] = evaluateCurve2d(cu, 1);
|
|
3594
|
-
const p1 = lift(u1, v1);
|
|
3595
|
-
const p2 = lift(u2, v2);
|
|
3596
|
-
return handle("edge", this.k.makeLineEdge(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]));
|
|
3597
|
-
}
|
|
3598
|
-
if (trimmed.basis && trimmed.basis.__bk2d === "circle") {
|
|
3599
|
-
const bounds = curveBounds(cu);
|
|
3600
|
-
const [u1, v1] = evaluateCurve2d(cu, bounds.first);
|
|
3601
|
-
const [um, vm] = evaluateCurve2d(cu, (bounds.first + bounds.last) / 2);
|
|
3602
|
-
const [u2, v2] = evaluateCurve2d(cu, bounds.last);
|
|
3603
|
-
const p1 = lift(u1, v1);
|
|
3604
|
-
const pm = lift(um, vm);
|
|
3605
|
-
const p2 = lift(u2, v2);
|
|
3606
|
-
return handle("edge", this.k.makeArcEdge(p1[0], p1[1], p1[2], pm[0], pm[1], pm[2], p2[0], p2[1], p2[2]));
|
|
3607
|
-
}
|
|
3608
|
-
}
|
|
3609
|
-
if (bk2dType === "circle") {
|
|
3610
|
-
const circleData = cu;
|
|
3611
|
-
if (circleData.cx !== void 0 && circleData.radius !== void 0) {
|
|
3612
|
-
const [pcx, pcy, pcz] = lift(circleData.cx, circleData.cy);
|
|
3613
|
-
return handle("edge", this.k.makeCircleEdge(pcx, pcy, pcz, zx, zy, zz, circleData.radius));
|
|
3614
|
-
}
|
|
3615
|
-
const bounds = curveBounds(cu);
|
|
3616
|
-
const [u1, v1] = evaluateCurve2d(cu, bounds.first);
|
|
3617
|
-
const [um, vm] = evaluateCurve2d(cu, (bounds.first + bounds.last) / 2);
|
|
3618
|
-
const [u2, v2] = evaluateCurve2d(cu, bounds.last);
|
|
3619
|
-
const p1 = lift(u1, v1);
|
|
3620
|
-
const pm = lift(um, vm);
|
|
3621
|
-
const p2 = lift(u2, v2);
|
|
3622
|
-
return handle("edge", this.k.makeArcEdge(p1[0], p1[1], p1[2], pm[0], pm[1], pm[2], p2[0], p2[1], p2[2]));
|
|
3623
|
-
}
|
|
3624
|
-
const bounds = curveBounds(cu);
|
|
3625
|
-
const nSamples = 24;
|
|
3626
|
-
const dt = (bounds.last - bounds.first) / nSamples;
|
|
3627
|
-
const pts = [];
|
|
3628
|
-
for (let i = 0; i <= nSamples; i++) {
|
|
3629
|
-
const [u, v] = evaluateCurve2d(cu, bounds.first + i * dt);
|
|
3630
|
-
const [px, py, pz] = lift(u, v);
|
|
3631
|
-
pts.push(px, py, pz);
|
|
3632
|
-
}
|
|
3633
|
-
const vec = new this.Module.VectorDouble();
|
|
3634
|
-
for (const p of pts) vec.push_back(p);
|
|
3635
|
-
try {
|
|
3636
|
-
return handle("edge", this.k.interpolatePoints(vec, false));
|
|
3637
|
-
} finally {
|
|
3638
|
-
vec.delete();
|
|
3639
|
-
}
|
|
3640
|
-
}
|
|
3641
|
-
buildEdgeOnSurface(curve, surface) {
|
|
3642
|
-
const cu = c2d(curve);
|
|
3643
|
-
const bounds = curveBounds(cu);
|
|
3644
|
-
const faceId = unwrap(surface);
|
|
3645
|
-
const nSamples = 30;
|
|
3646
|
-
const vec = new this.Module.VectorDouble();
|
|
3647
|
-
for (let i = 0; i <= nSamples; i++) {
|
|
3648
|
-
const [u, v] = evaluateCurve2d(cu, bounds.first + (bounds.last - bounds.first) * i / nSamples);
|
|
3649
|
-
const pt = this.k.pointOnSurface(faceId, u, v);
|
|
3650
|
-
vec.push_back(pt.get(0));
|
|
3651
|
-
vec.push_back(pt.get(1));
|
|
3652
|
-
vec.push_back(pt.get(2));
|
|
3653
|
-
pt.delete();
|
|
3654
|
-
}
|
|
3655
|
-
try {
|
|
3656
|
-
return handle("edge", this.k.interpolatePoints(vec, false));
|
|
3657
|
-
} finally {
|
|
3658
|
-
vec.delete();
|
|
3659
|
-
}
|
|
3660
|
-
}
|
|
3661
|
-
extractSurfaceFromFace(face) {
|
|
3662
|
-
return face;
|
|
3663
|
-
}
|
|
3664
|
-
extractCurve2dFromEdge(_edge, _face) {
|
|
3665
|
-
return c2dWrap(makeLine2d(0, 0, 1, 0));
|
|
3666
|
-
}
|
|
3667
|
-
buildCurves3d(wire) {
|
|
3668
|
-
this.k.buildCurves3d(unwrap(wire));
|
|
3669
|
-
}
|
|
3670
|
-
fixWireOnFace(wire, face, tolerance) {
|
|
3671
|
-
return handle("wire", this.k.fixWireOnFace(unwrap(wire), unwrap(face), tolerance));
|
|
3672
|
-
}
|
|
3673
|
-
fillSurface(_wires, _options) {
|
|
3674
|
-
notImplemented("fillSurface");
|
|
3675
|
-
}
|
|
3676
|
-
getNurbsCurveData(edge) {
|
|
3677
|
-
try {
|
|
3678
|
-
const data = this.k.getNurbsCurveData(unwrap(edge));
|
|
3679
|
-
try {
|
|
3680
|
-
const nPoles = data.poles.size() / 3;
|
|
3681
|
-
const poles = [];
|
|
3682
|
-
for (let i = 0; i < nPoles; i++) poles.push([
|
|
3683
|
-
data.poles.get(i * 3),
|
|
3684
|
-
data.poles.get(i * 3 + 1),
|
|
3685
|
-
data.poles.get(i * 3 + 2)
|
|
3686
|
-
]);
|
|
3687
|
-
const knots = [];
|
|
3688
|
-
for (let i = 0; i < data.knots.size(); i++) knots.push(data.knots.get(i));
|
|
3689
|
-
const multiplicities = [];
|
|
3690
|
-
for (let i = 0; i < data.multiplicities.size(); i++) multiplicities.push(data.multiplicities.get(i));
|
|
3691
|
-
const weights = [];
|
|
3692
|
-
if (data.rational) for (let i = 0; i < data.weights.size(); i++) weights.push(data.weights.get(i));
|
|
3693
|
-
else for (let i = 0; i < nPoles; i++) weights.push(1);
|
|
3694
|
-
return {
|
|
3695
|
-
degree: data.degree,
|
|
3696
|
-
poles,
|
|
3697
|
-
weights,
|
|
3698
|
-
knots,
|
|
3699
|
-
multiplicities,
|
|
3700
|
-
isPeriodic: data.periodic,
|
|
3701
|
-
isRational: data.rational
|
|
3702
|
-
};
|
|
3703
|
-
} finally {
|
|
3704
|
-
data.delete();
|
|
3705
|
-
}
|
|
3706
|
-
} catch {
|
|
3707
|
-
return null;
|
|
3708
|
-
}
|
|
3709
|
-
}
|
|
3710
|
-
};
|
|
3711
|
-
function multiplyMatrices4x4(a, b) {
|
|
3712
|
-
const result = new Array(16).fill(0);
|
|
3713
|
-
for (let i = 0; i < 4; i++) for (let j = 0; j < 4; j++) for (let k = 0; k < 4; k++) result[i * 4 + j] = result[i * 4 + j] + a[i * 4 + k] * b[k * 4 + j];
|
|
3714
|
-
return result;
|
|
3715
|
-
}
|
|
3716
|
-
function findHorizonEdges(faces, visible) {
|
|
3717
|
-
const visSet = new Set(visible);
|
|
3718
|
-
const horizon = [];
|
|
3719
|
-
for (const fi of visible) {
|
|
3720
|
-
const f = faces[fi];
|
|
3721
|
-
for (let ei = 0; ei < 3; ei++) {
|
|
3722
|
-
const a = f[ei], b = f[(ei + 1) % 3];
|
|
3723
|
-
if (faces.some((g, fj) => fj !== fi && !visSet.has(fj) && [
|
|
3724
|
-
0,
|
|
3725
|
-
1,
|
|
3726
|
-
2
|
|
3727
|
-
].some((ej) => g[ej] === b && g[(ej + 1) % 3] === a))) horizon.push([a, b]);
|
|
3728
|
-
}
|
|
3729
|
-
}
|
|
3730
|
-
return horizon;
|
|
3731
|
-
}
|
|
3732
|
-
function computeConvexHullFaces(pts) {
|
|
3733
|
-
const cross = (a, b) => ({
|
|
3734
|
-
x: a.y * b.z - a.z * b.y,
|
|
3735
|
-
y: a.z * b.x - a.x * b.z,
|
|
3736
|
-
z: a.x * b.y - a.y * b.x
|
|
3737
|
-
});
|
|
3738
|
-
const sub = (a, b) => ({
|
|
3739
|
-
x: a.x - b.x,
|
|
3740
|
-
y: a.y - b.y,
|
|
3741
|
-
z: a.z - b.z
|
|
3742
|
-
});
|
|
3743
|
-
const dot = (a, b) => a.x * b.x + a.y * b.y + a.z * b.z;
|
|
3744
|
-
const n = pts.length;
|
|
3745
|
-
const faces = [];
|
|
3746
|
-
const p0 = pts[0];
|
|
3747
|
-
let i1 = 1;
|
|
3748
|
-
while (i1 < n && Math.hypot(pts[i1].x - p0.x, pts[i1].y - p0.y, pts[i1].z - p0.z) < 1e-10) i1++;
|
|
3749
|
-
let i2 = i1 + 1;
|
|
3750
|
-
const e01 = sub(pts[i1], p0);
|
|
3751
|
-
while (i2 < n) {
|
|
3752
|
-
const c = cross(e01, sub(pts[i2], p0));
|
|
3753
|
-
if (Math.hypot(c.x, c.y, c.z) > 1e-10) break;
|
|
3754
|
-
i2++;
|
|
3755
|
-
}
|
|
3756
|
-
let i3 = i2 + 1;
|
|
3757
|
-
const norm = cross(e01, sub(pts[i2], p0));
|
|
3758
|
-
while (i3 < n) {
|
|
3759
|
-
if (Math.abs(dot(norm, sub(pts[i3], p0))) > 1e-10) break;
|
|
3760
|
-
i3++;
|
|
3761
|
-
}
|
|
3762
|
-
if (i3 >= n) return [[
|
|
3763
|
-
0,
|
|
3764
|
-
1,
|
|
3765
|
-
2
|
|
3766
|
-
]];
|
|
3767
|
-
if (dot(cross(sub(pts[i1], p0), sub(pts[i2], p0)), sub(pts[i3], p0)) > 0) faces.push([
|
|
3768
|
-
0,
|
|
3769
|
-
i1,
|
|
3770
|
-
i2
|
|
3771
|
-
], [
|
|
3772
|
-
0,
|
|
3773
|
-
i2,
|
|
3774
|
-
i3
|
|
3775
|
-
], [
|
|
3776
|
-
0,
|
|
3777
|
-
i3,
|
|
3778
|
-
i1
|
|
3779
|
-
], [
|
|
3780
|
-
i1,
|
|
3781
|
-
i3,
|
|
3782
|
-
i2
|
|
3783
|
-
]);
|
|
3784
|
-
else faces.push([
|
|
3785
|
-
0,
|
|
3786
|
-
i2,
|
|
3787
|
-
i1
|
|
3788
|
-
], [
|
|
3789
|
-
0,
|
|
3790
|
-
i3,
|
|
3791
|
-
i2
|
|
3792
|
-
], [
|
|
3793
|
-
0,
|
|
3794
|
-
i1,
|
|
3795
|
-
i3
|
|
3796
|
-
], [
|
|
3797
|
-
i2,
|
|
3798
|
-
i3,
|
|
3799
|
-
i1
|
|
3800
|
-
]);
|
|
3801
|
-
const used = new Set([
|
|
3802
|
-
0,
|
|
3803
|
-
i1,
|
|
3804
|
-
i2,
|
|
3805
|
-
i3
|
|
3806
|
-
]);
|
|
3807
|
-
for (let pi = 0; pi < n; pi++) {
|
|
3808
|
-
if (used.has(pi)) continue;
|
|
3809
|
-
const p = pts[pi];
|
|
3810
|
-
const visible = [];
|
|
3811
|
-
for (let fi = 0; fi < faces.length; fi++) {
|
|
3812
|
-
const f = faces[fi];
|
|
3813
|
-
if (dot(cross(sub(pts[f[1]], pts[f[0]]), sub(pts[f[2]], pts[f[0]])), sub(p, pts[f[0]])) > 1e-10) visible.push(fi);
|
|
3814
|
-
}
|
|
3815
|
-
if (visible.length === 0) continue;
|
|
3816
|
-
const horizon = findHorizonEdges(faces, visible);
|
|
3817
|
-
visible.sort((a2, b2) => b2 - a2);
|
|
3818
|
-
for (const fi of visible) faces.splice(fi, 1);
|
|
3819
|
-
for (const [a, b] of horizon) faces.push([
|
|
3820
|
-
a,
|
|
3821
|
-
b,
|
|
3822
|
-
pi
|
|
3823
|
-
]);
|
|
3824
|
-
}
|
|
3825
|
-
return faces;
|
|
3826
|
-
}
|
|
3827
|
-
function c2d(handle) {
|
|
3828
|
-
return handle;
|
|
3829
|
-
}
|
|
3830
|
-
function c2dWrap(obj) {
|
|
3831
|
-
return obj;
|
|
3832
|
-
}
|
|
3833
|
-
//#endregion
|
|
3834
|
-
Object.defineProperty(exports, "OcctWasmAdapter", {
|
|
3835
|
-
enumerable: true,
|
|
3836
|
-
get: function() {
|
|
3837
|
-
return OcctWasmAdapter;
|
|
3838
|
-
}
|
|
3839
|
-
});
|
|
3840
|
-
Object.defineProperty(exports, "addCurveToBBox", {
|
|
3841
|
-
enumerable: true,
|
|
3842
|
-
get: function() {
|
|
3843
|
-
return addCurveToBBox;
|
|
3844
|
-
}
|
|
3845
|
-
});
|
|
3846
|
-
Object.defineProperty(exports, "createBBox2d", {
|
|
3847
|
-
enumerable: true,
|
|
3848
|
-
get: function() {
|
|
3849
|
-
return createBBox2d;
|
|
3850
|
-
}
|
|
3851
|
-
});
|
|
3852
|
-
Object.defineProperty(exports, "curveBounds", {
|
|
3853
|
-
enumerable: true,
|
|
3854
|
-
get: function() {
|
|
3855
|
-
return curveBounds;
|
|
3856
|
-
}
|
|
3857
|
-
});
|
|
3858
|
-
Object.defineProperty(exports, "curveTypeName", {
|
|
3859
|
-
enumerable: true,
|
|
3860
|
-
get: function() {
|
|
3861
|
-
return curveTypeName;
|
|
3862
|
-
}
|
|
3863
|
-
});
|
|
3864
|
-
Object.defineProperty(exports, "deserializeCurve2d", {
|
|
3865
|
-
enumerable: true,
|
|
3866
|
-
get: function() {
|
|
3867
|
-
return deserializeCurve2d;
|
|
3868
|
-
}
|
|
3869
|
-
});
|
|
3870
|
-
Object.defineProperty(exports, "evaluateCurve2d", {
|
|
3871
|
-
enumerable: true,
|
|
3872
|
-
get: function() {
|
|
3873
|
-
return evaluateCurve2d;
|
|
3874
|
-
}
|
|
3875
|
-
});
|
|
3876
|
-
Object.defineProperty(exports, "intersectCurves2dFn", {
|
|
3877
|
-
enumerable: true,
|
|
3878
|
-
get: function() {
|
|
3879
|
-
return intersectCurves2dFn;
|
|
3880
|
-
}
|
|
3881
|
-
});
|
|
3882
|
-
Object.defineProperty(exports, "makeBezier2d", {
|
|
3883
|
-
enumerable: true,
|
|
3884
|
-
get: function() {
|
|
3885
|
-
return makeBezier2d;
|
|
3886
|
-
}
|
|
3887
|
-
});
|
|
3888
|
-
Object.defineProperty(exports, "makeCircle2d", {
|
|
3889
|
-
enumerable: true,
|
|
3890
|
-
get: function() {
|
|
3891
|
-
return makeCircle2d;
|
|
3892
|
-
}
|
|
3893
|
-
});
|
|
3894
|
-
Object.defineProperty(exports, "makeEllipse2d", {
|
|
3895
|
-
enumerable: true,
|
|
3896
|
-
get: function() {
|
|
3897
|
-
return makeEllipse2d;
|
|
3898
|
-
}
|
|
3899
|
-
});
|
|
3900
|
-
Object.defineProperty(exports, "makeLine2d", {
|
|
3901
|
-
enumerable: true,
|
|
3902
|
-
get: function() {
|
|
3903
|
-
return makeLine2d;
|
|
3904
|
-
}
|
|
3905
|
-
});
|
|
3906
|
-
Object.defineProperty(exports, "mirrorAcrossAxis", {
|
|
3907
|
-
enumerable: true,
|
|
3908
|
-
get: function() {
|
|
3909
|
-
return mirrorAcrossAxis;
|
|
3910
|
-
}
|
|
3911
|
-
});
|
|
3912
|
-
Object.defineProperty(exports, "mirrorAtPoint", {
|
|
3913
|
-
enumerable: true,
|
|
3914
|
-
get: function() {
|
|
3915
|
-
return mirrorAtPoint;
|
|
3916
|
-
}
|
|
3917
|
-
});
|
|
3918
|
-
Object.defineProperty(exports, "rotateCurve2d", {
|
|
3919
|
-
enumerable: true,
|
|
3920
|
-
get: function() {
|
|
3921
|
-
return rotateCurve2d;
|
|
3922
|
-
}
|
|
3923
|
-
});
|
|
3924
|
-
Object.defineProperty(exports, "scaleCurve2d", {
|
|
3925
|
-
enumerable: true,
|
|
3926
|
-
get: function() {
|
|
3927
|
-
return scaleCurve2d;
|
|
3928
|
-
}
|
|
3929
|
-
});
|
|
3930
|
-
Object.defineProperty(exports, "serializeCurve2d", {
|
|
3931
|
-
enumerable: true,
|
|
3932
|
-
get: function() {
|
|
3933
|
-
return serializeCurve2d;
|
|
3934
|
-
}
|
|
3935
|
-
});
|
|
3936
|
-
Object.defineProperty(exports, "tangentCurve2d", {
|
|
3937
|
-
enumerable: true,
|
|
3938
|
-
get: function() {
|
|
3939
|
-
return tangentCurve2d;
|
|
3940
|
-
}
|
|
3941
|
-
});
|
|
3942
|
-
Object.defineProperty(exports, "translateCurve2d", {
|
|
3943
|
-
enumerable: true,
|
|
3944
|
-
get: function() {
|
|
3945
|
-
return translateCurve2d;
|
|
3946
|
-
}
|
|
3947
|
-
});
|