brepjs 12.7.2 → 12.8.0
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/dist/2d.cjs +2 -2
- package/dist/2d.js +11 -11
- package/dist/{Blueprint-DymoCs1R.js → Blueprint-C3lWY1Jf.js} +21 -20
- package/dist/{Blueprint-E105uFXu.cjs → Blueprint-CnDVffSX.cjs} +2 -1
- package/dist/{boolean2D-BXO2hNfY.js → boolean2D-CwZAIJDS.js} +15 -17
- package/dist/{boolean2D-D857dStk.cjs → boolean2D-DyQJt8Na.cjs} +2 -4
- package/dist/{booleanFns-DpAod1nu.js → booleanFns-CcNUsgI8.js} +2 -2
- package/dist/{booleanFns-DeWK-2pA.cjs → booleanFns-D7HmkpYt.cjs} +1 -1
- package/dist/brepjs.cjs +37 -108
- package/dist/brepjs.js +935 -1006
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/{cornerFinder-xxlrRbwc.js → cornerFinder-BV-l1BCw.js} +1 -1
- package/dist/{curveFns-LRNGcHXh.js → curveFns-CloOqAQ_.js} +11 -11
- package/dist/{drawFns-ClKmj3al.js → drawFns-5myJTgtX.js} +68 -324
- package/dist/{drawFns-BKU3X1Qn.cjs → drawFns-CDNafQhv.cjs} +61 -317
- package/dist/{helpers-Dnw_sLuU.js → helpers-C9KvE1RW.js} +5 -5
- package/dist/io.cjs +1 -1
- package/dist/io.js +1 -1
- package/dist/kernel/brepkitAdapter.d.ts.map +1 -1
- package/dist/kernel/brepkitWasmTypes.d.ts +11 -1
- package/dist/kernel/brepkitWasmTypes.d.ts.map +1 -1
- package/dist/{loft-DsVv4yxU.js → loft-BcZUCGKi.js} +1 -1
- package/dist/{operations-DXt8hFxd.cjs → operations-DLFzmdFX.cjs} +1 -1
- package/dist/{operations-DE9wMwvN.js → operations-Dcz6YlOt.js} +2 -2
- package/dist/operations.cjs +1 -1
- package/dist/operations.js +2 -2
- package/dist/query.js +4 -4
- package/dist/sketching/Sketcher.d.ts +31 -77
- package/dist/sketching/Sketcher.d.ts.map +1 -1
- package/dist/sketching/Sketcher2d.d.ts +1 -1
- package/dist/sketching/Sketcher2d.d.ts.map +1 -1
- package/dist/sketching/draw.d.ts +2 -2
- package/dist/sketching/draw.d.ts.map +1 -1
- package/dist/sketching/sketcherlib.d.ts +32 -1
- package/dist/sketching/sketcherlib.d.ts.map +1 -1
- package/dist/sketching.cjs +2 -2
- package/dist/sketching.js +2 -2
- package/dist/{surfaceBuilders-D7ZH2QNS.js → surfaceBuilders-D6iDVPIM.js} +12 -12
- package/dist/{topology-Is3aThTo.cjs → topology-CKtCGLmb.cjs} +1 -1
- package/dist/{topology-DEi2sFry.js → topology-DxD58iQ6.js} +3 -3
- package/dist/topology.cjs +2 -2
- package/dist/topology.js +14 -14
- package/dist/{vectors-TlfO1hu2.cjs → vectors-BafmMf96.cjs} +0 -5
- package/dist/{vectors-cec8p8NQ.js → vectors-CESkzEm6.js} +1 -6
- package/dist/vectors.cjs +1 -1
- package/dist/vectors.js +1 -1
- package/package.json +3 -3
package/dist/brepjs.js
CHANGED
|
@@ -49,39 +49,39 @@ import { o as ok, z as translateKernelError, e as err, p as typeCastError, q as
|
|
|
49
49
|
import { O as O2, A as A2, a as a2, c, b as b2, f as f2, C as C2, g as g2, m as m2, h as h2, j, l as l2, D, E as E2, F, s as s2, G, H as H2, t as t2, n as n2, u, v as v2, w as w2, x as x2, I as I2 } from "./errors-B7kgv0cd.js";
|
|
50
50
|
import { c as vecDistance, H as HASH_CODE_MAX, n as vecScale, j as vecNormalize, f as vecIsZero } from "./vecOps-ZDdZWbwT.js";
|
|
51
51
|
import { D as D2, R as R2, v as v3, a as a3, b as b3, d as d2, e as e2, g as g3, h as h3, i as i2, k, l as l3, m as m3, o as o2 } from "./vecOps-ZDdZWbwT.js";
|
|
52
|
-
import { B,
|
|
53
|
-
import { b as b4, g as g4, r } from "./loft-
|
|
54
|
-
import { w as walkAssembly, e as extrude$1, r as revolve$1, s as sweep, c as circularPattern, l as linearPattern } from "./operations-
|
|
55
|
-
import { a as a4, b as b5, d as
|
|
56
|
-
import { B as B3, a as a5,
|
|
52
|
+
import { B, e as e3, C as C3, u as u2 } from "./Blueprint-C3lWY1Jf.js";
|
|
53
|
+
import { b as b4, g as g4, r } from "./loft-BcZUCGKi.js";
|
|
54
|
+
import { w as walkAssembly, e as extrude$1, r as revolve$1, s as sweep, c as circularPattern, l as linearPattern } from "./operations-Dcz6YlOt.js";
|
|
55
|
+
import { a as a4, b as b5, d as d3, f as f3, g as g5, h as h4, i as i3, j as j2, k as k2, m as m4, n as n3, o as o3, p, q, t as t3, u as u3, v as v4, x as x3, y as y2, z as z2, A as A3, B as B2, C as C4, D as D3, E as E3, F as F2, G as G2 } from "./operations-Dcz6YlOt.js";
|
|
56
|
+
import { B as B3, a as a5, c as c2, C as C5, F as F3, S as S2, d as d4, j as j3, f as f4, k as k3, h as h5, l as l4, o as o4, p as p2, r as r2 } from "./boolean2D-CwZAIJDS.js";
|
|
57
57
|
import { createBlueprint, curve2dBoundingBox, curve2dDistanceFrom, curve2dFirstPoint, curve2dIsOnCurve, curve2dLastPoint, curve2dParameter, curve2dSplitAt, curve2dTangentAt, getBounds2D, getOrientation2D, isInside2D, mirror2D, reverseCurve, rotate2D, scale2D, sketch2DOnFace, sketch2DOnPlane, stretch2D, toSVGPathD, translate2D } from "./2d.js";
|
|
58
|
-
import { l as createTypedFinder, m as faceFinder } from "./helpers-
|
|
59
|
-
import { g as
|
|
58
|
+
import { l as createTypedFinder, m as faceFinder } from "./helpers-C9KvE1RW.js";
|
|
59
|
+
import { g as g6 } from "./helpers-C9KvE1RW.js";
|
|
60
60
|
import { blueprintToDXF, exportDXF, exportGlb, exportGltf, exportOBJ, exportThreeMF, importIGES, importSTEP, importSTL, importSVG, importSVGPathD } from "./io.js";
|
|
61
|
-
import { C as C6, D as D4, a as a6, S as S3, b as b6, X, Y, c as
|
|
61
|
+
import { C as C6, D as D4, a as a6, S as S3, b as b6, X, Y, c as c3, d as d5, e as e4, f as f5, Z, g as g7, h as h6, i as i4, j as j4, k as k4, l as l5, m as m5, n as n4, o as o5, p as p3, q as q2, r as r3, s as s3, t as t4, u as u4, v as v5, w as w3, x as x4, y as y3, z as z3, _, $, a0, a1, A as A4, a2 as a22, B as B4, E as E4, a3 as a32, F as F4, G as G3, H as H3, I as I3, J, K, L, M as M2, N as N2, O as O3, P as P2, Q as Q2, R as R3, T, U, a4 as a42, V, a5 as a52, a6 as a62, W } from "./drawFns-5myJTgtX.js";
|
|
62
62
|
import { a as toVec3 } from "./types-CWDdqcrq.js";
|
|
63
|
-
import { r as r4, t as
|
|
64
|
-
import { c as
|
|
63
|
+
import { r as r4, t as t5 } from "./types-CWDdqcrq.js";
|
|
64
|
+
import { c as c4, a as a7, p as p4, r as r5, t as t6 } from "./vectors-CESkzEm6.js";
|
|
65
65
|
import { v as vertexPosition, a as getFaces, e as getVertices, d as getEdges, h as getBounds, b as propagateOriginsFromEvolution, g as getFaceOrigins, j as applyMatrix$1, k as clone$1, l as describe$1, m as isEmpty$1, n as mirror$1, r as rotate$1, s as scale$1, o as simplify$1, t as toBREP$1, q as transformCopy$1, u as translate$1, c as getWires } from "./shapeFns-D2PlLFE6.js";
|
|
66
66
|
import { w as w4, f as f6, x as x5, y as y4, i as i5, z as z4, A as A5, B as B5, C as C7, D as D5, E as E5 } from "./shapeFns-D2PlLFE6.js";
|
|
67
|
-
import { p as propagateFaceTagsFromEvolution, a as propagateColorsFromEvolution, h as hasFaceTags, b as hasColorMetadata, c as cut$1, f as fuse$1, i as intersect$1, s as section$1, d as sectionToFace$1, e as slice$1, g as split$1, j as fuseAll, k as cutAll } from "./booleanFns-
|
|
68
|
-
import { l as l6, m as m6, n as
|
|
69
|
-
import { c as chamferDistAngle, h as heal$1, i as isValid$1 } from "./topology-
|
|
70
|
-
import { a as a8, b as b7, d as d6, e as e5, f as f7, g as
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
67
|
+
import { p as propagateFaceTagsFromEvolution, a as propagateColorsFromEvolution, h as hasFaceTags, b as hasColorMetadata, c as cut$1, f as fuse$1, i as intersect$1, s as section$1, d as sectionToFace$1, e as slice$1, g as split$1, j as fuseAll, k as cutAll } from "./booleanFns-CcNUsgI8.js";
|
|
68
|
+
import { l as l6, m as m6, n as n5, o as o6, q as q3, r as r6, t as t7, u as u5, v as v6 } from "./booleanFns-CcNUsgI8.js";
|
|
69
|
+
import { c as chamferDistAngle, h as heal$1, i as isValid$1 } from "./topology-DxD58iQ6.js";
|
|
70
|
+
import { a as a8, b as b7, d as d6, e as e5, f as f7, g as g8, j as j5, k as k5, l as l7, m as m7, n as n6, o as o7, p as p5, q as q4, r as r7, s as s4, t as t8, u as u6, v as v7, w as w5, x as x6, y as y5, z as z5, A as A6, B as B6, C as C8, D as D6, E as E6, F as F5, G as G4, H as H4, I as I4, J as J2, K as K2, L as L2, M as M3, N as N3, O as O4, P as P3, Q as Q3 } from "./topology-DxD58iQ6.js";
|
|
71
|
+
import { b as curveIsClosed, c as curveStartPoint, a as curveTangentAt, d as curvePointAt, e as curveEndPoint, f as curveLength } from "./curveFns-CloOqAQ_.js";
|
|
72
|
+
import { h as h7, i as i6, j as j6, k as k6, l as l8, g as g9, m as m8, o as o8 } from "./curveFns-CloOqAQ_.js";
|
|
73
73
|
import { i as iterTopo, e as faceCenter, n as normalAt, j as fromBREP$1, k as innerWires, o as outerWire, g as getSurfaceType } from "./faceFns-B6ebRh5I.js";
|
|
74
|
-
import { l as l9, c as
|
|
74
|
+
import { l as l9, c as c5, m as m9, d as d7, f as f8, q as q5, r as r8, s as s5, p as p6, t as t9, v as v8, w as w6, u as u7, h as h8 } from "./faceFns-B6ebRh5I.js";
|
|
75
75
|
import { m as mesh$1, a as meshEdges$1 } from "./meshFns-DsLRd3tA.js";
|
|
76
|
-
import { c as
|
|
76
|
+
import { c as c6, b as b8, e as e6, d as d8, f as f9 } from "./meshFns-DsLRd3tA.js";
|
|
77
77
|
import { m as measureArea, a as measureSurfaceProps, b as measureVolumeProps, c as measureVolume } from "./measurement-oWvhSVZG.js";
|
|
78
|
-
import { d as d9, e as e7, f as
|
|
79
|
-
import { m as makeFace } from "./surfaceBuilders-
|
|
80
|
-
import {
|
|
78
|
+
import { d as d9, e as e7, f as f10, g as g10, h as h9, i as i7 } from "./measurement-oWvhSVZG.js";
|
|
79
|
+
import { m as makeFace } from "./surfaceBuilders-D6iDVPIM.js";
|
|
80
|
+
import { i as i8 } from "./surfaceBuilders-D6iDVPIM.js";
|
|
81
81
|
import { edgeFinder } from "./query.js";
|
|
82
82
|
import { c as makeCylinder } from "./solidBuilders-BXhh5hP2.js";
|
|
83
83
|
import { BrepBugError, bug } from "./result.js";
|
|
84
|
-
import { c as
|
|
84
|
+
import { c as c7 } from "./cornerFinder-BV-l1BCw.js";
|
|
85
85
|
import { createOperationRegistry, createTaskQueue, createWorkerClient, createWorkerHandler, dequeueTask, enqueueTask, isDisposeRequest, isErrorResponse, isInitRequest, isOperationRequest, isQueueEmpty, isSuccessResponse, pendingCount, registerHandler, rejectAll } from "./worker.js";
|
|
86
86
|
function supportsProjection(kernel) {
|
|
87
87
|
return "projectShape" in kernel;
|
|
@@ -89,91 +89,91 @@ function supportsProjection(kernel) {
|
|
|
89
89
|
function supportsConstraintSketch(kernel) {
|
|
90
90
|
return "sketchNew" in kernel && "sketchDof" in kernel;
|
|
91
91
|
}
|
|
92
|
-
function evaluateCurve2d(
|
|
93
|
-
switch (
|
|
92
|
+
function evaluateCurve2d(c8, t10) {
|
|
93
|
+
switch (c8.__bk2d) {
|
|
94
94
|
case "line":
|
|
95
|
-
return [
|
|
95
|
+
return [c8.ox + c8.dx * t10, c8.oy + c8.dy * t10];
|
|
96
96
|
case "circle": {
|
|
97
|
-
const angle =
|
|
98
|
-
return [
|
|
97
|
+
const angle = c8.sense ? t10 : -t10;
|
|
98
|
+
return [c8.cx + c8.radius * Math.cos(angle), c8.cy + c8.radius * Math.sin(angle)];
|
|
99
99
|
}
|
|
100
100
|
case "ellipse": {
|
|
101
|
-
const angle =
|
|
102
|
-
const cos = Math.cos(
|
|
103
|
-
const sin = Math.sin(
|
|
104
|
-
const x7 =
|
|
105
|
-
const y6 =
|
|
106
|
-
return [
|
|
101
|
+
const angle = c8.sense ? t10 : -t10;
|
|
102
|
+
const cos = Math.cos(c8.xDirAngle);
|
|
103
|
+
const sin = Math.sin(c8.xDirAngle);
|
|
104
|
+
const x7 = c8.majorRadius * Math.cos(angle);
|
|
105
|
+
const y6 = c8.minorRadius * Math.sin(angle);
|
|
106
|
+
return [c8.cx + x7 * cos - y6 * sin, c8.cy + x7 * sin + y6 * cos];
|
|
107
107
|
}
|
|
108
108
|
case "bezier":
|
|
109
|
-
return evaluateBezier(
|
|
109
|
+
return evaluateBezier(c8.poles, t10);
|
|
110
110
|
case "bspline":
|
|
111
|
-
return evaluateBSpline2d(
|
|
111
|
+
return evaluateBSpline2d(c8, t10);
|
|
112
112
|
case "trimmed": {
|
|
113
|
-
const mapped =
|
|
114
|
-
return evaluateCurve2d(
|
|
113
|
+
const mapped = c8.tStart + t10 * (c8.tEnd - c8.tStart);
|
|
114
|
+
return evaluateCurve2d(c8.basis, mapped);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
function tangentCurve2d(
|
|
119
|
-
switch (
|
|
118
|
+
function tangentCurve2d(c8, t10) {
|
|
119
|
+
switch (c8.__bk2d) {
|
|
120
120
|
case "line":
|
|
121
|
-
return [
|
|
121
|
+
return [c8.dx, c8.dy];
|
|
122
122
|
case "circle": {
|
|
123
|
-
const angle =
|
|
124
|
-
const sign =
|
|
125
|
-
return [-
|
|
123
|
+
const angle = c8.sense ? t10 : -t10;
|
|
124
|
+
const sign = c8.sense ? 1 : -1;
|
|
125
|
+
return [-c8.radius * Math.sin(angle) * sign, c8.radius * Math.cos(angle) * sign];
|
|
126
126
|
}
|
|
127
127
|
case "ellipse": {
|
|
128
|
-
const angle =
|
|
129
|
-
const sign =
|
|
130
|
-
const cos = Math.cos(
|
|
131
|
-
const sin = Math.sin(
|
|
132
|
-
const dx = -
|
|
133
|
-
const dy =
|
|
128
|
+
const angle = c8.sense ? t10 : -t10;
|
|
129
|
+
const sign = c8.sense ? 1 : -1;
|
|
130
|
+
const cos = Math.cos(c8.xDirAngle);
|
|
131
|
+
const sin = Math.sin(c8.xDirAngle);
|
|
132
|
+
const dx = -c8.majorRadius * Math.sin(angle) * sign;
|
|
133
|
+
const dy = c8.minorRadius * Math.cos(angle) * sign;
|
|
134
134
|
return [dx * cos - dy * sin, dx * sin + dy * cos];
|
|
135
135
|
}
|
|
136
136
|
case "bezier": {
|
|
137
|
-
const
|
|
138
|
-
const p0 = evaluateBezier(
|
|
139
|
-
const p1 = evaluateBezier(
|
|
140
|
-
const dt = Math.min(1,
|
|
137
|
+
const h10 = 1e-8;
|
|
138
|
+
const p0 = evaluateBezier(c8.poles, Math.max(0, t10 - h10));
|
|
139
|
+
const p1 = evaluateBezier(c8.poles, Math.min(1, t10 + h10));
|
|
140
|
+
const dt = Math.min(1, t10 + h10) - Math.max(0, t10 - h10);
|
|
141
141
|
return [(p1[0] - p0[0]) / dt, (p1[1] - p0[1]) / dt];
|
|
142
142
|
}
|
|
143
143
|
case "bspline": {
|
|
144
|
-
const
|
|
145
|
-
const kFirst =
|
|
146
|
-
const kLast =
|
|
147
|
-
const p0 = evaluateBSpline2d(
|
|
148
|
-
const p1 = evaluateBSpline2d(
|
|
149
|
-
const dt = Math.min(kLast,
|
|
144
|
+
const h10 = 1e-8;
|
|
145
|
+
const kFirst = c8.knots[0];
|
|
146
|
+
const kLast = c8.knots[c8.knots.length - 1];
|
|
147
|
+
const p0 = evaluateBSpline2d(c8, Math.max(kFirst, t10 - h10));
|
|
148
|
+
const p1 = evaluateBSpline2d(c8, Math.min(kLast, t10 + h10));
|
|
149
|
+
const dt = Math.min(kLast, t10 + h10) - Math.max(kFirst, t10 - h10);
|
|
150
150
|
return [(p1[0] - p0[0]) / dt, (p1[1] - p0[1]) / dt];
|
|
151
151
|
}
|
|
152
152
|
case "trimmed": {
|
|
153
|
-
const mapped =
|
|
154
|
-
const tan = tangentCurve2d(
|
|
155
|
-
const scale2 =
|
|
153
|
+
const mapped = c8.tStart + t10 * (c8.tEnd - c8.tStart);
|
|
154
|
+
const tan = tangentCurve2d(c8.basis, mapped);
|
|
155
|
+
const scale2 = c8.tEnd - c8.tStart;
|
|
156
156
|
return [tan[0] * scale2, tan[1] * scale2];
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
function curveBounds(
|
|
161
|
-
switch (
|
|
160
|
+
function curveBounds(c8) {
|
|
161
|
+
switch (c8.__bk2d) {
|
|
162
162
|
case "line":
|
|
163
|
-
return { first: 0, last:
|
|
163
|
+
return { first: 0, last: c8.len };
|
|
164
164
|
case "circle":
|
|
165
165
|
case "ellipse":
|
|
166
166
|
return { first: 0, last: 2 * Math.PI };
|
|
167
167
|
case "bezier":
|
|
168
168
|
return { first: 0, last: 1 };
|
|
169
169
|
case "bspline":
|
|
170
|
-
return { first:
|
|
170
|
+
return { first: c8.knots[0], last: c8.knots[c8.knots.length - 1] };
|
|
171
171
|
case "trimmed":
|
|
172
172
|
return { first: 0, last: 1 };
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
function curveTypeName(
|
|
176
|
-
switch (
|
|
175
|
+
function curveTypeName(c8) {
|
|
176
|
+
switch (c8.__bk2d) {
|
|
177
177
|
case "line":
|
|
178
178
|
return "LINE";
|
|
179
179
|
case "circle":
|
|
@@ -185,7 +185,7 @@ function curveTypeName(c7) {
|
|
|
185
185
|
case "bspline":
|
|
186
186
|
return "BSPLINE_CURVE";
|
|
187
187
|
case "trimmed":
|
|
188
|
-
return "TRIMMED_" + curveTypeName(
|
|
188
|
+
return "TRIMMED_" + curveTypeName(c8.basis);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
function makeLine2d(x1, y1, x22, y22) {
|
|
@@ -218,23 +218,23 @@ function makeEllipse2d(cx, cy, majorRadius, minorRadius, xDirX = 1, xDirY = 0, s
|
|
|
218
218
|
function makeBezier2d(poles) {
|
|
219
219
|
return { __bk2d: "bezier", poles: [...poles] };
|
|
220
220
|
}
|
|
221
|
-
function translateCurve2d(
|
|
222
|
-
switch (
|
|
221
|
+
function translateCurve2d(c8, dx, dy) {
|
|
222
|
+
switch (c8.__bk2d) {
|
|
223
223
|
case "line":
|
|
224
|
-
return { ...
|
|
224
|
+
return { ...c8, ox: c8.ox + dx, oy: c8.oy + dy };
|
|
225
225
|
case "circle":
|
|
226
|
-
return { ...
|
|
226
|
+
return { ...c8, cx: c8.cx + dx, cy: c8.cy + dy };
|
|
227
227
|
case "ellipse":
|
|
228
|
-
return { ...
|
|
228
|
+
return { ...c8, cx: c8.cx + dx, cy: c8.cy + dy };
|
|
229
229
|
case "bezier":
|
|
230
|
-
return { ...
|
|
230
|
+
return { ...c8, poles: c8.poles.map(([x7, y6]) => [x7 + dx, y6 + dy]) };
|
|
231
231
|
case "bspline":
|
|
232
|
-
return { ...
|
|
232
|
+
return { ...c8, poles: c8.poles.map(([x7, y6]) => [x7 + dx, y6 + dy]) };
|
|
233
233
|
case "trimmed":
|
|
234
|
-
return { ...
|
|
234
|
+
return { ...c8, basis: translateCurve2d(c8.basis, dx, dy) };
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
function rotateCurve2d(
|
|
237
|
+
function rotateCurve2d(c8, angle, cx, cy) {
|
|
238
238
|
const cos = Math.cos(angle);
|
|
239
239
|
const sin = Math.sin(angle);
|
|
240
240
|
const rotatePoint = (x7, y6) => {
|
|
@@ -242,65 +242,65 @@ function rotateCurve2d(c7, angle, cx, cy) {
|
|
|
242
242
|
const ry = y6 - cy;
|
|
243
243
|
return [cx + rx * cos - ry * sin, cy + rx * sin + ry * cos];
|
|
244
244
|
};
|
|
245
|
-
switch (
|
|
245
|
+
switch (c8.__bk2d) {
|
|
246
246
|
case "line": {
|
|
247
|
-
const [ox, oy] = rotatePoint(
|
|
248
|
-
const ndx =
|
|
249
|
-
const ndy =
|
|
250
|
-
return { ...
|
|
247
|
+
const [ox, oy] = rotatePoint(c8.ox, c8.oy);
|
|
248
|
+
const ndx = c8.dx * cos - c8.dy * sin;
|
|
249
|
+
const ndy = c8.dx * sin + c8.dy * cos;
|
|
250
|
+
return { ...c8, ox, oy, dx: ndx, dy: ndy };
|
|
251
251
|
}
|
|
252
252
|
case "circle": {
|
|
253
|
-
const [ncx, ncy] = rotatePoint(
|
|
254
|
-
return { ...
|
|
253
|
+
const [ncx, ncy] = rotatePoint(c8.cx, c8.cy);
|
|
254
|
+
return { ...c8, cx: ncx, cy: ncy };
|
|
255
255
|
}
|
|
256
256
|
case "ellipse": {
|
|
257
|
-
const [ncx, ncy] = rotatePoint(
|
|
258
|
-
return { ...
|
|
257
|
+
const [ncx, ncy] = rotatePoint(c8.cx, c8.cy);
|
|
258
|
+
return { ...c8, cx: ncx, cy: ncy, xDirAngle: c8.xDirAngle + angle };
|
|
259
259
|
}
|
|
260
260
|
case "bezier":
|
|
261
|
-
return { ...
|
|
261
|
+
return { ...c8, poles: c8.poles.map(([x7, y6]) => rotatePoint(x7, y6)) };
|
|
262
262
|
case "bspline":
|
|
263
|
-
return { ...
|
|
263
|
+
return { ...c8, poles: c8.poles.map(([x7, y6]) => rotatePoint(x7, y6)) };
|
|
264
264
|
case "trimmed":
|
|
265
|
-
return { ...
|
|
265
|
+
return { ...c8, basis: rotateCurve2d(c8.basis, angle, cx, cy) };
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
|
-
function scaleCurve2d(
|
|
268
|
+
function scaleCurve2d(c8, factor, cx, cy) {
|
|
269
269
|
const scalePoint = (x7, y6) => [
|
|
270
270
|
cx + (x7 - cx) * factor,
|
|
271
271
|
cy + (y6 - cy) * factor
|
|
272
272
|
];
|
|
273
|
-
switch (
|
|
273
|
+
switch (c8.__bk2d) {
|
|
274
274
|
case "line": {
|
|
275
|
-
const [ox, oy] = scalePoint(
|
|
276
|
-
return { ...
|
|
275
|
+
const [ox, oy] = scalePoint(c8.ox, c8.oy);
|
|
276
|
+
return { ...c8, ox, oy };
|
|
277
277
|
}
|
|
278
278
|
case "circle": {
|
|
279
|
-
const [ncx, ncy] = scalePoint(
|
|
280
|
-
return { ...
|
|
279
|
+
const [ncx, ncy] = scalePoint(c8.cx, c8.cy);
|
|
280
|
+
return { ...c8, cx: ncx, cy: ncy, radius: c8.radius * Math.abs(factor) };
|
|
281
281
|
}
|
|
282
282
|
case "ellipse": {
|
|
283
|
-
const [ncx, ncy] = scalePoint(
|
|
283
|
+
const [ncx, ncy] = scalePoint(c8.cx, c8.cy);
|
|
284
284
|
return {
|
|
285
|
-
...
|
|
285
|
+
...c8,
|
|
286
286
|
cx: ncx,
|
|
287
287
|
cy: ncy,
|
|
288
|
-
majorRadius:
|
|
289
|
-
minorRadius:
|
|
288
|
+
majorRadius: c8.majorRadius * Math.abs(factor),
|
|
289
|
+
minorRadius: c8.minorRadius * Math.abs(factor)
|
|
290
290
|
};
|
|
291
291
|
}
|
|
292
292
|
case "bezier":
|
|
293
|
-
return { ...
|
|
293
|
+
return { ...c8, poles: c8.poles.map(([x7, y6]) => scalePoint(x7, y6)) };
|
|
294
294
|
case "bspline":
|
|
295
|
-
return { ...
|
|
295
|
+
return { ...c8, poles: c8.poles.map(([x7, y6]) => scalePoint(x7, y6)) };
|
|
296
296
|
case "trimmed":
|
|
297
|
-
return { ...
|
|
297
|
+
return { ...c8, basis: scaleCurve2d(c8.basis, factor, cx, cy) };
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
|
-
function mirrorAtPoint(
|
|
301
|
-
return scaleCurve2d(
|
|
300
|
+
function mirrorAtPoint(c8, cx, cy) {
|
|
301
|
+
return scaleCurve2d(c8, -1, cx, cy);
|
|
302
302
|
}
|
|
303
|
-
function mirrorAcrossAxis(
|
|
303
|
+
function mirrorAcrossAxis(c8, ox, oy, dx, dy) {
|
|
304
304
|
const len = Math.sqrt(dx * dx + dy * dy);
|
|
305
305
|
const nx = dx / len;
|
|
306
306
|
const ny = dy / len;
|
|
@@ -310,33 +310,33 @@ function mirrorAcrossAxis(c7, ox, oy, dx, dy) {
|
|
|
310
310
|
const dot = rx * nx + ry * ny;
|
|
311
311
|
return [ox + 2 * dot * nx - rx, oy + 2 * dot * ny - ry];
|
|
312
312
|
};
|
|
313
|
-
switch (
|
|
313
|
+
switch (c8.__bk2d) {
|
|
314
314
|
case "line": {
|
|
315
|
-
const [nox, noy] = reflectPoint(
|
|
316
|
-
const ndx = 2 * (
|
|
317
|
-
const ndy = 2 * (
|
|
318
|
-
return { ...
|
|
315
|
+
const [nox, noy] = reflectPoint(c8.ox, c8.oy);
|
|
316
|
+
const ndx = 2 * (c8.dx * nx + c8.dy * ny) * nx - c8.dx;
|
|
317
|
+
const ndy = 2 * (c8.dx * nx + c8.dy * ny) * ny - c8.dy;
|
|
318
|
+
return { ...c8, ox: nox, oy: noy, dx: ndx, dy: ndy };
|
|
319
319
|
}
|
|
320
320
|
case "circle": {
|
|
321
|
-
const [ncx, ncy] = reflectPoint(
|
|
322
|
-
return { ...
|
|
321
|
+
const [ncx, ncy] = reflectPoint(c8.cx, c8.cy);
|
|
322
|
+
return { ...c8, cx: ncx, cy: ncy, sense: !c8.sense };
|
|
323
323
|
}
|
|
324
324
|
case "ellipse": {
|
|
325
|
-
const [ncx, ncy] = reflectPoint(
|
|
325
|
+
const [ncx, ncy] = reflectPoint(c8.cx, c8.cy);
|
|
326
326
|
const cos2 = nx * nx - ny * ny;
|
|
327
327
|
const sin2 = 2 * nx * ny;
|
|
328
328
|
const newAngle = Math.atan2(
|
|
329
|
-
sin2 * Math.cos(
|
|
330
|
-
cos2 * Math.cos(
|
|
329
|
+
sin2 * Math.cos(c8.xDirAngle) - cos2 * Math.sin(c8.xDirAngle),
|
|
330
|
+
cos2 * Math.cos(c8.xDirAngle) + sin2 * Math.sin(c8.xDirAngle)
|
|
331
331
|
);
|
|
332
|
-
return { ...
|
|
332
|
+
return { ...c8, cx: ncx, cy: ncy, xDirAngle: newAngle, sense: !c8.sense };
|
|
333
333
|
}
|
|
334
334
|
case "bezier":
|
|
335
|
-
return { ...
|
|
335
|
+
return { ...c8, poles: c8.poles.map(([x7, y6]) => reflectPoint(x7, y6)) };
|
|
336
336
|
case "bspline":
|
|
337
|
-
return { ...
|
|
337
|
+
return { ...c8, poles: c8.poles.map(([x7, y6]) => reflectPoint(x7, y6)) };
|
|
338
338
|
case "trimmed":
|
|
339
|
-
return { ...
|
|
339
|
+
return { ...c8, basis: mirrorAcrossAxis(c8.basis, ox, oy, dx, dy) };
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
function intersectCurves2dFn(c1, c22, tolerance) {
|
|
@@ -357,34 +357,34 @@ function intersectCurves2dFn(c1, c22, tolerance) {
|
|
|
357
357
|
const isSelf = c1 === c22;
|
|
358
358
|
return numericalIntersect(c1, c22, tolerance, isSelf);
|
|
359
359
|
}
|
|
360
|
-
function unwrapCurve(
|
|
361
|
-
let cur =
|
|
360
|
+
function unwrapCurve(c8) {
|
|
361
|
+
let cur = c8;
|
|
362
362
|
while (cur.__bk2d === "trimmed") cur = cur.basis;
|
|
363
363
|
return cur;
|
|
364
364
|
}
|
|
365
|
-
function inDomain(
|
|
366
|
-
const
|
|
367
|
-
return
|
|
365
|
+
function inDomain(c8, t10, tol) {
|
|
366
|
+
const b9 = curveBounds(c8);
|
|
367
|
+
return t10 >= b9.first - tol && t10 <= b9.last + tol;
|
|
368
368
|
}
|
|
369
|
-
function refineParam(
|
|
370
|
-
const bounds = curveBounds(
|
|
369
|
+
function refineParam(c8, px, py) {
|
|
370
|
+
const bounds = curveBounds(c8);
|
|
371
371
|
if (!isFinite(bounds.first) || !isFinite(bounds.last)) return null;
|
|
372
372
|
const N4 = 80;
|
|
373
373
|
const dt = (bounds.last - bounds.first) / N4;
|
|
374
374
|
let bestT = bounds.first;
|
|
375
375
|
let bestD = Infinity;
|
|
376
|
-
for (let
|
|
377
|
-
const
|
|
378
|
-
const [ex2, ey2] = evaluateCurve2d(
|
|
376
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
377
|
+
const t10 = bounds.first + i9 * dt;
|
|
378
|
+
const [ex2, ey2] = evaluateCurve2d(c8, t10);
|
|
379
379
|
const d10 = (ex2 - px) ** 2 + (ey2 - py) ** 2;
|
|
380
380
|
if (d10 < bestD) {
|
|
381
381
|
bestD = d10;
|
|
382
|
-
bestT =
|
|
382
|
+
bestT = t10;
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
-
const [sx, sy] = evaluateCurve2d(
|
|
386
|
-
const [ex, ey] = evaluateCurve2d(
|
|
387
|
-
const [mx, my] = evaluateCurve2d(
|
|
385
|
+
const [sx, sy] = evaluateCurve2d(c8, bounds.first);
|
|
386
|
+
const [ex, ey] = evaluateCurve2d(c8, bounds.last);
|
|
387
|
+
const [mx, my] = evaluateCurve2d(c8, (bounds.first + bounds.last) / 2);
|
|
388
388
|
const geomExtent = Math.max(
|
|
389
389
|
Math.sqrt((ex - sx) ** 2 + (ey - sy) ** 2),
|
|
390
390
|
Math.sqrt((mx - sx) ** 2 + (my - sy) ** 2),
|
|
@@ -427,14 +427,14 @@ function intersectLineCircle(cLine, line, cCirc, circ, tol) {
|
|
|
427
427
|
const fx = line.ox - circ.cx;
|
|
428
428
|
const fy = line.oy - circ.cy;
|
|
429
429
|
const a9 = line.dx * line.dx + line.dy * line.dy;
|
|
430
|
-
const
|
|
431
|
-
const
|
|
432
|
-
const disc =
|
|
430
|
+
const b9 = 2 * (fx * line.dx + fy * line.dy);
|
|
431
|
+
const c8 = fx * fx + fy * fy - circ.radius * circ.radius;
|
|
432
|
+
const disc = b9 * b9 - 4 * a9 * c8;
|
|
433
433
|
if (disc < -tol) return [];
|
|
434
434
|
const results = [];
|
|
435
435
|
const sqrtDisc = Math.sqrt(Math.max(0, disc));
|
|
436
|
-
const t1 = (-
|
|
437
|
-
const t22 = (-
|
|
436
|
+
const t1 = (-b9 - sqrtDisc) / (2 * a9);
|
|
437
|
+
const t22 = (-b9 + sqrtDisc) / (2 * a9);
|
|
438
438
|
for (const tLine of disc < tol * tol ? [t1] : [t1, t22]) {
|
|
439
439
|
if (!inDomain(cLine, tLine, tol)) continue;
|
|
440
440
|
const px = line.ox + tLine * line.dx;
|
|
@@ -456,12 +456,12 @@ function intersectCircleCircle(c1, circ1, c22, circ2, tol) {
|
|
|
456
456
|
if (d10 < 1e-14) return [];
|
|
457
457
|
const a9 = (circ1.radius * circ1.radius - circ2.radius * circ2.radius + d10 * d10) / (2 * d10);
|
|
458
458
|
const h22 = circ1.radius * circ1.radius - a9 * a9;
|
|
459
|
-
const
|
|
459
|
+
const h10 = Math.sqrt(Math.max(0, h22));
|
|
460
460
|
const mx = circ1.cx + a9 * dx / d10;
|
|
461
461
|
const my = circ1.cy + a9 * dy / d10;
|
|
462
|
-
const candidates =
|
|
463
|
-
[mx +
|
|
464
|
-
[mx -
|
|
462
|
+
const candidates = h10 < tol ? [[mx, my]] : [
|
|
463
|
+
[mx + h10 * dy / d10, my - h10 * dx / d10],
|
|
464
|
+
[mx - h10 * dy / d10, my + h10 * dx / d10]
|
|
465
465
|
];
|
|
466
466
|
const results = [];
|
|
467
467
|
for (const [px, py] of candidates) {
|
|
@@ -486,22 +486,22 @@ function numericalIntersect(c1, c22, tolerance, isSelf = false) {
|
|
|
486
486
|
const N4 = 100;
|
|
487
487
|
const pts1 = [];
|
|
488
488
|
const pts2 = [];
|
|
489
|
-
for (let
|
|
490
|
-
const t1 = b1.first + (b1.last - b1.first) *
|
|
489
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
490
|
+
const t1 = b1.first + (b1.last - b1.first) * i9 / N4;
|
|
491
491
|
const [x1, y1] = evaluateCurve2d(c1, t1);
|
|
492
492
|
pts1.push({ t: t1, x: x1, y: y1 });
|
|
493
|
-
const t22 = b22.first + (b22.last - b22.first) *
|
|
493
|
+
const t22 = b22.first + (b22.last - b22.first) * i9 / N4;
|
|
494
494
|
const [x22, y22] = evaluateCurve2d(c22, t22);
|
|
495
495
|
pts2.push({ t: t22, x: x22, y: y22 });
|
|
496
496
|
}
|
|
497
497
|
const crossTol = Math.max(tolerance * 100, 0.5);
|
|
498
498
|
const candidates = [];
|
|
499
|
-
for (let
|
|
500
|
-
const p1a = pts1[
|
|
501
|
-
const p1b = pts1[
|
|
502
|
-
for (let
|
|
503
|
-
const p2a = pts2[
|
|
504
|
-
const p2b = pts2[
|
|
499
|
+
for (let i9 = 0; i9 < N4; i9++) {
|
|
500
|
+
const p1a = pts1[i9];
|
|
501
|
+
const p1b = pts1[i9 + 1];
|
|
502
|
+
for (let j7 = 0; j7 < N4; j7++) {
|
|
503
|
+
const p2a = pts2[j7];
|
|
504
|
+
const p2b = pts2[j7 + 1];
|
|
505
505
|
const x1min = Math.min(p1a.x, p1b.x) - crossTol;
|
|
506
506
|
const x1max = Math.max(p1a.x, p1b.x) + crossTol;
|
|
507
507
|
const y1min = Math.min(p1a.y, p1b.y) - crossTol;
|
|
@@ -557,8 +557,8 @@ function numericalIntersect(c1, c22, tolerance, isSelf = false) {
|
|
|
557
557
|
}
|
|
558
558
|
return { points: found, segments: [] };
|
|
559
559
|
}
|
|
560
|
-
function serializeCurve2d(
|
|
561
|
-
return JSON.stringify(
|
|
560
|
+
function serializeCurve2d(c8) {
|
|
561
|
+
return JSON.stringify(c8);
|
|
562
562
|
}
|
|
563
563
|
function deserializeCurve2d(data) {
|
|
564
564
|
return JSON.parse(data);
|
|
@@ -566,68 +566,68 @@ function deserializeCurve2d(data) {
|
|
|
566
566
|
function createBBox2d() {
|
|
567
567
|
return { __bk2d_bbox: true, xMin: Infinity, yMin: Infinity, xMax: -Infinity, yMax: -Infinity };
|
|
568
568
|
}
|
|
569
|
-
function addCurveToBBox(bbox,
|
|
570
|
-
const bounds = curveBounds(
|
|
569
|
+
function addCurveToBBox(bbox, c8, _tol) {
|
|
570
|
+
const bounds = curveBounds(c8);
|
|
571
571
|
if (!isFinite(bounds.first) || !isFinite(bounds.last)) return;
|
|
572
572
|
const nSamples = 20;
|
|
573
573
|
const dt = (bounds.last - bounds.first) / nSamples;
|
|
574
|
-
for (let
|
|
575
|
-
const
|
|
576
|
-
const [x7, y6] = evaluateCurve2d(
|
|
574
|
+
for (let i9 = 0; i9 <= nSamples; i9++) {
|
|
575
|
+
const t10 = bounds.first + i9 * dt;
|
|
576
|
+
const [x7, y6] = evaluateCurve2d(c8, t10);
|
|
577
577
|
if (x7 < bbox.xMin) bbox.xMin = x7;
|
|
578
578
|
if (y6 < bbox.yMin) bbox.yMin = y6;
|
|
579
579
|
if (x7 > bbox.xMax) bbox.xMax = x7;
|
|
580
580
|
if (y6 > bbox.yMax) bbox.yMax = y6;
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
|
-
function evaluateBezier(poles,
|
|
584
|
-
const
|
|
583
|
+
function evaluateBezier(poles, t10) {
|
|
584
|
+
const n7 = poles.length;
|
|
585
585
|
const work = poles.map(([x7, y6]) => [x7, y6]);
|
|
586
|
-
for (let r9 = 1; r9 <
|
|
587
|
-
for (let
|
|
588
|
-
const wi = work[
|
|
589
|
-
const wi1 = work[
|
|
590
|
-
wi[0] = (1 -
|
|
591
|
-
wi[1] = (1 -
|
|
586
|
+
for (let r9 = 1; r9 < n7; r9++) {
|
|
587
|
+
for (let i9 = 0; i9 < n7 - r9; i9++) {
|
|
588
|
+
const wi = work[i9];
|
|
589
|
+
const wi1 = work[i9 + 1];
|
|
590
|
+
wi[0] = (1 - t10) * wi[0] + t10 * wi1[0];
|
|
591
|
+
wi[1] = (1 - t10) * wi[1] + t10 * wi1[1];
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
594
|
return work[0];
|
|
595
595
|
}
|
|
596
|
-
function evaluateBSpline2d(
|
|
596
|
+
function evaluateBSpline2d(c8, t10) {
|
|
597
597
|
const fullKnots = [];
|
|
598
|
-
for (let
|
|
599
|
-
const mult =
|
|
600
|
-
for (let
|
|
601
|
-
fullKnots.push(
|
|
598
|
+
for (let i9 = 0; i9 < c8.knots.length; i9++) {
|
|
599
|
+
const mult = c8.multiplicities[i9] ?? 1;
|
|
600
|
+
for (let j7 = 0; j7 < mult; j7++) {
|
|
601
|
+
fullKnots.push(c8.knots[i9]);
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
|
-
const p7 =
|
|
605
|
-
const
|
|
604
|
+
const p7 = c8.degree;
|
|
605
|
+
const n7 = c8.poles.length;
|
|
606
606
|
const k7 = fullKnots.length;
|
|
607
|
-
const tClamped = Math.max(fullKnots[p7], Math.min(fullKnots[k7 - p7 - 1],
|
|
607
|
+
const tClamped = Math.max(fullKnots[p7], Math.min(fullKnots[k7 - p7 - 1], t10));
|
|
608
608
|
let span = p7;
|
|
609
|
-
for (let
|
|
610
|
-
if (tClamped >= fullKnots[
|
|
611
|
-
span =
|
|
609
|
+
for (let i9 = p7; i9 < k7 - p7 - 1; i9++) {
|
|
610
|
+
if (tClamped >= fullKnots[i9] && tClamped < fullKnots[i9 + 1]) {
|
|
611
|
+
span = i9;
|
|
612
612
|
break;
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
615
|
if (tClamped >= fullKnots[k7 - p7 - 1]) span = k7 - p7 - 2;
|
|
616
616
|
const d10 = [];
|
|
617
|
-
for (let
|
|
618
|
-
const idx = Math.min(span - p7 +
|
|
619
|
-
const pole =
|
|
617
|
+
for (let j7 = 0; j7 <= p7; j7++) {
|
|
618
|
+
const idx = Math.min(span - p7 + j7, n7 - 1);
|
|
619
|
+
const pole = c8.poles[Math.max(0, idx)];
|
|
620
620
|
d10.push([pole[0], pole[1]]);
|
|
621
621
|
}
|
|
622
622
|
for (let r9 = 1; r9 <= p7; r9++) {
|
|
623
|
-
for (let
|
|
624
|
-
const
|
|
625
|
-
const left = fullKnots[
|
|
626
|
-
const right = fullKnots[
|
|
623
|
+
for (let j7 = p7; j7 >= r9; j7--) {
|
|
624
|
+
const i9 = span - p7 + j7;
|
|
625
|
+
const left = fullKnots[i9] ?? 0;
|
|
626
|
+
const right = fullKnots[i9 + p7 - r9 + 1] ?? 1;
|
|
627
627
|
const denom = right - left;
|
|
628
628
|
const alpha = denom > 1e-15 ? (tClamped - left) / denom : 0;
|
|
629
|
-
const dj = d10[
|
|
630
|
-
const djPrev = d10[
|
|
629
|
+
const dj = d10[j7];
|
|
630
|
+
const djPrev = d10[j7 - 1];
|
|
631
631
|
dj[0] = (1 - alpha) * djPrev[0] + alpha * dj[0];
|
|
632
632
|
dj[1] = (1 - alpha) * djPrev[1] + alpha * dj[1];
|
|
633
633
|
}
|
|
@@ -669,11 +669,11 @@ function shellHandle(id) {
|
|
|
669
669
|
return handle("shell", id);
|
|
670
670
|
}
|
|
671
671
|
function compoundHandle(id) {
|
|
672
|
-
const
|
|
672
|
+
const h10 = handle("compound", id);
|
|
673
673
|
if (syntheticCompounds.has(id)) {
|
|
674
|
-
return { ...
|
|
674
|
+
return { ...h10, delete: () => syntheticCompounds.delete(id) };
|
|
675
675
|
}
|
|
676
|
-
return
|
|
676
|
+
return h10;
|
|
677
677
|
}
|
|
678
678
|
function vertexHandle(id) {
|
|
679
679
|
return handle("vertex", id);
|
|
@@ -746,20 +746,20 @@ function translationMatrix(x7, y6, z6) {
|
|
|
746
746
|
}
|
|
747
747
|
function rotationMatrix(angleDeg, axis = [0, 0, 1], center = [0, 0, 0]) {
|
|
748
748
|
const rad = angleDeg * Math.PI / 180;
|
|
749
|
-
const
|
|
749
|
+
const c8 = Math.cos(rad);
|
|
750
750
|
const s6 = Math.sin(rad);
|
|
751
|
-
const
|
|
751
|
+
const t10 = 1 - c8;
|
|
752
752
|
const len = Math.sqrt(axis[0] ** 2 + axis[1] ** 2 + axis[2] ** 2);
|
|
753
753
|
const [ux, uy, uz] = [axis[0] / len, axis[1] / len, axis[2] / len];
|
|
754
|
-
const r00 =
|
|
755
|
-
const r01 =
|
|
756
|
-
const r02 =
|
|
757
|
-
const r10 =
|
|
758
|
-
const r11 =
|
|
759
|
-
const r12 =
|
|
760
|
-
const r20 =
|
|
761
|
-
const r21 =
|
|
762
|
-
const r22 =
|
|
754
|
+
const r00 = t10 * ux * ux + c8;
|
|
755
|
+
const r01 = t10 * ux * uy - s6 * uz;
|
|
756
|
+
const r02 = t10 * ux * uz + s6 * uy;
|
|
757
|
+
const r10 = t10 * uy * ux + s6 * uz;
|
|
758
|
+
const r11 = t10 * uy * uy + c8;
|
|
759
|
+
const r12 = t10 * uy * uz - s6 * ux;
|
|
760
|
+
const r20 = t10 * uz * ux - s6 * uy;
|
|
761
|
+
const r21 = t10 * uz * uy + s6 * ux;
|
|
762
|
+
const r22 = t10 * uz * uz + c8;
|
|
763
763
|
const [cx, cy, cz] = center;
|
|
764
764
|
const tx = cx - (r00 * cx + r01 * cy + r02 * cz);
|
|
765
765
|
const ty = cy - (r10 * cx + r11 * cy + r12 * cz);
|
|
@@ -949,9 +949,9 @@ class BrepkitAdapter {
|
|
|
949
949
|
if (this.bk.compoundFuse) {
|
|
950
950
|
const solidIds = [];
|
|
951
951
|
for (const shape2 of shapes) {
|
|
952
|
-
const
|
|
953
|
-
if (
|
|
954
|
-
solidIds.push(...toArray(this.bk.getCompoundSolids(
|
|
952
|
+
const h10 = shape2;
|
|
953
|
+
if (h10.type === "compound") {
|
|
954
|
+
solidIds.push(...toArray(this.bk.getCompoundSolids(h10.id)));
|
|
955
955
|
} else {
|
|
956
956
|
solidIds.push(unwrapSolidOrThrow(shape2, "fuseAll"));
|
|
957
957
|
}
|
|
@@ -965,11 +965,11 @@ class BrepkitAdapter {
|
|
|
965
965
|
let current = [...shapes];
|
|
966
966
|
while (current.length > 1) {
|
|
967
967
|
const next = [];
|
|
968
|
-
for (let
|
|
969
|
-
if (
|
|
970
|
-
next.push(this.fuse(current[
|
|
968
|
+
for (let i9 = 0; i9 < current.length; i9 += 2) {
|
|
969
|
+
if (i9 + 1 < current.length) {
|
|
970
|
+
next.push(this.fuse(current[i9], current[i9 + 1], options));
|
|
971
971
|
} else {
|
|
972
|
-
next.push(current[
|
|
972
|
+
next.push(current[i9]);
|
|
973
973
|
}
|
|
974
974
|
}
|
|
975
975
|
current = next;
|
|
@@ -982,9 +982,9 @@ class BrepkitAdapter {
|
|
|
982
982
|
const baseId = unwrapSolidOrThrow(shape2, "cutAll");
|
|
983
983
|
const toolIds = [];
|
|
984
984
|
for (const tool of tools) {
|
|
985
|
-
const
|
|
986
|
-
if (
|
|
987
|
-
toolIds.push(...toArray(this.bk.getCompoundSolids(
|
|
985
|
+
const h10 = tool;
|
|
986
|
+
if (h10.type === "compound") {
|
|
987
|
+
toolIds.push(...toArray(this.bk.getCompoundSolids(h10.id)));
|
|
988
988
|
} else {
|
|
989
989
|
toolIds.push(unwrapSolidOrThrow(tool, "cutAll"));
|
|
990
990
|
}
|
|
@@ -1015,15 +1015,15 @@ class BrepkitAdapter {
|
|
|
1015
1015
|
hull(shapes, _tolerance) {
|
|
1016
1016
|
const coords = [];
|
|
1017
1017
|
for (const shape2 of shapes) {
|
|
1018
|
-
const
|
|
1019
|
-
if (
|
|
1020
|
-
const vertIds = toArray(this.bk.getSolidVertices(
|
|
1018
|
+
const h10 = shape2;
|
|
1019
|
+
if (h10.type === "solid") {
|
|
1020
|
+
const vertIds = toArray(this.bk.getSolidVertices(h10.id));
|
|
1021
1021
|
for (const vid of vertIds) {
|
|
1022
1022
|
const pos = this.bk.getVertexPosition(vid);
|
|
1023
1023
|
coords.push(pos[0], pos[1], pos[2]);
|
|
1024
1024
|
}
|
|
1025
|
-
} else if (
|
|
1026
|
-
const pos = this.bk.getVertexPosition(
|
|
1025
|
+
} else if (h10.type === "vertex") {
|
|
1026
|
+
const pos = this.bk.getVertexPosition(h10.id);
|
|
1027
1027
|
coords.push(pos[0], pos[1], pos[2]);
|
|
1028
1028
|
}
|
|
1029
1029
|
}
|
|
@@ -1042,18 +1042,18 @@ class BrepkitAdapter {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
buildSolidFromFaces(points, faces, _tolerance) {
|
|
1044
1044
|
const positions = new Float64Array(points.length * 3);
|
|
1045
|
-
for (let
|
|
1046
|
-
const p7 = points[
|
|
1047
|
-
positions[
|
|
1048
|
-
positions[
|
|
1049
|
-
positions[
|
|
1045
|
+
for (let i9 = 0; i9 < points.length; i9++) {
|
|
1046
|
+
const p7 = points[i9];
|
|
1047
|
+
positions[i9 * 3] = p7.x;
|
|
1048
|
+
positions[i9 * 3 + 1] = p7.y;
|
|
1049
|
+
positions[i9 * 3 + 2] = p7.z;
|
|
1050
1050
|
}
|
|
1051
1051
|
const indices = new Uint32Array(faces.length * 3);
|
|
1052
|
-
for (let
|
|
1053
|
-
const
|
|
1054
|
-
indices[
|
|
1055
|
-
indices[
|
|
1056
|
-
indices[
|
|
1052
|
+
for (let i9 = 0; i9 < faces.length; i9++) {
|
|
1053
|
+
const f11 = faces[i9];
|
|
1054
|
+
indices[i9 * 3] = f11[0];
|
|
1055
|
+
indices[i9 * 3 + 1] = f11[1];
|
|
1056
|
+
indices[i9 * 3 + 2] = f11[2];
|
|
1057
1057
|
}
|
|
1058
1058
|
const id = this.bk.importIndexedMesh(positions, indices);
|
|
1059
1059
|
return solidHandle(id);
|
|
@@ -1091,9 +1091,9 @@ class BrepkitAdapter {
|
|
|
1091
1091
|
makeWire(edges) {
|
|
1092
1092
|
const edgeIds = [];
|
|
1093
1093
|
for (const e8 of edges) {
|
|
1094
|
-
const
|
|
1095
|
-
if (
|
|
1096
|
-
for (const childEdgeId of toArray(this.bk.getWireEdges(
|
|
1094
|
+
const h10 = e8;
|
|
1095
|
+
if (h10.type === "wire") {
|
|
1096
|
+
for (const childEdgeId of toArray(this.bk.getWireEdges(h10.id))) {
|
|
1097
1097
|
edgeIds.push(childEdgeId);
|
|
1098
1098
|
}
|
|
1099
1099
|
} else {
|
|
@@ -1104,9 +1104,9 @@ class BrepkitAdapter {
|
|
|
1104
1104
|
return wireHandle(id);
|
|
1105
1105
|
}
|
|
1106
1106
|
makeFace(wire, _planar) {
|
|
1107
|
-
const
|
|
1108
|
-
if (
|
|
1109
|
-
const wireId = this.bk.makeWire([
|
|
1107
|
+
const h10 = wire;
|
|
1108
|
+
if (h10.type === "edge") {
|
|
1109
|
+
const wireId = this.bk.makeWire([h10.id], true);
|
|
1110
1110
|
const id2 = this.bk.makeFaceFromWire(wireId);
|
|
1111
1111
|
return faceHandle(id2);
|
|
1112
1112
|
}
|
|
@@ -1215,40 +1215,21 @@ class BrepkitAdapter {
|
|
|
1215
1215
|
p1[1] + ccx * ux[1] + ccy * uy[1],
|
|
1216
1216
|
p1[2] + ccx * ux[2] + ccy * uy[2]
|
|
1217
1217
|
];
|
|
1218
|
-
const
|
|
1219
|
-
|
|
1218
|
+
const id = this.bk.makeCircleArc3d(
|
|
1219
|
+
p1[0],
|
|
1220
|
+
p1[1],
|
|
1221
|
+
p1[2],
|
|
1222
|
+
p32[0],
|
|
1223
|
+
p32[1],
|
|
1224
|
+
p32[2],
|
|
1225
|
+
center[0],
|
|
1226
|
+
center[1],
|
|
1227
|
+
center[2],
|
|
1228
|
+
nz[0],
|
|
1229
|
+
nz[1],
|
|
1230
|
+
nz[2]
|
|
1220
1231
|
);
|
|
1221
|
-
|
|
1222
|
-
const id = this.bk.makeCircleArc3d(
|
|
1223
|
-
p1[0],
|
|
1224
|
-
p1[1],
|
|
1225
|
-
p1[2],
|
|
1226
|
-
p32[0],
|
|
1227
|
-
p32[1],
|
|
1228
|
-
p32[2],
|
|
1229
|
-
center[0],
|
|
1230
|
-
center[1],
|
|
1231
|
-
center[2],
|
|
1232
|
-
nz[0],
|
|
1233
|
-
nz[1],
|
|
1234
|
-
nz[2]
|
|
1235
|
-
);
|
|
1236
|
-
return edgeHandle(id);
|
|
1237
|
-
}
|
|
1238
|
-
const lx = [p1[0] - center[0], p1[1] - center[1], p1[2] - center[2]];
|
|
1239
|
-
const lxLen = Math.sqrt(lx[0] ** 2 + lx[1] ** 2 + lx[2] ** 2);
|
|
1240
|
-
const uxA = [lx[0] / lxLen, lx[1] / lxLen, lx[2] / lxLen];
|
|
1241
|
-
const uyA = [
|
|
1242
|
-
nz[1] * uxA[2] - nz[2] * uxA[1],
|
|
1243
|
-
nz[2] * uxA[0] - nz[0] * uxA[2],
|
|
1244
|
-
nz[0] * uxA[1] - nz[1] * uxA[0]
|
|
1245
|
-
];
|
|
1246
|
-
const v3f = [p32[0] - center[0], p32[1] - center[1], p32[2] - center[2]];
|
|
1247
|
-
const dotX = v3f[0] * uxA[0] + v3f[1] * uxA[1] + v3f[2] * uxA[2];
|
|
1248
|
-
const dotY = v3f[0] * uyA[0] + v3f[1] * uyA[1] + v3f[2] * uyA[2];
|
|
1249
|
-
let endAngle = Math.atan2(dotY, dotX);
|
|
1250
|
-
if (endAngle <= 0) endAngle += 2 * Math.PI;
|
|
1251
|
-
return this.makeCircleNurbs(center, normal, radius, 0, endAngle);
|
|
1232
|
+
return edgeHandle(id);
|
|
1252
1233
|
}
|
|
1253
1234
|
makeEllipseEdge(center, normal, majorRadius, minorRadius, xDir) {
|
|
1254
1235
|
return this.makeEllipseNurbs(center, normal, majorRadius, minorRadius, 0, 2 * Math.PI, xDir);
|
|
@@ -1267,12 +1248,12 @@ class BrepkitAdapter {
|
|
|
1267
1248
|
makeBezierEdge(points) {
|
|
1268
1249
|
if (points.length < 2) throw new Error("brepkit: bezier requires at least 2 points");
|
|
1269
1250
|
const degree = points.length - 1;
|
|
1270
|
-
const
|
|
1251
|
+
const n7 = points.length;
|
|
1271
1252
|
const knots = [...Array(degree + 1).fill(0), ...Array(degree + 1).fill(1)];
|
|
1272
|
-
const weights = Array(
|
|
1253
|
+
const weights = Array(n7).fill(1);
|
|
1273
1254
|
const flatCp = points.flatMap(([x7, y6, z6]) => [x7, y6, z6]);
|
|
1274
1255
|
const startPt = points[0];
|
|
1275
|
-
const endPt = points[
|
|
1256
|
+
const endPt = points[n7 - 1];
|
|
1276
1257
|
const id = this.bk.makeNurbsEdge(
|
|
1277
1258
|
startPt[0],
|
|
1278
1259
|
startPt[1],
|
|
@@ -1288,73 +1269,21 @@ class BrepkitAdapter {
|
|
|
1288
1269
|
return edgeHandle(id);
|
|
1289
1270
|
}
|
|
1290
1271
|
makeTangentArc(startPoint, startTangent, endPoint) {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
ch[1] - chDotT * t11[1],
|
|
1307
|
-
ch[2] - chDotT * t11[2]
|
|
1308
|
-
];
|
|
1309
|
-
const perpLen = Math.sqrt(perp[0] ** 2 + perp[1] ** 2 + perp[2] ** 2);
|
|
1310
|
-
if (perpLen < 1e-12) return this.makeLineEdge(startPoint, endPoint);
|
|
1311
|
-
const n9 = [perp[0] / perpLen, perp[1] / perpLen, perp[2] / perpLen];
|
|
1312
|
-
const chord2 = ch[0] ** 2 + ch[1] ** 2 + ch[2] ** 2;
|
|
1313
|
-
const nDotCh = n9[0] * ch[0] + n9[1] * ch[1] + n9[2] * ch[2];
|
|
1314
|
-
const s6 = -chord2 / (2 * nDotCh);
|
|
1315
|
-
const center = [
|
|
1316
|
-
startPoint[0] + s6 * n9[0],
|
|
1317
|
-
startPoint[1] + s6 * n9[1],
|
|
1318
|
-
startPoint[2] + s6 * n9[2]
|
|
1319
|
-
];
|
|
1320
|
-
const radius = Math.abs(s6);
|
|
1321
|
-
const e1 = [
|
|
1322
|
-
(startPoint[0] - center[0]) / radius,
|
|
1323
|
-
(startPoint[1] - center[1]) / radius,
|
|
1324
|
-
(startPoint[2] - center[2]) / radius
|
|
1325
|
-
];
|
|
1326
|
-
const e22 = [
|
|
1327
|
-
(endPoint[0] - center[0]) / radius,
|
|
1328
|
-
(endPoint[1] - center[1]) / radius,
|
|
1329
|
-
(endPoint[2] - center[2]) / radius
|
|
1330
|
-
];
|
|
1331
|
-
let mx = e1[0] + e22[0];
|
|
1332
|
-
let my = e1[1] + e22[1];
|
|
1333
|
-
let mz = e1[2] + e22[2];
|
|
1334
|
-
let mLen = Math.sqrt(mx * mx + my * my + mz * mz);
|
|
1335
|
-
if (mLen < 1e-12) {
|
|
1336
|
-
mx = t11[0];
|
|
1337
|
-
my = t11[1];
|
|
1338
|
-
mz = t11[2];
|
|
1339
|
-
mLen = 1;
|
|
1340
|
-
}
|
|
1341
|
-
const mid = [
|
|
1342
|
-
center[0] + radius * mx / mLen,
|
|
1343
|
-
center[1] + radius * my / mLen,
|
|
1344
|
-
center[2] + radius * mz / mLen
|
|
1345
|
-
];
|
|
1346
|
-
const toMid = [
|
|
1347
|
-
mid[0] - startPoint[0],
|
|
1348
|
-
mid[1] - startPoint[1],
|
|
1349
|
-
mid[2] - startPoint[2]
|
|
1350
|
-
];
|
|
1351
|
-
const dotTM = t11[0] * toMid[0] + t11[1] * toMid[1] + t11[2] * toMid[2];
|
|
1352
|
-
if (dotTM < 0) {
|
|
1353
|
-
mid[0] = center[0] - radius * mx / mLen;
|
|
1354
|
-
mid[1] = center[1] - radius * my / mLen;
|
|
1355
|
-
mid[2] = center[2] - radius * mz / mLen;
|
|
1356
|
-
}
|
|
1357
|
-
return this.makeArcEdge(startPoint, mid, endPoint);
|
|
1272
|
+
if (!this.bk.makeTangentArc3d) {
|
|
1273
|
+
throw new Error("makeTangentArc requires brepkit-wasm >= 1.1.0");
|
|
1274
|
+
}
|
|
1275
|
+
const id = this.bk.makeTangentArc3d(
|
|
1276
|
+
startPoint[0],
|
|
1277
|
+
startPoint[1],
|
|
1278
|
+
startPoint[2],
|
|
1279
|
+
startTangent[0],
|
|
1280
|
+
startTangent[1],
|
|
1281
|
+
startTangent[2],
|
|
1282
|
+
endPoint[0],
|
|
1283
|
+
endPoint[1],
|
|
1284
|
+
endPoint[2]
|
|
1285
|
+
);
|
|
1286
|
+
return edgeHandle(id);
|
|
1358
1287
|
}
|
|
1359
1288
|
makeHelixWire(pitch, height, radius, center, _direction, leftHanded) {
|
|
1360
1289
|
const turns = height / pitch;
|
|
@@ -1365,10 +1294,10 @@ class BrepkitAdapter {
|
|
|
1365
1294
|
const cz = center?.[2] ?? 0;
|
|
1366
1295
|
const sign = leftHanded ? -1 : 1;
|
|
1367
1296
|
const points = [];
|
|
1368
|
-
for (let
|
|
1369
|
-
const
|
|
1370
|
-
const angle = sign * 2 * Math.PI * turns *
|
|
1371
|
-
points.push([cx + radius * Math.cos(angle), cy + radius * Math.sin(angle), cz + height *
|
|
1297
|
+
for (let i9 = 0; i9 <= nSamples; i9++) {
|
|
1298
|
+
const t10 = i9 / nSamples;
|
|
1299
|
+
const angle = sign * 2 * Math.PI * turns * t10;
|
|
1300
|
+
points.push([cx + radius * Math.cos(angle), cy + radius * Math.sin(angle), cz + height * t10]);
|
|
1372
1301
|
}
|
|
1373
1302
|
const edge = this.interpolatePoints(points);
|
|
1374
1303
|
return this.makeWire([edge]);
|
|
@@ -1376,11 +1305,11 @@ class BrepkitAdapter {
|
|
|
1376
1305
|
makeWireFromMixed(items) {
|
|
1377
1306
|
const edgeIds = [];
|
|
1378
1307
|
for (const item of items) {
|
|
1379
|
-
const
|
|
1380
|
-
if (
|
|
1381
|
-
edgeIds.push(
|
|
1382
|
-
} else if (
|
|
1383
|
-
for (const childEdgeId of toArray(this.bk.getWireEdges(
|
|
1308
|
+
const h10 = item;
|
|
1309
|
+
if (h10.type === "edge") {
|
|
1310
|
+
edgeIds.push(h10.id);
|
|
1311
|
+
} else if (h10.type === "wire") {
|
|
1312
|
+
for (const childEdgeId of toArray(this.bk.getWireEdges(h10.id))) {
|
|
1384
1313
|
edgeIds.push(childEdgeId);
|
|
1385
1314
|
}
|
|
1386
1315
|
}
|
|
@@ -1395,9 +1324,9 @@ class BrepkitAdapter {
|
|
|
1395
1324
|
if (handles.length === 0) {
|
|
1396
1325
|
throw new Error("brepkit: makeCompound requires at least one shape");
|
|
1397
1326
|
}
|
|
1398
|
-
const allSolids = handles.every((
|
|
1327
|
+
const allSolids = handles.every((h10) => h10.type === "solid");
|
|
1399
1328
|
if (allSolids) {
|
|
1400
|
-
const id2 = this.bk.makeCompound(handles.map((
|
|
1329
|
+
const id2 = this.bk.makeCompound(handles.map((h10) => h10.id));
|
|
1401
1330
|
return compoundHandle(id2);
|
|
1402
1331
|
}
|
|
1403
1332
|
const id = syntheticCompoundCounter++;
|
|
@@ -1406,9 +1335,9 @@ class BrepkitAdapter {
|
|
|
1406
1335
|
}
|
|
1407
1336
|
makeBoxFromCorners(p1, p22) {
|
|
1408
1337
|
const w7 = Math.abs(p22[0] - p1[0]);
|
|
1409
|
-
const
|
|
1338
|
+
const h10 = Math.abs(p22[1] - p1[1]);
|
|
1410
1339
|
const d10 = Math.abs(p22[2] - p1[2]);
|
|
1411
|
-
const box = this.makeBox(w7,
|
|
1340
|
+
const box = this.makeBox(w7, h10, d10);
|
|
1412
1341
|
const minX = Math.min(p1[0], p22[0]);
|
|
1413
1342
|
const minY = Math.min(p1[1], p22[1]);
|
|
1414
1343
|
const minZ = Math.min(p1[2], p22[2]);
|
|
@@ -1418,15 +1347,15 @@ class BrepkitAdapter {
|
|
|
1418
1347
|
return box;
|
|
1419
1348
|
}
|
|
1420
1349
|
solidFromShell(shell2) {
|
|
1421
|
-
const
|
|
1422
|
-
if (
|
|
1423
|
-
if (
|
|
1350
|
+
const h10 = shell2;
|
|
1351
|
+
if (h10.type === "solid") return shell2;
|
|
1352
|
+
if (h10.type === "shell") {
|
|
1424
1353
|
try {
|
|
1425
|
-
this.bk.getSolidFaces(
|
|
1426
|
-
return solidHandle(
|
|
1354
|
+
this.bk.getSolidFaces(h10.id);
|
|
1355
|
+
return solidHandle(h10.id);
|
|
1427
1356
|
} catch {
|
|
1428
1357
|
}
|
|
1429
|
-
const id2 = this.bk.solidFromShell(
|
|
1358
|
+
const id2 = this.bk.solidFromShell(h10.id);
|
|
1430
1359
|
return solidHandle(id2);
|
|
1431
1360
|
}
|
|
1432
1361
|
const id = this.bk.solidFromShell(unwrap(shell2, "shell"));
|
|
@@ -1487,9 +1416,9 @@ class BrepkitAdapter {
|
|
|
1487
1416
|
);
|
|
1488
1417
|
}
|
|
1489
1418
|
const faceIds = wires.map((w7) => {
|
|
1490
|
-
const
|
|
1491
|
-
if (
|
|
1492
|
-
return this.bk.makeFaceFromWire(
|
|
1419
|
+
const h10 = w7;
|
|
1420
|
+
if (h10.type === "wire") {
|
|
1421
|
+
return this.bk.makeFaceFromWire(h10.id);
|
|
1493
1422
|
}
|
|
1494
1423
|
return unwrap(w7, "face");
|
|
1495
1424
|
});
|
|
@@ -1555,8 +1484,8 @@ class BrepkitAdapter {
|
|
|
1555
1484
|
return solidHandle(this.bk.fillet(solidId, edgeIds, radius));
|
|
1556
1485
|
}
|
|
1557
1486
|
const spec = [];
|
|
1558
|
-
for (const [
|
|
1559
|
-
const edgeId = edgeIds[
|
|
1487
|
+
for (const [i9, edge] of edges.entries()) {
|
|
1488
|
+
const edgeId = edgeIds[i9] ?? 0;
|
|
1560
1489
|
let r9;
|
|
1561
1490
|
if (typeof radius === "function") {
|
|
1562
1491
|
r9 = radius(edge);
|
|
@@ -1599,8 +1528,8 @@ class BrepkitAdapter {
|
|
|
1599
1528
|
const solidId = unwrapSolidOrThrow(shape2, "shell");
|
|
1600
1529
|
const solidFaces = toArray(this.bk.getSolidFaces(solidId));
|
|
1601
1530
|
const solidFaceSet = new Set(solidFaces);
|
|
1602
|
-
const resolvedFaceIds = faces.map((
|
|
1603
|
-
const fid = unwrap(
|
|
1531
|
+
const resolvedFaceIds = faces.map((f11) => {
|
|
1532
|
+
const fid = unwrap(f11, "face");
|
|
1604
1533
|
if (solidFaceSet.has(fid)) return fid;
|
|
1605
1534
|
try {
|
|
1606
1535
|
const origNormal = this.bk.getFaceNormal(fid);
|
|
@@ -1626,9 +1555,9 @@ class BrepkitAdapter {
|
|
|
1626
1555
|
return solidHandle(id);
|
|
1627
1556
|
}
|
|
1628
1557
|
thicken(shape2, thickness) {
|
|
1629
|
-
const
|
|
1630
|
-
if (
|
|
1631
|
-
const id = this.bk.thicken(
|
|
1558
|
+
const h10 = shape2;
|
|
1559
|
+
if (h10.type === "face") {
|
|
1560
|
+
const id = this.bk.thicken(h10.id, thickness);
|
|
1632
1561
|
return solidHandle(id);
|
|
1633
1562
|
}
|
|
1634
1563
|
throw new Error("brepkit: thicken() requires a face");
|
|
@@ -1640,9 +1569,9 @@ class BrepkitAdapter {
|
|
|
1640
1569
|
"offset() tolerance parameter is not supported; brepkit uses its own internal tolerance."
|
|
1641
1570
|
);
|
|
1642
1571
|
}
|
|
1643
|
-
const
|
|
1644
|
-
if (
|
|
1645
|
-
const id2 = this.bk.thicken(
|
|
1572
|
+
const h10 = shape2;
|
|
1573
|
+
if (h10.type === "face") {
|
|
1574
|
+
const id2 = this.bk.thicken(h10.id, distance);
|
|
1646
1575
|
return solidHandle(id2);
|
|
1647
1576
|
}
|
|
1648
1577
|
const id = this.bk.offsetSolid(unwrapSolidOrThrow(shape2, "offset"), distance);
|
|
@@ -1664,10 +1593,10 @@ class BrepkitAdapter {
|
|
|
1664
1593
|
return this.applyMatrix(shape2, rotationMatrix(angle, axis, center));
|
|
1665
1594
|
}
|
|
1666
1595
|
mirror(shape2, origin, normal) {
|
|
1667
|
-
const
|
|
1668
|
-
if (
|
|
1596
|
+
const h10 = shape2;
|
|
1597
|
+
if (h10.type === "solid") {
|
|
1669
1598
|
const id = this.bk.mirror(
|
|
1670
|
-
|
|
1599
|
+
h10.id,
|
|
1671
1600
|
origin[0],
|
|
1672
1601
|
origin[1],
|
|
1673
1602
|
origin[2],
|
|
@@ -1737,16 +1666,16 @@ class BrepkitAdapter {
|
|
|
1737
1666
|
* fallback when hash matching fails (brepkit always creates new face IDs).
|
|
1738
1667
|
*/
|
|
1739
1668
|
buildEvolution(resultShape, inputFaceHashes, hashUpperBound, isTransform, originalShape) {
|
|
1740
|
-
const
|
|
1669
|
+
const h10 = resultShape;
|
|
1741
1670
|
const modified = /* @__PURE__ */ new Map();
|
|
1742
1671
|
const generated = /* @__PURE__ */ new Map();
|
|
1743
1672
|
const deleted = /* @__PURE__ */ new Set();
|
|
1744
|
-
if (
|
|
1745
|
-
const outputFaces = toArray(this.bk.getSolidFaces(
|
|
1673
|
+
if (h10.type === "solid") {
|
|
1674
|
+
const outputFaces = toArray(this.bk.getSolidFaces(h10.id));
|
|
1746
1675
|
const outputHashes = outputFaces.map((fid) => fid % hashUpperBound);
|
|
1747
1676
|
if (isTransform) {
|
|
1748
|
-
for (let
|
|
1749
|
-
modified.set(inputFaceHashes[
|
|
1677
|
+
for (let i9 = 0; i9 < inputFaceHashes.length && i9 < outputHashes.length; i9++) {
|
|
1678
|
+
modified.set(inputFaceHashes[i9], [outputHashes[i9]]);
|
|
1750
1679
|
}
|
|
1751
1680
|
} else {
|
|
1752
1681
|
const inputSet = new Set(inputFaceHashes);
|
|
@@ -1784,8 +1713,8 @@ class BrepkitAdapter {
|
|
|
1784
1713
|
deleted
|
|
1785
1714
|
);
|
|
1786
1715
|
} else {
|
|
1787
|
-
for (let
|
|
1788
|
-
modified.set(inputFaceHashes[
|
|
1716
|
+
for (let i9 = 0; i9 < inputFaceHashes.length && i9 < outputHashes.length; i9++) {
|
|
1717
|
+
modified.set(inputFaceHashes[i9], [outputHashes[i9]]);
|
|
1789
1718
|
}
|
|
1790
1719
|
if (outputHashes.length > inputFaceHashes.length && inputFaceHashes.length > 0) {
|
|
1791
1720
|
generated.set(inputFaceHashes[0], outputHashes.slice(inputFaceHashes.length));
|
|
@@ -1825,10 +1754,10 @@ class BrepkitAdapter {
|
|
|
1825
1754
|
}
|
|
1826
1755
|
}
|
|
1827
1756
|
/** Squared Euclidean distance between two 3-component centroids. */
|
|
1828
|
-
static centroidDistSq(a9,
|
|
1829
|
-
const dx = a9[0] -
|
|
1830
|
-
const dy = a9[1] -
|
|
1831
|
-
const dz = a9[2] -
|
|
1757
|
+
static centroidDistSq(a9, b9) {
|
|
1758
|
+
const dx = a9[0] - b9[0];
|
|
1759
|
+
const dy = a9[1] - b9[1];
|
|
1760
|
+
const dz = a9[2] - b9[2];
|
|
1832
1761
|
return dx * dx + dy * dy + dz * dz;
|
|
1833
1762
|
}
|
|
1834
1763
|
/** Compute face centroid as the average of tessellation vertices. */
|
|
@@ -1840,10 +1769,10 @@ class BrepkitAdapter {
|
|
|
1840
1769
|
let cy = 0;
|
|
1841
1770
|
let cz = 0;
|
|
1842
1771
|
const nVerts = pos.length / 3;
|
|
1843
|
-
for (let
|
|
1844
|
-
cx += pos[
|
|
1845
|
-
cy += pos[
|
|
1846
|
-
cz += pos[
|
|
1772
|
+
for (let i9 = 0; i9 < pos.length; i9 += 3) {
|
|
1773
|
+
cx += pos[i9];
|
|
1774
|
+
cy += pos[i9 + 1];
|
|
1775
|
+
cz += pos[i9 + 2];
|
|
1847
1776
|
}
|
|
1848
1777
|
return [cx / nVerts, cy / nVerts, cz / nVerts];
|
|
1849
1778
|
} catch {
|
|
@@ -1860,15 +1789,15 @@ class BrepkitAdapter {
|
|
|
1860
1789
|
const inputFaceIds = toArray(this.bk.getSolidFaces(orig.id));
|
|
1861
1790
|
const hashCount = Math.min(inputFaceIds.length, inputFaceHashes.length);
|
|
1862
1791
|
const inputSigs = [];
|
|
1863
|
-
for (let
|
|
1864
|
-
const fid = inputFaceIds[
|
|
1792
|
+
for (let i9 = 0; i9 < hashCount; i9++) {
|
|
1793
|
+
const fid = inputFaceIds[i9];
|
|
1865
1794
|
try {
|
|
1866
1795
|
const normal = this.bk.getFaceNormal(fid);
|
|
1867
1796
|
const centroid = this.faceCentroidById(fid);
|
|
1868
|
-
inputSigs.push({ hash: inputFaceHashes[
|
|
1797
|
+
inputSigs.push({ hash: inputFaceHashes[i9] ?? fid % hashUpperBound, normal, centroid });
|
|
1869
1798
|
} catch {
|
|
1870
1799
|
inputSigs.push({
|
|
1871
|
-
hash: inputFaceHashes[
|
|
1800
|
+
hash: inputFaceHashes[i9] ?? fid % hashUpperBound,
|
|
1872
1801
|
normal: [0, 0, 0],
|
|
1873
1802
|
centroid: this.faceCentroidById(fid)
|
|
1874
1803
|
});
|
|
@@ -1894,8 +1823,8 @@ class BrepkitAdapter {
|
|
|
1894
1823
|
for (const out of outputSigs) {
|
|
1895
1824
|
let bestScore = -Infinity;
|
|
1896
1825
|
let bestIdx = -1;
|
|
1897
|
-
for (let
|
|
1898
|
-
const inp = inputSigs[
|
|
1826
|
+
for (let i9 = 0; i9 < inputSigs.length; i9++) {
|
|
1827
|
+
const inp = inputSigs[i9];
|
|
1899
1828
|
const dot = (out.normal[0] ?? 0) * (inp.normal[0] ?? 0) + (out.normal[1] ?? 0) * (inp.normal[1] ?? 0) + (out.normal[2] ?? 0) * (inp.normal[2] ?? 0);
|
|
1900
1829
|
if (dot < NORMAL_THRESHOLD) continue;
|
|
1901
1830
|
const distSq = BrepkitAdapter.centroidDistSq(out.centroid, inp.centroid);
|
|
@@ -1903,7 +1832,7 @@ class BrepkitAdapter {
|
|
|
1903
1832
|
const score = dot - distSq / CENTROID_DIST_SQ_MAX;
|
|
1904
1833
|
if (score > bestScore) {
|
|
1905
1834
|
bestScore = score;
|
|
1906
|
-
bestIdx =
|
|
1835
|
+
bestIdx = i9;
|
|
1907
1836
|
}
|
|
1908
1837
|
}
|
|
1909
1838
|
if (bestIdx >= 0) {
|
|
@@ -1929,9 +1858,9 @@ class BrepkitAdapter {
|
|
|
1929
1858
|
}
|
|
1930
1859
|
}
|
|
1931
1860
|
}
|
|
1932
|
-
for (let
|
|
1933
|
-
if (!matchedInputIndices.has(
|
|
1934
|
-
deleted.add(inputSigs[
|
|
1861
|
+
for (let i9 = 0; i9 < inputSigs.length; i9++) {
|
|
1862
|
+
if (!matchedInputIndices.has(i9)) {
|
|
1863
|
+
deleted.add(inputSigs[i9].hash);
|
|
1935
1864
|
}
|
|
1936
1865
|
}
|
|
1937
1866
|
}
|
|
@@ -2048,8 +1977,8 @@ class BrepkitAdapter {
|
|
|
2048
1977
|
inputFaceHashes,
|
|
2049
1978
|
hashUpperBound,
|
|
2050
1979
|
options,
|
|
2051
|
-
(a9,
|
|
2052
|
-
(s6,
|
|
1980
|
+
(a9, b9) => this.bk.fuseWithEvolution(a9, b9),
|
|
1981
|
+
(s6, t10, o9) => this.fuse(s6, t10, o9),
|
|
2053
1982
|
"fuseWithHistory"
|
|
2054
1983
|
);
|
|
2055
1984
|
}
|
|
@@ -2060,8 +1989,8 @@ class BrepkitAdapter {
|
|
|
2060
1989
|
inputFaceHashes,
|
|
2061
1990
|
hashUpperBound,
|
|
2062
1991
|
options,
|
|
2063
|
-
(a9,
|
|
2064
|
-
(s6,
|
|
1992
|
+
(a9, b9) => this.bk.cutWithEvolution(a9, b9),
|
|
1993
|
+
(s6, t10, o9) => this.cut(s6, t10, o9),
|
|
2065
1994
|
"cutWithHistory"
|
|
2066
1995
|
);
|
|
2067
1996
|
}
|
|
@@ -2072,8 +2001,8 @@ class BrepkitAdapter {
|
|
|
2072
2001
|
inputFaceHashes,
|
|
2073
2002
|
hashUpperBound,
|
|
2074
2003
|
options,
|
|
2075
|
-
(a9,
|
|
2076
|
-
(s6,
|
|
2004
|
+
(a9, b9) => this.bk.intersectWithEvolution(a9, b9),
|
|
2005
|
+
(s6, t10, o9) => this.intersect(s6, t10, o9),
|
|
2077
2006
|
"intersectWithHistory"
|
|
2078
2007
|
);
|
|
2079
2008
|
}
|
|
@@ -2132,14 +2061,14 @@ class BrepkitAdapter {
|
|
|
2132
2061
|
"mesh angularTolerance is not supported; only linear deflection is used."
|
|
2133
2062
|
);
|
|
2134
2063
|
}
|
|
2135
|
-
const
|
|
2064
|
+
const h10 = unwrap(shape2);
|
|
2136
2065
|
const bkHandle = shape2;
|
|
2137
2066
|
const deflection = options.tolerance || DEFAULT_DEFLECTION;
|
|
2138
2067
|
let result;
|
|
2139
2068
|
if (bkHandle.type === "solid") {
|
|
2140
|
-
result = this.meshSolid(
|
|
2069
|
+
result = this.meshSolid(h10, deflection, !!options.includeUVs);
|
|
2141
2070
|
} else if (bkHandle.type === "face") {
|
|
2142
|
-
result = this.meshSingleFace(
|
|
2071
|
+
result = this.meshSingleFace(h10, deflection, 0);
|
|
2143
2072
|
} else {
|
|
2144
2073
|
throw new Error(`brepkit: cannot mesh shape of type '${bkHandle.type}'`);
|
|
2145
2074
|
}
|
|
@@ -2162,16 +2091,16 @@ class BrepkitAdapter {
|
|
|
2162
2091
|
if (bkHandle.type !== "solid") {
|
|
2163
2092
|
return { lines: new Float32Array(0), edgeGroups: [] };
|
|
2164
2093
|
}
|
|
2165
|
-
const edgeLines = this.bk.meshEdges(bkHandle.id, tolerance);
|
|
2094
|
+
const edgeLines = this.bk.meshEdgesAll ? this.bk.meshEdgesAll(bkHandle.id, tolerance) : this.bk.meshEdges(bkHandle.id, tolerance);
|
|
2166
2095
|
const positions = edgeLines.positions;
|
|
2167
2096
|
const offsets = edgeLines.offsets;
|
|
2168
2097
|
const edgeCount = edgeLines.edgeCount;
|
|
2169
2098
|
const edgeGroups = [];
|
|
2170
|
-
for (let
|
|
2171
|
-
const startIdx = offsets[
|
|
2172
|
-
const endIdx =
|
|
2099
|
+
for (let i9 = 0; i9 < edgeCount; i9++) {
|
|
2100
|
+
const startIdx = offsets[i9];
|
|
2101
|
+
const endIdx = i9 + 1 < edgeCount ? offsets[i9 + 1] : positions.length;
|
|
2173
2102
|
const pointCount = (endIdx - startIdx) / 3;
|
|
2174
|
-
edgeGroups.push({ start: startIdx / 3, count: pointCount, edgeHash:
|
|
2103
|
+
edgeGroups.push({ start: startIdx / 3, count: pointCount, edgeHash: i9 });
|
|
2175
2104
|
}
|
|
2176
2105
|
return {
|
|
2177
2106
|
lines: new Float32Array(positions),
|
|
@@ -2236,11 +2165,11 @@ class BrepkitAdapter {
|
|
|
2236
2165
|
// Measurement
|
|
2237
2166
|
// ═══════════════════════════════════════════════════════════════════════
|
|
2238
2167
|
volume(shape2) {
|
|
2239
|
-
const
|
|
2240
|
-
if (
|
|
2168
|
+
const h10 = shape2;
|
|
2169
|
+
if (h10.type === "solid") {
|
|
2241
2170
|
return this.bk.volume(unwrap(shape2), DEFAULT_DEFLECTION);
|
|
2242
2171
|
}
|
|
2243
|
-
if (
|
|
2172
|
+
if (h10.type === "compound") {
|
|
2244
2173
|
const solids = this.iterShapes(shape2, "solid");
|
|
2245
2174
|
let total = 0;
|
|
2246
2175
|
for (const s6 of solids) {
|
|
@@ -2251,14 +2180,14 @@ class BrepkitAdapter {
|
|
|
2251
2180
|
return 0;
|
|
2252
2181
|
}
|
|
2253
2182
|
area(shape2) {
|
|
2254
|
-
const
|
|
2255
|
-
if (
|
|
2183
|
+
const h10 = shape2;
|
|
2184
|
+
if (h10.type === "face") {
|
|
2256
2185
|
return this.bk.faceArea(unwrap(shape2), DEFAULT_DEFLECTION);
|
|
2257
2186
|
}
|
|
2258
|
-
if (
|
|
2187
|
+
if (h10.type === "solid") {
|
|
2259
2188
|
return this.bk.surfaceArea(unwrap(shape2), DEFAULT_DEFLECTION);
|
|
2260
2189
|
}
|
|
2261
|
-
if (
|
|
2190
|
+
if (h10.type === "compound") {
|
|
2262
2191
|
const faces = this.iterShapes(shape2, "face");
|
|
2263
2192
|
let total = 0;
|
|
2264
2193
|
for (const face of faces) {
|
|
@@ -2269,39 +2198,39 @@ class BrepkitAdapter {
|
|
|
2269
2198
|
return 0;
|
|
2270
2199
|
}
|
|
2271
2200
|
length(shape2) {
|
|
2272
|
-
const
|
|
2273
|
-
if (
|
|
2201
|
+
const h10 = shape2;
|
|
2202
|
+
if (h10.type === "edge") {
|
|
2274
2203
|
return this.bk.edgeLength(unwrap(shape2));
|
|
2275
2204
|
}
|
|
2276
|
-
if (
|
|
2205
|
+
if (h10.type === "face") {
|
|
2277
2206
|
return this.bk.facePerimeter(unwrap(shape2));
|
|
2278
2207
|
}
|
|
2279
|
-
if (
|
|
2280
|
-
return this.bk.wireLength(
|
|
2208
|
+
if (h10.type === "wire") {
|
|
2209
|
+
return this.bk.wireLength(h10.id);
|
|
2281
2210
|
}
|
|
2282
2211
|
throw new Error("brepkit: length() requires an edge, wire, or face");
|
|
2283
2212
|
}
|
|
2284
2213
|
centerOfMass(shape2) {
|
|
2285
|
-
const
|
|
2286
|
-
if (
|
|
2214
|
+
const h10 = shape2;
|
|
2215
|
+
if (h10.type === "solid") {
|
|
2287
2216
|
const result = this.bk.centerOfMass(unwrap(shape2), DEFAULT_DEFLECTION);
|
|
2288
2217
|
return [result[0], result[1], result[2]];
|
|
2289
2218
|
}
|
|
2290
|
-
if (
|
|
2219
|
+
if (h10.type === "face") {
|
|
2291
2220
|
const domain = this.uvBounds(shape2);
|
|
2292
2221
|
const uMid = (domain.uMin + domain.uMax) / 2;
|
|
2293
2222
|
const vMid = (domain.vMin + domain.vMax) / 2;
|
|
2294
2223
|
return this.pointOnSurface(shape2, uMid, vMid);
|
|
2295
2224
|
}
|
|
2296
|
-
if (
|
|
2297
|
-
const verts = this.bk.getEdgeVertices(
|
|
2225
|
+
if (h10.type === "edge") {
|
|
2226
|
+
const verts = this.bk.getEdgeVertices(h10.id);
|
|
2298
2227
|
return [
|
|
2299
2228
|
(verts[0] + verts[3]) / 2,
|
|
2300
2229
|
(verts[1] + verts[4]) / 2,
|
|
2301
2230
|
(verts[2] + verts[5]) / 2
|
|
2302
2231
|
];
|
|
2303
2232
|
}
|
|
2304
|
-
if (
|
|
2233
|
+
if (h10.type === "vertex") {
|
|
2305
2234
|
return this.vertexPosition(shape2);
|
|
2306
2235
|
}
|
|
2307
2236
|
const vertices = this.iterShapes(shape2, "vertex");
|
|
@@ -2318,9 +2247,9 @@ class BrepkitAdapter {
|
|
|
2318
2247
|
return [0, 0, 0];
|
|
2319
2248
|
}
|
|
2320
2249
|
linearCenterOfMass(shape2) {
|
|
2321
|
-
const
|
|
2322
|
-
if (
|
|
2323
|
-
const verts = this.bk.getEdgeVertices(
|
|
2250
|
+
const h10 = shape2;
|
|
2251
|
+
if (h10.type === "edge") {
|
|
2252
|
+
const verts = this.bk.getEdgeVertices(h10.id);
|
|
2324
2253
|
return [
|
|
2325
2254
|
(verts[0] + verts[3]) / 2,
|
|
2326
2255
|
(verts[1] + verts[4]) / 2,
|
|
@@ -2330,15 +2259,15 @@ class BrepkitAdapter {
|
|
|
2330
2259
|
return this.centerOfMass(shape2);
|
|
2331
2260
|
}
|
|
2332
2261
|
boundingBox(shape2) {
|
|
2333
|
-
const
|
|
2334
|
-
if (
|
|
2262
|
+
const h10 = shape2;
|
|
2263
|
+
if (h10.type === "solid") {
|
|
2335
2264
|
const bb = this.bk.boundingBox(unwrap(shape2));
|
|
2336
2265
|
return {
|
|
2337
2266
|
min: [bb[0], bb[1], bb[2]],
|
|
2338
2267
|
max: [bb[3], bb[4], bb[5]]
|
|
2339
2268
|
};
|
|
2340
2269
|
}
|
|
2341
|
-
if (
|
|
2270
|
+
if (h10.type === "vertex") {
|
|
2342
2271
|
const pos = this.vertexPosition(shape2);
|
|
2343
2272
|
return { min: [...pos], max: [...pos] };
|
|
2344
2273
|
}
|
|
@@ -2349,8 +2278,8 @@ class BrepkitAdapter {
|
|
|
2349
2278
|
const first = this.vertexPosition(vertices[0]);
|
|
2350
2279
|
let minX = first[0], minY = first[1], minZ = first[2];
|
|
2351
2280
|
let maxX = first[0], maxY = first[1], maxZ = first[2];
|
|
2352
|
-
for (let
|
|
2353
|
-
const p7 = this.vertexPosition(vertices[
|
|
2281
|
+
for (let i9 = 1; i9 < vertices.length; i9++) {
|
|
2282
|
+
const p7 = this.vertexPosition(vertices[i9]);
|
|
2354
2283
|
if (p7[0] < minX) minX = p7[0];
|
|
2355
2284
|
if (p7[0] > maxX) maxX = p7[0];
|
|
2356
2285
|
if (p7[1] < minY) minY = p7[1];
|
|
@@ -2364,11 +2293,11 @@ class BrepkitAdapter {
|
|
|
2364
2293
|
// Topology introspection
|
|
2365
2294
|
// ═══════════════════════════════════════════════════════════════════════
|
|
2366
2295
|
iterShapes(shape2, type) {
|
|
2367
|
-
const
|
|
2296
|
+
const h10 = unwrap(shape2);
|
|
2368
2297
|
const bkHandle = shape2;
|
|
2369
2298
|
switch (bkHandle.type) {
|
|
2370
2299
|
case "compound": {
|
|
2371
|
-
const children = syntheticCompounds.get(
|
|
2300
|
+
const children = syntheticCompounds.get(h10);
|
|
2372
2301
|
if (children) {
|
|
2373
2302
|
const results = [];
|
|
2374
2303
|
for (const child of children) {
|
|
@@ -2381,10 +2310,10 @@ class BrepkitAdapter {
|
|
|
2381
2310
|
return results;
|
|
2382
2311
|
}
|
|
2383
2312
|
if (type === "solid") {
|
|
2384
|
-
return toArray(this.bk.getCompoundSolids(
|
|
2313
|
+
return toArray(this.bk.getCompoundSolids(h10)).map(solidHandle);
|
|
2385
2314
|
}
|
|
2386
2315
|
if (type === "face" || type === "edge" || type === "vertex" || type === "wire") {
|
|
2387
|
-
const solids = toArray(this.bk.getCompoundSolids(
|
|
2316
|
+
const solids = toArray(this.bk.getCompoundSolids(h10)).map(solidHandle);
|
|
2388
2317
|
return solids.flatMap((s6) => this.iterShapes(s6, type));
|
|
2389
2318
|
}
|
|
2390
2319
|
return [];
|
|
@@ -2392,13 +2321,13 @@ class BrepkitAdapter {
|
|
|
2392
2321
|
case "solid": {
|
|
2393
2322
|
switch (type) {
|
|
2394
2323
|
case "face":
|
|
2395
|
-
return toArray(this.bk.getSolidFaces(
|
|
2324
|
+
return toArray(this.bk.getSolidFaces(h10)).map(faceHandle);
|
|
2396
2325
|
case "edge":
|
|
2397
|
-
return toArray(this.bk.getSolidEdges(
|
|
2326
|
+
return toArray(this.bk.getSolidEdges(h10)).map(edgeHandle);
|
|
2398
2327
|
case "vertex":
|
|
2399
|
-
return toArray(this.bk.getSolidVertices(
|
|
2328
|
+
return toArray(this.bk.getSolidVertices(h10)).map(vertexHandle);
|
|
2400
2329
|
case "wire":
|
|
2401
|
-
return toArray(this.bk.getSolidFaces(
|
|
2330
|
+
return toArray(this.bk.getSolidFaces(h10)).flatMap(
|
|
2402
2331
|
(faceId) => toArray(this.bk.getFaceWires(faceId)).map(wireHandle)
|
|
2403
2332
|
);
|
|
2404
2333
|
default:
|
|
@@ -2407,10 +2336,10 @@ class BrepkitAdapter {
|
|
|
2407
2336
|
}
|
|
2408
2337
|
case "shell": {
|
|
2409
2338
|
if (type === "face") {
|
|
2410
|
-
return toArray(this.bk.getShellFaces(
|
|
2339
|
+
return toArray(this.bk.getShellFaces(h10)).map(faceHandle);
|
|
2411
2340
|
}
|
|
2412
2341
|
if (type === "edge" || type === "vertex") {
|
|
2413
|
-
const faces = toArray(this.bk.getShellFaces(
|
|
2342
|
+
const faces = toArray(this.bk.getShellFaces(h10)).map(faceHandle);
|
|
2414
2343
|
const seen = /* @__PURE__ */ new Set();
|
|
2415
2344
|
const results = [];
|
|
2416
2345
|
for (const face of faces) {
|
|
@@ -2431,13 +2360,13 @@ class BrepkitAdapter {
|
|
|
2431
2360
|
return [shape2];
|
|
2432
2361
|
}
|
|
2433
2362
|
if (type === "edge") {
|
|
2434
|
-
return toArray(this.bk.getFaceEdges(
|
|
2363
|
+
return toArray(this.bk.getFaceEdges(h10)).map(edgeHandle);
|
|
2435
2364
|
}
|
|
2436
2365
|
if (type === "vertex") {
|
|
2437
|
-
return toArray(this.bk.getFaceVertices(
|
|
2366
|
+
return toArray(this.bk.getFaceVertices(h10)).map(vertexHandle);
|
|
2438
2367
|
}
|
|
2439
2368
|
if (type === "wire") {
|
|
2440
|
-
return toArray(this.bk.getFaceWires(
|
|
2369
|
+
return toArray(this.bk.getFaceWires(h10)).map(wireHandle);
|
|
2441
2370
|
}
|
|
2442
2371
|
return [];
|
|
2443
2372
|
}
|
|
@@ -2446,10 +2375,10 @@ class BrepkitAdapter {
|
|
|
2446
2375
|
return [shape2];
|
|
2447
2376
|
}
|
|
2448
2377
|
if (type === "edge") {
|
|
2449
|
-
return toArray(this.bk.getWireEdges(
|
|
2378
|
+
return toArray(this.bk.getWireEdges(h10)).map(edgeHandle);
|
|
2450
2379
|
}
|
|
2451
2380
|
if (type === "vertex") {
|
|
2452
|
-
const edgeIds = toArray(this.bk.getWireEdges(
|
|
2381
|
+
const edgeIds = toArray(this.bk.getWireEdges(h10));
|
|
2453
2382
|
const seen = /* @__PURE__ */ new Set();
|
|
2454
2383
|
const results = [];
|
|
2455
2384
|
for (const eid of edgeIds) {
|
|
@@ -2475,7 +2404,7 @@ class BrepkitAdapter {
|
|
|
2475
2404
|
return [shape2];
|
|
2476
2405
|
}
|
|
2477
2406
|
if (type === "vertex") {
|
|
2478
|
-
const verts = this.bk.getEdgeVertices(
|
|
2407
|
+
const verts = this.bk.getEdgeVertices(h10);
|
|
2479
2408
|
const v1 = this.bk.makeVertex(verts[0], verts[1], verts[2]);
|
|
2480
2409
|
const v22 = this.bk.makeVertex(verts[3], verts[4], verts[5]);
|
|
2481
2410
|
return [vertexHandle(v1), vertexHandle(v22)];
|
|
@@ -2495,11 +2424,11 @@ class BrepkitAdapter {
|
|
|
2495
2424
|
if (isBrepkitHandle(shape2)) return shape2.type;
|
|
2496
2425
|
throw new Error("brepkit: cannot determine shape type of non-brepkit handle");
|
|
2497
2426
|
}
|
|
2498
|
-
isSame(a9,
|
|
2499
|
-
return isBrepkitHandle(a9) && isBrepkitHandle(
|
|
2427
|
+
isSame(a9, b9) {
|
|
2428
|
+
return isBrepkitHandle(a9) && isBrepkitHandle(b9) && a9.id === b9.id && a9.type === b9.type;
|
|
2500
2429
|
}
|
|
2501
|
-
isEqual(a9,
|
|
2502
|
-
return this.isSame(a9,
|
|
2430
|
+
isEqual(a9, b9) {
|
|
2431
|
+
return this.isSame(a9, b9);
|
|
2503
2432
|
}
|
|
2504
2433
|
downcast(shape2, _type) {
|
|
2505
2434
|
return shape2;
|
|
@@ -2512,8 +2441,8 @@ class BrepkitAdapter {
|
|
|
2512
2441
|
return !shape2 || !isBrepkitHandle(shape2);
|
|
2513
2442
|
}
|
|
2514
2443
|
shapeOrientation(shape2) {
|
|
2515
|
-
const
|
|
2516
|
-
const orient = this.bk.getShapeOrientation(
|
|
2444
|
+
const h10 = unwrap(shape2);
|
|
2445
|
+
const orient = this.bk.getShapeOrientation(h10);
|
|
2517
2446
|
return orient;
|
|
2518
2447
|
}
|
|
2519
2448
|
// ═══════════════════════════════════════════════════════════════════════
|
|
@@ -2538,12 +2467,12 @@ class BrepkitAdapter {
|
|
|
2538
2467
|
const id = this.bk.getFaceOuterWire(unwrap(face, "face"));
|
|
2539
2468
|
return wireHandle(id);
|
|
2540
2469
|
}
|
|
2541
|
-
surfaceNormal(face,
|
|
2542
|
-
const
|
|
2543
|
-
return [
|
|
2470
|
+
surfaceNormal(face, u8, v9) {
|
|
2471
|
+
const n7 = this.bk.evaluateSurfaceNormal(unwrap(face, "face"), u8, v9);
|
|
2472
|
+
return [n7[0], n7[1], n7[2]];
|
|
2544
2473
|
}
|
|
2545
|
-
pointOnSurface(face,
|
|
2546
|
-
const p7 = this.bk.evaluateSurface(unwrap(face, "face"),
|
|
2474
|
+
pointOnSurface(face, u8, v9) {
|
|
2475
|
+
const p7 = this.bk.evaluateSurface(unwrap(face, "face"), u8, v9);
|
|
2547
2476
|
return [p7[0], p7[1], p7[2]];
|
|
2548
2477
|
}
|
|
2549
2478
|
uvFromPoint(face, point) {
|
|
@@ -2573,11 +2502,11 @@ class BrepkitAdapter {
|
|
|
2573
2502
|
// Geometry queries: edge / curve
|
|
2574
2503
|
// ═══════════════════════════════════════════════════════════════════════
|
|
2575
2504
|
curveTangent(shape2, param) {
|
|
2576
|
-
const
|
|
2505
|
+
const h10 = shape2;
|
|
2577
2506
|
let edgeId;
|
|
2578
2507
|
let evalParam = param;
|
|
2579
|
-
if (
|
|
2580
|
-
const edgeIds = toArray(this.bk.getWireEdges(
|
|
2508
|
+
if (h10.type === "wire") {
|
|
2509
|
+
const edgeIds = toArray(this.bk.getWireEdges(h10.id));
|
|
2581
2510
|
edgeId = edgeIds[edgeIds.length - 1];
|
|
2582
2511
|
let cumulative = 0;
|
|
2583
2512
|
for (const eid of edgeIds) {
|
|
@@ -2600,9 +2529,9 @@ class BrepkitAdapter {
|
|
|
2600
2529
|
};
|
|
2601
2530
|
}
|
|
2602
2531
|
curveParameters(shape2) {
|
|
2603
|
-
const
|
|
2604
|
-
if (
|
|
2605
|
-
const edgeIds = toArray(this.bk.getWireEdges(
|
|
2532
|
+
const h10 = shape2;
|
|
2533
|
+
if (h10.type === "wire") {
|
|
2534
|
+
const edgeIds = toArray(this.bk.getWireEdges(h10.id));
|
|
2606
2535
|
if (edgeIds.length === 0) return [0, 0];
|
|
2607
2536
|
let total = 0;
|
|
2608
2537
|
for (const eid of edgeIds) {
|
|
@@ -2616,9 +2545,9 @@ class BrepkitAdapter {
|
|
|
2616
2545
|
return [params[0], params[1]];
|
|
2617
2546
|
}
|
|
2618
2547
|
curvePointAtParam(shape2, param) {
|
|
2619
|
-
const
|
|
2620
|
-
if (
|
|
2621
|
-
const edgeIds = toArray(this.bk.getWireEdges(
|
|
2548
|
+
const h10 = shape2;
|
|
2549
|
+
if (h10.type === "wire") {
|
|
2550
|
+
const edgeIds = toArray(this.bk.getWireEdges(h10.id));
|
|
2622
2551
|
let cumulative = 0;
|
|
2623
2552
|
for (const eid of edgeIds) {
|
|
2624
2553
|
const p22 = this.bk.getEdgeCurveParameters(eid);
|
|
@@ -2638,9 +2567,9 @@ class BrepkitAdapter {
|
|
|
2638
2567
|
return [p7[0], p7[1], p7[2]];
|
|
2639
2568
|
}
|
|
2640
2569
|
curveIsClosed(shape2) {
|
|
2641
|
-
const
|
|
2642
|
-
if (
|
|
2643
|
-
const edgeIds = toArray(this.bk.getWireEdges(
|
|
2570
|
+
const h10 = shape2;
|
|
2571
|
+
if (h10.type === "wire") {
|
|
2572
|
+
const edgeIds = toArray(this.bk.getWireEdges(h10.id));
|
|
2644
2573
|
if (edgeIds.length === 0) return false;
|
|
2645
2574
|
if (edgeIds.length === 1) {
|
|
2646
2575
|
const verts2 = this.bk.getEdgeVertices(edgeIds[0]);
|
|
@@ -2655,7 +2584,7 @@ class BrepkitAdapter {
|
|
|
2655
2584
|
const unmatched = [];
|
|
2656
2585
|
for (const pt of endpoints) {
|
|
2657
2586
|
const matchIdx = unmatched.findIndex(
|
|
2658
|
-
(
|
|
2587
|
+
(u8) => dist3(u8[0], u8[1], u8[2], pt[0], pt[1], pt[2]) < 1e-7
|
|
2659
2588
|
);
|
|
2660
2589
|
if (matchIdx >= 0) {
|
|
2661
2590
|
unmatched.splice(matchIdx, 1);
|
|
@@ -2669,11 +2598,11 @@ class BrepkitAdapter {
|
|
|
2669
2598
|
return dist3(verts[0], verts[1], verts[2], verts[3], verts[4], verts[5]) < 1e-7;
|
|
2670
2599
|
}
|
|
2671
2600
|
curveIsPeriodic(shape2) {
|
|
2672
|
-
const
|
|
2601
|
+
const h10 = shape2;
|
|
2673
2602
|
try {
|
|
2674
|
-
if (
|
|
2675
|
-
if (
|
|
2676
|
-
const edgeIds = toArray(this.bk.getWireEdges(
|
|
2603
|
+
if (h10.type === "edge") return this.curveIsClosed(shape2);
|
|
2604
|
+
if (h10.type === "wire") {
|
|
2605
|
+
const edgeIds = toArray(this.bk.getWireEdges(h10.id));
|
|
2677
2606
|
if (edgeIds.length === 1) return this.curveIsClosed(shape2);
|
|
2678
2607
|
}
|
|
2679
2608
|
} catch {
|
|
@@ -2691,8 +2620,8 @@ class BrepkitAdapter {
|
|
|
2691
2620
|
return 0;
|
|
2692
2621
|
}
|
|
2693
2622
|
curveType(shape2) {
|
|
2694
|
-
const
|
|
2695
|
-
if (
|
|
2623
|
+
const h10 = shape2;
|
|
2624
|
+
if (h10.type === "wire") {
|
|
2696
2625
|
const edges = this.iterShapes(shape2, "edge");
|
|
2697
2626
|
const first = edges[0];
|
|
2698
2627
|
if (first) return this.bk.getEdgeCurveType(unwrap(first, "edge"));
|
|
@@ -2738,15 +2667,15 @@ class BrepkitAdapter {
|
|
|
2738
2667
|
sew(shapes, tolerance) {
|
|
2739
2668
|
const faceIds = [];
|
|
2740
2669
|
for (const s6 of shapes) {
|
|
2741
|
-
const
|
|
2742
|
-
if (
|
|
2743
|
-
faceIds.push(
|
|
2744
|
-
} else if (
|
|
2745
|
-
for (const fid of toArray(this.bk.getSolidFaces(
|
|
2670
|
+
const h10 = s6;
|
|
2671
|
+
if (h10.type === "face") {
|
|
2672
|
+
faceIds.push(h10.id);
|
|
2673
|
+
} else if (h10.type === "solid") {
|
|
2674
|
+
for (const fid of toArray(this.bk.getSolidFaces(h10.id))) {
|
|
2746
2675
|
faceIds.push(fid);
|
|
2747
2676
|
}
|
|
2748
|
-
} else if (
|
|
2749
|
-
for (const fid of toArray(this.bk.getShellFaces(
|
|
2677
|
+
} else if (h10.type === "shell") {
|
|
2678
|
+
for (const fid of toArray(this.bk.getShellFaces(h10.id))) {
|
|
2750
2679
|
faceIds.push(fid);
|
|
2751
2680
|
}
|
|
2752
2681
|
}
|
|
@@ -2762,10 +2691,10 @@ class BrepkitAdapter {
|
|
|
2762
2691
|
return shellHandle(id);
|
|
2763
2692
|
}
|
|
2764
2693
|
healSolid(shape2) {
|
|
2765
|
-
const
|
|
2766
|
-
if (
|
|
2694
|
+
const h10 = shape2;
|
|
2695
|
+
if (h10.type !== "solid") {
|
|
2767
2696
|
throw new Error(
|
|
2768
|
-
`brepkit: healSolid requires a solid, got ${
|
|
2697
|
+
`brepkit: healSolid requires a solid, got ${h10.type}. Consider using makeCompound() to combine shapes first.`
|
|
2769
2698
|
);
|
|
2770
2699
|
}
|
|
2771
2700
|
try {
|
|
@@ -2810,8 +2739,8 @@ class BrepkitAdapter {
|
|
|
2810
2739
|
if (coords2d.length < 6) return wire;
|
|
2811
2740
|
const result = this.bk.offsetPolygon2d(coords2d, offset2, 1e-10);
|
|
2812
2741
|
const coords3d = [];
|
|
2813
|
-
for (let
|
|
2814
|
-
coords3d.push(result[
|
|
2742
|
+
for (let i9 = 0; i9 < result.length; i9 += 2) {
|
|
2743
|
+
coords3d.push(result[i9], result[i9 + 1], 0);
|
|
2815
2744
|
}
|
|
2816
2745
|
const wireId = this.bk.makePolygonWire(coords3d);
|
|
2817
2746
|
return wireHandle(wireId);
|
|
@@ -2874,7 +2803,7 @@ class BrepkitAdapter {
|
|
|
2874
2803
|
// ═══════════════════════════════════════════════════════════════════════
|
|
2875
2804
|
// Classification
|
|
2876
2805
|
// ═══════════════════════════════════════════════════════════════════════
|
|
2877
|
-
classifyPointOnFace(face,
|
|
2806
|
+
classifyPointOnFace(face, u8, v9, tolerance) {
|
|
2878
2807
|
if (tolerance !== void 0) {
|
|
2879
2808
|
warnOnce(
|
|
2880
2809
|
"classify-tolerance",
|
|
@@ -2883,7 +2812,7 @@ class BrepkitAdapter {
|
|
|
2883
2812
|
}
|
|
2884
2813
|
const faceId = unwrap(face, "face");
|
|
2885
2814
|
const domain = this.bk.getSurfaceDomain(faceId);
|
|
2886
|
-
if (
|
|
2815
|
+
if (u8 < domain[0] || u8 > domain[1] || v9 < domain[2] || v9 > domain[3]) {
|
|
2887
2816
|
return "out";
|
|
2888
2817
|
}
|
|
2889
2818
|
return "in";
|
|
@@ -2989,8 +2918,8 @@ class BrepkitAdapter {
|
|
|
2989
2918
|
}
|
|
2990
2919
|
loftAdvanced(wires, options) {
|
|
2991
2920
|
const faceIds = wires.map((w7) => {
|
|
2992
|
-
const
|
|
2993
|
-
if (
|
|
2921
|
+
const h10 = w7;
|
|
2922
|
+
if (h10.type === "wire") return this.bk.makeFaceFromWire(h10.id);
|
|
2994
2923
|
return unwrap(w7, "face");
|
|
2995
2924
|
});
|
|
2996
2925
|
try {
|
|
@@ -3056,8 +2985,8 @@ class BrepkitAdapter {
|
|
|
3056
2985
|
}
|
|
3057
2986
|
linearPattern(shape2, direction, spacing, count) {
|
|
3058
2987
|
const results = [shape2];
|
|
3059
|
-
for (let
|
|
3060
|
-
const offset2 = spacing *
|
|
2988
|
+
for (let i9 = 1; i9 < count; i9++) {
|
|
2989
|
+
const offset2 = spacing * i9;
|
|
3061
2990
|
results.push(
|
|
3062
2991
|
this.translate(shape2, direction[0] * offset2, direction[1] * offset2, direction[2] * offset2)
|
|
3063
2992
|
);
|
|
@@ -3066,8 +2995,8 @@ class BrepkitAdapter {
|
|
|
3066
2995
|
}
|
|
3067
2996
|
circularPattern(shape2, center, axis, angleStep, count) {
|
|
3068
2997
|
const results = [shape2];
|
|
3069
|
-
for (let
|
|
3070
|
-
results.push(this.rotate(shape2, angleStep *
|
|
2998
|
+
for (let i9 = 1; i9 < count; i9++) {
|
|
2999
|
+
results.push(this.rotate(shape2, angleStep * i9, axis, center));
|
|
3071
3000
|
}
|
|
3072
3001
|
return results;
|
|
3073
3002
|
}
|
|
@@ -3122,11 +3051,11 @@ class BrepkitAdapter {
|
|
|
3122
3051
|
triangulatedSurface(points, rows, cols) {
|
|
3123
3052
|
const faces = [];
|
|
3124
3053
|
for (let r9 = 0; r9 < rows - 1; r9++) {
|
|
3125
|
-
for (let
|
|
3126
|
-
const i00 = r9 * cols +
|
|
3127
|
-
const i10 = (r9 + 1) * cols +
|
|
3128
|
-
const i01 = r9 * cols + (
|
|
3129
|
-
const i11 = (r9 + 1) * cols + (
|
|
3054
|
+
for (let c8 = 0; c8 < cols - 1; c8++) {
|
|
3055
|
+
const i00 = r9 * cols + c8;
|
|
3056
|
+
const i10 = (r9 + 1) * cols + c8;
|
|
3057
|
+
const i01 = r9 * cols + (c8 + 1);
|
|
3058
|
+
const i11 = (r9 + 1) * cols + (c8 + 1);
|
|
3130
3059
|
const f1 = this.buildTriFace(points[i00], points[i10], points[i01]);
|
|
3131
3060
|
if (f1) faces.push(f1);
|
|
3132
3061
|
const f22 = this.buildTriFace(points[i10], points[i11], points[i01]);
|
|
@@ -3139,9 +3068,9 @@ class BrepkitAdapter {
|
|
|
3139
3068
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3140
3069
|
// Mesh sewing -> solid
|
|
3141
3070
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3142
|
-
buildTriFace(a9,
|
|
3143
|
-
const ab = [
|
|
3144
|
-
const ac = [
|
|
3071
|
+
buildTriFace(a9, b9, c8) {
|
|
3072
|
+
const ab = [b9[0] - a9[0], b9[1] - a9[1], b9[2] - a9[2]];
|
|
3073
|
+
const ac = [c8[0] - a9[0], c8[1] - a9[1], c8[2] - a9[2]];
|
|
3145
3074
|
const cross = [
|
|
3146
3075
|
ab[1] * ac[2] - ab[2] * ac[1],
|
|
3147
3076
|
ab[2] * ac[0] - ab[0] * ac[2],
|
|
@@ -3150,9 +3079,9 @@ class BrepkitAdapter {
|
|
|
3150
3079
|
const area = Math.sqrt(cross[0] ** 2 + cross[1] ** 2 + cross[2] ** 2);
|
|
3151
3080
|
if (area < 1e-12) return null;
|
|
3152
3081
|
try {
|
|
3153
|
-
const e1 = this.makeLineEdge(a9,
|
|
3154
|
-
const e22 = this.makeLineEdge(
|
|
3155
|
-
const e32 = this.makeLineEdge(
|
|
3082
|
+
const e1 = this.makeLineEdge(a9, b9);
|
|
3083
|
+
const e22 = this.makeLineEdge(b9, c8);
|
|
3084
|
+
const e32 = this.makeLineEdge(c8, a9);
|
|
3156
3085
|
const wire = this.makeWire([e1, e22, e32]);
|
|
3157
3086
|
return this.makeFace(wire);
|
|
3158
3087
|
} catch (e8) {
|
|
@@ -3169,9 +3098,9 @@ class BrepkitAdapter {
|
|
|
3169
3098
|
// Repair
|
|
3170
3099
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3171
3100
|
fixShape(shape2) {
|
|
3172
|
-
const
|
|
3173
|
-
if (
|
|
3174
|
-
this.bk.healSolid(
|
|
3101
|
+
const h10 = shape2;
|
|
3102
|
+
if (h10.type === "solid") {
|
|
3103
|
+
this.bk.healSolid(h10.id);
|
|
3175
3104
|
}
|
|
3176
3105
|
return shape2;
|
|
3177
3106
|
}
|
|
@@ -3181,9 +3110,9 @@ class BrepkitAdapter {
|
|
|
3181
3110
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3182
3111
|
// Measurement (advanced)
|
|
3183
3112
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3184
|
-
surfaceCurvature(face,
|
|
3113
|
+
surfaceCurvature(face, u8, v9) {
|
|
3185
3114
|
const fid = unwrap(face, "face");
|
|
3186
|
-
const data = this.bk.measureCurvatureAtSurface(fid,
|
|
3115
|
+
const data = this.bk.measureCurvatureAtSurface(fid, u8, v9);
|
|
3187
3116
|
if (data.length < 8) {
|
|
3188
3117
|
throw new Error(
|
|
3189
3118
|
`brepkit: measureCurvatureAtSurface returned ${data.length} values, expected 8`
|
|
@@ -3207,8 +3136,8 @@ class BrepkitAdapter {
|
|
|
3207
3136
|
const pos = mesh2.positions;
|
|
3208
3137
|
const idx = mesh2.indices;
|
|
3209
3138
|
let cx = 0, cy = 0, cz = 0, totalArea = 0;
|
|
3210
|
-
for (let
|
|
3211
|
-
const i0 = idx[
|
|
3139
|
+
for (let t10 = 0; t10 < idx.length; t10 += 3) {
|
|
3140
|
+
const i0 = idx[t10] * 3, i1 = idx[t10 + 1] * 3, i22 = idx[t10 + 2] * 3;
|
|
3212
3141
|
const tcx = (pos[i0] + pos[i1] + pos[i22]) / 3;
|
|
3213
3142
|
const tcy = (pos[i0 + 1] + pos[i1 + 1] + pos[i22 + 1]) / 3;
|
|
3214
3143
|
const tcz = (pos[i0 + 2] + pos[i1 + 2] + pos[i22 + 2]) / 3;
|
|
@@ -3298,11 +3227,11 @@ class BrepkitAdapter {
|
|
|
3298
3227
|
getBezierPenultimatePole(edge) {
|
|
3299
3228
|
const nurbsData = this.extractNurbsFromEdge(edge);
|
|
3300
3229
|
if (!nurbsData || nurbsData.controlPoints.length < 6) return null;
|
|
3301
|
-
const
|
|
3230
|
+
const n7 = nurbsData.controlPoints.length;
|
|
3302
3231
|
return [
|
|
3303
|
-
nurbsData.controlPoints[
|
|
3304
|
-
nurbsData.controlPoints[
|
|
3305
|
-
nurbsData.controlPoints[
|
|
3232
|
+
nurbsData.controlPoints[n7 - 6],
|
|
3233
|
+
nurbsData.controlPoints[n7 - 5],
|
|
3234
|
+
nurbsData.controlPoints[n7 - 4]
|
|
3306
3235
|
];
|
|
3307
3236
|
}
|
|
3308
3237
|
// ═══════════════════════════════════════════════════════════════════════
|
|
@@ -3355,9 +3284,9 @@ class BrepkitAdapter {
|
|
|
3355
3284
|
// Shape reversal
|
|
3356
3285
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3357
3286
|
reverseShape(shape2) {
|
|
3358
|
-
const
|
|
3359
|
-
const newId = this.bk.reverseShape(
|
|
3360
|
-
return handle(
|
|
3287
|
+
const h10 = shape2;
|
|
3288
|
+
const newId = this.bk.reverseShape(h10.id);
|
|
3289
|
+
return handle(h10.type, newId);
|
|
3361
3290
|
}
|
|
3362
3291
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3363
3292
|
// Dispose
|
|
@@ -3389,17 +3318,17 @@ class BrepkitAdapter {
|
|
|
3389
3318
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3390
3319
|
// Kernel2DCapability — pure TypeScript implementation
|
|
3391
3320
|
// ═══════════════════════════════════════════════════════════════════════
|
|
3392
|
-
c2d(
|
|
3393
|
-
return
|
|
3321
|
+
c2d(h10) {
|
|
3322
|
+
return h10;
|
|
3394
3323
|
}
|
|
3395
3324
|
/** Unwrap any trimmed wrappers to get the underlying geometry. */
|
|
3396
|
-
c2dBasis(
|
|
3397
|
-
let
|
|
3398
|
-
while (
|
|
3399
|
-
return
|
|
3325
|
+
c2dBasis(h10) {
|
|
3326
|
+
let c8 = this.c2d(h10);
|
|
3327
|
+
while (c8.__bk2d === "trimmed") c8 = c8.basis;
|
|
3328
|
+
return c8;
|
|
3400
3329
|
}
|
|
3401
|
-
bb2d(
|
|
3402
|
-
return
|
|
3330
|
+
bb2d(h10) {
|
|
3331
|
+
return h10;
|
|
3403
3332
|
}
|
|
3404
3333
|
createPoint2d(x7, y6) {
|
|
3405
3334
|
return { x: x7, y: y6 };
|
|
@@ -3464,10 +3393,10 @@ class BrepkitAdapter {
|
|
|
3464
3393
|
return makeLine2d(sx, sy, ex, ey);
|
|
3465
3394
|
}
|
|
3466
3395
|
const chord2 = dx * dx + dy * dy;
|
|
3467
|
-
const
|
|
3468
|
-
const cx = sx -
|
|
3469
|
-
const cy = sy +
|
|
3470
|
-
const radius = Math.abs(
|
|
3396
|
+
const t10 = -chord2 / denom;
|
|
3397
|
+
const cx = sx - t10 * nty;
|
|
3398
|
+
const cy = sy + t10 * ntx;
|
|
3399
|
+
const radius = Math.abs(t10);
|
|
3471
3400
|
const a12 = Math.atan2(sy - cy, sx - cx);
|
|
3472
3401
|
const a23 = Math.atan2(ey - cy, ex - cx);
|
|
3473
3402
|
const ccwTanX = -(sy - cy) / radius;
|
|
@@ -3498,15 +3427,15 @@ class BrepkitAdapter {
|
|
|
3498
3427
|
return makeBezier2d(points);
|
|
3499
3428
|
}
|
|
3500
3429
|
makeBSpline2d(points, _options) {
|
|
3501
|
-
const
|
|
3502
|
-
const degree = Math.min(3,
|
|
3430
|
+
const n7 = points.length;
|
|
3431
|
+
const degree = Math.min(3, n7 - 1);
|
|
3503
3432
|
const knots = [];
|
|
3504
3433
|
const mults = [];
|
|
3505
3434
|
knots.push(0);
|
|
3506
3435
|
mults.push(degree + 1);
|
|
3507
|
-
const nInternal =
|
|
3508
|
-
for (let
|
|
3509
|
-
knots.push(
|
|
3436
|
+
const nInternal = n7 - degree - 1;
|
|
3437
|
+
for (let i9 = 1; i9 <= nInternal; i9++) {
|
|
3438
|
+
knots.push(i9 / (nInternal + 1));
|
|
3510
3439
|
mults.push(1);
|
|
3511
3440
|
}
|
|
3512
3441
|
knots.push(1);
|
|
@@ -3544,14 +3473,14 @@ class BrepkitAdapter {
|
|
|
3544
3473
|
return JSON.parse(JSON.stringify(curve));
|
|
3545
3474
|
}
|
|
3546
3475
|
offsetCurve2d(curve, offset2) {
|
|
3547
|
-
const
|
|
3548
|
-
const bounds = curveBounds(
|
|
3476
|
+
const c8 = this.c2d(curve);
|
|
3477
|
+
const bounds = curveBounds(c8);
|
|
3549
3478
|
const N4 = 30;
|
|
3550
3479
|
const poles = [];
|
|
3551
|
-
for (let
|
|
3552
|
-
const
|
|
3553
|
-
const [px, py] = evaluateCurve2d(
|
|
3554
|
-
const [tx, ty] = tangentCurve2d(
|
|
3480
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
3481
|
+
const t10 = bounds.first + (bounds.last - bounds.first) * i9 / N4;
|
|
3482
|
+
const [px, py] = evaluateCurve2d(c8, t10);
|
|
3483
|
+
const [tx, ty] = tangentCurve2d(c8, t10);
|
|
3555
3484
|
const tLen = Math.sqrt(tx * tx + ty * ty);
|
|
3556
3485
|
if (tLen > 1e-12) {
|
|
3557
3486
|
poles.push([px - ty / tLen * offset2, py + tx / tLen * offset2]);
|
|
@@ -3624,8 +3553,8 @@ class BrepkitAdapter {
|
|
|
3624
3553
|
return this._gtrsf([-1, 0, 0, 0, -1, 0, 0, 0, 1], 2 * cx, 2 * cy);
|
|
3625
3554
|
}
|
|
3626
3555
|
createRotationGTrsf2d(angle, cx, cy) {
|
|
3627
|
-
const
|
|
3628
|
-
return this._gtrsf([
|
|
3556
|
+
const c8 = Math.cos(angle), s6 = Math.sin(angle);
|
|
3557
|
+
return this._gtrsf([c8, -s6, 0, s6, c8, 0, 0, 0, 1], cx - c8 * cx + s6 * cy, cy - s6 * cx - c8 * cy);
|
|
3629
3558
|
}
|
|
3630
3559
|
createScaleGTrsf2d(factor, cx, cy) {
|
|
3631
3560
|
return this._gtrsf([factor, 0, 0, 0, factor, 0, 0, 0, 1], cx * (1 - factor), cy * (1 - factor));
|
|
@@ -3635,17 +3564,17 @@ class BrepkitAdapter {
|
|
|
3635
3564
|
gtrsf.ty = dy;
|
|
3636
3565
|
}
|
|
3637
3566
|
multiplyGTrsf2d(base, other) {
|
|
3638
|
-
const a9 = base.m,
|
|
3567
|
+
const a9 = base.m, b9 = other.m;
|
|
3639
3568
|
const r9 = [
|
|
3640
|
-
a9[0] *
|
|
3641
|
-
a9[0] *
|
|
3642
|
-
a9[0] *
|
|
3643
|
-
a9[3] *
|
|
3644
|
-
a9[3] *
|
|
3645
|
-
a9[3] *
|
|
3646
|
-
a9[6] *
|
|
3647
|
-
a9[6] *
|
|
3648
|
-
a9[6] *
|
|
3569
|
+
a9[0] * b9[0] + a9[1] * b9[3] + a9[2] * b9[6],
|
|
3570
|
+
a9[0] * b9[1] + a9[1] * b9[4] + a9[2] * b9[7],
|
|
3571
|
+
a9[0] * b9[2] + a9[1] * b9[5] + a9[2] * b9[8],
|
|
3572
|
+
a9[3] * b9[0] + a9[4] * b9[3] + a9[5] * b9[6],
|
|
3573
|
+
a9[3] * b9[1] + a9[4] * b9[4] + a9[5] * b9[7],
|
|
3574
|
+
a9[3] * b9[2] + a9[4] * b9[5] + a9[5] * b9[8],
|
|
3575
|
+
a9[6] * b9[0] + a9[7] * b9[3] + a9[8] * b9[6],
|
|
3576
|
+
a9[6] * b9[1] + a9[7] * b9[4] + a9[8] * b9[7],
|
|
3577
|
+
a9[6] * b9[2] + a9[7] * b9[5] + a9[8] * b9[8]
|
|
3649
3578
|
];
|
|
3650
3579
|
base.m = r9;
|
|
3651
3580
|
const oldTx = base.tx, oldTy = base.ty;
|
|
@@ -3654,19 +3583,19 @@ class BrepkitAdapter {
|
|
|
3654
3583
|
base.ty = a9[3] * otx + a9[4] * oty + oldTy;
|
|
3655
3584
|
}
|
|
3656
3585
|
transformCurve2dGeneral(curve, gtrsf) {
|
|
3657
|
-
const
|
|
3586
|
+
const c8 = this.c2d(curve);
|
|
3658
3587
|
const m10 = gtrsf.m ?? [1, 0, 0, 0, 1, 0, 0, 0, 1];
|
|
3659
3588
|
const tx = Number(gtrsf.tx) || 0, ty = Number(gtrsf.ty) || 0;
|
|
3660
3589
|
const isIdentityMatrix = Math.abs(m10[0] - 1) < 1e-12 && Math.abs(m10[4] - 1) < 1e-12 && Math.abs(m10[1]) < 1e-12 && Math.abs(m10[3]) < 1e-12;
|
|
3661
3590
|
if (isIdentityMatrix) {
|
|
3662
|
-
return translateCurve2d(
|
|
3591
|
+
return translateCurve2d(c8, tx, ty);
|
|
3663
3592
|
}
|
|
3664
|
-
const bounds = curveBounds(
|
|
3593
|
+
const bounds = curveBounds(c8);
|
|
3665
3594
|
const N4 = 20;
|
|
3666
3595
|
const pts = [];
|
|
3667
|
-
for (let
|
|
3668
|
-
const
|
|
3669
|
-
const [px, py] = evaluateCurve2d(
|
|
3596
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
3597
|
+
const t10 = bounds.first + (bounds.last - bounds.first) * i9 / N4;
|
|
3598
|
+
const [px, py] = evaluateCurve2d(c8, t10);
|
|
3670
3599
|
pts.push([m10[0] * px + m10[1] * py + tx, m10[3] * px + m10[4] * py + ty]);
|
|
3671
3600
|
}
|
|
3672
3601
|
return makeBezier2d(pts);
|
|
@@ -3683,40 +3612,40 @@ class BrepkitAdapter {
|
|
|
3683
3612
|
return { points: result.points, segments };
|
|
3684
3613
|
}
|
|
3685
3614
|
projectPointOnCurve2d(curve, x7, y6) {
|
|
3686
|
-
const
|
|
3687
|
-
const bounds = curveBounds(
|
|
3688
|
-
if (
|
|
3689
|
-
const dx = x7 -
|
|
3690
|
-
const dy = y6 -
|
|
3691
|
-
const
|
|
3692
|
-
const [px, py] = evaluateCurve2d(
|
|
3693
|
-
return { param:
|
|
3694
|
-
}
|
|
3695
|
-
if (
|
|
3696
|
-
const angle = Math.atan2(y6 -
|
|
3697
|
-
let
|
|
3698
|
-
while (
|
|
3699
|
-
while (
|
|
3700
|
-
const [px, py] = evaluateCurve2d(
|
|
3701
|
-
return { param:
|
|
3615
|
+
const c8 = this.c2d(curve);
|
|
3616
|
+
const bounds = curveBounds(c8);
|
|
3617
|
+
if (c8.__bk2d === "line") {
|
|
3618
|
+
const dx = x7 - c8.ox;
|
|
3619
|
+
const dy = y6 - c8.oy;
|
|
3620
|
+
const t10 = Math.max(bounds.first, Math.min(bounds.last, dx * c8.dx + dy * c8.dy));
|
|
3621
|
+
const [px, py] = evaluateCurve2d(c8, t10);
|
|
3622
|
+
return { param: t10, distance: Math.sqrt((px - x7) ** 2 + (py - y6) ** 2) };
|
|
3623
|
+
}
|
|
3624
|
+
if (c8.__bk2d === "circle") {
|
|
3625
|
+
const angle = Math.atan2(y6 - c8.cy, x7 - c8.cx);
|
|
3626
|
+
let t10 = c8.sense ? angle : -angle;
|
|
3627
|
+
while (t10 < 0) t10 += 2 * Math.PI;
|
|
3628
|
+
while (t10 > 2 * Math.PI) t10 -= 2 * Math.PI;
|
|
3629
|
+
const [px, py] = evaluateCurve2d(c8, t10);
|
|
3630
|
+
return { param: t10, distance: Math.sqrt((px - x7) ** 2 + (py - y6) ** 2) };
|
|
3702
3631
|
}
|
|
3703
3632
|
if (!isFinite(bounds.first) || !isFinite(bounds.last)) return null;
|
|
3704
3633
|
let bestT = bounds.first;
|
|
3705
3634
|
let bestDist = Infinity;
|
|
3706
3635
|
const N4 = 200;
|
|
3707
3636
|
const dt = (bounds.last - bounds.first) / N4;
|
|
3708
|
-
for (let
|
|
3709
|
-
const
|
|
3710
|
-
const [px, py] = evaluateCurve2d(
|
|
3637
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
3638
|
+
const t10 = bounds.first + i9 * dt;
|
|
3639
|
+
const [px, py] = evaluateCurve2d(c8, t10);
|
|
3711
3640
|
const d10 = (px - x7) ** 2 + (py - y6) ** 2;
|
|
3712
3641
|
if (d10 < bestDist) {
|
|
3713
3642
|
bestDist = d10;
|
|
3714
|
-
bestT =
|
|
3643
|
+
bestT = t10;
|
|
3715
3644
|
}
|
|
3716
3645
|
}
|
|
3717
3646
|
for (let iter = 0; iter < 10; iter++) {
|
|
3718
|
-
const [px, py] = evaluateCurve2d(
|
|
3719
|
-
const [tx, ty] = tangentCurve2d(
|
|
3647
|
+
const [px, py] = evaluateCurve2d(c8, bestT);
|
|
3648
|
+
const [tx, ty] = tangentCurve2d(c8, bestT);
|
|
3720
3649
|
const dot = (px - x7) * tx + (py - y6) * ty;
|
|
3721
3650
|
const denom = tx * tx + ty * ty;
|
|
3722
3651
|
if (denom < 1e-20) break;
|
|
@@ -3725,7 +3654,7 @@ class BrepkitAdapter {
|
|
|
3725
3654
|
if (Math.abs(newT - bestT) < 1e-14) break;
|
|
3726
3655
|
bestT = newT;
|
|
3727
3656
|
}
|
|
3728
|
-
const [fx, fy] = evaluateCurve2d(
|
|
3657
|
+
const [fx, fy] = evaluateCurve2d(c8, bestT);
|
|
3729
3658
|
return { param: bestT, distance: Math.sqrt((fx - x7) ** 2 + (fy - y6) ** 2) };
|
|
3730
3659
|
}
|
|
3731
3660
|
distanceBetweenCurves2d(c1, c22, p1s, p1e, p2s, p2e) {
|
|
@@ -3735,11 +3664,11 @@ class BrepkitAdapter {
|
|
|
3735
3664
|
let bestT2 = p2s;
|
|
3736
3665
|
let minDistSq = Infinity;
|
|
3737
3666
|
const N4 = 50;
|
|
3738
|
-
for (let
|
|
3739
|
-
const t12 = p1s + (p1e - p1s) *
|
|
3667
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
3668
|
+
const t12 = p1s + (p1e - p1s) * i9 / N4;
|
|
3740
3669
|
const [x1, y1] = evaluateCurve2d(curve1, t12);
|
|
3741
|
-
for (let
|
|
3742
|
-
const t222 = p2s + (p2e - p2s) *
|
|
3670
|
+
for (let j7 = 0; j7 <= N4; j7++) {
|
|
3671
|
+
const t222 = p2s + (p2e - p2s) * j7 / N4;
|
|
3743
3672
|
const [x22, y22] = evaluateCurve2d(curve2, t222);
|
|
3744
3673
|
const d10 = (x22 - x1) ** 2 + (y22 - y1) ** 2;
|
|
3745
3674
|
if (d10 < minDistSq) {
|
|
@@ -3774,8 +3703,8 @@ class BrepkitAdapter {
|
|
|
3774
3703
|
return Math.sqrt((fx2 - fx1) ** 2 + (fy2 - fy1) ** 2);
|
|
3775
3704
|
}
|
|
3776
3705
|
approximateCurve2dAsBSpline(curve, tol, cont, maxSeg) {
|
|
3777
|
-
const
|
|
3778
|
-
const bounds = curveBounds(
|
|
3706
|
+
const c8 = this.c2d(curve);
|
|
3707
|
+
const bounds = curveBounds(c8);
|
|
3779
3708
|
const contDeg = cont === "C0" ? 1 : cont === "C1" ? 2 : cont === "C2" ? 3 : 4;
|
|
3780
3709
|
const degree = Math.max(3, contDeg);
|
|
3781
3710
|
let N4 = Math.max(100, maxSeg * 10);
|
|
@@ -3783,16 +3712,16 @@ class BrepkitAdapter {
|
|
|
3783
3712
|
let maxErr = Infinity;
|
|
3784
3713
|
for (let attempt = 0; attempt < 3 && maxErr > tol; attempt++) {
|
|
3785
3714
|
poles = [];
|
|
3786
|
-
for (let
|
|
3787
|
-
const
|
|
3788
|
-
poles.push(evaluateCurve2d(
|
|
3715
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
3716
|
+
const t10 = bounds.first + (bounds.last - bounds.first) * i9 / N4;
|
|
3717
|
+
poles.push(evaluateCurve2d(c8, t10));
|
|
3789
3718
|
}
|
|
3790
3719
|
maxErr = 0;
|
|
3791
|
-
for (let
|
|
3792
|
-
const tMid = bounds.first + (bounds.last - bounds.first) * (
|
|
3793
|
-
const [ex, ey] = evaluateCurve2d(
|
|
3794
|
-
const p0 = poles[
|
|
3795
|
-
const p1 = poles[
|
|
3720
|
+
for (let i9 = 0; i9 < N4; i9++) {
|
|
3721
|
+
const tMid = bounds.first + (bounds.last - bounds.first) * (i9 + 0.5) / N4;
|
|
3722
|
+
const [ex, ey] = evaluateCurve2d(c8, tMid);
|
|
3723
|
+
const p0 = poles[i9];
|
|
3724
|
+
const p1 = poles[i9 + 1];
|
|
3796
3725
|
const mx = (p0[0] + p1[0]) / 2;
|
|
3797
3726
|
const my = (p0[1] + p1[1]) / 2;
|
|
3798
3727
|
const err2 = Math.sqrt((ex - mx) ** 2 + (ey - my) ** 2);
|
|
@@ -3803,9 +3732,9 @@ class BrepkitAdapter {
|
|
|
3803
3732
|
return this.makeBSpline2d(poles, { degMax: degree });
|
|
3804
3733
|
}
|
|
3805
3734
|
decomposeBSpline2dToBeziers(curve) {
|
|
3806
|
-
const
|
|
3807
|
-
if (
|
|
3808
|
-
if (
|
|
3735
|
+
const c8 = this.c2dBasis(curve);
|
|
3736
|
+
if (c8.__bk2d === "bezier") return [curve];
|
|
3737
|
+
if (c8.__bk2d !== "bspline") {
|
|
3809
3738
|
const approx = this.approximateCurve2dAsBSpline(curve, 1e-6, "C2", 10);
|
|
3810
3739
|
return this.decomposeBSpline2dToBeziers(approx);
|
|
3811
3740
|
}
|
|
@@ -3813,20 +3742,20 @@ class BrepkitAdapter {
|
|
|
3813
3742
|
const first = trimBounds.first;
|
|
3814
3743
|
const last = trimBounds.last;
|
|
3815
3744
|
const internalKnots = [];
|
|
3816
|
-
for (const k7 of
|
|
3745
|
+
for (const k7 of c8.knots) {
|
|
3817
3746
|
if (k7 > first + 1e-12 && k7 < last - 1e-12) internalKnots.push(k7);
|
|
3818
3747
|
}
|
|
3819
3748
|
const breakpoints = [first, ...internalKnots, last];
|
|
3820
3749
|
const result = [];
|
|
3821
|
-
for (let
|
|
3822
|
-
const t0 = breakpoints[
|
|
3823
|
-
const t1 = breakpoints[
|
|
3750
|
+
for (let i9 = 0; i9 < breakpoints.length - 1; i9++) {
|
|
3751
|
+
const t0 = breakpoints[i9];
|
|
3752
|
+
const t1 = breakpoints[i9 + 1];
|
|
3824
3753
|
const span = t1 - t0;
|
|
3825
3754
|
if (span < 1e-15) continue;
|
|
3826
|
-
const p0 = evaluateCurve2d(
|
|
3827
|
-
const p32 = evaluateCurve2d(
|
|
3828
|
-
const tan0 = tangentCurve2d(
|
|
3829
|
-
const tan3 = tangentCurve2d(
|
|
3755
|
+
const p0 = evaluateCurve2d(c8, t0);
|
|
3756
|
+
const p32 = evaluateCurve2d(c8, t1);
|
|
3757
|
+
const tan0 = tangentCurve2d(c8, t0);
|
|
3758
|
+
const tan3 = tangentCurve2d(c8, t1);
|
|
3830
3759
|
const s6 = span / 3;
|
|
3831
3760
|
const bezier = {
|
|
3832
3761
|
__bk2d: "bezier",
|
|
@@ -3849,60 +3778,60 @@ class BrepkitAdapter {
|
|
|
3849
3778
|
addCurveToBBox(this.bb2d(bbox), this.c2d(curve));
|
|
3850
3779
|
}
|
|
3851
3780
|
getBBox2dBounds(bbox) {
|
|
3852
|
-
const
|
|
3853
|
-
return { xMin:
|
|
3781
|
+
const b9 = this.bb2d(bbox);
|
|
3782
|
+
return { xMin: b9.xMin, yMin: b9.yMin, xMax: b9.xMax, yMax: b9.yMax };
|
|
3854
3783
|
}
|
|
3855
3784
|
mergeBBox2d(target, other) {
|
|
3856
|
-
const
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
}
|
|
3862
|
-
isBBox2dOut(a9,
|
|
3863
|
-
const ba = this.bb2d(a9), bb = this.bb2d(
|
|
3785
|
+
const t10 = this.bb2d(target), o9 = this.bb2d(other);
|
|
3786
|
+
t10.xMin = Math.min(t10.xMin, o9.xMin);
|
|
3787
|
+
t10.yMin = Math.min(t10.yMin, o9.yMin);
|
|
3788
|
+
t10.xMax = Math.max(t10.xMax, o9.xMax);
|
|
3789
|
+
t10.yMax = Math.max(t10.yMax, o9.yMax);
|
|
3790
|
+
}
|
|
3791
|
+
isBBox2dOut(a9, b9) {
|
|
3792
|
+
const ba = this.bb2d(a9), bb = this.bb2d(b9);
|
|
3864
3793
|
return ba.xMax < bb.xMin || bb.xMax < ba.xMin || ba.yMax < bb.yMin || bb.yMax < ba.yMin;
|
|
3865
3794
|
}
|
|
3866
3795
|
isBBox2dOutPoint(bbox, x7, y6) {
|
|
3867
|
-
const
|
|
3868
|
-
return x7 <
|
|
3796
|
+
const b9 = this.bb2d(bbox);
|
|
3797
|
+
return x7 < b9.xMin || x7 > b9.xMax || y6 < b9.yMin || y6 > b9.yMax;
|
|
3869
3798
|
}
|
|
3870
3799
|
// --- 2D type extraction ---
|
|
3871
3800
|
getCurve2dCircleData(curve) {
|
|
3872
|
-
const
|
|
3873
|
-
if (
|
|
3801
|
+
const c8 = this.c2dBasis(curve);
|
|
3802
|
+
if (c8.__bk2d === "circle") return { cx: c8.cx, cy: c8.cy, radius: c8.radius, isDirect: c8.sense };
|
|
3874
3803
|
return null;
|
|
3875
3804
|
}
|
|
3876
3805
|
getCurve2dEllipseData(curve) {
|
|
3877
|
-
const
|
|
3878
|
-
if (
|
|
3806
|
+
const c8 = this.c2dBasis(curve);
|
|
3807
|
+
if (c8.__bk2d === "ellipse")
|
|
3879
3808
|
return {
|
|
3880
|
-
majorRadius:
|
|
3881
|
-
minorRadius:
|
|
3882
|
-
xAxisAngle:
|
|
3883
|
-
isDirect:
|
|
3809
|
+
majorRadius: c8.majorRadius,
|
|
3810
|
+
minorRadius: c8.minorRadius,
|
|
3811
|
+
xAxisAngle: c8.xDirAngle,
|
|
3812
|
+
isDirect: c8.sense
|
|
3884
3813
|
};
|
|
3885
3814
|
return null;
|
|
3886
3815
|
}
|
|
3887
3816
|
getCurve2dBezierPoles(curve) {
|
|
3888
|
-
const
|
|
3889
|
-
if (
|
|
3817
|
+
const c8 = this.c2dBasis(curve);
|
|
3818
|
+
if (c8.__bk2d === "bezier") return [...c8.poles];
|
|
3890
3819
|
return null;
|
|
3891
3820
|
}
|
|
3892
3821
|
getCurve2dBezierDegree(curve) {
|
|
3893
|
-
const
|
|
3894
|
-
if (
|
|
3822
|
+
const c8 = this.c2dBasis(curve);
|
|
3823
|
+
if (c8.__bk2d === "bezier") return c8.poles.length - 1;
|
|
3895
3824
|
return null;
|
|
3896
3825
|
}
|
|
3897
3826
|
getCurve2dBSplineData(curve) {
|
|
3898
|
-
const
|
|
3899
|
-
if (
|
|
3827
|
+
const c8 = this.c2dBasis(curve);
|
|
3828
|
+
if (c8.__bk2d === "bspline")
|
|
3900
3829
|
return {
|
|
3901
|
-
poles: [...
|
|
3902
|
-
knots: [...
|
|
3903
|
-
multiplicities: [...
|
|
3904
|
-
degree:
|
|
3905
|
-
isPeriodic:
|
|
3830
|
+
poles: [...c8.poles],
|
|
3831
|
+
knots: [...c8.knots],
|
|
3832
|
+
multiplicities: [...c8.multiplicities],
|
|
3833
|
+
degree: c8.degree,
|
|
3834
|
+
isPeriodic: c8.isPeriodic
|
|
3906
3835
|
};
|
|
3907
3836
|
return null;
|
|
3908
3837
|
}
|
|
@@ -3915,49 +3844,49 @@ class BrepkitAdapter {
|
|
|
3915
3844
|
}
|
|
3916
3845
|
// --- 2D curve splitting ---
|
|
3917
3846
|
splitCurve2d(curve, params) {
|
|
3918
|
-
const
|
|
3919
|
-
const bounds = curveBounds(
|
|
3920
|
-
const sortedParams = [bounds.first, ...params.sort((a9,
|
|
3847
|
+
const c8 = this.c2d(curve);
|
|
3848
|
+
const bounds = curveBounds(c8);
|
|
3849
|
+
const sortedParams = [bounds.first, ...params.sort((a9, b9) => a9 - b9), bounds.last];
|
|
3921
3850
|
const result = [];
|
|
3922
|
-
for (let
|
|
3851
|
+
for (let i9 = 0; i9 < sortedParams.length - 1; i9++) {
|
|
3923
3852
|
result.push({
|
|
3924
3853
|
__bk2d: "trimmed",
|
|
3925
|
-
basis:
|
|
3926
|
-
tStart: sortedParams[
|
|
3927
|
-
tEnd: sortedParams[
|
|
3854
|
+
basis: c8,
|
|
3855
|
+
tStart: sortedParams[i9],
|
|
3856
|
+
tEnd: sortedParams[i9 + 1]
|
|
3928
3857
|
});
|
|
3929
3858
|
}
|
|
3930
3859
|
return result;
|
|
3931
3860
|
}
|
|
3932
3861
|
// --- 2D → 3D projection ---
|
|
3933
3862
|
liftCurve2dToPlane(curve, origin, planeZ, planeX) {
|
|
3934
|
-
const
|
|
3863
|
+
const c8 = this.c2d(curve);
|
|
3935
3864
|
const y6 = [
|
|
3936
3865
|
planeZ[1] * planeX[2] - planeZ[2] * planeX[1],
|
|
3937
3866
|
planeZ[2] * planeX[0] - planeZ[0] * planeX[2],
|
|
3938
3867
|
planeZ[0] * planeX[1] - planeZ[1] * planeX[0]
|
|
3939
3868
|
];
|
|
3940
|
-
const lift = (
|
|
3941
|
-
origin[0] +
|
|
3942
|
-
origin[1] +
|
|
3943
|
-
origin[2] +
|
|
3869
|
+
const lift = (u8, v9) => [
|
|
3870
|
+
origin[0] + u8 * planeX[0] + v9 * y6[0],
|
|
3871
|
+
origin[1] + u8 * planeX[1] + v9 * y6[1],
|
|
3872
|
+
origin[2] + u8 * planeX[2] + v9 * y6[2]
|
|
3944
3873
|
];
|
|
3945
|
-
if (
|
|
3946
|
-
const p1 = lift(
|
|
3947
|
-
const p22 = lift(
|
|
3874
|
+
if (c8.__bk2d === "line") {
|
|
3875
|
+
const p1 = lift(c8.ox, c8.oy);
|
|
3876
|
+
const p22 = lift(c8.ox + c8.dx * c8.len, c8.oy + c8.dy * c8.len);
|
|
3948
3877
|
return this.makeLineEdge(p1, p22);
|
|
3949
3878
|
}
|
|
3950
|
-
if (
|
|
3951
|
-
let basis =
|
|
3879
|
+
if (c8.__bk2d === "circle" || c8.__bk2d === "trimmed") {
|
|
3880
|
+
let basis = c8;
|
|
3952
3881
|
while (basis.__bk2d === "trimmed") basis = basis.basis;
|
|
3953
3882
|
if (basis.__bk2d === "circle") {
|
|
3954
3883
|
const circ = basis;
|
|
3955
3884
|
const center3d = lift(circ.cx, circ.cy);
|
|
3956
3885
|
const axis = circ.sense ? planeZ : [-planeZ[0], -planeZ[1], -planeZ[2]];
|
|
3957
|
-
const bounds2 = curveBounds(
|
|
3886
|
+
const bounds2 = curveBounds(c8);
|
|
3958
3887
|
let angularSpan;
|
|
3959
|
-
if (
|
|
3960
|
-
angularSpan = Math.abs(
|
|
3888
|
+
if (c8.__bk2d === "trimmed") {
|
|
3889
|
+
angularSpan = Math.abs(c8.tEnd - c8.tStart);
|
|
3961
3890
|
} else {
|
|
3962
3891
|
angularSpan = 2 * Math.PI;
|
|
3963
3892
|
}
|
|
@@ -3965,8 +3894,8 @@ class BrepkitAdapter {
|
|
|
3965
3894
|
const segmentSpan = (bounds2.last - bounds2.first) / nSegments;
|
|
3966
3895
|
const edgeIds = [];
|
|
3967
3896
|
for (let seg = 0; seg < nSegments; seg++) {
|
|
3968
|
-
const [su, sv] = evaluateCurve2d(
|
|
3969
|
-
const [eu, ev] = evaluateCurve2d(
|
|
3897
|
+
const [su, sv] = evaluateCurve2d(c8, bounds2.first + seg * segmentSpan);
|
|
3898
|
+
const [eu, ev] = evaluateCurve2d(c8, bounds2.first + (seg + 1) * segmentSpan);
|
|
3970
3899
|
edgeIds.push(
|
|
3971
3900
|
this.bk.makeCircleArc3d(...lift(su, sv), ...lift(eu, ev), ...center3d, ...axis)
|
|
3972
3901
|
);
|
|
@@ -3975,21 +3904,21 @@ class BrepkitAdapter {
|
|
|
3975
3904
|
return wireHandle(this.bk.makeWire(edgeIds, false));
|
|
3976
3905
|
}
|
|
3977
3906
|
}
|
|
3978
|
-
if (
|
|
3979
|
-
const points3d =
|
|
3907
|
+
if (c8.__bk2d === "bezier" || c8.__bk2d === "bspline") {
|
|
3908
|
+
const points3d = c8.poles.map(([u8, v9]) => lift(u8, v9));
|
|
3980
3909
|
if (points3d.length === 2) return this.makeLineEdge(points3d[0], points3d[1]);
|
|
3981
3910
|
const degree = Math.min(3, points3d.length - 1);
|
|
3982
3911
|
const coords = points3d.flatMap(([px, py, pz]) => [px, py, pz]);
|
|
3983
3912
|
const id = this.bk.interpolatePoints(coords, degree);
|
|
3984
3913
|
return edgeHandle(id);
|
|
3985
3914
|
}
|
|
3986
|
-
const bounds = curveBounds(
|
|
3915
|
+
const bounds = curveBounds(c8);
|
|
3987
3916
|
const nSamples = 100;
|
|
3988
3917
|
const points = [];
|
|
3989
|
-
for (let
|
|
3990
|
-
const
|
|
3991
|
-
const [
|
|
3992
|
-
points.push(lift(
|
|
3918
|
+
for (let i9 = 0; i9 <= nSamples; i9++) {
|
|
3919
|
+
const t10 = bounds.first + (bounds.last - bounds.first) * i9 / nSamples;
|
|
3920
|
+
const [u8, v9] = evaluateCurve2d(c8, t10);
|
|
3921
|
+
points.push(lift(u8, v9));
|
|
3993
3922
|
}
|
|
3994
3923
|
return this.interpolatePoints(points);
|
|
3995
3924
|
}
|
|
@@ -3997,15 +3926,15 @@ class BrepkitAdapter {
|
|
|
3997
3926
|
if (!isBrepkitHandle(surface))
|
|
3998
3927
|
throw new Error("brepkit: buildEdgeOnSurface requires a face handle as surface");
|
|
3999
3928
|
const fid = unwrap(surface, "face");
|
|
4000
|
-
const
|
|
4001
|
-
const bounds = curveBounds(
|
|
3929
|
+
const c8 = this.c2d(curve);
|
|
3930
|
+
const bounds = curveBounds(c8);
|
|
4002
3931
|
const surfType = this.bk.getSurfaceType(fid);
|
|
4003
3932
|
const N4 = surfType === "plane" ? 50 : 100;
|
|
4004
3933
|
const points = [];
|
|
4005
|
-
for (let
|
|
4006
|
-
const
|
|
4007
|
-
const [
|
|
4008
|
-
const p7 = this.bk.evaluateSurface(fid,
|
|
3934
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
3935
|
+
const t10 = bounds.first + (bounds.last - bounds.first) * i9 / N4;
|
|
3936
|
+
const [u8, v9] = evaluateCurve2d(c8, t10);
|
|
3937
|
+
const p7 = this.bk.evaluateSurface(fid, u8, v9);
|
|
4009
3938
|
points.push([p7[0], p7[1], p7[2]]);
|
|
4010
3939
|
}
|
|
4011
3940
|
return this.interpolatePoints(points);
|
|
@@ -4023,37 +3952,37 @@ class BrepkitAdapter {
|
|
|
4023
3952
|
const MAX_N = 80;
|
|
4024
3953
|
const REFINE_THRESHOLD = 0.05;
|
|
4025
3954
|
const tValues = [];
|
|
4026
|
-
for (let
|
|
4027
|
-
tValues.push(tMin + (tMax - tMin) *
|
|
3955
|
+
for (let i9 = 0; i9 <= BASE_N; i9++) {
|
|
3956
|
+
tValues.push(tMin + (tMax - tMin) * i9 / BASE_N);
|
|
4028
3957
|
}
|
|
4029
|
-
const evaluateUV = (
|
|
4030
|
-
const pt = this.bk.evaluateEdgeCurve(eid,
|
|
3958
|
+
const evaluateUV = (t10) => {
|
|
3959
|
+
const pt = this.bk.evaluateEdgeCurve(eid, t10);
|
|
4031
3960
|
const uv = this.bk.projectPointOnSurface(fid, pt[0], pt[1], pt[2]);
|
|
4032
3961
|
return [uv[0], uv[1]];
|
|
4033
3962
|
};
|
|
4034
|
-
const uvSamples = tValues.map((
|
|
4035
|
-
t:
|
|
4036
|
-
uv: evaluateUV(
|
|
3963
|
+
const uvSamples = tValues.map((t10) => ({
|
|
3964
|
+
t: t10,
|
|
3965
|
+
uv: evaluateUV(t10)
|
|
4037
3966
|
}));
|
|
4038
3967
|
let refinements = 0;
|
|
4039
3968
|
while (uvSamples.length < MAX_N) {
|
|
4040
3969
|
const insertions = [];
|
|
4041
|
-
for (let
|
|
4042
|
-
const a9 = uvSamples[
|
|
4043
|
-
const
|
|
4044
|
-
const tMid = (a9.t +
|
|
3970
|
+
for (let i9 = 0; i9 < uvSamples.length - 1; i9++) {
|
|
3971
|
+
const a9 = uvSamples[i9];
|
|
3972
|
+
const b9 = uvSamples[i9 + 1];
|
|
3973
|
+
const tMid = (a9.t + b9.t) / 2;
|
|
4045
3974
|
const uvMid = evaluateUV(tMid);
|
|
4046
|
-
const interpU = (a9.uv[0] +
|
|
4047
|
-
const interpV = (a9.uv[1] +
|
|
3975
|
+
const interpU = (a9.uv[0] + b9.uv[0]) / 2;
|
|
3976
|
+
const interpV = (a9.uv[1] + b9.uv[1]) / 2;
|
|
4048
3977
|
const deviation = Math.sqrt((uvMid[0] - interpU) ** 2 + (uvMid[1] - interpV) ** 2);
|
|
4049
3978
|
if (deviation > REFINE_THRESHOLD) {
|
|
4050
|
-
insertions.push({ index:
|
|
3979
|
+
insertions.push({ index: i9 + 1, t: tMid, uv: uvMid });
|
|
4051
3980
|
}
|
|
4052
3981
|
}
|
|
4053
3982
|
if (insertions.length === 0) break;
|
|
4054
3983
|
let budget = MAX_N - uvSamples.length;
|
|
4055
|
-
for (let
|
|
4056
|
-
const ins = insertions[
|
|
3984
|
+
for (let j7 = insertions.length - 1; j7 >= 0 && budget > 0; j7--) {
|
|
3985
|
+
const ins = insertions[j7];
|
|
4057
3986
|
uvSamples.splice(ins.index, 0, { t: ins.t, uv: ins.uv });
|
|
4058
3987
|
budget--;
|
|
4059
3988
|
}
|
|
@@ -4089,9 +4018,9 @@ class BrepkitAdapter {
|
|
|
4089
4018
|
const tMin = params[0], tMax = params[1];
|
|
4090
4019
|
const N4 = 10;
|
|
4091
4020
|
const pts = [];
|
|
4092
|
-
for (let
|
|
4093
|
-
const
|
|
4094
|
-
const p7 = this.bk.evaluateEdgeCurve(edgeId,
|
|
4021
|
+
for (let i9 = 0; i9 <= N4; i9++) {
|
|
4022
|
+
const t10 = tMin + (tMax - tMin) * i9 / N4;
|
|
4023
|
+
const p7 = this.bk.evaluateEdgeCurve(edgeId, t10);
|
|
4095
4024
|
pts.push(p7[0], p7[1], p7[2]);
|
|
4096
4025
|
}
|
|
4097
4026
|
allCoords.push(...pts);
|
|
@@ -4113,13 +4042,13 @@ class BrepkitAdapter {
|
|
|
4113
4042
|
// Private helpers
|
|
4114
4043
|
// ═══════════════════════════════════════════════════════════════════════
|
|
4115
4044
|
applyMatrix(shape2, matrix) {
|
|
4116
|
-
const
|
|
4045
|
+
const h10 = shape2;
|
|
4117
4046
|
if (!isBrepkitHandle(shape2)) {
|
|
4118
4047
|
throw new Error("brepkit: applyMatrix requires a BrepkitHandle");
|
|
4119
4048
|
}
|
|
4120
|
-
switch (
|
|
4049
|
+
switch (h10.type) {
|
|
4121
4050
|
case "solid": {
|
|
4122
|
-
const copy = this.bk.copySolid(
|
|
4051
|
+
const copy = this.bk.copySolid(h10.id);
|
|
4123
4052
|
this.bk.transformSolid(copy, matrix);
|
|
4124
4053
|
return solidHandle(copy);
|
|
4125
4054
|
}
|
|
@@ -4129,7 +4058,7 @@ class BrepkitAdapter {
|
|
|
4129
4058
|
"brepkit: applyMatrix for faces requires copyFace/transformFace WASM exports"
|
|
4130
4059
|
);
|
|
4131
4060
|
}
|
|
4132
|
-
const copy = this.bk.copyFace(
|
|
4061
|
+
const copy = this.bk.copyFace(h10.id);
|
|
4133
4062
|
this.bk.transformFace(copy, matrix);
|
|
4134
4063
|
return faceHandle(copy);
|
|
4135
4064
|
}
|
|
@@ -4139,7 +4068,7 @@ class BrepkitAdapter {
|
|
|
4139
4068
|
"brepkit: applyMatrix for wires requires copyWire/transformWire WASM exports"
|
|
4140
4069
|
);
|
|
4141
4070
|
}
|
|
4142
|
-
const copy = this.bk.copyWire(
|
|
4071
|
+
const copy = this.bk.copyWire(h10.id);
|
|
4143
4072
|
this.bk.transformWire(copy, matrix);
|
|
4144
4073
|
return wireHandle(copy);
|
|
4145
4074
|
}
|
|
@@ -4149,12 +4078,12 @@ class BrepkitAdapter {
|
|
|
4149
4078
|
"brepkit: applyMatrix for edges requires copyEdge/transformEdge WASM exports"
|
|
4150
4079
|
);
|
|
4151
4080
|
}
|
|
4152
|
-
const copy = this.bk.copyEdge(
|
|
4081
|
+
const copy = this.bk.copyEdge(h10.id);
|
|
4153
4082
|
this.bk.transformEdge(copy, matrix);
|
|
4154
4083
|
return edgeHandle(copy);
|
|
4155
4084
|
}
|
|
4156
4085
|
default:
|
|
4157
|
-
throw new Error(`brepkit: applyMatrix does not support '${
|
|
4086
|
+
throw new Error(`brepkit: applyMatrix does not support '${h10.type}' shapes`);
|
|
4158
4087
|
}
|
|
4159
4088
|
}
|
|
4160
4089
|
/** Check if we need to transform from default placement (origin, +Z). */
|
|
@@ -4216,14 +4145,14 @@ class BrepkitAdapter {
|
|
|
4216
4145
|
);
|
|
4217
4146
|
}
|
|
4218
4147
|
const faceGroups = [];
|
|
4219
|
-
for (let
|
|
4220
|
-
const start = data.faceOffsets[
|
|
4221
|
-
const count = data.faceOffsets[
|
|
4148
|
+
for (let i9 = 0; i9 < data.faceOffsets.length - 1; i9++) {
|
|
4149
|
+
const start = data.faceOffsets[i9];
|
|
4150
|
+
const count = data.faceOffsets[i9 + 1] - start;
|
|
4222
4151
|
if (count === 0) continue;
|
|
4223
4152
|
faceGroups.push({
|
|
4224
4153
|
start,
|
|
4225
4154
|
count,
|
|
4226
|
-
faceHash: faceIds[
|
|
4155
|
+
faceHash: faceIds[i9] ?? 0
|
|
4227
4156
|
});
|
|
4228
4157
|
}
|
|
4229
4158
|
let uvs = new Float32Array(0);
|
|
@@ -4268,11 +4197,11 @@ class BrepkitAdapter {
|
|
|
4268
4197
|
if (vertCount === 0) continue;
|
|
4269
4198
|
const triStart = allTriangles.length;
|
|
4270
4199
|
for (const v9 of positions) allVertices.push(v9);
|
|
4271
|
-
for (const
|
|
4200
|
+
for (const n7 of normals) allNormals.push(n7);
|
|
4272
4201
|
for (const idx of indices) {
|
|
4273
4202
|
allTriangles.push(idx + vertexOffset);
|
|
4274
4203
|
}
|
|
4275
|
-
for (let
|
|
4204
|
+
for (let i9 = 0; i9 < vertCount; i9++) {
|
|
4276
4205
|
allUVs.push(0, 0);
|
|
4277
4206
|
}
|
|
4278
4207
|
faceGroups.push({
|
|
@@ -4301,7 +4230,7 @@ class BrepkitAdapter {
|
|
|
4301
4230
|
const indices = faceMesh.indices;
|
|
4302
4231
|
const vertCount = positions.length / 3;
|
|
4303
4232
|
const uvs = [];
|
|
4304
|
-
for (let
|
|
4233
|
+
for (let i9 = 0; i9 < vertCount; i9++) {
|
|
4305
4234
|
uvs.push(0, 0);
|
|
4306
4235
|
}
|
|
4307
4236
|
return {
|
|
@@ -4340,15 +4269,15 @@ class BrepkitAdapter {
|
|
|
4340
4269
|
const dAngle = (endAngle - startAngle) / nSegments;
|
|
4341
4270
|
const controlPoints = [];
|
|
4342
4271
|
const weights = [];
|
|
4343
|
-
for (let
|
|
4344
|
-
const angle = startAngle +
|
|
4272
|
+
for (let i9 = 0; i9 <= nSegments; i9++) {
|
|
4273
|
+
const angle = startAngle + i9 * dAngle;
|
|
4345
4274
|
const cos = Math.cos(angle);
|
|
4346
4275
|
const sin = Math.sin(angle);
|
|
4347
4276
|
const px = center[0] + radius * (cos * xAxis[0] + sin * yAxis[0]);
|
|
4348
4277
|
const py = center[1] + radius * (cos * xAxis[1] + sin * yAxis[1]);
|
|
4349
4278
|
const pz = center[2] + radius * (cos * xAxis[2] + sin * yAxis[2]);
|
|
4350
|
-
if (
|
|
4351
|
-
const midAngle = startAngle + (
|
|
4279
|
+
if (i9 > 0) {
|
|
4280
|
+
const midAngle = startAngle + (i9 - 0.5) * dAngle;
|
|
4352
4281
|
const midCos = Math.cos(midAngle);
|
|
4353
4282
|
const midSin = Math.sin(midAngle);
|
|
4354
4283
|
const midR = radius / Math.cos(dAngle / 2);
|
|
@@ -4363,13 +4292,13 @@ class BrepkitAdapter {
|
|
|
4363
4292
|
}
|
|
4364
4293
|
const degree = 2;
|
|
4365
4294
|
const knots = Array(degree + 1).fill(0);
|
|
4366
|
-
for (let
|
|
4367
|
-
knots.push(
|
|
4295
|
+
for (let i9 = 1; i9 < nSegments; i9++) {
|
|
4296
|
+
knots.push(i9, i9);
|
|
4368
4297
|
}
|
|
4369
4298
|
knots.push(...Array(degree + 1).fill(nSegments));
|
|
4370
4299
|
const kMax = knots[knots.length - 1];
|
|
4371
|
-
for (let
|
|
4372
|
-
knots[
|
|
4300
|
+
for (let i9 = 0; i9 < knots.length; i9++) {
|
|
4301
|
+
knots[i9] = knots[i9] / kMax;
|
|
4373
4302
|
}
|
|
4374
4303
|
const startPt = controlPoints.slice(0, 3);
|
|
4375
4304
|
const endPt = controlPoints.slice(-3);
|
|
@@ -4393,9 +4322,9 @@ class BrepkitAdapter {
|
|
|
4393
4322
|
* Returns {degree, knots, controlPoints, weights} for NURBS edges.
|
|
4394
4323
|
*/
|
|
4395
4324
|
extractNurbsFromEdge(shape2) {
|
|
4396
|
-
const
|
|
4397
|
-
if (
|
|
4398
|
-
const nurbsJson = this.bk.getEdgeNurbsData(
|
|
4325
|
+
const h10 = shape2;
|
|
4326
|
+
if (h10.type !== "edge") return null;
|
|
4327
|
+
const nurbsJson = this.bk.getEdgeNurbsData(h10.id);
|
|
4399
4328
|
if (nurbsJson) {
|
|
4400
4329
|
const data = JSON.parse(nurbsJson);
|
|
4401
4330
|
return {
|
|
@@ -4405,7 +4334,7 @@ class BrepkitAdapter {
|
|
|
4405
4334
|
weights: data.weights
|
|
4406
4335
|
};
|
|
4407
4336
|
}
|
|
4408
|
-
const verts = this.bk.getEdgeVertices(
|
|
4337
|
+
const verts = this.bk.getEdgeVertices(h10.id);
|
|
4409
4338
|
return {
|
|
4410
4339
|
degree: 1,
|
|
4411
4340
|
knots: [0, 0, 1, 1],
|
|
@@ -4444,15 +4373,15 @@ class BrepkitAdapter {
|
|
|
4444
4373
|
const dAngle = (endAngle - startAngle) / nSegments;
|
|
4445
4374
|
const controlPoints = [];
|
|
4446
4375
|
const weights = [];
|
|
4447
|
-
for (let
|
|
4448
|
-
const angle = startAngle +
|
|
4376
|
+
for (let i9 = 0; i9 <= nSegments; i9++) {
|
|
4377
|
+
const angle = startAngle + i9 * dAngle;
|
|
4449
4378
|
const cos = Math.cos(angle);
|
|
4450
4379
|
const sin = Math.sin(angle);
|
|
4451
4380
|
const px = center[0] + majorRadius * cos * xAxis[0] + minorRadius * sin * yAxis[0];
|
|
4452
4381
|
const py = center[1] + majorRadius * cos * xAxis[1] + minorRadius * sin * yAxis[1];
|
|
4453
4382
|
const pz = center[2] + majorRadius * cos * xAxis[2] + minorRadius * sin * yAxis[2];
|
|
4454
|
-
if (
|
|
4455
|
-
const midAngle = startAngle + (
|
|
4383
|
+
if (i9 > 0) {
|
|
4384
|
+
const midAngle = startAngle + (i9 - 0.5) * dAngle;
|
|
4456
4385
|
const midCos = Math.cos(midAngle);
|
|
4457
4386
|
const midSin = Math.sin(midAngle);
|
|
4458
4387
|
const scale2 = 1 / Math.cos(dAngle / 2);
|
|
@@ -4467,13 +4396,13 @@ class BrepkitAdapter {
|
|
|
4467
4396
|
}
|
|
4468
4397
|
const degree = 2;
|
|
4469
4398
|
const knots = Array(degree + 1).fill(0);
|
|
4470
|
-
for (let
|
|
4471
|
-
knots.push(
|
|
4399
|
+
for (let i9 = 1; i9 < nSegments; i9++) {
|
|
4400
|
+
knots.push(i9, i9);
|
|
4472
4401
|
}
|
|
4473
4402
|
knots.push(...Array(degree + 1).fill(nSegments));
|
|
4474
4403
|
const kMax = knots[knots.length - 1];
|
|
4475
|
-
for (let
|
|
4476
|
-
knots[
|
|
4404
|
+
for (let i9 = 0; i9 < knots.length; i9++) {
|
|
4405
|
+
knots[i9] = knots[i9] / kMax;
|
|
4477
4406
|
}
|
|
4478
4407
|
const startPt = controlPoints.slice(0, 3);
|
|
4479
4408
|
const endPt = controlPoints.slice(-3);
|
|
@@ -4497,16 +4426,16 @@ class BrepkitAdapter {
|
|
|
4497
4426
|
*/
|
|
4498
4427
|
extractPlaneFromFace(faceShape) {
|
|
4499
4428
|
let faceId;
|
|
4500
|
-
const
|
|
4501
|
-
if (
|
|
4429
|
+
const h10 = faceShape;
|
|
4430
|
+
if (h10.type === "solid" || h10.type === "compound") {
|
|
4502
4431
|
const faces = this.iterShapes(faceShape, "face");
|
|
4503
4432
|
if (faces.length === 0) throw new Error("brepkit: extractPlaneFromFace: no faces found");
|
|
4504
4433
|
const firstFace = faces[0];
|
|
4505
4434
|
if (!firstFace) throw new Error("brepkit: extractPlaneFromFace: no faces found");
|
|
4506
4435
|
let bestId = unwrap(firstFace, "face");
|
|
4507
4436
|
let bestArea = 0;
|
|
4508
|
-
for (const
|
|
4509
|
-
const id = unwrap(
|
|
4437
|
+
for (const f11 of faces) {
|
|
4438
|
+
const id = unwrap(f11, "face");
|
|
4510
4439
|
try {
|
|
4511
4440
|
const a9 = this.bk.faceArea(id, DEFAULT_DEFLECTION);
|
|
4512
4441
|
if (a9 > bestArea) {
|
|
@@ -4520,8 +4449,8 @@ class BrepkitAdapter {
|
|
|
4520
4449
|
} else {
|
|
4521
4450
|
faceId = unwrap(faceShape, "face");
|
|
4522
4451
|
}
|
|
4523
|
-
const
|
|
4524
|
-
const normal = [
|
|
4452
|
+
const n7 = this.bk.getFaceNormal(faceId);
|
|
4453
|
+
const normal = [n7[0], n7[1], n7[2]];
|
|
4525
4454
|
const mesh2 = this.bk.tessellateFace(faceId, 1);
|
|
4526
4455
|
const positions = mesh2.positions;
|
|
4527
4456
|
if (positions.length >= 3) {
|
|
@@ -4620,7 +4549,7 @@ class BrepkitAdapter {
|
|
|
4620
4549
|
}
|
|
4621
4550
|
draft(shape2, faces, pullDirection, neutralPlane, angleDeg) {
|
|
4622
4551
|
const solidId = unwrapSolidOrThrow(shape2, "draft");
|
|
4623
|
-
const faceIds = faces.map((
|
|
4552
|
+
const faceIds = faces.map((f11) => unwrap(f11, "face"));
|
|
4624
4553
|
return solidHandle(
|
|
4625
4554
|
this.bk.draft(
|
|
4626
4555
|
solidId,
|
|
@@ -4637,7 +4566,7 @@ class BrepkitAdapter {
|
|
|
4637
4566
|
}
|
|
4638
4567
|
defeature(shape2, faces) {
|
|
4639
4568
|
const solidId = unwrapSolidOrThrow(shape2, "defeature");
|
|
4640
|
-
const faceIds = faces.map((
|
|
4569
|
+
const faceIds = faces.map((f11) => unwrap(f11, "face"));
|
|
4641
4570
|
return solidHandle(this.bk.defeature(solidId, faceIds));
|
|
4642
4571
|
}
|
|
4643
4572
|
// ═══════════════════════════════════════════════════════════════════════
|
|
@@ -4755,12 +4684,12 @@ class BrepkitAdapter {
|
|
|
4755
4684
|
return this.bk.executeBatch(json);
|
|
4756
4685
|
}
|
|
4757
4686
|
}
|
|
4758
|
-
function multiplyMatrices(a9,
|
|
4687
|
+
function multiplyMatrices(a9, b9) {
|
|
4759
4688
|
const result = new Array(16).fill(0);
|
|
4760
|
-
for (let
|
|
4761
|
-
for (let
|
|
4689
|
+
for (let i9 = 0; i9 < 4; i9++) {
|
|
4690
|
+
for (let j7 = 0; j7 < 4; j7++) {
|
|
4762
4691
|
for (let k7 = 0; k7 < 4; k7++) {
|
|
4763
|
-
result[
|
|
4692
|
+
result[i9 * 4 + j7] = result[i9 * 4 + j7] + a9[i9 * 4 + k7] * b9[k7 * 4 + j7];
|
|
4764
4693
|
}
|
|
4765
4694
|
}
|
|
4766
4695
|
}
|
|
@@ -4889,11 +4818,11 @@ function withNearestPostFilter(baseFinder, nearestPoint) {
|
|
|
4889
4818
|
if (candidates.length === 0) return [];
|
|
4890
4819
|
let bestIdx = 0;
|
|
4891
4820
|
let bestDist = vecDistance(vertexPosition(candidates[0]), nearestPoint);
|
|
4892
|
-
for (let
|
|
4893
|
-
const d10 = vecDistance(vertexPosition(candidates[
|
|
4821
|
+
for (let i9 = 1; i9 < candidates.length; i9++) {
|
|
4822
|
+
const d10 = vecDistance(vertexPosition(candidates[i9]), nearestPoint);
|
|
4894
4823
|
if (d10 < bestDist) {
|
|
4895
4824
|
bestDist = d10;
|
|
4896
|
-
bestIdx =
|
|
4825
|
+
bestIdx = i9;
|
|
4897
4826
|
}
|
|
4898
4827
|
}
|
|
4899
4828
|
return [candidates[bestIdx]];
|
|
@@ -5027,10 +4956,10 @@ function surfaceFromGrid(heights, options = {}) {
|
|
|
5027
4956
|
function buildBSplineSurface(heights, rows, cols, dx, dy, scaleZ) {
|
|
5028
4957
|
const points = [];
|
|
5029
4958
|
for (let r9 = 0; r9 < rows; r9++) {
|
|
5030
|
-
for (let
|
|
4959
|
+
for (let c8 = 0; c8 < cols; c8++) {
|
|
5031
4960
|
const row = heights[r9];
|
|
5032
|
-
const z6 = (row ? row[
|
|
5033
|
-
points.push([
|
|
4961
|
+
const z6 = (row ? row[c8] ?? 0 : 0) * scaleZ;
|
|
4962
|
+
points.push([c8 * dx, r9 * dy, z6]);
|
|
5034
4963
|
}
|
|
5035
4964
|
}
|
|
5036
4965
|
const faceShape = getKernel().bsplineSurface(points, rows, cols);
|
|
@@ -5044,10 +4973,10 @@ function buildBSplineSurface(heights, rows, cols, dx, dy, scaleZ) {
|
|
|
5044
4973
|
function buildTriangulatedSurface(heights, rows, cols, dx, dy, scaleZ) {
|
|
5045
4974
|
const points = [];
|
|
5046
4975
|
for (let r9 = 0; r9 < rows; r9++) {
|
|
5047
|
-
for (let
|
|
4976
|
+
for (let c8 = 0; c8 < cols; c8++) {
|
|
5048
4977
|
const row = heights[r9];
|
|
5049
|
-
const z6 = (row ? row[
|
|
5050
|
-
points.push([
|
|
4978
|
+
const z6 = (row ? row[c8] ?? 0 : 0) * scaleZ;
|
|
4979
|
+
points.push([c8 * dx, r9 * dy, z6]);
|
|
5051
4980
|
}
|
|
5052
4981
|
}
|
|
5053
4982
|
const resultShape = getKernel().triangulatedSurface(points, rows, cols);
|
|
@@ -5086,13 +5015,13 @@ async function surfaceFromImage(blob, options = {}) {
|
|
|
5086
5015
|
);
|
|
5087
5016
|
}
|
|
5088
5017
|
const w7 = bitmap.width;
|
|
5089
|
-
const
|
|
5090
|
-
if (w7 < 2 ||
|
|
5018
|
+
const h10 = bitmap.height;
|
|
5019
|
+
if (w7 < 2 || h10 < 2) {
|
|
5091
5020
|
bitmap.close();
|
|
5092
5021
|
return err(
|
|
5093
5022
|
validationError(
|
|
5094
5023
|
BrepErrorCode.SURFACE_GRID_TOO_SMALL,
|
|
5095
|
-
`surfaceFromImage: image too small (${w7}x${
|
|
5024
|
+
`surfaceFromImage: image too small (${w7}x${h10}), need at least 2x2`
|
|
5096
5025
|
)
|
|
5097
5026
|
);
|
|
5098
5027
|
}
|
|
@@ -5105,7 +5034,7 @@ async function surfaceFromImage(blob, options = {}) {
|
|
|
5105
5034
|
)
|
|
5106
5035
|
);
|
|
5107
5036
|
}
|
|
5108
|
-
const canvas = new OffscreenCanvas(w7,
|
|
5037
|
+
const canvas = new OffscreenCanvas(w7, h10);
|
|
5109
5038
|
const ctx = canvas.getContext("2d");
|
|
5110
5039
|
if (!ctx) {
|
|
5111
5040
|
bitmap.close();
|
|
@@ -5115,29 +5044,29 @@ async function surfaceFromImage(blob, options = {}) {
|
|
|
5115
5044
|
}
|
|
5116
5045
|
ctx.drawImage(bitmap, 0, 0);
|
|
5117
5046
|
bitmap.close();
|
|
5118
|
-
const imageData = ctx.getImageData(0, 0, w7,
|
|
5047
|
+
const imageData = ctx.getImageData(0, 0, w7, h10);
|
|
5119
5048
|
const data = imageData.data;
|
|
5120
5049
|
const rows = [];
|
|
5121
|
-
for (let y6 = 0; y6 <
|
|
5050
|
+
for (let y6 = 0; y6 < h10; y6 += downsample) {
|
|
5122
5051
|
const row = [];
|
|
5123
5052
|
for (let x7 = 0; x7 < w7; x7 += downsample) {
|
|
5124
5053
|
const idx = (y6 * w7 + x7) * 4;
|
|
5125
5054
|
const r9 = data[idx] ?? 0;
|
|
5126
|
-
const
|
|
5127
|
-
const
|
|
5055
|
+
const g11 = data[idx + 1] ?? 0;
|
|
5056
|
+
const b9 = data[idx + 2] ?? 0;
|
|
5128
5057
|
let value;
|
|
5129
5058
|
switch (channel) {
|
|
5130
5059
|
case "r":
|
|
5131
5060
|
value = r9 / 255;
|
|
5132
5061
|
break;
|
|
5133
5062
|
case "g":
|
|
5134
|
-
value =
|
|
5063
|
+
value = g11 / 255;
|
|
5135
5064
|
break;
|
|
5136
5065
|
case "b":
|
|
5137
|
-
value =
|
|
5066
|
+
value = b9 / 255;
|
|
5138
5067
|
break;
|
|
5139
5068
|
default:
|
|
5140
|
-
value = (REC601_R * r9 + REC601_G *
|
|
5069
|
+
value = (REC601_R * r9 + REC601_G * g11 + REC601_B * b9) / 255;
|
|
5141
5070
|
break;
|
|
5142
5071
|
}
|
|
5143
5072
|
row.push(value);
|
|
@@ -5168,8 +5097,8 @@ function hull(shapes, options = {}) {
|
|
|
5168
5097
|
)
|
|
5169
5098
|
);
|
|
5170
5099
|
}
|
|
5171
|
-
for (const [
|
|
5172
|
-
const check = validateNotNull$1(shape2, `hull: shapes[${
|
|
5100
|
+
for (const [i9, shape2] of shapes.entries()) {
|
|
5101
|
+
const check = validateNotNull$1(shape2, `hull: shapes[${i9}]`);
|
|
5173
5102
|
if (isErr(check)) return check;
|
|
5174
5103
|
}
|
|
5175
5104
|
const tolerance = options.tolerance ?? 0.1;
|
|
@@ -5325,8 +5254,8 @@ function polyhedron(points, faces, options = {}) {
|
|
|
5325
5254
|
}
|
|
5326
5255
|
if (face.length < 3) continue;
|
|
5327
5256
|
const v0 = face[0];
|
|
5328
|
-
for (let
|
|
5329
|
-
triangles.push([v0, face[
|
|
5257
|
+
for (let i9 = 1; i9 < face.length - 1; i9++) {
|
|
5258
|
+
triangles.push([v0, face[i9], face[i9 + 1]]);
|
|
5330
5259
|
}
|
|
5331
5260
|
}
|
|
5332
5261
|
try {
|
|
@@ -5357,20 +5286,20 @@ function multiSectionSweep(sections, spine, options) {
|
|
|
5357
5286
|
}
|
|
5358
5287
|
const { solid = true, ruled = false, tolerance = 1e-6 } = options ?? {};
|
|
5359
5288
|
const explicitLocations = sections.map((s6) => s6.location);
|
|
5360
|
-
for (let
|
|
5361
|
-
const loc = explicitLocations[
|
|
5289
|
+
for (let i9 = 0; i9 < explicitLocations.length; i9++) {
|
|
5290
|
+
const loc = explicitLocations[i9];
|
|
5362
5291
|
if (loc !== void 0 && (loc < 0 || loc > 1)) {
|
|
5363
5292
|
return err(
|
|
5364
5293
|
validationError(
|
|
5365
5294
|
BrepErrorCode.MULTI_SWEEP_FAILED,
|
|
5366
|
-
`Section ${
|
|
5295
|
+
`Section ${i9} location ${loc} is out of range [0, 1]`
|
|
5367
5296
|
)
|
|
5368
5297
|
);
|
|
5369
5298
|
}
|
|
5370
5299
|
}
|
|
5371
5300
|
const definedLocs = explicitLocations.filter((l10) => l10 !== void 0);
|
|
5372
|
-
for (let
|
|
5373
|
-
if ((definedLocs[
|
|
5301
|
+
for (let i9 = 1; i9 < definedLocs.length; i9++) {
|
|
5302
|
+
if ((definedLocs[i9] ?? 0) <= (definedLocs[i9 - 1] ?? 0)) {
|
|
5374
5303
|
return err(
|
|
5375
5304
|
validationError(
|
|
5376
5305
|
BrepErrorCode.MULTI_SWEEP_FAILED,
|
|
@@ -5383,16 +5312,16 @@ function multiSectionSweep(sections, spine, options) {
|
|
|
5383
5312
|
const kernel = getKernel();
|
|
5384
5313
|
const [uFirst, uLast] = kernel.curveParameters(spine.wrapped);
|
|
5385
5314
|
const uRange = uLast - uFirst;
|
|
5386
|
-
const params = sections.map((s6,
|
|
5315
|
+
const params = sections.map((s6, i9) => {
|
|
5387
5316
|
if (s6.location !== void 0) {
|
|
5388
5317
|
return uFirst + s6.location * uRange;
|
|
5389
5318
|
}
|
|
5390
|
-
return uFirst +
|
|
5319
|
+
return uFirst + i9 / (sections.length - 1) * uRange;
|
|
5391
5320
|
});
|
|
5392
5321
|
const positionedWires = [];
|
|
5393
|
-
for (let
|
|
5394
|
-
const param = params[
|
|
5395
|
-
const section2 = sections[
|
|
5322
|
+
for (let i9 = 0; i9 < sections.length; i9++) {
|
|
5323
|
+
const param = params[i9];
|
|
5324
|
+
const section2 = sections[i9];
|
|
5396
5325
|
if (param === void 0 || section2 === void 0) continue;
|
|
5397
5326
|
const positioned = kernel.positionOnCurve(section2.wire.wrapped, spine.wrapped, param);
|
|
5398
5327
|
positionedWires.push(kernel.downcast(positioned, "wire"));
|
|
@@ -5445,25 +5374,25 @@ function dot2(ax, ay, bx, by) {
|
|
|
5445
5374
|
function len2(x7, y6) {
|
|
5446
5375
|
return Math.sqrt(x7 * x7 + y6 * y6);
|
|
5447
5376
|
}
|
|
5448
|
-
function polyAt(poly,
|
|
5449
|
-
const p7 = poly[(
|
|
5450
|
-
if (!p7) throw new Error(`Invalid polygon index ${
|
|
5377
|
+
function polyAt(poly, i9) {
|
|
5378
|
+
const p7 = poly[(i9 % poly.length + poly.length) % poly.length];
|
|
5379
|
+
if (!p7) throw new Error(`Invalid polygon index ${i9} for length ${poly.length}`);
|
|
5451
5380
|
return p7;
|
|
5452
5381
|
}
|
|
5453
5382
|
function ensureCCW(poly) {
|
|
5454
5383
|
let area = 0;
|
|
5455
|
-
for (let
|
|
5456
|
-
const cur = polyAt(poly,
|
|
5457
|
-
const nxt = polyAt(poly,
|
|
5384
|
+
for (let i9 = 0; i9 < poly.length; i9++) {
|
|
5385
|
+
const cur = polyAt(poly, i9);
|
|
5386
|
+
const nxt = polyAt(poly, i9 + 1);
|
|
5458
5387
|
area += cur.x * nxt.y - nxt.x * cur.y;
|
|
5459
5388
|
}
|
|
5460
5389
|
if (area < 0) return [...poly].reverse();
|
|
5461
5390
|
return poly;
|
|
5462
5391
|
}
|
|
5463
|
-
function bisector(poly,
|
|
5464
|
-
const prev = polyAt(poly,
|
|
5465
|
-
const cur = polyAt(poly,
|
|
5466
|
-
const next = polyAt(poly,
|
|
5392
|
+
function bisector(poly, i9) {
|
|
5393
|
+
const prev = polyAt(poly, i9 - 1);
|
|
5394
|
+
const cur = polyAt(poly, i9);
|
|
5395
|
+
const next = polyAt(poly, i9 + 1);
|
|
5467
5396
|
const e1x = cur.x - prev.x;
|
|
5468
5397
|
const e1y = cur.y - prev.y;
|
|
5469
5398
|
const e1l = len2(e1x, e1y);
|
|
@@ -5493,23 +5422,23 @@ function isLavNodeReflex(node) {
|
|
|
5493
5422
|
return cross2(node.x - prev.x, node.y - prev.y, next.x - node.x, next.y - node.y) < -EPS;
|
|
5494
5423
|
}
|
|
5495
5424
|
function createLav(poly) {
|
|
5496
|
-
const nodes = poly.map((p7,
|
|
5497
|
-
const
|
|
5425
|
+
const nodes = poly.map((p7, i9) => {
|
|
5426
|
+
const b9 = bisector(poly, i9);
|
|
5498
5427
|
return {
|
|
5499
5428
|
x: p7.x,
|
|
5500
5429
|
y: p7.y,
|
|
5501
|
-
bx:
|
|
5502
|
-
by:
|
|
5503
|
-
origIdx:
|
|
5430
|
+
bx: b9.dx,
|
|
5431
|
+
by: b9.dy,
|
|
5432
|
+
origIdx: i9,
|
|
5504
5433
|
prev: null,
|
|
5505
5434
|
next: null,
|
|
5506
5435
|
active: true
|
|
5507
5436
|
};
|
|
5508
5437
|
});
|
|
5509
|
-
for (let
|
|
5510
|
-
const node = nodes[
|
|
5511
|
-
const prevNode = nodes[(
|
|
5512
|
-
const nextNode = nodes[(
|
|
5438
|
+
for (let i9 = 0; i9 < nodes.length; i9++) {
|
|
5439
|
+
const node = nodes[i9];
|
|
5440
|
+
const prevNode = nodes[(i9 - 1 + nodes.length) % nodes.length];
|
|
5441
|
+
const nextNode = nodes[(i9 + 1) % nodes.length];
|
|
5513
5442
|
if (node && prevNode && nextNode) {
|
|
5514
5443
|
node.prev = prevNode;
|
|
5515
5444
|
node.next = nextNode;
|
|
@@ -5527,26 +5456,26 @@ function lavSize(start) {
|
|
|
5527
5456
|
}
|
|
5528
5457
|
return count;
|
|
5529
5458
|
}
|
|
5530
|
-
function bisectorIntersectTime(a9,
|
|
5531
|
-
const ddx = a9.bx -
|
|
5532
|
-
const ddy = a9.by -
|
|
5533
|
-
const dxp =
|
|
5534
|
-
const dyp =
|
|
5459
|
+
function bisectorIntersectTime(a9, b9) {
|
|
5460
|
+
const ddx = a9.bx - b9.bx;
|
|
5461
|
+
const ddy = a9.by - b9.by;
|
|
5462
|
+
const dxp = b9.x - a9.x;
|
|
5463
|
+
const dyp = b9.y - a9.y;
|
|
5535
5464
|
if (Math.abs(ddx) < EPS && Math.abs(ddy) < EPS) return null;
|
|
5536
|
-
let
|
|
5465
|
+
let t10;
|
|
5537
5466
|
if (Math.abs(ddx) > Math.abs(ddy)) {
|
|
5538
|
-
|
|
5467
|
+
t10 = dxp / ddx;
|
|
5539
5468
|
} else {
|
|
5540
|
-
|
|
5469
|
+
t10 = dyp / ddy;
|
|
5541
5470
|
}
|
|
5542
|
-
if (
|
|
5471
|
+
if (t10 < EPS) return null;
|
|
5543
5472
|
const otherDd = Math.abs(ddx) > Math.abs(ddy) ? ddy : ddx;
|
|
5544
5473
|
const otherDp = Math.abs(ddx) > Math.abs(ddy) ? dyp : dxp;
|
|
5545
5474
|
if (Math.abs(otherDd) > EPS) {
|
|
5546
5475
|
const t22 = otherDp / otherDd;
|
|
5547
|
-
if (Math.abs(
|
|
5476
|
+
if (Math.abs(t10 - t22) > 1e-4 * Math.max(1, Math.abs(t10))) return null;
|
|
5548
5477
|
}
|
|
5549
|
-
return
|
|
5478
|
+
return t10;
|
|
5550
5479
|
}
|
|
5551
5480
|
function raySplitTime(node, eA, eB) {
|
|
5552
5481
|
const edx = eB.x - eA.x;
|
|
@@ -5560,31 +5489,31 @@ function raySplitTime(node, eA, eB) {
|
|
|
5560
5489
|
const relBy = node.by - (eA.by + eB.by) / 2;
|
|
5561
5490
|
const dRate = relBx * enx + relBy * eny;
|
|
5562
5491
|
if (Math.abs(dRate) < EPS) return null;
|
|
5563
|
-
const
|
|
5564
|
-
if (
|
|
5565
|
-
const px = node.x +
|
|
5566
|
-
const py = node.y +
|
|
5567
|
-
const ax = eA.x +
|
|
5568
|
-
const ay = eA.y +
|
|
5569
|
-
const bxx = eB.x +
|
|
5570
|
-
const byy = eB.y +
|
|
5492
|
+
const t10 = -d0 / dRate;
|
|
5493
|
+
if (t10 < EPS) return null;
|
|
5494
|
+
const px = node.x + t10 * node.bx;
|
|
5495
|
+
const py = node.y + t10 * node.by;
|
|
5496
|
+
const ax = eA.x + t10 * eA.bx;
|
|
5497
|
+
const ay = eA.y + t10 * eA.by;
|
|
5498
|
+
const bxx = eB.x + t10 * eB.bx;
|
|
5499
|
+
const byy = eB.y + t10 * eB.by;
|
|
5571
5500
|
const segDx = bxx - ax;
|
|
5572
5501
|
const segDy = byy - ay;
|
|
5573
5502
|
const segL = len2(segDx, segDy);
|
|
5574
|
-
if (segL < EPS) return
|
|
5503
|
+
if (segL < EPS) return t10;
|
|
5575
5504
|
const s6 = dot2(px - ax, py - ay, segDx, segDy) / (segL * segL);
|
|
5576
5505
|
if (s6 < -0.01 || s6 > 1.01) return null;
|
|
5577
|
-
return
|
|
5506
|
+
return t10;
|
|
5578
5507
|
}
|
|
5579
5508
|
function computeEvents(lavNodes) {
|
|
5580
5509
|
const events = [];
|
|
5581
5510
|
for (const node of lavNodes) {
|
|
5582
5511
|
if (!node.active) continue;
|
|
5583
|
-
const
|
|
5584
|
-
if (
|
|
5585
|
-
const x7 = node.x +
|
|
5586
|
-
const y6 = node.y +
|
|
5587
|
-
events.push({ time:
|
|
5512
|
+
const t10 = bisectorIntersectTime(node, node.next);
|
|
5513
|
+
if (t10 !== null && t10 > EPS) {
|
|
5514
|
+
const x7 = node.x + t10 * node.bx;
|
|
5515
|
+
const y6 = node.y + t10 * node.by;
|
|
5516
|
+
events.push({ time: t10, x: x7, y: y6, nodeA: node, nodeB: node.next, type: "edge" });
|
|
5588
5517
|
}
|
|
5589
5518
|
if (isLavNodeReflex(node)) {
|
|
5590
5519
|
let cur = node.next.next;
|
|
@@ -5601,7 +5530,7 @@ function computeEvents(lavNodes) {
|
|
|
5601
5530
|
}
|
|
5602
5531
|
}
|
|
5603
5532
|
}
|
|
5604
|
-
events.sort((a9,
|
|
5533
|
+
events.sort((a9, b9) => a9.time - b9.time);
|
|
5605
5534
|
return events;
|
|
5606
5535
|
}
|
|
5607
5536
|
function computeStraightSkeleton(polygon) {
|
|
@@ -5609,12 +5538,12 @@ function computeStraightSkeleton(polygon) {
|
|
|
5609
5538
|
return { nodes: [], faces: [] };
|
|
5610
5539
|
}
|
|
5611
5540
|
const poly = ensureCCW(polygon);
|
|
5612
|
-
const
|
|
5541
|
+
const n7 = poly.length;
|
|
5613
5542
|
const skeletonNodes = [];
|
|
5614
|
-
const vertexToSkelNodes = Array.from({ length:
|
|
5543
|
+
const vertexToSkelNodes = Array.from({ length: n7 }, () => []);
|
|
5615
5544
|
const lavNodes = createLav(poly);
|
|
5616
5545
|
let iterations = 0;
|
|
5617
|
-
const maxIter =
|
|
5546
|
+
const maxIter = n7 * n7 * 2;
|
|
5618
5547
|
while (iterations < maxIter) {
|
|
5619
5548
|
iterations++;
|
|
5620
5549
|
const activeStart = lavNodes.find((nd) => nd.active);
|
|
@@ -5623,26 +5552,26 @@ function computeStraightSkeleton(polygon) {
|
|
|
5623
5552
|
if (sz <= 3) {
|
|
5624
5553
|
if (sz === 3) {
|
|
5625
5554
|
const a9 = activeStart;
|
|
5626
|
-
const
|
|
5627
|
-
const
|
|
5628
|
-
const
|
|
5629
|
-
const time =
|
|
5630
|
-
const mx = (a9.x +
|
|
5631
|
-
const my = (a9.y +
|
|
5555
|
+
const b9 = a9.next;
|
|
5556
|
+
const c8 = b9.next;
|
|
5557
|
+
const t10 = bisectorIntersectTime(a9, b9);
|
|
5558
|
+
const time = t10 !== null && t10 > EPS ? t10 : 0;
|
|
5559
|
+
const mx = (a9.x + b9.x + c8.x) / 3 + time * (a9.bx + b9.bx + c8.bx) / 3;
|
|
5560
|
+
const my = (a9.y + b9.y + c8.y) / 3 + time * (a9.by + b9.by + c8.by) / 3;
|
|
5632
5561
|
const nodeIdx = skeletonNodes.length;
|
|
5633
5562
|
skeletonNodes.push({ x: mx, y: my, height: time });
|
|
5634
5563
|
const aNodes = vertexToSkelNodes[a9.origIdx];
|
|
5635
|
-
const bNodes = vertexToSkelNodes[
|
|
5636
|
-
const cNodes = vertexToSkelNodes[
|
|
5564
|
+
const bNodes = vertexToSkelNodes[b9.origIdx];
|
|
5565
|
+
const cNodes = vertexToSkelNodes[c8.origIdx];
|
|
5637
5566
|
if (aNodes) aNodes.push(nodeIdx);
|
|
5638
5567
|
if (bNodes) bNodes.push(nodeIdx);
|
|
5639
5568
|
if (cNodes) cNodes.push(nodeIdx);
|
|
5640
5569
|
a9.active = false;
|
|
5641
|
-
|
|
5642
|
-
|
|
5570
|
+
b9.active = false;
|
|
5571
|
+
c8.active = false;
|
|
5643
5572
|
} else {
|
|
5644
5573
|
let cur = activeStart;
|
|
5645
|
-
for (let
|
|
5574
|
+
for (let i9 = 0; i9 < sz; i9++) {
|
|
5646
5575
|
cur.active = false;
|
|
5647
5576
|
cur = cur.next;
|
|
5648
5577
|
}
|
|
@@ -5661,19 +5590,19 @@ function computeStraightSkeleton(polygon) {
|
|
|
5661
5590
|
if (!ev) break;
|
|
5662
5591
|
if (ev.type === "edge") {
|
|
5663
5592
|
const a9 = ev.nodeA;
|
|
5664
|
-
const
|
|
5665
|
-
if (!a9.active || !
|
|
5593
|
+
const b9 = ev.nodeB;
|
|
5594
|
+
if (!a9.active || !b9.active) continue;
|
|
5666
5595
|
const nodeIdx = skeletonNodes.length;
|
|
5667
5596
|
skeletonNodes.push({ x: ev.x, y: ev.y, height: ev.time });
|
|
5668
5597
|
const aNodes = vertexToSkelNodes[a9.origIdx];
|
|
5669
|
-
const bNodes = vertexToSkelNodes[
|
|
5598
|
+
const bNodes = vertexToSkelNodes[b9.origIdx];
|
|
5670
5599
|
if (aNodes) aNodes.push(nodeIdx);
|
|
5671
5600
|
if (bNodes) bNodes.push(nodeIdx);
|
|
5672
5601
|
a9.x = ev.x;
|
|
5673
5602
|
a9.y = ev.y;
|
|
5674
|
-
a9.next =
|
|
5675
|
-
|
|
5676
|
-
|
|
5603
|
+
a9.next = b9.next;
|
|
5604
|
+
b9.next.prev = a9;
|
|
5605
|
+
b9.active = false;
|
|
5677
5606
|
const lavPoly = [];
|
|
5678
5607
|
let cur = a9;
|
|
5679
5608
|
do {
|
|
@@ -5685,13 +5614,13 @@ function computeStraightSkeleton(polygon) {
|
|
|
5685
5614
|
a9.by = bDir.dy;
|
|
5686
5615
|
} else {
|
|
5687
5616
|
const a9 = ev.nodeA;
|
|
5688
|
-
const
|
|
5689
|
-
if (!a9.active || !
|
|
5617
|
+
const b9 = ev.nodeB;
|
|
5618
|
+
if (!a9.active || !b9.active) continue;
|
|
5690
5619
|
const nodeIdx = skeletonNodes.length;
|
|
5691
5620
|
skeletonNodes.push({ x: ev.x, y: ev.y, height: ev.time });
|
|
5692
5621
|
const aNodes = vertexToSkelNodes[a9.origIdx];
|
|
5693
5622
|
if (aNodes) aNodes.push(nodeIdx);
|
|
5694
|
-
const bNodes = vertexToSkelNodes[
|
|
5623
|
+
const bNodes = vertexToSkelNodes[b9.origIdx];
|
|
5695
5624
|
if (bNodes) bNodes.push(nodeIdx);
|
|
5696
5625
|
const aCopy = {
|
|
5697
5626
|
x: ev.x,
|
|
@@ -5707,20 +5636,20 @@ function computeStraightSkeleton(polygon) {
|
|
|
5707
5636
|
a9.x = ev.x;
|
|
5708
5637
|
a9.y = ev.y;
|
|
5709
5638
|
const aNext = a9.next;
|
|
5710
|
-
const bNext =
|
|
5639
|
+
const bNext = b9.next;
|
|
5711
5640
|
a9.next = bNext;
|
|
5712
5641
|
bNext.prev = a9;
|
|
5713
5642
|
aCopy.next = aNext;
|
|
5714
5643
|
aNext.prev = aCopy;
|
|
5715
|
-
aCopy.prev =
|
|
5716
|
-
|
|
5644
|
+
aCopy.prev = b9;
|
|
5645
|
+
b9.next = aCopy;
|
|
5717
5646
|
const buildLavPoly = (start) => {
|
|
5718
5647
|
const poly2 = [];
|
|
5719
|
-
let
|
|
5648
|
+
let c8 = start;
|
|
5720
5649
|
do {
|
|
5721
|
-
poly2.push({ x:
|
|
5722
|
-
|
|
5723
|
-
} while (
|
|
5650
|
+
poly2.push({ x: c8.x, y: c8.y });
|
|
5651
|
+
c8 = c8.next;
|
|
5652
|
+
} while (c8 !== start);
|
|
5724
5653
|
return poly2;
|
|
5725
5654
|
};
|
|
5726
5655
|
const lav1Poly = buildLavPoly(a9);
|
|
@@ -5734,14 +5663,14 @@ function computeStraightSkeleton(polygon) {
|
|
|
5734
5663
|
}
|
|
5735
5664
|
}
|
|
5736
5665
|
const faces = [];
|
|
5737
|
-
for (let
|
|
5738
|
-
const
|
|
5739
|
-
const pi = polyAt(poly,
|
|
5740
|
-
const pj = polyAt(poly,
|
|
5666
|
+
for (let i9 = 0; i9 < n7; i9++) {
|
|
5667
|
+
const j7 = (i9 + 1) % n7;
|
|
5668
|
+
const pi = polyAt(poly, i9);
|
|
5669
|
+
const pj = polyAt(poly, j7);
|
|
5741
5670
|
const faceVerts = [pi, pj];
|
|
5742
5671
|
const faceHeights = [0, 0];
|
|
5743
|
-
const jNodes = vertexToSkelNodes[
|
|
5744
|
-
const iNodes = vertexToSkelNodes[
|
|
5672
|
+
const jNodes = vertexToSkelNodes[j7];
|
|
5673
|
+
const iNodes = vertexToSkelNodes[i9];
|
|
5745
5674
|
if (jNodes) {
|
|
5746
5675
|
for (const ni of jNodes) {
|
|
5747
5676
|
const sn = skeletonNodes[ni];
|
|
@@ -5796,8 +5725,8 @@ function extractPolygon(w7) {
|
|
|
5796
5725
|
}
|
|
5797
5726
|
function fanTriangulate(count) {
|
|
5798
5727
|
const tris = [];
|
|
5799
|
-
for (let
|
|
5800
|
-
tris.push([0,
|
|
5728
|
+
for (let i9 = 1; i9 < count - 1; i9++) {
|
|
5729
|
+
tris.push([0, i9, i9 + 1]);
|
|
5801
5730
|
}
|
|
5802
5731
|
return tris;
|
|
5803
5732
|
}
|
|
@@ -5813,42 +5742,42 @@ function pointInTriangle(px, py, ax, ay, bx, by, cx, cy) {
|
|
|
5813
5742
|
return !(hasNeg && hasPos);
|
|
5814
5743
|
}
|
|
5815
5744
|
function earClipTriangulate(poly) {
|
|
5816
|
-
const
|
|
5817
|
-
if (
|
|
5818
|
-
if (
|
|
5745
|
+
const n7 = poly.length;
|
|
5746
|
+
if (n7 < 3) return [];
|
|
5747
|
+
if (n7 === 3) return [[0, 1, 2]];
|
|
5819
5748
|
let area2 = 0;
|
|
5820
|
-
for (let
|
|
5821
|
-
const a9 = poly[
|
|
5822
|
-
const
|
|
5823
|
-
if (a9 &&
|
|
5749
|
+
for (let i9 = 0; i9 < n7; i9++) {
|
|
5750
|
+
const a9 = poly[i9];
|
|
5751
|
+
const b9 = poly[(i9 + 1) % n7];
|
|
5752
|
+
if (a9 && b9) area2 += a9.x * b9.y - b9.x * a9.y;
|
|
5824
5753
|
}
|
|
5825
5754
|
const tris = [];
|
|
5826
|
-
const idx = Array.from({ length:
|
|
5755
|
+
const idx = Array.from({ length: n7 }, (_2, i9) => i9);
|
|
5827
5756
|
if (area2 < 0) idx.reverse();
|
|
5828
5757
|
const isEar = (prev, curr, next) => {
|
|
5829
5758
|
const a9 = poly[prev];
|
|
5830
|
-
const
|
|
5831
|
-
const
|
|
5832
|
-
if (!a9 || !
|
|
5833
|
-
if (cross2d(a9.x, a9.y,
|
|
5759
|
+
const b9 = poly[curr];
|
|
5760
|
+
const c8 = poly[next];
|
|
5761
|
+
if (!a9 || !b9 || !c8) return false;
|
|
5762
|
+
if (cross2d(a9.x, a9.y, b9.x, b9.y, c8.x, c8.y) <= 0) return false;
|
|
5834
5763
|
for (const vi of idx) {
|
|
5835
5764
|
if (vi === prev || vi === curr || vi === next) continue;
|
|
5836
5765
|
const p7 = poly[vi];
|
|
5837
5766
|
if (!p7) continue;
|
|
5838
|
-
if (pointInTriangle(p7.x, p7.y, a9.x, a9.y,
|
|
5767
|
+
if (pointInTriangle(p7.x, p7.y, a9.x, a9.y, b9.x, b9.y, c8.x, c8.y)) return false;
|
|
5839
5768
|
}
|
|
5840
5769
|
return true;
|
|
5841
5770
|
};
|
|
5842
5771
|
while (idx.length > 3) {
|
|
5843
5772
|
let clipped = false;
|
|
5844
|
-
for (let
|
|
5845
|
-
const prev = idx[(
|
|
5846
|
-
const curr = idx[
|
|
5847
|
-
const next = idx[(
|
|
5773
|
+
for (let i9 = 0; i9 < idx.length; i9++) {
|
|
5774
|
+
const prev = idx[(i9 - 1 + idx.length) % idx.length];
|
|
5775
|
+
const curr = idx[i9];
|
|
5776
|
+
const next = idx[(i9 + 1) % idx.length];
|
|
5848
5777
|
if (prev === void 0 || curr === void 0 || next === void 0) continue;
|
|
5849
5778
|
if (isEar(prev, curr, next)) {
|
|
5850
5779
|
tris.push([prev, curr, next]);
|
|
5851
|
-
idx.splice(
|
|
5780
|
+
idx.splice(i9, 1);
|
|
5852
5781
|
clipped = true;
|
|
5853
5782
|
break;
|
|
5854
5783
|
}
|
|
@@ -5856,8 +5785,8 @@ function earClipTriangulate(poly) {
|
|
|
5856
5785
|
if (!clipped) break;
|
|
5857
5786
|
}
|
|
5858
5787
|
if (idx.length === 3) {
|
|
5859
|
-
const [a9,
|
|
5860
|
-
if (a9 !== void 0 &&
|
|
5788
|
+
const [a9, b9, c8] = idx;
|
|
5789
|
+
if (a9 !== void 0 && b9 !== void 0 && c8 !== void 0) tris.push([a9, b9, c8]);
|
|
5861
5790
|
}
|
|
5862
5791
|
return tris;
|
|
5863
5792
|
}
|
|
@@ -5884,10 +5813,10 @@ function roof(w7, options) {
|
|
|
5884
5813
|
const triFaces = [];
|
|
5885
5814
|
for (const skFace of skeleton.faces) {
|
|
5886
5815
|
const verts3d = skFace.vertices.map(
|
|
5887
|
-
(v9,
|
|
5816
|
+
(v9, i9) => [
|
|
5888
5817
|
v9.x,
|
|
5889
5818
|
v9.y,
|
|
5890
|
-
(skFace.heights[
|
|
5819
|
+
(skFace.heights[i9] ?? 0) * tanAngle
|
|
5891
5820
|
]
|
|
5892
5821
|
);
|
|
5893
5822
|
const tris = fanTriangulate(verts3d.length);
|
|
@@ -5962,36 +5891,36 @@ function solveConstraints(nodes, constraints) {
|
|
|
5962
5891
|
});
|
|
5963
5892
|
}
|
|
5964
5893
|
const unsupported = [];
|
|
5965
|
-
for (const
|
|
5966
|
-
if (
|
|
5967
|
-
const a9 =
|
|
5968
|
-
const
|
|
5969
|
-
if (a9.entity.type === "plane" &&
|
|
5894
|
+
for (const c8 of constraints) {
|
|
5895
|
+
if (c8.type === "coincident" && c8.entityA && c8.entityB) {
|
|
5896
|
+
const a9 = c8.entityA;
|
|
5897
|
+
const b9 = c8.entityB;
|
|
5898
|
+
if (a9.entity.type === "plane" && b9.entity.type === "plane") {
|
|
5970
5899
|
const aNormal = a9.entity.normal ?? [0, 0, 1];
|
|
5971
5900
|
const aOrigin = a9.entity.origin;
|
|
5972
|
-
const bOrigin =
|
|
5901
|
+
const bOrigin = b9.entity.origin;
|
|
5973
5902
|
const dot = aNormal[0] * (aOrigin[0] - bOrigin[0]) + aNormal[1] * (aOrigin[1] - bOrigin[1]) + aNormal[2] * (aOrigin[2] - bOrigin[2]);
|
|
5974
5903
|
const pos = [dot * aNormal[0], dot * aNormal[1], dot * aNormal[2]];
|
|
5975
|
-
transforms.set(
|
|
5904
|
+
transforms.set(b9.node, { position: pos, rotation: [1, 0, 0, 0] });
|
|
5976
5905
|
} else {
|
|
5977
|
-
unsupported.push(`coincident(${a9.entity.type}-${
|
|
5906
|
+
unsupported.push(`coincident(${a9.entity.type}-${b9.entity.type})`);
|
|
5978
5907
|
}
|
|
5979
|
-
} else if (
|
|
5980
|
-
const a9 =
|
|
5981
|
-
const
|
|
5982
|
-
if (a9.entity.type === "plane" &&
|
|
5908
|
+
} else if (c8.type === "distance" && c8.entityA && c8.entityB && c8.value !== void 0) {
|
|
5909
|
+
const a9 = c8.entityA;
|
|
5910
|
+
const b9 = c8.entityB;
|
|
5911
|
+
if (a9.entity.type === "plane" && b9.entity.type === "plane") {
|
|
5983
5912
|
const aNormal = a9.entity.normal ?? [0, 0, 1];
|
|
5984
5913
|
const aOrigin = a9.entity.origin;
|
|
5985
|
-
const bOrigin =
|
|
5914
|
+
const bOrigin = b9.entity.origin;
|
|
5986
5915
|
const currentDist = aNormal[0] * (aOrigin[0] - bOrigin[0]) + aNormal[1] * (aOrigin[1] - bOrigin[1]) + aNormal[2] * (aOrigin[2] - bOrigin[2]);
|
|
5987
|
-
const offset2 = currentDist +
|
|
5916
|
+
const offset2 = currentDist + c8.value;
|
|
5988
5917
|
const pos = [offset2 * aNormal[0], offset2 * aNormal[1], offset2 * aNormal[2]];
|
|
5989
|
-
transforms.set(
|
|
5918
|
+
transforms.set(b9.node, { position: pos, rotation: [1, 0, 0, 0] });
|
|
5990
5919
|
} else {
|
|
5991
|
-
unsupported.push(`distance(${a9.entity.type}-${
|
|
5920
|
+
unsupported.push(`distance(${a9.entity.type}-${b9.entity.type})`);
|
|
5992
5921
|
}
|
|
5993
|
-
} else if (
|
|
5994
|
-
unsupported.push(
|
|
5922
|
+
} else if (c8.type === "concentric" || c8.type === "angle") {
|
|
5923
|
+
unsupported.push(c8.type);
|
|
5995
5924
|
}
|
|
5996
5925
|
}
|
|
5997
5926
|
const dof = unsupported.reduce((sum, type) => {
|
|
@@ -6011,9 +5940,9 @@ function extractEntity(mate) {
|
|
|
6011
5940
|
}
|
|
6012
5941
|
return null;
|
|
6013
5942
|
}
|
|
6014
|
-
function extractPair(a9,
|
|
5943
|
+
function extractPair(a9, b9) {
|
|
6015
5944
|
const entA = extractEntity(a9);
|
|
6016
|
-
const entB = extractEntity(
|
|
5945
|
+
const entB = extractEntity(b9);
|
|
6017
5946
|
if (!entA || !entB) {
|
|
6018
5947
|
return err(
|
|
6019
5948
|
validationError(
|
|
@@ -6024,7 +5953,7 @@ function extractPair(a9, b10) {
|
|
|
6024
5953
|
}
|
|
6025
5954
|
return ok({
|
|
6026
5955
|
entityA: { node: a9.node, entity: entA },
|
|
6027
|
-
entityB: { node:
|
|
5956
|
+
entityB: { node: b9.node, entity: entB }
|
|
6028
5957
|
});
|
|
6029
5958
|
}
|
|
6030
5959
|
function addMate(assembly, constraint) {
|
|
@@ -6115,28 +6044,28 @@ function checkInterference(shape1, shape2, tolerance = 1e-6) {
|
|
|
6115
6044
|
function checkAllInterferences(shapes, tolerance = 1e-6) {
|
|
6116
6045
|
const pairs = [];
|
|
6117
6046
|
const boxes = shapes.map((s6) => getBounds(s6));
|
|
6118
|
-
shapes.forEach((si,
|
|
6119
|
-
for (let
|
|
6120
|
-
if (aabbDisjoint(boxes[
|
|
6121
|
-
const result = unwrap$1(checkInterference(si, shapes[
|
|
6047
|
+
shapes.forEach((si, i9) => {
|
|
6048
|
+
for (let j7 = i9 + 1; j7 < shapes.length; j7++) {
|
|
6049
|
+
if (aabbDisjoint(boxes[i9], boxes[j7], tolerance)) continue;
|
|
6050
|
+
const result = unwrap$1(checkInterference(si, shapes[j7], tolerance));
|
|
6122
6051
|
if (result.hasInterference) {
|
|
6123
|
-
pairs.push({ i:
|
|
6052
|
+
pairs.push({ i: i9, j: j7, result });
|
|
6124
6053
|
}
|
|
6125
6054
|
}
|
|
6126
6055
|
});
|
|
6127
6056
|
return pairs;
|
|
6128
6057
|
}
|
|
6129
|
-
function aabbDisjoint(a9,
|
|
6130
|
-
return a9.xMax + tolerance <
|
|
6058
|
+
function aabbDisjoint(a9, b9, tolerance) {
|
|
6059
|
+
return a9.xMax + tolerance < b9.xMin || b9.xMax + tolerance < a9.xMin || a9.yMax + tolerance < b9.yMin || b9.yMax + tolerance < a9.yMin || a9.zMax + tolerance < b9.zMin || b9.zMax + tolerance < a9.zMin;
|
|
6131
6060
|
}
|
|
6132
6061
|
function parseEntities(text) {
|
|
6133
6062
|
const lines = text.split(/\r?\n/);
|
|
6134
6063
|
const entities = [];
|
|
6135
6064
|
let inEntities = false;
|
|
6136
6065
|
let current;
|
|
6137
|
-
for (let
|
|
6138
|
-
const codeLine = lines[
|
|
6139
|
-
const valueLine = lines[
|
|
6066
|
+
for (let i9 = 0; i9 < lines.length - 1; i9 += 2) {
|
|
6067
|
+
const codeLine = lines[i9];
|
|
6068
|
+
const valueLine = lines[i9 + 1];
|
|
6140
6069
|
if (codeLine === void 0 || valueLine === void 0) continue;
|
|
6141
6070
|
const code = parseInt(codeLine.trim(), 10);
|
|
6142
6071
|
const value = valueLine.trim();
|
|
@@ -6168,8 +6097,8 @@ function parseEntities(text) {
|
|
|
6168
6097
|
function getNum(data, code, fallback = 0) {
|
|
6169
6098
|
const v9 = data.get(code);
|
|
6170
6099
|
if (v9 === void 0) return fallback;
|
|
6171
|
-
const
|
|
6172
|
-
return isNaN(
|
|
6100
|
+
const n7 = parseFloat(v9);
|
|
6101
|
+
return isNaN(n7) ? fallback : n7;
|
|
6173
6102
|
}
|
|
6174
6103
|
function entityToEdge(entity) {
|
|
6175
6104
|
const { type, data } = entity;
|
|
@@ -6273,10 +6202,10 @@ function buildSolidFromMesh$1(vertices, faces) {
|
|
|
6273
6202
|
const kernel = getKernel();
|
|
6274
6203
|
const triFaces = [];
|
|
6275
6204
|
for (const face of faces) {
|
|
6276
|
-
for (let
|
|
6205
|
+
for (let i9 = 1; i9 < face.length - 1; i9++) {
|
|
6277
6206
|
const rawA = face[0] ?? 0;
|
|
6278
|
-
const rawB = face[
|
|
6279
|
-
const rawC = face[
|
|
6207
|
+
const rawB = face[i9] ?? 0;
|
|
6208
|
+
const rawC = face[i9 + 1] ?? 0;
|
|
6280
6209
|
const ai = rawA > 0 ? rawA - 1 : vertices.length + rawA;
|
|
6281
6210
|
const bi = rawB > 0 ? rawB - 1 : vertices.length + rawB;
|
|
6282
6211
|
const ci = rawC > 0 ? rawC - 1 : vertices.length + rawC;
|
|
@@ -6307,9 +6236,9 @@ function buildSolidFromMesh$1(vertices, faces) {
|
|
|
6307
6236
|
}
|
|
6308
6237
|
function extractFromZip(data, target) {
|
|
6309
6238
|
let eocdOffset = -1;
|
|
6310
|
-
for (let
|
|
6311
|
-
if (data[
|
|
6312
|
-
eocdOffset =
|
|
6239
|
+
for (let i9 = data.length - 22; i9 >= 0; i9--) {
|
|
6240
|
+
if (data[i9] === 80 && data[i9 + 1] === 75 && data[i9 + 2] === 5 && data[i9 + 3] === 6) {
|
|
6241
|
+
eocdOffset = i9;
|
|
6313
6242
|
break;
|
|
6314
6243
|
}
|
|
6315
6244
|
}
|
|
@@ -6714,7 +6643,7 @@ function shell$1(shape2, faces, thickness, tolerance = 1e-3) {
|
|
|
6714
6643
|
const inputFaceHashes = collectInputFaceHashes([shape2]);
|
|
6715
6644
|
const { shape: resultShape, evolution } = getKernel().shellWithHistory(
|
|
6716
6645
|
shape2.wrapped,
|
|
6717
|
-
faces.map((
|
|
6646
|
+
faces.map((f11) => f11.wrapped),
|
|
6718
6647
|
thickness,
|
|
6719
6648
|
inputFaceHashes,
|
|
6720
6649
|
HASH_CODE_MAX,
|
|
@@ -6790,14 +6719,14 @@ function applyMatrix(shape2, matrix) {
|
|
|
6790
6719
|
function transformCopy(shape2, composed) {
|
|
6791
6720
|
return transformCopy$1(resolve(shape2), composed);
|
|
6792
6721
|
}
|
|
6793
|
-
function fuse(a9,
|
|
6794
|
-
return fuse$1(resolve(a9), resolve(
|
|
6722
|
+
function fuse(a9, b9, options) {
|
|
6723
|
+
return fuse$1(resolve(a9), resolve(b9), options);
|
|
6795
6724
|
}
|
|
6796
6725
|
function cut(base, tool, options) {
|
|
6797
6726
|
return cut$1(resolve(base), resolve(tool), options);
|
|
6798
6727
|
}
|
|
6799
|
-
function intersect(a9,
|
|
6800
|
-
return intersect$1(resolve(a9), resolve(
|
|
6728
|
+
function intersect(a9, b9, options) {
|
|
6729
|
+
return intersect$1(resolve(a9), resolve(b9), options);
|
|
6801
6730
|
}
|
|
6802
6731
|
function section(shape2, plane, options) {
|
|
6803
6732
|
return section$1(resolve(shape2), plane, options);
|
|
@@ -6947,9 +6876,9 @@ function loft$1(wires, { ruled = true, startPoint, endPoint, tolerance = 1e-6 }
|
|
|
6947
6876
|
}
|
|
6948
6877
|
}
|
|
6949
6878
|
function extrude(face, height) {
|
|
6950
|
-
const
|
|
6879
|
+
const f11 = resolve(face);
|
|
6951
6880
|
const vec = typeof height === "number" ? [0, 0, height] : height;
|
|
6952
|
-
return extrude$1(
|
|
6881
|
+
return extrude$1(f11, vec);
|
|
6953
6882
|
}
|
|
6954
6883
|
function revolve(face, options) {
|
|
6955
6884
|
const pivotPoint = options?.at ?? [0, 0, 0];
|
|
@@ -6974,11 +6903,11 @@ function resolveTargetFace(shape2, faceSpec) {
|
|
|
6974
6903
|
}
|
|
6975
6904
|
let best = faces[0];
|
|
6976
6905
|
let bestZ = faceCenter(best)[2];
|
|
6977
|
-
for (let
|
|
6978
|
-
const
|
|
6979
|
-
const z6 = faceCenter(
|
|
6906
|
+
for (let i9 = 1; i9 < faces.length; i9++) {
|
|
6907
|
+
const f11 = faces[i9];
|
|
6908
|
+
const z6 = faceCenter(f11)[2];
|
|
6980
6909
|
if (z6 > bestZ) {
|
|
6981
|
-
best =
|
|
6910
|
+
best = f11;
|
|
6982
6911
|
bestZ = z6;
|
|
6983
6912
|
}
|
|
6984
6913
|
}
|
|
@@ -7021,23 +6950,23 @@ function drill(shape2, options) {
|
|
|
7021
6950
|
if (options.depth !== void 0) {
|
|
7022
6951
|
tool = makeCylinder(radius, options.depth, pos, dir);
|
|
7023
6952
|
} else {
|
|
7024
|
-
const
|
|
6953
|
+
const b9 = getBounds(s6);
|
|
7025
6954
|
const corners = [
|
|
7026
|
-
[
|
|
7027
|
-
[
|
|
7028
|
-
[
|
|
7029
|
-
[
|
|
7030
|
-
[
|
|
7031
|
-
[
|
|
7032
|
-
[
|
|
7033
|
-
[
|
|
6955
|
+
[b9.xMin, b9.yMin, b9.zMin],
|
|
6956
|
+
[b9.xMax, b9.yMin, b9.zMin],
|
|
6957
|
+
[b9.xMin, b9.yMax, b9.zMin],
|
|
6958
|
+
[b9.xMax, b9.yMax, b9.zMin],
|
|
6959
|
+
[b9.xMin, b9.yMin, b9.zMax],
|
|
6960
|
+
[b9.xMax, b9.yMin, b9.zMax],
|
|
6961
|
+
[b9.xMin, b9.yMax, b9.zMax],
|
|
6962
|
+
[b9.xMax, b9.yMax, b9.zMax]
|
|
7034
6963
|
];
|
|
7035
6964
|
let tMin = Infinity;
|
|
7036
6965
|
let tMax = -Infinity;
|
|
7037
|
-
for (const
|
|
7038
|
-
const
|
|
7039
|
-
if (
|
|
7040
|
-
if (
|
|
6966
|
+
for (const c8 of corners) {
|
|
6967
|
+
const t10 = (c8[0] - pos[0]) * dir[0] + (c8[1] - pos[1]) * dir[1] + (c8[2] - pos[2]) * dir[2];
|
|
6968
|
+
if (t10 < tMin) tMin = t10;
|
|
6969
|
+
if (t10 > tMax) tMax = t10;
|
|
7041
6970
|
}
|
|
7042
6971
|
const overshoot = 1;
|
|
7043
6972
|
tMin -= overshoot;
|
|
@@ -7240,8 +7169,8 @@ function createWrappedCurve(val) {
|
|
|
7240
7169
|
length: () => curveLength(val),
|
|
7241
7170
|
startPoint: () => curveStartPoint(val),
|
|
7242
7171
|
endPoint: () => curveEndPoint(val),
|
|
7243
|
-
pointAt: (
|
|
7244
|
-
tangentAt: (
|
|
7172
|
+
pointAt: (t10) => curvePointAt(val, t10),
|
|
7173
|
+
tangentAt: (t10) => curveTangentAt(val, t10),
|
|
7245
7174
|
isClosed: () => curveIsClosed(val),
|
|
7246
7175
|
sweep(spine, opts) {
|
|
7247
7176
|
if (!isWire(val)) throw new Error("sweep requires a Wire");
|
|
@@ -7292,8 +7221,8 @@ export {
|
|
|
7292
7221
|
B3 as BaseSketcher2d,
|
|
7293
7222
|
B as Blueprint,
|
|
7294
7223
|
a5 as BlueprintSketcher,
|
|
7295
|
-
|
|
7296
|
-
|
|
7224
|
+
c2 as Blueprints,
|
|
7225
|
+
e3 as BoundingBox2d,
|
|
7297
7226
|
BrepBugError,
|
|
7298
7227
|
BrepErrorCode,
|
|
7299
7228
|
BrepWrapperError,
|
|
@@ -7321,7 +7250,7 @@ export {
|
|
|
7321
7250
|
a2 as andThen,
|
|
7322
7251
|
applyGlue,
|
|
7323
7252
|
applyMatrix,
|
|
7324
|
-
|
|
7253
|
+
h7 as approximateCurve,
|
|
7325
7254
|
M as as2D,
|
|
7326
7255
|
N as as3D,
|
|
7327
7256
|
l9 as asTopo,
|
|
@@ -7331,38 +7260,38 @@ export {
|
|
|
7331
7260
|
blueprintToDXF,
|
|
7332
7261
|
boss,
|
|
7333
7262
|
f7 as box,
|
|
7334
|
-
|
|
7263
|
+
g8 as bsplineApprox,
|
|
7335
7264
|
bug,
|
|
7336
7265
|
X as cameraFromPlane,
|
|
7337
7266
|
Y as cameraLookAt,
|
|
7338
|
-
|
|
7267
|
+
c5 as cast,
|
|
7339
7268
|
castShape,
|
|
7340
7269
|
O as castShape3D,
|
|
7341
7270
|
chamfer,
|
|
7342
7271
|
chamferDistAngle as chamferDistAngleShape,
|
|
7343
7272
|
checkAllInterferences,
|
|
7344
7273
|
checkInterference,
|
|
7345
|
-
|
|
7274
|
+
j5 as circle,
|
|
7346
7275
|
circularPattern,
|
|
7347
7276
|
m9 as classifyPointOnFace,
|
|
7348
|
-
|
|
7277
|
+
c6 as clearMeshCache,
|
|
7349
7278
|
clone,
|
|
7350
7279
|
a as closedWire,
|
|
7351
7280
|
c as collect,
|
|
7352
|
-
|
|
7281
|
+
d3 as collectShapes,
|
|
7353
7282
|
l6 as colorFaces,
|
|
7354
7283
|
m6 as colorShape,
|
|
7355
7284
|
f3 as complexExtrude,
|
|
7356
7285
|
w4 as composeTransforms,
|
|
7357
7286
|
k5 as compound,
|
|
7358
|
-
|
|
7287
|
+
c3 as compoundSketchExtrude,
|
|
7359
7288
|
d5 as compoundSketchFace,
|
|
7360
7289
|
e4 as compoundSketchLoft,
|
|
7361
7290
|
f5 as compoundSketchRevolve,
|
|
7362
7291
|
b2 as computationError,
|
|
7363
7292
|
computeStraightSkeleton,
|
|
7364
7293
|
l7 as cone,
|
|
7365
|
-
|
|
7294
|
+
c7 as cornerFinder,
|
|
7366
7295
|
g5 as countNodes,
|
|
7367
7296
|
h4 as createAssembly,
|
|
7368
7297
|
i3 as createAssemblyNode,
|
|
@@ -7375,8 +7304,8 @@ export {
|
|
|
7375
7304
|
b as createHandle,
|
|
7376
7305
|
j2 as createHistory,
|
|
7377
7306
|
d as createKernelHandle,
|
|
7378
|
-
|
|
7379
|
-
|
|
7307
|
+
b8 as createMeshCache,
|
|
7308
|
+
c4 as createNamedPlane,
|
|
7380
7309
|
createOperationRegistry,
|
|
7381
7310
|
a7 as createPlane,
|
|
7382
7311
|
k2 as createRegistry,
|
|
@@ -7397,37 +7326,37 @@ export {
|
|
|
7397
7326
|
curve2dTangentAt,
|
|
7398
7327
|
curveEndPoint,
|
|
7399
7328
|
curveIsClosed,
|
|
7400
|
-
|
|
7329
|
+
i6 as curveIsPeriodic,
|
|
7401
7330
|
curveLength,
|
|
7402
|
-
|
|
7331
|
+
j6 as curvePeriod,
|
|
7403
7332
|
curvePointAt,
|
|
7404
7333
|
curveStartPoint,
|
|
7405
7334
|
curveTangentAt,
|
|
7406
7335
|
cut,
|
|
7407
|
-
|
|
7336
|
+
d4 as cut2D,
|
|
7408
7337
|
cutAll,
|
|
7409
|
-
|
|
7338
|
+
j3 as cutBlueprints,
|
|
7410
7339
|
m7 as cylinder,
|
|
7411
7340
|
dequeueTask,
|
|
7412
7341
|
describe,
|
|
7413
|
-
|
|
7342
|
+
g7 as deserializeDrawing,
|
|
7414
7343
|
m4 as deserializeHistory,
|
|
7415
7344
|
fromBREP$1 as deserializeShape,
|
|
7416
7345
|
d7 as downcast,
|
|
7417
|
-
|
|
7346
|
+
h6 as draw,
|
|
7418
7347
|
i4 as drawCircle,
|
|
7419
|
-
|
|
7348
|
+
j4 as drawEllipse,
|
|
7420
7349
|
k4 as drawFaceOutline,
|
|
7421
7350
|
l5 as drawParametricFunction,
|
|
7422
7351
|
m5 as drawPointsInterpolation,
|
|
7423
|
-
|
|
7352
|
+
n4 as drawPolysides,
|
|
7424
7353
|
o5 as drawProjection,
|
|
7425
7354
|
p3 as drawRectangle,
|
|
7426
|
-
|
|
7355
|
+
q2 as drawRoundedRectangle,
|
|
7427
7356
|
r3 as drawSingleCircle,
|
|
7428
7357
|
s3 as drawSingleEllipse,
|
|
7429
|
-
|
|
7430
|
-
|
|
7358
|
+
t4 as drawText,
|
|
7359
|
+
u4 as drawingChamfer,
|
|
7431
7360
|
v5 as drawingCut,
|
|
7432
7361
|
w3 as drawingFillet,
|
|
7433
7362
|
x4 as drawingFuse,
|
|
@@ -7435,10 +7364,10 @@ export {
|
|
|
7435
7364
|
z3 as drawingToSketchOnPlane,
|
|
7436
7365
|
drill,
|
|
7437
7366
|
edgeFinder,
|
|
7438
|
-
|
|
7367
|
+
n6 as edgesOfFace,
|
|
7439
7368
|
o7 as ellipse,
|
|
7440
7369
|
p5 as ellipseArc,
|
|
7441
|
-
|
|
7370
|
+
q4 as ellipsoid,
|
|
7442
7371
|
enqueueTask,
|
|
7443
7372
|
err,
|
|
7444
7373
|
n3 as exportAssemblySTEP,
|
|
@@ -7448,25 +7377,25 @@ export {
|
|
|
7448
7377
|
e6 as exportIGES,
|
|
7449
7378
|
exportOBJ,
|
|
7450
7379
|
d8 as exportSTEP,
|
|
7451
|
-
|
|
7380
|
+
f9 as exportSTL,
|
|
7452
7381
|
exportThreeMF,
|
|
7453
7382
|
extrude,
|
|
7454
7383
|
r7 as face,
|
|
7455
7384
|
faceCenter,
|
|
7456
7385
|
faceFinder,
|
|
7457
|
-
|
|
7458
|
-
|
|
7386
|
+
f8 as faceGeomType,
|
|
7387
|
+
q5 as faceOrientation,
|
|
7459
7388
|
s4 as facesOfEdge,
|
|
7460
|
-
|
|
7461
|
-
|
|
7389
|
+
i8 as fill,
|
|
7390
|
+
t8 as filledFace,
|
|
7462
7391
|
fillet,
|
|
7463
7392
|
findCurveType,
|
|
7464
|
-
|
|
7393
|
+
n5 as findFacesByTag,
|
|
7465
7394
|
o3 as findNode,
|
|
7466
7395
|
p as findStep,
|
|
7467
7396
|
f2 as flatMap,
|
|
7468
7397
|
r8 as flipFaceOrientation,
|
|
7469
|
-
|
|
7398
|
+
k6 as flipOrientation,
|
|
7470
7399
|
_ as fontMetrics,
|
|
7471
7400
|
fromBREP,
|
|
7472
7401
|
fromKernelDir,
|
|
@@ -7474,34 +7403,34 @@ export {
|
|
|
7474
7403
|
fromKernelVec,
|
|
7475
7404
|
C2 as fromNullable,
|
|
7476
7405
|
fuse,
|
|
7477
|
-
|
|
7406
|
+
f4 as fuse2D,
|
|
7478
7407
|
fuseAll,
|
|
7479
|
-
|
|
7408
|
+
k3 as fuseBlueprints,
|
|
7480
7409
|
g4 as genericSweep,
|
|
7481
7410
|
getBounds,
|
|
7482
7411
|
getBounds2D,
|
|
7483
|
-
|
|
7412
|
+
l8 as getCurveType,
|
|
7484
7413
|
getEdges,
|
|
7485
7414
|
o6 as getFaceColor,
|
|
7486
7415
|
getFaceOrigins,
|
|
7487
|
-
|
|
7416
|
+
q3 as getFaceTags,
|
|
7488
7417
|
getFaces,
|
|
7489
7418
|
$ as getFont,
|
|
7490
7419
|
f6 as getHashCode,
|
|
7491
7420
|
q as getHistoryShape,
|
|
7492
7421
|
getKernel,
|
|
7493
|
-
|
|
7422
|
+
g9 as getOrientation,
|
|
7494
7423
|
getOrientation2D,
|
|
7495
7424
|
r6 as getShapeColor,
|
|
7496
7425
|
g as getShapeKind,
|
|
7497
|
-
|
|
7426
|
+
g6 as getSingleFace,
|
|
7498
7427
|
getSurfaceType,
|
|
7499
|
-
|
|
7428
|
+
t7 as getTagMetadata,
|
|
7500
7429
|
getVertices,
|
|
7501
7430
|
getWires,
|
|
7502
7431
|
guidedSweep,
|
|
7503
7432
|
heal,
|
|
7504
|
-
|
|
7433
|
+
u6 as healFace,
|
|
7505
7434
|
v7 as healSolid,
|
|
7506
7435
|
w5 as healWire,
|
|
7507
7436
|
x6 as helix,
|
|
@@ -7518,8 +7447,8 @@ export {
|
|
|
7518
7447
|
innerWires,
|
|
7519
7448
|
m8 as interpolateCurve,
|
|
7520
7449
|
intersect,
|
|
7521
|
-
|
|
7522
|
-
|
|
7450
|
+
h5 as intersect2D,
|
|
7451
|
+
l4 as intersectBlueprints,
|
|
7523
7452
|
x5 as invalidateShapeCache,
|
|
7524
7453
|
ioError,
|
|
7525
7454
|
i as is2D,
|
|
@@ -7570,7 +7499,7 @@ export {
|
|
|
7570
7499
|
a1 as loadFont,
|
|
7571
7500
|
loft,
|
|
7572
7501
|
A4 as makeBaseBox,
|
|
7573
|
-
|
|
7502
|
+
u2 as makePlane,
|
|
7574
7503
|
a22 as makeProjectedEdges,
|
|
7575
7504
|
v as manifoldShell,
|
|
7576
7505
|
m2 as map,
|
|
@@ -7578,10 +7507,10 @@ export {
|
|
|
7578
7507
|
j as match,
|
|
7579
7508
|
measureArea,
|
|
7580
7509
|
e7 as measureCurvatureAt,
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7510
|
+
f10 as measureCurvatureAtMid,
|
|
7511
|
+
g10 as measureDistance,
|
|
7512
|
+
h9 as measureLength,
|
|
7513
|
+
i7 as measureLinearProps,
|
|
7585
7514
|
measureSurfaceProps,
|
|
7586
7515
|
measureVolume,
|
|
7587
7516
|
measureVolumeProps,
|
|
@@ -7592,7 +7521,7 @@ export {
|
|
|
7592
7521
|
mirror2D,
|
|
7593
7522
|
B4 as mirrorDrawing,
|
|
7594
7523
|
mirrorJoin,
|
|
7595
|
-
|
|
7524
|
+
t3 as modifyStep,
|
|
7596
7525
|
l2 as moduleInitError,
|
|
7597
7526
|
multiSectionSweep,
|
|
7598
7527
|
normalAt,
|
|
@@ -7615,12 +7544,12 @@ export {
|
|
|
7615
7544
|
E4 as polysideInnerRadius,
|
|
7616
7545
|
p2 as polysidesBlueprint,
|
|
7617
7546
|
a32 as projectEdges,
|
|
7618
|
-
|
|
7547
|
+
t9 as projectPointOnFace,
|
|
7619
7548
|
queryError,
|
|
7620
7549
|
rectangularPattern,
|
|
7621
7550
|
registerHandler,
|
|
7622
7551
|
R as registerKernel,
|
|
7623
|
-
|
|
7552
|
+
u3 as registerOperation,
|
|
7624
7553
|
v4 as registerShape,
|
|
7625
7554
|
rejectAll,
|
|
7626
7555
|
x3 as removeChild,
|
|
@@ -7647,7 +7576,7 @@ export {
|
|
|
7647
7576
|
sectionToFace,
|
|
7648
7577
|
A3 as serializeHistory,
|
|
7649
7578
|
E5 as setShapeOrigin,
|
|
7650
|
-
|
|
7579
|
+
u5 as setTagMetadata,
|
|
7651
7580
|
B6 as sewShells,
|
|
7652
7581
|
shape,
|
|
7653
7582
|
w6 as shapeType,
|
|
@@ -7701,14 +7630,14 @@ export {
|
|
|
7701
7630
|
toKernelVec,
|
|
7702
7631
|
K2 as toLineGeometryData,
|
|
7703
7632
|
toSVGPathD,
|
|
7704
|
-
|
|
7633
|
+
t5 as toVec2,
|
|
7705
7634
|
toVec3,
|
|
7706
7635
|
L2 as torus,
|
|
7707
7636
|
transformCopy,
|
|
7708
7637
|
translate,
|
|
7709
7638
|
translate2D,
|
|
7710
7639
|
W as translateDrawing,
|
|
7711
|
-
|
|
7640
|
+
t6 as translatePlane,
|
|
7712
7641
|
t2 as tryCatch,
|
|
7713
7642
|
n2 as tryCatchAsync,
|
|
7714
7643
|
E3 as twistExtrude,
|
|
@@ -7720,8 +7649,8 @@ export {
|
|
|
7720
7649
|
w2 as unwrapOr,
|
|
7721
7650
|
x2 as unwrapOrElse,
|
|
7722
7651
|
G2 as updateNode,
|
|
7723
|
-
|
|
7724
|
-
|
|
7652
|
+
u7 as uvBounds,
|
|
7653
|
+
h8 as uvCoordinates,
|
|
7725
7654
|
x as validSolid,
|
|
7726
7655
|
validationError,
|
|
7727
7656
|
v3 as vecAdd,
|