@tscircuit/3d-viewer 0.0.390 → 0.0.391

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.
Files changed (2) hide show
  1. package/dist/index.js +400 -219
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1129,13 +1129,13 @@ var require_squaredLength = __commonJS({
1129
1129
  var require_subtract = __commonJS({
1130
1130
  "node_modules/@jscad/modeling/src/maths/vec3/subtract.js"(exports, module) {
1131
1131
  "use strict";
1132
- var subtract3 = (out, a, b) => {
1132
+ var subtract4 = (out, a, b) => {
1133
1133
  out[0] = a[0] - b[0];
1134
1134
  out[1] = a[1] - b[1];
1135
1135
  out[2] = a[2] - b[2];
1136
1136
  return out;
1137
1137
  };
1138
- module.exports = subtract3;
1138
+ module.exports = subtract4;
1139
1139
  }
1140
1140
  });
1141
1141
 
@@ -1676,7 +1676,7 @@ var require_scale2 = __commonJS({
1676
1676
  var require_subtract2 = __commonJS({
1677
1677
  "node_modules/@jscad/modeling/src/maths/mat4/subtract.js"(exports, module) {
1678
1678
  "use strict";
1679
- var subtract3 = (out, a, b) => {
1679
+ var subtract4 = (out, a, b) => {
1680
1680
  out[0] = a[0] - b[0];
1681
1681
  out[1] = a[1] - b[1];
1682
1682
  out[2] = a[2] - b[2];
@@ -1695,7 +1695,7 @@ var require_subtract2 = __commonJS({
1695
1695
  out[15] = a[15] - b[15];
1696
1696
  return out;
1697
1697
  };
1698
- module.exports = subtract3;
1698
+ module.exports = subtract4;
1699
1699
  }
1700
1700
  });
1701
1701
 
@@ -2205,12 +2205,12 @@ var require_squaredLength2 = __commonJS({
2205
2205
  var require_subtract3 = __commonJS({
2206
2206
  "node_modules/@jscad/modeling/src/maths/vec2/subtract.js"(exports, module) {
2207
2207
  "use strict";
2208
- var subtract3 = (out, a, b) => {
2208
+ var subtract4 = (out, a, b) => {
2209
2209
  out[0] = a[0] - b[0];
2210
2210
  out[1] = a[1] - b[1];
2211
2211
  return out;
2212
2212
  };
2213
- module.exports = subtract3;
2213
+ module.exports = subtract4;
2214
2214
  }
2215
2215
  });
2216
2216
 
@@ -2671,14 +2671,14 @@ var require_point_line_distance = __commonJS({
2671
2671
  "node_modules/@jscad/modeling/src/operations/hulls/quickhull/point-line-distance.js"(exports, module) {
2672
2672
  "use strict";
2673
2673
  var cross = require_cross();
2674
- var subtract3 = require_subtract();
2674
+ var subtract4 = require_subtract();
2675
2675
  var squaredLength = require_squaredLength();
2676
2676
  var distanceSquared = (p, a, b) => {
2677
2677
  const ab = [];
2678
2678
  const ap = [];
2679
2679
  const cr = [];
2680
- subtract3(ab, b, a);
2681
- subtract3(ap, p, a);
2680
+ subtract4(ab, b, a);
2681
+ subtract4(ap, p, a);
2682
2682
  const area = squaredLength(cross(cr, ap, ab));
2683
2683
  const s = squaredLength(ab);
2684
2684
  if (s === 0) {
@@ -2697,11 +2697,11 @@ var require_get_plane_normal = __commonJS({
2697
2697
  "use strict";
2698
2698
  var cross = require_cross();
2699
2699
  var normalize = require_normalize();
2700
- var subtract3 = require_subtract();
2700
+ var subtract4 = require_subtract();
2701
2701
  var planeNormal = (out, point1, point2, point32) => {
2702
2702
  const tmp = [0, 0, 0];
2703
- subtract3(out, point1, point2);
2704
- subtract3(tmp, point2, point32);
2703
+ subtract4(out, point1, point2);
2704
+ subtract4(tmp, point2, point32);
2705
2705
  cross(out, out, tmp);
2706
2706
  return normalize(out, out);
2707
2707
  };
@@ -2915,7 +2915,7 @@ var require_Face = __commonJS({
2915
2915
  var length2 = require_length();
2916
2916
  var normalize = require_normalize();
2917
2917
  var scale2 = require_scale();
2918
- var subtract3 = require_subtract();
2918
+ var subtract4 = require_subtract();
2919
2919
  var HalfEdge = require_HalfEdge();
2920
2920
  var VISIBLE = 0;
2921
2921
  var NON_CONVEX = 1;
@@ -2949,14 +2949,14 @@ var require_Face = __commonJS({
2949
2949
  const e0 = this.edge;
2950
2950
  const e1 = e0.next;
2951
2951
  let e2 = e1.next;
2952
- const v2 = subtract3([], e1.head().point, e0.head().point);
2952
+ const v2 = subtract4([], e1.head().point, e0.head().point);
2953
2953
  const t = [];
2954
2954
  const v1 = [];
2955
2955
  this.nVertices = 2;
2956
2956
  this.normal = [0, 0, 0];
2957
2957
  while (e2 !== e0) {
2958
2958
  copy(v1, v2);
2959
- subtract3(v2, e2.head().point, e0.head().point);
2959
+ subtract4(v2, e2.head().point, e0.head().point);
2960
2960
  add(this.normal, this.normal, cross(t, v1, v2));
2961
2961
  e2 = e2.next;
2962
2962
  this.nVertices += 1;
@@ -2980,7 +2980,7 @@ var require_Face = __commonJS({
2980
2980
  } while (edge !== this.edge);
2981
2981
  const p1 = maxEdge.tail().point;
2982
2982
  const p2 = maxEdge.head().point;
2983
- const maxVector = subtract3([], p2, p1);
2983
+ const maxVector = subtract4([], p2, p1);
2984
2984
  const maxLength = Math.sqrt(maxSquaredLength);
2985
2985
  scale2(maxVector, maxVector, 1 / maxLength);
2986
2986
  const maxProjection = dot(this.normal, maxVector);
@@ -4102,11 +4102,11 @@ var require_invert2 = __commonJS({
4102
4102
  "use strict";
4103
4103
  var plane = require_plane();
4104
4104
  var create = require_create6();
4105
- var invert = (polygon2) => {
4106
- const vertices = polygon2.vertices.slice().reverse();
4105
+ var invert = (polygon3) => {
4106
+ const vertices = polygon3.vertices.slice().reverse();
4107
4107
  const inverted = create(vertices);
4108
- if (polygon2.plane) {
4109
- inverted.plane = plane.flip(plane.create(), polygon2.plane);
4108
+ if (polygon3.plane) {
4109
+ inverted.plane = plane.flip(plane.create(), polygon3.plane);
4110
4110
  }
4111
4111
  return inverted;
4112
4112
  };
@@ -4138,7 +4138,7 @@ var require_isConvex = __commonJS({
4138
4138
  "use strict";
4139
4139
  var plane = require_plane();
4140
4140
  var vec3 = require_vec3();
4141
- var isConvex = (polygon2) => areVerticesConvex(polygon2.vertices);
4141
+ var isConvex = (polygon3) => areVerticesConvex(polygon3.vertices);
4142
4142
  var areVerticesConvex = (vertices) => {
4143
4143
  const numvertices = vertices.length;
4144
4144
  if (numvertices > 2) {
@@ -4174,11 +4174,11 @@ var require_plane2 = __commonJS({
4174
4174
  "node_modules/@jscad/modeling/src/geometries/poly3/plane.js"(exports, module) {
4175
4175
  "use strict";
4176
4176
  var mplane = require_plane();
4177
- var plane = (polygon2) => {
4178
- if (!polygon2.plane) {
4179
- polygon2.plane = mplane.fromPoints(mplane.create(), ...polygon2.vertices);
4177
+ var plane = (polygon3) => {
4178
+ if (!polygon3.plane) {
4179
+ polygon3.plane = mplane.fromPoints(mplane.create(), ...polygon3.vertices);
4180
4180
  }
4181
- return polygon2.plane;
4181
+ return polygon3.plane;
4182
4182
  };
4183
4183
  module.exports = plane;
4184
4184
  }
@@ -4189,13 +4189,13 @@ var require_measureArea = __commonJS({
4189
4189
  "node_modules/@jscad/modeling/src/geometries/poly3/measureArea.js"(exports, module) {
4190
4190
  "use strict";
4191
4191
  var plane = require_plane2();
4192
- var measureArea = (polygon2) => {
4193
- const n = polygon2.vertices.length;
4192
+ var measureArea = (polygon3) => {
4193
+ const n = polygon3.vertices.length;
4194
4194
  if (n < 3) {
4195
4195
  return 0;
4196
4196
  }
4197
- const vertices = polygon2.vertices;
4198
- const normal = plane(polygon2);
4197
+ const vertices = polygon3.vertices;
4198
+ const normal = plane(polygon3);
4199
4199
  const ax = Math.abs(normal[0]);
4200
4200
  const ay = Math.abs(normal[1]);
4201
4201
  const az = Math.abs(normal[2]);
@@ -4254,8 +4254,8 @@ var require_measureBoundingBox = __commonJS({
4254
4254
  "node_modules/@jscad/modeling/src/geometries/poly3/measureBoundingBox.js"(exports, module) {
4255
4255
  "use strict";
4256
4256
  var vec3 = require_vec3();
4257
- var measureBoundingBox = (polygon2) => {
4258
- const vertices = polygon2.vertices;
4257
+ var measureBoundingBox = (polygon3) => {
4258
+ const vertices = polygon3.vertices;
4259
4259
  const numvertices = vertices.length;
4260
4260
  const min = numvertices === 0 ? vec3.create() : vec3.clone(vertices[0]);
4261
4261
  const max = vec3.clone(min);
@@ -4333,10 +4333,10 @@ var require_measureBoundingSphere = __commonJS({
4333
4333
  "use strict";
4334
4334
  var vec4 = require_vec4();
4335
4335
  var cache = /* @__PURE__ */ new WeakMap();
4336
- var measureBoundingSphere = (polygon2) => {
4337
- const boundingSphere = cache.get(polygon2);
4336
+ var measureBoundingSphere = (polygon3) => {
4337
+ const boundingSphere = cache.get(polygon3);
4338
4338
  if (boundingSphere) return boundingSphere;
4339
- const vertices = polygon2.vertices;
4339
+ const vertices = polygon3.vertices;
4340
4340
  const out = vec4.create();
4341
4341
  if (vertices.length === 0) {
4342
4342
  out[0] = 0;
@@ -4366,7 +4366,7 @@ var require_measureBoundingSphere = __commonJS({
4366
4366
  const y = out[1] - maxy[1];
4367
4367
  const z105 = out[2] - maxz[2];
4368
4368
  out[3] = Math.sqrt(x * x + y * y + z105 * z105);
4369
- cache.set(polygon2, out);
4369
+ cache.set(polygon3, out);
4370
4370
  return out;
4371
4371
  };
4372
4372
  module.exports = measureBoundingSphere;
@@ -4378,9 +4378,9 @@ var require_measureSignedVolume = __commonJS({
4378
4378
  "node_modules/@jscad/modeling/src/geometries/poly3/measureSignedVolume.js"(exports, module) {
4379
4379
  "use strict";
4380
4380
  var vec3 = require_vec3();
4381
- var measureSignedVolume = (polygon2) => {
4381
+ var measureSignedVolume = (polygon3) => {
4382
4382
  let signedVolume = 0;
4383
- const vertices = polygon2.vertices;
4383
+ const vertices = polygon3.vertices;
4384
4384
  const cross = vec3.create();
4385
4385
  for (let i = 0; i < vertices.length - 2; i++) {
4386
4386
  vec3.cross(cross, vertices[i + 1], vertices[i + 2]);
@@ -4397,7 +4397,7 @@ var require_measureSignedVolume = __commonJS({
4397
4397
  var require_toPoints2 = __commonJS({
4398
4398
  "node_modules/@jscad/modeling/src/geometries/poly3/toPoints.js"(exports, module) {
4399
4399
  "use strict";
4400
- var toPoints = (polygon2) => polygon2.vertices;
4400
+ var toPoints = (polygon3) => polygon3.vertices;
4401
4401
  module.exports = toPoints;
4402
4402
  }
4403
4403
  });
@@ -4407,9 +4407,9 @@ var require_toString6 = __commonJS({
4407
4407
  "node_modules/@jscad/modeling/src/geometries/poly3/toString.js"(exports, module) {
4408
4408
  "use strict";
4409
4409
  var vec3 = require_vec3();
4410
- var toString = (polygon2) => {
4410
+ var toString = (polygon3) => {
4411
4411
  let result = "poly3: vertices: [";
4412
- polygon2.vertices.forEach((vertex) => {
4412
+ polygon3.vertices.forEach((vertex) => {
4413
4413
  result += `${vec3.toString(vertex)}, `;
4414
4414
  });
4415
4415
  result += "]";
@@ -4426,8 +4426,8 @@ var require_transform6 = __commonJS({
4426
4426
  var mat4 = require_mat4();
4427
4427
  var vec3 = require_vec3();
4428
4428
  var create = require_create6();
4429
- var transform2 = (matrix, polygon2) => {
4430
- const vertices = polygon2.vertices.map((vertex) => vec3.transform(vec3.create(), vertex, matrix));
4429
+ var transform2 = (matrix, polygon3) => {
4430
+ const vertices = polygon3.vertices.map((vertex) => vec3.transform(vec3.create(), vertex, matrix));
4431
4431
  if (mat4.isMirroring(matrix)) {
4432
4432
  vertices.reverse();
4433
4433
  }
@@ -4543,8 +4543,8 @@ var require_fromPoints4 = __commonJS({
4543
4543
  throw new Error("the given points must be an array");
4544
4544
  }
4545
4545
  const polygons = listofpoints.map((points, index) => {
4546
- const polygon2 = poly3.create(points);
4547
- return polygon2;
4546
+ const polygon3 = poly3.create(points);
4547
+ return polygon3;
4548
4548
  });
4549
4549
  const result = create(polygons);
4550
4550
  return result;
@@ -4595,7 +4595,7 @@ var require_applyTransforms2 = __commonJS({
4595
4595
  var poly3 = require_poly3();
4596
4596
  var applyTransforms = (geometry) => {
4597
4597
  if (mat4.isIdentity(geometry.transforms)) return geometry;
4598
- geometry.polygons = geometry.polygons.map((polygon2) => poly3.transform(geometry.transforms, polygon2));
4598
+ geometry.polygons = geometry.polygons.map((polygon3) => poly3.transform(geometry.transforms, polygon3));
4599
4599
  geometry.transforms = mat4.create();
4600
4600
  return geometry;
4601
4601
  };
@@ -4622,7 +4622,7 @@ var require_invert3 = __commonJS({
4622
4622
  var toPolygons = require_toPolygons();
4623
4623
  var invert = (geometry) => {
4624
4624
  const polygons = toPolygons(geometry);
4625
- const newpolygons = polygons.map((polygon2) => poly3.invert(polygon2));
4625
+ const newpolygons = polygons.map((polygon3) => poly3.invert(polygon3));
4626
4626
  return create(newpolygons);
4627
4627
  };
4628
4628
  module.exports = invert;
@@ -4655,7 +4655,7 @@ var require_toPoints3 = __commonJS({
4655
4655
  var toPolygons = require_toPolygons();
4656
4656
  var toPoints = (geometry) => {
4657
4657
  const polygons = toPolygons(geometry);
4658
- const listofpoints = polygons.map((polygon2) => poly3.toPoints(polygon2));
4658
+ const listofpoints = polygons.map((polygon3) => poly3.toPoints(polygon3));
4659
4659
  return listofpoints;
4660
4660
  };
4661
4661
  module.exports = toPoints;
@@ -4671,8 +4671,8 @@ var require_toString7 = __commonJS({
4671
4671
  var toString = (geometry) => {
4672
4672
  const polygons = toPolygons(geometry);
4673
4673
  let result = "geom3 (" + polygons.length + " polygons):\n";
4674
- polygons.forEach((polygon2) => {
4675
- result += " " + poly3.toString(polygon2) + "\n";
4674
+ polygons.forEach((polygon3) => {
4675
+ result += " " + poly3.toString(polygon3) + "\n";
4676
4676
  });
4677
4677
  return result;
4678
4678
  };
@@ -4689,7 +4689,7 @@ var require_toCompactBinary2 = __commonJS({
4689
4689
  const polygons = geometry.polygons;
4690
4690
  const transforms2 = geometry.transforms;
4691
4691
  const numberOfPolygons = polygons.length;
4692
- const numberOfVertices = polygons.reduce((count, polygon2) => count + polygon2.vertices.length, 0);
4692
+ const numberOfVertices = polygons.reduce((count, polygon3) => count + polygon3.vertices.length, 0);
4693
4693
  let color = [-1, -1, -1, -1];
4694
4694
  if (geometry.color) color = geometry.color;
4695
4695
  const compacted = new Float32Array(1 + 16 + 4 + 1 + numberOfPolygons + numberOfVertices * 3);
@@ -4717,8 +4717,8 @@ var require_toCompactBinary2 = __commonJS({
4717
4717
  compacted[21] = numberOfVertices;
4718
4718
  let ci = 22;
4719
4719
  let vi = ci + numberOfPolygons;
4720
- polygons.forEach((polygon2) => {
4721
- const points = poly3.toPoints(polygon2);
4720
+ polygons.forEach((polygon3) => {
4721
+ const points = poly3.toPoints(polygon3);
4722
4722
  compacted[ci] = points.length;
4723
4723
  ci++;
4724
4724
  for (let i = 0; i < points.length; i++) {
@@ -6146,7 +6146,7 @@ var require_measureArea2 = __commonJS({
6146
6146
  "node_modules/@jscad/modeling/src/geometries/poly2/measureArea.js"(exports, module) {
6147
6147
  "use strict";
6148
6148
  var area = require_area();
6149
- var measureArea = (polygon2) => area(polygon2.vertices);
6149
+ var measureArea = (polygon3) => area(polygon3.vertices);
6150
6150
  module.exports = measureArea;
6151
6151
  }
6152
6152
  });
@@ -6170,8 +6170,8 @@ var require_flip2 = __commonJS({
6170
6170
  "node_modules/@jscad/modeling/src/geometries/poly2/flip.js"(exports, module) {
6171
6171
  "use strict";
6172
6172
  var create = require_create10();
6173
- var flip = (polygon2) => {
6174
- const vertices = polygon2.vertices.slice().reverse();
6173
+ var flip = (polygon3) => {
6174
+ const vertices = polygon3.vertices.slice().reverse();
6175
6175
  return create(vertices);
6176
6176
  };
6177
6177
  module.exports = flip;
@@ -6184,22 +6184,22 @@ var require_arePointsInside = __commonJS({
6184
6184
  "use strict";
6185
6185
  var measureArea = require_measureArea2();
6186
6186
  var flip = require_flip2();
6187
- var arePointsInside = (points, polygon2) => {
6187
+ var arePointsInside = (points, polygon3) => {
6188
6188
  if (points.length === 0) return 0;
6189
- const vertices = polygon2.vertices;
6189
+ const vertices = polygon3.vertices;
6190
6190
  if (vertices.length < 3) return 0;
6191
- if (measureArea(polygon2) < 0) {
6192
- polygon2 = flip(polygon2);
6191
+ if (measureArea(polygon3) < 0) {
6192
+ polygon3 = flip(polygon3);
6193
6193
  }
6194
6194
  const sum = points.reduce((acc, point2) => acc + isPointInside(point2, vertices), 0);
6195
6195
  return sum === points.length ? 1 : 0;
6196
6196
  };
6197
- var isPointInside = (point2, polygon2) => {
6198
- const numverts = polygon2.length;
6197
+ var isPointInside = (point2, polygon3) => {
6198
+ const numverts = polygon3.length;
6199
6199
  const tx = point2[0];
6200
6200
  const ty = point2[1];
6201
- let vtx0 = polygon2[numverts - 1];
6202
- let vtx1 = polygon2[0];
6201
+ let vtx0 = polygon3[numverts - 1];
6202
+ let vtx1 = polygon3[0];
6203
6203
  let yflag0 = vtx0[1] > ty;
6204
6204
  let insideFlag = 0;
6205
6205
  let i = 0;
@@ -6218,7 +6218,7 @@ var require_arePointsInside = __commonJS({
6218
6218
  }
6219
6219
  yflag0 = yflag1;
6220
6220
  vtx0 = vtx1;
6221
- vtx1 = polygon2[++i];
6221
+ vtx1 = polygon3[++i];
6222
6222
  }
6223
6223
  return insideFlag;
6224
6224
  };
@@ -6897,7 +6897,7 @@ var require_measureArea3 = __commonJS({
6897
6897
  let area = cache.get(geometry);
6898
6898
  if (area) return area;
6899
6899
  const polygons = geom3.toPolygons(geometry);
6900
- area = polygons.reduce((area2, polygon2) => area2 + poly3.measureArea(polygon2), 0);
6900
+ area = polygons.reduce((area2, polygon3) => area2 + poly3.measureArea(polygon3), 0);
6901
6901
  cache.set(geometry, area);
6902
6902
  return area;
6903
6903
  };
@@ -7000,8 +7000,8 @@ var require_measureBoundingBox2 = __commonJS({
7000
7000
  vec3.copy(minpoint, points[0]);
7001
7001
  }
7002
7002
  let maxpoint = vec3.clone(minpoint);
7003
- polygons.forEach((polygon2) => {
7004
- poly3.toPoints(polygon2).forEach((point2) => {
7003
+ polygons.forEach((polygon3) => {
7004
+ poly3.toPoints(polygon3).forEach((point2) => {
7005
7005
  vec3.min(minpoint, minpoint, point2);
7006
7006
  vec3.max(maxpoint, maxpoint, point2);
7007
7007
  });
@@ -7108,7 +7108,7 @@ var require_measureVolume = __commonJS({
7108
7108
  let volume = cache.get(geometry);
7109
7109
  if (volume) return volume;
7110
7110
  const polygons = geom3.toPolygons(geometry);
7111
- volume = polygons.reduce((volume2, polygon2) => volume2 + poly3.measureSignedVolume(polygon2), 0);
7111
+ volume = polygons.reduce((volume2, polygon3) => volume2 + poly3.measureSignedVolume(polygon3), 0);
7112
7112
  cache.set(geometry, volume);
7113
7113
  return volume;
7114
7114
  };
@@ -7213,15 +7213,15 @@ var require_measureBoundingSphere2 = __commonJS({
7213
7213
  const polygons = geom3.toPolygons(geometry);
7214
7214
  if (polygons.length > 0) {
7215
7215
  let numPoints = 0;
7216
- polygons.forEach((polygon2) => {
7217
- poly3.toPoints(polygon2).forEach((point2) => {
7216
+ polygons.forEach((polygon3) => {
7217
+ poly3.toPoints(polygon3).forEach((point2) => {
7218
7218
  vec3.add(centroid, centroid, point2);
7219
7219
  numPoints++;
7220
7220
  });
7221
7221
  });
7222
7222
  vec3.scale(centroid, centroid, 1 / numPoints);
7223
- polygons.forEach((polygon2) => {
7224
- poly3.toPoints(polygon2).forEach((point2) => {
7223
+ polygons.forEach((polygon3) => {
7224
+ poly3.toPoints(polygon3).forEach((point2) => {
7225
7225
  radius = Math.max(radius, vec3.squaredDistance(centroid, point2));
7226
7226
  });
7227
7227
  });
@@ -7309,8 +7309,8 @@ var require_measureCenterOfMass = __commonJS({
7309
7309
  if (polygons.length === 0) return centerOfMass;
7310
7310
  let totalVolume = 0;
7311
7311
  const vector = vec3.create();
7312
- polygons.forEach((polygon2) => {
7313
- const vertices = polygon2.vertices;
7312
+ polygons.forEach((polygon3) => {
7313
+ const vertices = polygon3.vertices;
7314
7314
  for (let i = 0; i < vertices.length - 2; i++) {
7315
7315
  vec3.cross(vector, vertices[i + 1], vertices[i + 2]);
7316
7316
  const volume = vec3.dot(vertices[0], vector) / 6;
@@ -7891,9 +7891,9 @@ var require_polyhedron = __commonJS({
7891
7891
  faces.forEach((face) => face.reverse());
7892
7892
  }
7893
7893
  const polygons = faces.map((face, findex) => {
7894
- const polygon2 = poly3.create(face.map((pindex) => points[pindex]));
7895
- if (colors2 && colors2[findex]) polygon2.color = colors2[findex];
7896
- return polygon2;
7894
+ const polygon3 = poly3.create(face.map((pindex) => points[pindex]));
7895
+ if (colors2 && colors2[findex]) polygon3.color = colors2[findex];
7896
+ return polygon3;
7897
7897
  });
7898
7898
  return geom3.create(polygons);
7899
7899
  };
@@ -8046,7 +8046,7 @@ var require_polygon = __commonJS({
8046
8046
  "node_modules/@jscad/modeling/src/primitives/polygon.js"(exports, module) {
8047
8047
  "use strict";
8048
8048
  var geom2 = require_geom2();
8049
- var polygon2 = (options) => {
8049
+ var polygon3 = (options) => {
8050
8050
  const defaults = {
8051
8051
  points: [],
8052
8052
  paths: [],
@@ -8087,7 +8087,7 @@ var require_polygon = __commonJS({
8087
8087
  }
8088
8088
  return geometry;
8089
8089
  };
8090
- module.exports = polygon2;
8090
+ module.exports = polygon3;
8091
8091
  }
8092
8092
  });
8093
8093
 
@@ -10343,12 +10343,12 @@ var require_fromFakePolygons = __commonJS({
10343
10343
  "use strict";
10344
10344
  var vec2 = require_vec2();
10345
10345
  var geom2 = require_geom2();
10346
- var fromFakePolygon = (epsilon, polygon2) => {
10347
- if (polygon2.vertices.length < 4) {
10346
+ var fromFakePolygon = (epsilon, polygon3) => {
10347
+ if (polygon3.vertices.length < 4) {
10348
10348
  return null;
10349
10349
  }
10350
10350
  const vert1Indices = [];
10351
- const points3D = polygon2.vertices.filter((vertex, i) => {
10351
+ const points3D = polygon3.vertices.filter((vertex, i) => {
10352
10352
  if (vertex[2] > 0) {
10353
10353
  vert1Indices.push(i);
10354
10354
  return true;
@@ -10375,7 +10375,7 @@ var require_fromFakePolygons = __commonJS({
10375
10375
  return points2D;
10376
10376
  };
10377
10377
  var fromFakePolygons = (epsilon, polygons) => {
10378
- const sides = polygons.map((polygon2) => fromFakePolygon(epsilon, polygon2)).filter((polygon2) => polygon2 !== null);
10378
+ const sides = polygons.map((polygon3) => fromFakePolygon(epsilon, polygon3)).filter((polygon3) => polygon3 !== null);
10379
10379
  return geom2.create(sides);
10380
10380
  };
10381
10381
  module.exports = fromFakePolygons;
@@ -10732,8 +10732,8 @@ var require_reTesselateCoplanarPolygons = __commonJS({
10732
10732
  prevpolygon.outpolygon.leftpoints.reverse();
10733
10733
  const points2d = prevpolygon.outpolygon.rightpoints.concat(prevpolygon.outpolygon.leftpoints);
10734
10734
  const vertices3d = points2d.map((point2d) => orthobasis.to3D(point2d));
10735
- const polygon2 = poly3.fromPointsAndPlane(vertices3d, plane);
10736
- if (polygon2.vertices.length) destpolygons.push(polygon2);
10735
+ const polygon3 = poly3.fromPointsAndPlane(vertices3d, plane);
10736
+ if (polygon3.vertices.length) destpolygons.push(polygon3);
10737
10737
  }
10738
10738
  }
10739
10739
  }
@@ -10777,7 +10777,7 @@ var require_retessellate = __commonJS({
10777
10777
  if (geometry.isRetesselated) {
10778
10778
  return geometry;
10779
10779
  }
10780
- const polygons = geom3.toPolygons(geometry).map((polygon2, index) => ({ vertices: polygon2.vertices, plane: poly3.plane(polygon2), index }));
10780
+ const polygons = geom3.toPolygons(geometry).map((polygon3, index) => ({ vertices: polygon3.vertices, plane: poly3.plane(polygon3), index }));
10781
10781
  const classified = classifyPolygons(polygons);
10782
10782
  const destPolygons = [];
10783
10783
  classified.forEach((group) => {
@@ -10823,8 +10823,8 @@ var require_retessellate = __commonJS({
10823
10823
  clusters.forEach((cluster) => {
10824
10824
  if (cluster[0]) result[cluster[0].index] = cluster;
10825
10825
  });
10826
- nonCoplanar.forEach((polygon2) => {
10827
- result[polygon2.index] = polygon2;
10826
+ nonCoplanar.forEach((polygon3) => {
10827
+ result[polygon3.index] = polygon3;
10828
10828
  });
10829
10829
  return result;
10830
10830
  };
@@ -11016,15 +11016,15 @@ var require_splitPolygonByPlane = __commonJS({
11016
11016
  var vec3 = require_vec3();
11017
11017
  var poly3 = require_poly3();
11018
11018
  var splitLineSegmentByPlane = require_splitLineSegmentByPlane();
11019
- var splitPolygonByPlane = (splane, polygon2) => {
11019
+ var splitPolygonByPlane = (splane, polygon3) => {
11020
11020
  const result = {
11021
11021
  type: null,
11022
11022
  front: null,
11023
11023
  back: null
11024
11024
  };
11025
- const vertices = polygon2.vertices;
11025
+ const vertices = polygon3.vertices;
11026
11026
  const numvertices = vertices.length;
11027
- const pplane = poly3.plane(polygon2);
11027
+ const pplane = poly3.plane(polygon3);
11028
11028
  if (plane.equals(pplane, splane)) {
11029
11029
  result.type = 0;
11030
11030
  } else {
@@ -11124,10 +11124,10 @@ var require_PolygonTreeNode = __commonJS({
11124
11124
  var splitPolygonByPlane = require_splitPolygonByPlane();
11125
11125
  var PolygonTreeNode = class _PolygonTreeNode {
11126
11126
  // constructor creates the root node
11127
- constructor(parent, polygon2) {
11127
+ constructor(parent, polygon3) {
11128
11128
  this.parent = parent;
11129
11129
  this.children = [];
11130
- this.polygon = polygon2;
11130
+ this.polygon = polygon3;
11131
11131
  this.removed = false;
11132
11132
  }
11133
11133
  // fill the tree with polygons. Should be called on the root node only; child nodes must
@@ -11137,8 +11137,8 @@ var require_PolygonTreeNode = __commonJS({
11137
11137
  throw new Error("Assertion failed");
11138
11138
  }
11139
11139
  const _this = this;
11140
- polygons.forEach((polygon2) => {
11141
- _this.addChild(polygon2);
11140
+ polygons.forEach((polygon3) => {
11141
+ _this.addChild(polygon3);
11142
11142
  });
11143
11143
  }
11144
11144
  // remove a node
@@ -11215,9 +11215,9 @@ var require_PolygonTreeNode = __commonJS({
11215
11215
  }
11216
11216
  // only to be called for nodes with no children
11217
11217
  _splitByPlane(splane, coplanarfrontnodes, coplanarbacknodes, frontnodes, backnodes) {
11218
- const polygon2 = this.polygon;
11219
- if (polygon2) {
11220
- const bound = poly3.measureBoundingSphere(polygon2);
11218
+ const polygon3 = this.polygon;
11219
+ if (polygon3) {
11220
+ const bound = poly3.measureBoundingSphere(polygon3);
11221
11221
  const sphereradius = bound[3] + EPS;
11222
11222
  const spherecenter = bound;
11223
11223
  const d = vec3.dot(splane, spherecenter) - splane[3];
@@ -11226,7 +11226,7 @@ var require_PolygonTreeNode = __commonJS({
11226
11226
  } else if (d < -sphereradius) {
11227
11227
  backnodes.push(this);
11228
11228
  } else {
11229
- const splitresult = splitPolygonByPlane(splane, polygon2);
11229
+ const splitresult = splitPolygonByPlane(splane, polygon3);
11230
11230
  switch (splitresult.type) {
11231
11231
  case 0:
11232
11232
  coplanarfrontnodes.push(this);
@@ -11259,8 +11259,8 @@ var require_PolygonTreeNode = __commonJS({
11259
11259
  // this should be called whenever the polygon is split
11260
11260
  // a child should be created for every fragment of the split polygon
11261
11261
  // returns the newly created child
11262
- addChild(polygon2) {
11263
- const newchild = new _PolygonTreeNode(this, polygon2);
11262
+ addChild(polygon3) {
11263
+ const newchild = new _PolygonTreeNode(this, polygon3);
11264
11264
  this.children.push(newchild);
11265
11265
  return newchild;
11266
11266
  }
@@ -11510,14 +11510,14 @@ var require_scissionGeom3 = __commonJS({
11510
11510
  const pl = polygons.length;
11511
11511
  const indexesPerPoint = /* @__PURE__ */ new Map();
11512
11512
  const temp = vec3.create();
11513
- polygons.forEach((polygon2, index) => {
11514
- polygon2.vertices.forEach((point2) => {
11513
+ polygons.forEach((polygon3, index) => {
11514
+ polygon3.vertices.forEach((point2) => {
11515
11515
  insertMapping(indexesPerPoint, vec3.snap(temp, point2, eps), index);
11516
11516
  });
11517
11517
  });
11518
- const indexesPerPolygon = polygons.map((polygon2) => {
11518
+ const indexesPerPolygon = polygons.map((polygon3) => {
11519
11519
  let indexes = [];
11520
- polygon2.vertices.forEach((point2) => {
11520
+ polygon3.vertices.forEach((point2) => {
11521
11521
  indexes = indexes.concat(findMapping(indexesPerPoint, vec3.snap(temp, point2, eps)));
11522
11522
  });
11523
11523
  return { e: 1, d: sortNb(indexes) };
@@ -11612,7 +11612,7 @@ var require_subtractGeom3 = __commonJS({
11612
11612
  var flatten = require_flatten();
11613
11613
  var retessellate = require_retessellate();
11614
11614
  var subtractSub = require_subtractGeom3Sub();
11615
- var subtract3 = (...geometries2) => {
11615
+ var subtract4 = (...geometries2) => {
11616
11616
  geometries2 = flatten(geometries2);
11617
11617
  let newgeometry = geometries2.shift();
11618
11618
  geometries2.forEach((geometry) => {
@@ -11621,7 +11621,7 @@ var require_subtractGeom3 = __commonJS({
11621
11621
  newgeometry = retessellate(newgeometry);
11622
11622
  return newgeometry;
11623
11623
  };
11624
- module.exports = subtract3;
11624
+ module.exports = subtract4;
11625
11625
  }
11626
11626
  });
11627
11627
 
@@ -11635,14 +11635,14 @@ var require_subtractGeom2 = __commonJS({
11635
11635
  var fromFakePolygons = require_fromFakePolygons();
11636
11636
  var to3DWalls = require_to3DWalls();
11637
11637
  var subtractGeom3 = require_subtractGeom3();
11638
- var subtract3 = (...geometries2) => {
11638
+ var subtract4 = (...geometries2) => {
11639
11639
  geometries2 = flatten(geometries2);
11640
11640
  const newgeometries = geometries2.map((geometry) => to3DWalls({ z0: -1, z1: 1 }, geometry));
11641
11641
  const newgeom3 = subtractGeom3(newgeometries);
11642
11642
  const epsilon = measureEpsilon(newgeom3);
11643
11643
  return fromFakePolygons(epsilon, geom3.toPolygons(newgeom3));
11644
11644
  };
11645
- module.exports = subtract3;
11645
+ module.exports = subtract4;
11646
11646
  }
11647
11647
  });
11648
11648
 
@@ -11656,7 +11656,7 @@ var require_subtract4 = __commonJS({
11656
11656
  var geom3 = require_geom3();
11657
11657
  var subtractGeom2 = require_subtractGeom2();
11658
11658
  var subtractGeom3 = require_subtractGeom3();
11659
- var subtract3 = (...geometries2) => {
11659
+ var subtract4 = (...geometries2) => {
11660
11660
  geometries2 = flatten(geometries2);
11661
11661
  if (geometries2.length === 0) throw new Error("wrong number of arguments");
11662
11662
  if (!areAllShapesTheSameType(geometries2)) {
@@ -11667,7 +11667,7 @@ var require_subtract4 = __commonJS({
11667
11667
  if (geom3.isA(geometry)) return subtractGeom3(geometries2);
11668
11668
  return geometry;
11669
11669
  };
11670
- module.exports = subtract3;
11670
+ module.exports = subtract4;
11671
11671
  }
11672
11672
  });
11673
11673
 
@@ -11963,19 +11963,19 @@ var require_extrudePolygon = __commonJS({
11963
11963
  polygon1 = poly3.invert(polygon1);
11964
11964
  }
11965
11965
  const newpolygons = [polygon1];
11966
- const polygon2 = poly3.transform(mat4.fromTranslation(mat4.create(), offsetvector), polygon1);
11966
+ const polygon22 = poly3.transform(mat4.fromTranslation(mat4.create(), offsetvector), polygon1);
11967
11967
  const numvertices = polygon1.vertices.length;
11968
11968
  for (let i = 0; i < numvertices; i++) {
11969
11969
  const nexti = i < numvertices - 1 ? i + 1 : 0;
11970
11970
  const sideFacePolygon = poly3.create([
11971
11971
  polygon1.vertices[i],
11972
- polygon2.vertices[i],
11973
- polygon2.vertices[nexti],
11972
+ polygon22.vertices[i],
11973
+ polygon22.vertices[nexti],
11974
11974
  polygon1.vertices[nexti]
11975
11975
  ]);
11976
11976
  newpolygons.push(sideFacePolygon);
11977
11977
  }
11978
- newpolygons.push(poly3.invert(polygon2));
11978
+ newpolygons.push(poly3.invert(polygon22));
11979
11979
  return geom3.create(newpolygons);
11980
11980
  };
11981
11981
  module.exports = extrudePolygon;
@@ -12036,17 +12036,17 @@ var require_expandShell = __commonJS({
12036
12036
  const v1 = vec3.create();
12037
12037
  const v2 = vec3.create();
12038
12038
  const polygons = geom3.toPolygons(geometry);
12039
- polygons.forEach((polygon2, index) => {
12040
- const extrudevector = vec3.scale(vec3.create(), poly3.plane(polygon2), 2 * delta);
12041
- const translatedpolygon = poly3.transform(mat4.fromTranslation(mat4.create(), vec3.scale(vec3.create(), extrudevector, -0.5)), polygon2);
12039
+ polygons.forEach((polygon3, index) => {
12040
+ const extrudevector = vec3.scale(vec3.create(), poly3.plane(polygon3), 2 * delta);
12041
+ const translatedpolygon = poly3.transform(mat4.fromTranslation(mat4.create(), vec3.scale(vec3.create(), extrudevector, -0.5)), polygon3);
12042
12042
  const extrudedface = extrudePolygon(extrudevector, translatedpolygon);
12043
12043
  result = unionGeom3Sub(result, extrudedface);
12044
- const vertices = polygon2.vertices;
12044
+ const vertices = polygon3.vertices;
12045
12045
  for (let i = 0; i < vertices.length; i++) {
12046
- mapPlaneToVertex(vertices2planes, vertices[i], poly3.plane(polygon2));
12046
+ mapPlaneToVertex(vertices2planes, vertices[i], poly3.plane(polygon3));
12047
12047
  const j = (i + 1) % vertices.length;
12048
12048
  const edge = [vertices[i], vertices[j]];
12049
- mapPlaneToEdge(edges2planes, edge, poly3.plane(polygon2));
12049
+ mapPlaneToEdge(edges2planes, edge, poly3.plane(polygon3));
12050
12050
  }
12051
12051
  });
12052
12052
  edges2planes.forEach((item) => {
@@ -12100,8 +12100,8 @@ var require_expandShell = __commonJS({
12100
12100
  startfacevertices.push(p1);
12101
12101
  endfacevertices.push(p2);
12102
12102
  const points = [prevp2, p2, p1, prevp1];
12103
- const polygon2 = poly3.create(points);
12104
- polygons2.push(polygon2);
12103
+ const polygon3 = poly3.create(points);
12104
+ polygons2.push(polygon3);
12105
12105
  }
12106
12106
  prevp1 = p1;
12107
12107
  prevp2 = p2;
@@ -12303,7 +12303,7 @@ var require_offsetGeom2 = __commonJS({
12303
12303
  }
12304
12304
  const outlines = geom2.toOutlines(geometry);
12305
12305
  const newoutlines = outlines.map((outline) => {
12306
- const level = outlines.reduce((acc, polygon2) => acc + poly2.arePointsInside(outline, poly2.create(polygon2)), 0);
12306
+ const level = outlines.reduce((acc, polygon3) => acc + poly2.arePointsInside(outline, poly2.create(polygon3)), 0);
12307
12307
  const outside = level % 2 === 0;
12308
12308
  options = {
12309
12309
  delta: outside ? delta : -delta,
@@ -12920,24 +12920,24 @@ var require_snapPolygons = __commonJS({
12920
12920
  "use strict";
12921
12921
  var vec3 = require_vec3();
12922
12922
  var poly3 = require_poly3();
12923
- var isValidPoly3 = (epsilon, polygon2) => {
12924
- const area = Math.abs(poly3.measureArea(polygon2));
12923
+ var isValidPoly3 = (epsilon, polygon3) => {
12924
+ const area = Math.abs(poly3.measureArea(polygon3));
12925
12925
  return Number.isFinite(area) && area > epsilon;
12926
12926
  };
12927
12927
  var snapPolygons = (epsilon, polygons) => {
12928
- let newpolygons = polygons.map((polygon2) => {
12929
- const snapvertices = polygon2.vertices.map((vertice) => vec3.snap(vec3.create(), vertice, epsilon));
12928
+ let newpolygons = polygons.map((polygon3) => {
12929
+ const snapvertices = polygon3.vertices.map((vertice) => vec3.snap(vec3.create(), vertice, epsilon));
12930
12930
  const newvertices = [];
12931
12931
  for (let i = 0; i < snapvertices.length; i++) {
12932
12932
  const j = (i + 1) % snapvertices.length;
12933
12933
  if (!vec3.equals(snapvertices[i], snapvertices[j])) newvertices.push(snapvertices[i]);
12934
12934
  }
12935
12935
  const newpolygon = poly3.create(newvertices);
12936
- if (polygon2.color) newpolygon.color = polygon2.color;
12936
+ if (polygon3.color) newpolygon.color = polygon3.color;
12937
12937
  return newpolygon;
12938
12938
  });
12939
12939
  const epsilonArea = epsilon * epsilon * Math.sqrt(3) / 4;
12940
- newpolygons = newpolygons.filter((polygon2) => isValidPoly3(epsilonArea, polygon2));
12940
+ newpolygons = newpolygons.filter((polygon3) => isValidPoly3(epsilonArea, polygon3));
12941
12941
  return newpolygons;
12942
12942
  };
12943
12943
  module.exports = snapPolygons;
@@ -12951,8 +12951,8 @@ var require_mergePolygons = __commonJS({
12951
12951
  var aboutEqualNormals = require_aboutEqualNormals();
12952
12952
  var vec3 = require_vec3();
12953
12953
  var poly3 = require_poly3();
12954
- var createEdges = (polygon2) => {
12955
- const points = poly3.toPoints(polygon2);
12954
+ var createEdges = (polygon3) => {
12955
+ const points = poly3.toPoints(polygon3);
12956
12956
  const edges = [];
12957
12957
  for (let i = 0; i < points.length; i++) {
12958
12958
  const j = (i + 1) % points.length;
@@ -13001,7 +13001,7 @@ var require_mergePolygons = __commonJS({
13001
13001
  return vec3.dot(d0, normal);
13002
13002
  };
13003
13003
  var createPolygonAnd = (edge) => {
13004
- let polygon2;
13004
+ let polygon3;
13005
13005
  const points = [];
13006
13006
  while (edge.next) {
13007
13007
  const next = edge.next;
@@ -13012,8 +13012,8 @@ var require_mergePolygons = __commonJS({
13012
13012
  edge.prev = null;
13013
13013
  edge = next;
13014
13014
  }
13015
- if (points.length > 0) polygon2 = poly3.create(points);
13016
- return polygon2;
13015
+ if (points.length > 0) polygon3 = poly3.create(points);
13016
+ return polygon3;
13017
13017
  };
13018
13018
  var mergeCoplanarPolygons = (sourcepolygons) => {
13019
13019
  if (sourcepolygons.length < 2) return sourcepolygons;
@@ -13021,8 +13021,8 @@ var require_mergePolygons = __commonJS({
13021
13021
  const polygons = sourcepolygons.slice();
13022
13022
  const edgeList = /* @__PURE__ */ new Map();
13023
13023
  while (polygons.length > 0) {
13024
- const polygon2 = polygons.shift();
13025
- const edges = createEdges(polygon2);
13024
+ const polygon3 = polygons.shift();
13025
+ const edges = createEdges(polygon3);
13026
13026
  for (let i = 0; i < edges.length; i++) {
13027
13027
  const current2 = edges[i];
13028
13028
  const opposite = findOppositeEdge(edgeList, current2);
@@ -13078,8 +13078,8 @@ var require_mergePolygons = __commonJS({
13078
13078
  }
13079
13079
  const destpolygons = [];
13080
13080
  edgeList.forEach((edge) => {
13081
- const polygon2 = createPolygonAnd(edge);
13082
- if (polygon2) destpolygons.push(polygon2);
13081
+ const polygon3 = createPolygonAnd(edge);
13082
+ if (polygon3) destpolygons.push(polygon3);
13083
13083
  });
13084
13084
  edgeList.clear();
13085
13085
  return destpolygons;
@@ -13092,13 +13092,13 @@ var require_mergePolygons = __commonJS({
13092
13092
  };
13093
13093
  var mergePolygons = (epsilon, polygons) => {
13094
13094
  const polygonsPerPlane = [];
13095
- polygons.forEach((polygon2) => {
13096
- const mapping = polygonsPerPlane.find((element) => coplanar(element[0], poly3.plane(polygon2)));
13095
+ polygons.forEach((polygon3) => {
13096
+ const mapping = polygonsPerPlane.find((element) => coplanar(element[0], poly3.plane(polygon3)));
13097
13097
  if (mapping) {
13098
13098
  const polygons2 = mapping[1];
13099
- polygons2.push(polygon2);
13099
+ polygons2.push(polygon3);
13100
13100
  } else {
13101
- polygonsPerPlane.push([poly3.plane(polygon2), [polygon2]]);
13101
+ polygonsPerPlane.push([poly3.plane(polygon3), [polygon3]]);
13102
13102
  }
13103
13103
  });
13104
13104
  let destpolygons = [];
@@ -13194,15 +13194,15 @@ var require_insertTjunctions = __commonJS({
13194
13194
  var insertTjunctions = (polygons) => {
13195
13195
  const sidemap = /* @__PURE__ */ new Map();
13196
13196
  for (let polygonindex = 0; polygonindex < polygons.length; polygonindex++) {
13197
- const polygon2 = polygons[polygonindex];
13198
- const numvertices = polygon2.vertices.length;
13197
+ const polygon3 = polygons[polygonindex];
13198
+ const numvertices = polygon3.vertices.length;
13199
13199
  if (numvertices >= 3) {
13200
- let vertex = polygon2.vertices[0];
13200
+ let vertex = polygon3.vertices[0];
13201
13201
  let vertextag = getTag(vertex);
13202
13202
  for (let vertexindex = 0; vertexindex < numvertices; vertexindex++) {
13203
13203
  let nextvertexindex = vertexindex + 1;
13204
13204
  if (nextvertexindex === numvertices) nextvertexindex = 0;
13205
- const nextvertex = polygon2.vertices[nextvertexindex];
13205
+ const nextvertex = polygon3.vertices[nextvertexindex];
13206
13206
  const nextvertextag = getTag(nextvertex);
13207
13207
  const sidetag = `${vertextag}/${nextvertextag}`;
13208
13208
  const reversesidetag = `${nextvertextag}/${vertextag}`;
@@ -13310,17 +13310,17 @@ var require_insertTjunctions = __commonJS({
13310
13310
  const distancesquared = vec3.squaredDistance(closestpoint, endpos);
13311
13311
  if (distancesquared < constants.EPS * constants.EPS) {
13312
13312
  const polygonindex = matchingside.polygonindex;
13313
- const polygon2 = newpolygons[polygonindex];
13313
+ const polygon3 = newpolygons[polygonindex];
13314
13314
  const insertionvertextag = getTag(matchingside.vertex1);
13315
13315
  let insertionvertextagindex = -1;
13316
- for (let i = 0; i < polygon2.vertices.length; i++) {
13317
- if (getTag(polygon2.vertices[i]) === insertionvertextag) {
13316
+ for (let i = 0; i < polygon3.vertices.length; i++) {
13317
+ if (getTag(polygon3.vertices[i]) === insertionvertextag) {
13318
13318
  insertionvertextagindex = i;
13319
13319
  break;
13320
13320
  }
13321
13321
  }
13322
13322
  if (assert && insertionvertextagindex < 0) throw new Error("assert failed");
13323
- const newvertices = polygon2.vertices.slice(0);
13323
+ const newvertices = polygon3.vertices.slice(0);
13324
13324
  newvertices.splice(insertionvertextagindex, 0, endvertex);
13325
13325
  const newpolygon = poly3.create(newvertices);
13326
13326
  newpolygons[polygonindex] = newpolygon;
@@ -13360,35 +13360,35 @@ var require_triangulatePolygons = __commonJS({
13360
13360
  "use strict";
13361
13361
  var vec3 = require_vec3();
13362
13362
  var poly3 = require_poly3();
13363
- var triangulatePolygon = (epsilon, polygon2, triangles) => {
13364
- const nv = polygon2.vertices.length;
13363
+ var triangulatePolygon = (epsilon, polygon3, triangles) => {
13364
+ const nv = polygon3.vertices.length;
13365
13365
  if (nv > 3) {
13366
13366
  if (nv > 4) {
13367
13367
  const midpoint = [0, 0, 0];
13368
- polygon2.vertices.forEach((vertice) => vec3.add(midpoint, midpoint, vertice));
13368
+ polygon3.vertices.forEach((vertice) => vec3.add(midpoint, midpoint, vertice));
13369
13369
  vec3.snap(midpoint, vec3.divide(midpoint, midpoint, [nv, nv, nv]), epsilon);
13370
13370
  for (let i = 0; i < nv; i++) {
13371
- const poly = poly3.create([midpoint, polygon2.vertices[i], polygon2.vertices[(i + 1) % nv]]);
13372
- if (polygon2.color) poly.color = polygon2.color;
13371
+ const poly = poly3.create([midpoint, polygon3.vertices[i], polygon3.vertices[(i + 1) % nv]]);
13372
+ if (polygon3.color) poly.color = polygon3.color;
13373
13373
  triangles.push(poly);
13374
13374
  }
13375
13375
  return;
13376
13376
  }
13377
- const poly0 = poly3.create([polygon2.vertices[0], polygon2.vertices[1], polygon2.vertices[2]]);
13378
- const poly1 = poly3.create([polygon2.vertices[0], polygon2.vertices[2], polygon2.vertices[3]]);
13379
- if (polygon2.color) {
13380
- poly0.color = polygon2.color;
13381
- poly1.color = polygon2.color;
13377
+ const poly0 = poly3.create([polygon3.vertices[0], polygon3.vertices[1], polygon3.vertices[2]]);
13378
+ const poly1 = poly3.create([polygon3.vertices[0], polygon3.vertices[2], polygon3.vertices[3]]);
13379
+ if (polygon3.color) {
13380
+ poly0.color = polygon3.color;
13381
+ poly1.color = polygon3.color;
13382
13382
  }
13383
13383
  triangles.push(poly0, poly1);
13384
13384
  return;
13385
13385
  }
13386
- triangles.push(polygon2);
13386
+ triangles.push(polygon3);
13387
13387
  };
13388
13388
  var triangulatePolygons = (epsilon, polygons) => {
13389
13389
  const triangles = [];
13390
- polygons.forEach((polygon2) => {
13391
- triangulatePolygon(epsilon, polygon2, triangles);
13390
+ polygons.forEach((polygon3) => {
13391
+ triangulatePolygon(epsilon, polygon3, triangles);
13392
13392
  });
13393
13393
  return triangles;
13394
13394
  };
@@ -24160,8 +24160,8 @@ var SmdChipLead = (props) => {
24160
24160
  const { thickness, width: width10, padContactLength, bodyDistance, height: height10, rotation: rotation2 } = props;
24161
24161
  const N = 15;
24162
24162
  const points = Array.from({ length: N }).map((_, i) => i / (N - 1) * bodyDistance).map((x) => [x, calculateSCurve(x, props)]);
24163
- const polygon2 = getExpandedStroke(points, thickness);
24164
- return /* @__PURE__ */ jsx5(Colorize, { color: "#fff", children: /* @__PURE__ */ jsx5(Translate, { offset: { z: 0, y: 0, x: 0, ...props.position }, children: /* @__PURE__ */ jsx5(Rotate, { rotation: ["90deg", 0, rotation2 ?? 0], children: /* @__PURE__ */ jsx5(Translate, { offset: { x: 0, y: 0, z: -width10 / 2 }, children: /* @__PURE__ */ jsx5(ExtrudeLinear, { height: width10, children: /* @__PURE__ */ jsx5(Polygon, { points: polygon2.map((p) => [p.x, p.y]) }) }) }) }) }) });
24163
+ const polygon3 = getExpandedStroke(points, thickness);
24164
+ return /* @__PURE__ */ jsx5(Colorize, { color: "#fff", children: /* @__PURE__ */ jsx5(Translate, { offset: { z: 0, y: 0, x: 0, ...props.position }, children: /* @__PURE__ */ jsx5(Rotate, { rotation: ["90deg", 0, rotation2 ?? 0], children: /* @__PURE__ */ jsx5(Translate, { offset: { x: 0, y: 0, z: -width10 / 2 }, children: /* @__PURE__ */ jsx5(ExtrudeLinear, { height: width10, children: /* @__PURE__ */ jsx5(Polygon, { points: polygon3.map((p) => [p.x, p.y]) }) }) }) }) }) });
24165
24165
  };
24166
24166
  var Tssop = ({
24167
24167
  pinCount,
@@ -25218,7 +25218,7 @@ var PushButtonLeg = (props) => {
25218
25218
  [-verticalLength / 5, horizontalLength / 4],
25219
25219
  [0, 0]
25220
25220
  ];
25221
- const polygon2 = getExpandedStroke(points, thickness);
25221
+ const polygon3 = getExpandedStroke(points, thickness);
25222
25222
  return /* @__PURE__ */ jsx5(Colorize, { color: "#f2f2f2", children: /* @__PURE__ */ jsx5(
25223
25223
  Translate,
25224
25224
  {
@@ -25227,7 +25227,7 @@ var PushButtonLeg = (props) => {
25227
25227
  y: position?.y || 0,
25228
25228
  z: position?.z || 0
25229
25229
  },
25230
- children: /* @__PURE__ */ jsx5(Rotate, { rotation: [0, 55, rotation2], children: /* @__PURE__ */ jsx5(ExtrudeLinear, { height: width10, children: /* @__PURE__ */ jsx5(Polygon, { points: polygon2.map((p) => [p.y, p.x]) }) }) })
25230
+ children: /* @__PURE__ */ jsx5(Rotate, { rotation: [0, 55, rotation2], children: /* @__PURE__ */ jsx5(ExtrudeLinear, { height: width10, children: /* @__PURE__ */ jsx5(Polygon, { points: polygon3.map((p) => [p.y, p.x]) }) }) })
25231
25231
  }
25232
25232
  ) });
25233
25233
  };
@@ -25619,8 +25619,8 @@ function convertCSGToThreeGeom(csg) {
25619
25619
  const indices = [];
25620
25620
  const colors2 = [];
25621
25621
  let idx = 0;
25622
- for (const polygon2 of csg.polygons) {
25623
- for (const vertex of polygon2.vertices) {
25622
+ for (const polygon3 of csg.polygons) {
25623
+ for (const vertex of polygon3.vertices) {
25624
25624
  vertex.index = idx;
25625
25625
  vertices.push(vertex[0], vertex[1], vertex[2]);
25626
25626
  if (csg.color && csg.color.length >= 3) {
@@ -25630,10 +25630,10 @@ function convertCSGToThreeGeom(csg) {
25630
25630
  }
25631
25631
  idx++;
25632
25632
  }
25633
- const first = polygon2.vertices[0].index;
25634
- for (let i = 2; i < polygon2.vertices.length; i++) {
25635
- const second = polygon2.vertices[i - 1].index;
25636
- const third = polygon2.vertices[i].index;
25633
+ const first = polygon3.vertices[0].index;
25634
+ for (let i = 2; i < polygon3.vertices.length; i++) {
25635
+ const second = polygon3.vertices[i - 1].index;
25636
+ const third = polygon3.vertices[i].index;
25637
25637
  indices.push(first, second, third);
25638
25638
  }
25639
25639
  }
@@ -26033,7 +26033,7 @@ import * as THREE11 from "three";
26033
26033
  // package.json
26034
26034
  var package_default = {
26035
26035
  name: "@tscircuit/3d-viewer",
26036
- version: "0.0.389",
26036
+ version: "0.0.390",
26037
26037
  main: "./dist/index.js",
26038
26038
  module: "./dist/index.js",
26039
26039
  type: "module",
@@ -26883,9 +26883,9 @@ var createBoardGeomFromCircuitJson = (circuitJson, opts = {}) => {
26883
26883
 
26884
26884
  // src/BoardGeomBuilder.ts
26885
26885
  var import_transforms3 = __toESM(require_transforms(), 1);
26886
- var import_primitives5 = __toESM(require_primitives(), 1);
26886
+ var import_primitives6 = __toESM(require_primitives(), 1);
26887
26887
  var import_colors4 = __toESM(require_colors(), 1);
26888
- var import_booleans2 = __toESM(require_booleans(), 1);
26888
+ var import_booleans3 = __toESM(require_booleans(), 1);
26889
26889
  import { su as su3 } from "@tscircuit/circuit-json-util";
26890
26890
 
26891
26891
  // src/geoms/plated-hole.ts
@@ -27432,6 +27432,91 @@ function createSilkscreenPathGeom(sp, ctx) {
27432
27432
  return pathGeom;
27433
27433
  }
27434
27434
 
27435
+ // src/geoms/brep-converter.ts
27436
+ var import_primitives5 = __toESM(require_primitives(), 1);
27437
+ var import_booleans2 = __toESM(require_booleans(), 1);
27438
+ function segmentToPoints(p1, p2, bulge, arcSegments) {
27439
+ if (!bulge || Math.abs(bulge) < 1e-9) {
27440
+ return [];
27441
+ }
27442
+ const theta = 4 * Math.atan(bulge);
27443
+ const dx = p2[0] - p1[0];
27444
+ const dy = p2[1] - p1[1];
27445
+ const dist = Math.sqrt(dx * dx + dy * dy);
27446
+ if (dist < 1e-9) return [];
27447
+ const radius = Math.abs(dist / (2 * Math.sin(theta / 2)));
27448
+ const m = Math.sqrt(Math.max(0, radius * radius - dist / 2 * (dist / 2)));
27449
+ const midPoint = [(p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2];
27450
+ const ux = dx / dist;
27451
+ const uy = dy / dist;
27452
+ const nx = -uy;
27453
+ const ny = ux;
27454
+ const centerX = midPoint[0] + nx * m * Math.sign(bulge);
27455
+ const centerY = midPoint[1] + ny * m * Math.sign(bulge);
27456
+ const startAngle = Math.atan2(p1[1] - centerY, p1[0] - centerX);
27457
+ const points = [];
27458
+ const numSteps = Math.max(
27459
+ 2,
27460
+ Math.ceil(arcSegments * Math.abs(theta) / (Math.PI * 2) * 4)
27461
+ );
27462
+ const angleStep = theta / numSteps;
27463
+ for (let i = 1; i < numSteps; i++) {
27464
+ const angle = startAngle + angleStep * i;
27465
+ points.push([
27466
+ centerX + radius * Math.cos(angle),
27467
+ centerY + radius * Math.sin(angle)
27468
+ ]);
27469
+ }
27470
+ return points;
27471
+ }
27472
+ function ringToPoints(ring2, arcSegments) {
27473
+ const allPoints = [];
27474
+ const vertices = ring2.vertices;
27475
+ for (let i = 0; i < vertices.length; i++) {
27476
+ const p1 = vertices[i];
27477
+ const p2 = vertices[(i + 1) % vertices.length];
27478
+ allPoints.push([p1.x, p1.y]);
27479
+ if (p1.bulge) {
27480
+ const arcPoints = segmentToPoints(
27481
+ [p1.x, p1.y],
27482
+ [p2.x, p2.y],
27483
+ p1.bulge,
27484
+ arcSegments
27485
+ );
27486
+ allPoints.push(...arcPoints);
27487
+ }
27488
+ }
27489
+ return allPoints;
27490
+ }
27491
+ function arePointsClockwise2(points) {
27492
+ let area = 0;
27493
+ for (let i = 0; i < points.length; i++) {
27494
+ const j = (i + 1) % points.length;
27495
+ area += points[i][0] * points[j][1];
27496
+ area -= points[j][0] * points[i][1];
27497
+ }
27498
+ return area / 2 <= 0;
27499
+ }
27500
+ function createGeom2FromBRep(brep, arcSegments = 16) {
27501
+ let outerPoints = ringToPoints(brep.outer_ring, arcSegments);
27502
+ if (arePointsClockwise2(outerPoints)) {
27503
+ outerPoints.reverse();
27504
+ }
27505
+ const outerGeom = (0, import_primitives5.polygon)({ points: outerPoints });
27506
+ if (!brep.inner_rings || brep.inner_rings.length === 0) {
27507
+ return outerGeom;
27508
+ }
27509
+ const innerGeoms = brep.inner_rings.map((ring2) => {
27510
+ let innerPoints = ringToPoints(ring2, arcSegments);
27511
+ if (arePointsClockwise2(innerPoints)) {
27512
+ innerPoints.reverse();
27513
+ }
27514
+ return (0, import_primitives5.polygon)({ points: innerPoints });
27515
+ });
27516
+ if (innerGeoms.length === 0) return outerGeom;
27517
+ return (0, import_booleans2.subtract)(outerGeom, innerGeoms);
27518
+ }
27519
+
27435
27520
  // src/BoardGeomBuilder.ts
27436
27521
  var buildStateOrder = [
27437
27522
  "initializing",
@@ -27517,7 +27602,7 @@ var BoardGeomBuilder = class {
27517
27602
  this.ctx.pcbThickness
27518
27603
  );
27519
27604
  } else {
27520
- this.boardGeom = (0, import_primitives5.cuboid)({
27605
+ this.boardGeom = (0, import_primitives6.cuboid)({
27521
27606
  size: [this.board.width, this.board.height, this.ctx.pcbThickness],
27522
27607
  center: [this.board.center.x, this.board.center.y, 0]
27523
27608
  });
@@ -27623,7 +27708,7 @@ var BoardGeomBuilder = class {
27623
27708
  const cutoutHeight = this.ctx.pcbThickness * 1.5;
27624
27709
  switch (cutout.shape) {
27625
27710
  case "rect":
27626
- cutoutGeom = (0, import_primitives5.cuboid)({
27711
+ cutoutGeom = (0, import_primitives6.cuboid)({
27627
27712
  center: [cutout.center.x, cutout.center.y, 0],
27628
27713
  size: [cutout.width, cutout.height, cutoutHeight]
27629
27714
  });
@@ -27633,7 +27718,7 @@ var BoardGeomBuilder = class {
27633
27718
  }
27634
27719
  break;
27635
27720
  case "circle":
27636
- cutoutGeom = (0, import_primitives5.cylinder)({
27721
+ cutoutGeom = (0, import_primitives6.cylinder)({
27637
27722
  center: [cutout.center.x, cutout.center.y, 0],
27638
27723
  radius: cutout.radius,
27639
27724
  height: cutoutHeight
@@ -27650,13 +27735,13 @@ var BoardGeomBuilder = class {
27650
27735
  if (arePointsClockwise(pointsVec2)) {
27651
27736
  pointsVec2 = pointsVec2.reverse();
27652
27737
  }
27653
- const polygon2d = (0, import_primitives5.polygon)({ points: pointsVec2 });
27738
+ const polygon2d = (0, import_primitives6.polygon)({ points: pointsVec2 });
27654
27739
  cutoutGeom = (0, import_extrusions3.extrudeLinear)({ height: cutoutHeight }, polygon2d);
27655
27740
  cutoutGeom = (0, import_transforms3.translate)([0, 0, -cutoutHeight / 2], cutoutGeom);
27656
27741
  break;
27657
27742
  }
27658
27743
  if (cutoutGeom) {
27659
- this.boardGeom = (0, import_booleans2.subtract)(this.boardGeom, cutoutGeom);
27744
+ this.boardGeom = (0, import_booleans3.subtract)(this.boardGeom, cutoutGeom);
27660
27745
  }
27661
27746
  }
27662
27747
  processCopperPour(pour) {
@@ -27664,7 +27749,7 @@ var BoardGeomBuilder = class {
27664
27749
  const zPos = layerSign * this.ctx.pcbThickness / 2 + layerSign * M;
27665
27750
  let pourGeom = null;
27666
27751
  if (pour.shape === "rect") {
27667
- let baseGeom = (0, import_primitives5.cuboid)({
27752
+ let baseGeom = (0, import_primitives6.cuboid)({
27668
27753
  center: [0, 0, 0],
27669
27754
  // Create at origin for rotation
27670
27755
  size: [pour.width, pour.height, M]
@@ -27674,6 +27759,13 @@ var BoardGeomBuilder = class {
27674
27759
  baseGeom = (0, import_transforms3.rotateZ)(rotationRadians, baseGeom);
27675
27760
  }
27676
27761
  pourGeom = (0, import_transforms3.translate)([pour.center.x, pour.center.y, zPos], baseGeom);
27762
+ } else if (pour.shape === "brep") {
27763
+ const brepShape = pour.brep_shape;
27764
+ if (brepShape && brepShape.outer_ring) {
27765
+ const pourGeom2 = createGeom2FromBRep(brepShape);
27766
+ pourGeom = (0, import_extrusions3.extrudeLinear)({ height: M }, pourGeom2);
27767
+ pourGeom = (0, import_transforms3.translate)([0, 0, zPos], pourGeom);
27768
+ }
27677
27769
  } else if (pour.shape === "polygon") {
27678
27770
  let pointsVec2 = pour.points.map((p) => [p.x, p.y]);
27679
27771
  if (pointsVec2.length < 3) {
@@ -27685,7 +27777,7 @@ var BoardGeomBuilder = class {
27685
27777
  if (arePointsClockwise(pointsVec2)) {
27686
27778
  pointsVec2 = pointsVec2.reverse();
27687
27779
  }
27688
- const polygon2d = (0, import_primitives5.polygon)({ points: pointsVec2 });
27780
+ const polygon2d = (0, import_primitives6.polygon)({ points: pointsVec2 });
27689
27781
  pourGeom = (0, import_extrusions3.extrudeLinear)({ height: M }, polygon2d);
27690
27782
  pourGeom = (0, import_transforms3.translate)([0, 0, zPos], pourGeom);
27691
27783
  }
@@ -27697,7 +27789,7 @@ var BoardGeomBuilder = class {
27697
27789
  processPlatedHole(ph, opts = {}) {
27698
27790
  if (!this.boardGeom) return;
27699
27791
  if (ph.shape === "circle" || ph.shape === "circular_hole_with_rect_pad") {
27700
- const cyGeom = (0, import_primitives5.cylinder)({
27792
+ const cyGeom = (0, import_primitives6.cylinder)({
27701
27793
  center: [ph.x, ph.y, 0],
27702
27794
  radius: ph.hole_diameter / 2 + M,
27703
27795
  // Add margin for subtraction
@@ -27705,10 +27797,10 @@ var BoardGeomBuilder = class {
27705
27797
  // Ensure it cuts through
27706
27798
  });
27707
27799
  if (!opts.dontCutBoard) {
27708
- this.boardGeom = (0, import_booleans2.subtract)(this.boardGeom, cyGeom);
27800
+ this.boardGeom = (0, import_booleans3.subtract)(this.boardGeom, cyGeom);
27709
27801
  }
27710
27802
  this.padGeoms = this.padGeoms.map(
27711
- (pg) => (0, import_colors4.colorize)(colors.copper, (0, import_booleans2.subtract)(pg, cyGeom))
27803
+ (pg) => (0, import_colors4.colorize)(colors.copper, (0, import_booleans3.subtract)(pg, cyGeom))
27712
27804
  );
27713
27805
  const platedHoleGeom = platedHole(ph, this.ctx);
27714
27806
  this.platedHoleGeoms.push(platedHoleGeom);
@@ -27718,27 +27810,27 @@ var BoardGeomBuilder = class {
27718
27810
  const holeHeight = shouldRotate ? ph.hole_width : ph.hole_height;
27719
27811
  const holeRadius = holeHeight / 2;
27720
27812
  const rectLength = Math.abs(holeWidth - holeHeight);
27721
- const pillHole = (0, import_booleans2.union)(
27722
- (0, import_primitives5.cuboid)({
27813
+ const pillHole = (0, import_booleans3.union)(
27814
+ (0, import_primitives6.cuboid)({
27723
27815
  center: [ph.x, ph.y, 0],
27724
27816
  size: shouldRotate ? [holeHeight, rectLength, this.ctx.pcbThickness * 1.5] : [rectLength, holeHeight, this.ctx.pcbThickness * 1.5]
27725
27817
  }),
27726
- (0, import_primitives5.cylinder)({
27818
+ (0, import_primitives6.cylinder)({
27727
27819
  center: shouldRotate ? [ph.x, ph.y - rectLength / 2, 0] : [ph.x - rectLength / 2, ph.y, 0],
27728
27820
  radius: holeRadius,
27729
27821
  height: this.ctx.pcbThickness * 1.5
27730
27822
  }),
27731
- (0, import_primitives5.cylinder)({
27823
+ (0, import_primitives6.cylinder)({
27732
27824
  center: shouldRotate ? [ph.x, ph.y + rectLength / 2, 0] : [ph.x + rectLength / 2, ph.y, 0],
27733
27825
  radius: holeRadius,
27734
27826
  height: this.ctx.pcbThickness * 1.5
27735
27827
  })
27736
27828
  );
27737
27829
  if (!opts.dontCutBoard) {
27738
- this.boardGeom = (0, import_booleans2.subtract)(this.boardGeom, pillHole);
27830
+ this.boardGeom = (0, import_booleans3.subtract)(this.boardGeom, pillHole);
27739
27831
  }
27740
27832
  this.padGeoms = this.padGeoms.map(
27741
- (pg) => (0, import_colors4.colorize)(colors.copper, (0, import_booleans2.subtract)(pg, pillHole))
27833
+ (pg) => (0, import_colors4.colorize)(colors.copper, (0, import_booleans3.subtract)(pg, pillHole))
27742
27834
  );
27743
27835
  const platedHoleGeom = platedHole(ph, this.ctx);
27744
27836
  this.platedHoleGeoms.push(platedHoleGeom);
@@ -27747,16 +27839,16 @@ var BoardGeomBuilder = class {
27747
27839
  processHole(hole) {
27748
27840
  if (!this.boardGeom) return;
27749
27841
  if (hole.hole_shape === "round" || hole.hole_shape === "circle") {
27750
- const cyGeom = (0, import_primitives5.cylinder)({
27842
+ const cyGeom = (0, import_primitives6.cylinder)({
27751
27843
  center: [hole.x, hole.y, 0],
27752
27844
  radius: hole.hole_diameter / 2 + M,
27753
27845
  // Add margin for subtraction
27754
27846
  height: this.ctx.pcbThickness * 1.5
27755
27847
  // Ensure it cuts through
27756
27848
  });
27757
- this.boardGeom = (0, import_booleans2.subtract)(this.boardGeom, cyGeom);
27849
+ this.boardGeom = (0, import_booleans3.subtract)(this.boardGeom, cyGeom);
27758
27850
  this.padGeoms = this.padGeoms.map(
27759
- (pg) => (0, import_colors4.colorize)(colors.copper, (0, import_booleans2.subtract)(pg, cyGeom))
27851
+ (pg) => (0, import_colors4.colorize)(colors.copper, (0, import_booleans3.subtract)(pg, cyGeom))
27760
27852
  );
27761
27853
  }
27762
27854
  }
@@ -27766,14 +27858,14 @@ var BoardGeomBuilder = class {
27766
27858
  if (pad2.shape === "rect") {
27767
27859
  const padGeom = (0, import_colors4.colorize)(
27768
27860
  colors.copper,
27769
- (0, import_primitives5.cuboid)({
27861
+ (0, import_primitives6.cuboid)({
27770
27862
  center: [pad2.x, pad2.y, zPos],
27771
27863
  size: [pad2.width, pad2.height, M]
27772
27864
  })
27773
27865
  );
27774
27866
  this.padGeoms.push(padGeom);
27775
27867
  } else if (pad2.shape === "rotated_rect") {
27776
- let basePadGeom = (0, import_primitives5.cuboid)({
27868
+ let basePadGeom = (0, import_primitives6.cuboid)({
27777
27869
  // Create at origin for rotation, then translate
27778
27870
  center: [0, 0, 0],
27779
27871
  size: [pad2.width, pad2.height, M]
@@ -27786,7 +27878,7 @@ var BoardGeomBuilder = class {
27786
27878
  } else if (pad2.shape === "circle") {
27787
27879
  const padGeom = (0, import_colors4.colorize)(
27788
27880
  colors.copper,
27789
- (0, import_primitives5.cylinder)({
27881
+ (0, import_primitives6.cylinder)({
27790
27882
  center: [pad2.x, pad2.y, zPos],
27791
27883
  radius: pad2.radius,
27792
27884
  height: M
@@ -27805,7 +27897,7 @@ var BoardGeomBuilder = class {
27805
27897
  if (currentSegmentPoints.length >= 2 && currentLayer) {
27806
27898
  const layerSign = currentLayer === "bottom" ? -1 : 1;
27807
27899
  const zPos = layerSign * this.ctx.pcbThickness / 2 + layerSign * M;
27808
- const linePath = (0, import_primitives5.line)(currentSegmentPoints);
27900
+ const linePath = (0, import_primitives6.line)(currentSegmentPoints);
27809
27901
  const expandedPath = (0, import_expansions2.expand)(
27810
27902
  { delta: currentWidth / 2, corners: "round" },
27811
27903
  linePath
@@ -27821,21 +27913,21 @@ var BoardGeomBuilder = class {
27821
27913
  startPointCoords[1]
27822
27914
  );
27823
27915
  if (startHole) {
27824
- const cuttingCylinder = (0, import_primitives5.cylinder)({
27916
+ const cuttingCylinder = (0, import_primitives6.cylinder)({
27825
27917
  center: [startPointCoords[0], startPointCoords[1], zPos + M / 2],
27826
27918
  radius: startHole.diameter / 2 + M,
27827
27919
  height: M
27828
27920
  });
27829
- traceGeom = (0, import_booleans2.subtract)(traceGeom, cuttingCylinder);
27921
+ traceGeom = (0, import_booleans3.subtract)(traceGeom, cuttingCylinder);
27830
27922
  }
27831
27923
  const endHole = this.getHoleToCut(endPointCoords[0], endPointCoords[1]);
27832
27924
  if (endHole) {
27833
- const cuttingCylinder = (0, import_primitives5.cylinder)({
27925
+ const cuttingCylinder = (0, import_primitives6.cylinder)({
27834
27926
  center: [endPointCoords[0], endPointCoords[1], zPos + M / 2],
27835
27927
  radius: endHole.diameter / 2 + M,
27836
27928
  height: M
27837
27929
  });
27838
- traceGeom = (0, import_booleans2.subtract)(traceGeom, cuttingCylinder);
27930
+ traceGeom = (0, import_booleans3.subtract)(traceGeom, cuttingCylinder);
27839
27931
  }
27840
27932
  const tracesMaterialColor = tracesMaterialColors[this.board.material] ?? colors.fr4GreenSolderWithMask;
27841
27933
  traceGeom = (0, import_colors4.colorize)(tracesMaterialColor, traceGeom);
@@ -27905,7 +27997,7 @@ var BoardGeomBuilder = class {
27905
27997
  point2[0] + xOffset + st.anchor_position.x,
27906
27998
  point2[1] + yOffset + st.anchor_position.y
27907
27999
  ]);
27908
- const textPath = (0, import_primitives5.line)(alignedOutline);
28000
+ const textPath = (0, import_primitives6.line)(alignedOutline);
27909
28001
  const fontSize = st.font_size || 0.25;
27910
28002
  const expansionDelta = Math.min(
27911
28003
  Math.max(0.01, fontSize * 0.1),
@@ -28986,7 +29078,7 @@ function processSmtPadsForManifold(Manifold, circuitJson, pcbThickness, manifold
28986
29078
  }
28987
29079
 
28988
29080
  // src/utils/manifold/create-manifold-board.ts
28989
- var arePointsClockwise2 = (points) => {
29081
+ var arePointsClockwise3 = (points) => {
28990
29082
  let area = 0;
28991
29083
  for (let i = 0; i < points.length; i++) {
28992
29084
  const j = (i + 1) % points.length;
@@ -29005,7 +29097,7 @@ function createManifoldBoard(Manifold, CrossSection, boardData, pcbThickness, ma
29005
29097
  p.x,
29006
29098
  p.y
29007
29099
  ]);
29008
- if (arePointsClockwise2(outlineVec2)) {
29100
+ if (arePointsClockwise3(outlineVec2)) {
29009
29101
  outlineVec2 = outlineVec2.reverse();
29010
29102
  }
29011
29103
  const crossSection = CrossSection.ofPolygons([outlineVec2]);
@@ -29044,7 +29136,7 @@ function createManifoldBoard(Manifold, CrossSection, boardData, pcbThickness, ma
29044
29136
  // src/utils/manifold/process-copper-pours.ts
29045
29137
  import * as THREE20 from "three";
29046
29138
  var COPPER_COLOR4 = new THREE20.Color(...colors.copper);
29047
- var arePointsClockwise3 = (points) => {
29139
+ var arePointsClockwise4 = (points) => {
29048
29140
  let area = 0;
29049
29141
  for (let i = 0; i < points.length; i++) {
29050
29142
  const j = (i + 1) % points.length;
@@ -29056,6 +29148,59 @@ var arePointsClockwise3 = (points) => {
29056
29148
  const signedArea = area / 2;
29057
29149
  return signedArea <= 0;
29058
29150
  };
29151
+ function segmentToPoints2(p1, p2, bulge, arcSegments) {
29152
+ if (!bulge || Math.abs(bulge) < 1e-9) {
29153
+ return [];
29154
+ }
29155
+ const theta = 4 * Math.atan(bulge);
29156
+ const dx = p2[0] - p1[0];
29157
+ const dy = p2[1] - p1[1];
29158
+ const dist = Math.sqrt(dx * dx + dy * dy);
29159
+ if (dist < 1e-9) return [];
29160
+ const radius = Math.abs(dist / (2 * Math.sin(theta / 2)));
29161
+ const m = Math.sqrt(Math.max(0, radius * radius - dist / 2 * (dist / 2)));
29162
+ const midPoint = [(p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2];
29163
+ const ux = dx / dist;
29164
+ const uy = dy / dist;
29165
+ const nx = -uy;
29166
+ const ny = ux;
29167
+ const centerX = midPoint[0] + nx * m * Math.sign(bulge);
29168
+ const centerY = midPoint[1] + ny * m * Math.sign(bulge);
29169
+ const startAngle = Math.atan2(p1[1] - centerY, p1[0] - centerX);
29170
+ const points = [];
29171
+ const numSteps = Math.max(
29172
+ 2,
29173
+ Math.ceil(arcSegments * Math.abs(theta) / (Math.PI * 2) * 4)
29174
+ );
29175
+ const angleStep = theta / numSteps;
29176
+ for (let i = 1; i < numSteps; i++) {
29177
+ const angle = startAngle + angleStep * i;
29178
+ points.push([
29179
+ centerX + radius * Math.cos(angle),
29180
+ centerY + radius * Math.sin(angle)
29181
+ ]);
29182
+ }
29183
+ return points;
29184
+ }
29185
+ function ringToPoints2(ring2, arcSegments) {
29186
+ const allPoints = [];
29187
+ const vertices = ring2.vertices;
29188
+ for (let i = 0; i < vertices.length; i++) {
29189
+ const p1 = vertices[i];
29190
+ const p2 = vertices[(i + 1) % vertices.length];
29191
+ allPoints.push([p1.x, p1.y]);
29192
+ if (p1.bulge) {
29193
+ const arcPoints = segmentToPoints2(
29194
+ [p1.x, p1.y],
29195
+ [p2.x, p2.y],
29196
+ p1.bulge,
29197
+ arcSegments
29198
+ );
29199
+ allPoints.push(...arcPoints);
29200
+ }
29201
+ }
29202
+ return allPoints;
29203
+ }
29059
29204
  function processCopperPoursForManifold(Manifold, CrossSection, circuitJson, pcbThickness, manifoldInstancesForCleanup, holeUnion) {
29060
29205
  const copperPourGeoms = [];
29061
29206
  const copperPours = circuitJson.filter(
@@ -29082,7 +29227,7 @@ function processCopperPoursForManifold(Manifold, CrossSection, circuitJson, pcbT
29082
29227
  p.x,
29083
29228
  p.y
29084
29229
  ]);
29085
- if (arePointsClockwise3(pointsVec2)) {
29230
+ if (arePointsClockwise4(pointsVec2)) {
29086
29231
  pointsVec2 = pointsVec2.reverse();
29087
29232
  }
29088
29233
  const crossSection = CrossSection.ofPolygons([pointsVec2]);
@@ -29100,6 +29245,42 @@ function processCopperPoursForManifold(Manifold, CrossSection, circuitJson, pcbT
29100
29245
  // center extrusion
29101
29246
  ).translate([0, 0, zPos]);
29102
29247
  manifoldInstancesForCleanup.push(pourOp);
29248
+ } else if (pour.shape === "brep") {
29249
+ const brepShape = pour.brep_shape;
29250
+ if (!brepShape || !brepShape.outer_ring) continue;
29251
+ let outerRingPoints = ringToPoints2(
29252
+ brepShape.outer_ring,
29253
+ SMOOTH_CIRCLE_SEGMENTS
29254
+ );
29255
+ if (arePointsClockwise4(outerRingPoints)) {
29256
+ outerRingPoints = outerRingPoints.reverse();
29257
+ }
29258
+ const polygons = [outerRingPoints];
29259
+ if (brepShape.inner_rings) {
29260
+ const innerRingsPoints = brepShape.inner_rings.map((ring2) => {
29261
+ let points = ringToPoints2(ring2, SMOOTH_CIRCLE_SEGMENTS);
29262
+ if (!arePointsClockwise4(points)) {
29263
+ points = points.reverse();
29264
+ }
29265
+ return points;
29266
+ });
29267
+ polygons.push(...innerRingsPoints);
29268
+ }
29269
+ const crossSection = CrossSection.ofPolygons(polygons);
29270
+ manifoldInstancesForCleanup.push(crossSection);
29271
+ pourOp = Manifold.extrude(
29272
+ crossSection,
29273
+ pourThickness,
29274
+ 0,
29275
+ // nDivisions
29276
+ 0,
29277
+ // twistDegrees
29278
+ [1, 1],
29279
+ // scaleTop
29280
+ true
29281
+ // center extrusion
29282
+ ).translate([0, 0, zPos]);
29283
+ manifoldInstancesForCleanup.push(pourOp);
29103
29284
  }
29104
29285
  if (pourOp) {
29105
29286
  if (holeUnion) {
@@ -29120,7 +29301,7 @@ function processCopperPoursForManifold(Manifold, CrossSection, circuitJson, pcbT
29120
29301
 
29121
29302
  // src/utils/manifold/process-cutouts.ts
29122
29303
  import { su as su11 } from "@tscircuit/circuit-json-util";
29123
- var arePointsClockwise4 = (points) => {
29304
+ var arePointsClockwise5 = (points) => {
29124
29305
  let area = 0;
29125
29306
  for (let i = 0; i < points.length; i++) {
29126
29307
  const j = (i + 1) % points.length;
@@ -29185,7 +29366,7 @@ function processCutoutsForManifold(Manifold, CrossSection, circuitJson, pcbThick
29185
29366
  p.x,
29186
29367
  p.y
29187
29368
  ]);
29188
- if (arePointsClockwise4(pointsVec2)) {
29369
+ if (arePointsClockwise5(pointsVec2)) {
29189
29370
  pointsVec2 = pointsVec2.reverse();
29190
29371
  }
29191
29372
  const crossSection = CrossSection.ofPolygons([pointsVec2]);
@@ -30118,17 +30299,17 @@ function createGeometryFromPolygons(polygons) {
30118
30299
  const geometry = new BufferGeometry3();
30119
30300
  const vertices = [];
30120
30301
  const normals = [];
30121
- for (const polygon2 of polygons) {
30122
- for (let i = 1; i < polygon2.vertices.length - 1; i++) {
30302
+ for (const polygon3 of polygons) {
30303
+ for (let i = 1; i < polygon3.vertices.length - 1; i++) {
30123
30304
  vertices.push(
30124
- ...polygon2.vertices[0],
30125
- ...polygon2.vertices[i],
30126
- ...polygon2.vertices[i + 1]
30305
+ ...polygon3.vertices[0],
30306
+ ...polygon3.vertices[i],
30307
+ ...polygon3.vertices[i + 1]
30127
30308
  // Third vertex
30128
30309
  );
30129
- const v1 = new THREE24.Vector3(...polygon2.vertices[0]);
30130
- const v2 = new THREE24.Vector3(...polygon2.vertices[i]);
30131
- const v3 = new THREE24.Vector3(...polygon2.vertices[i + 1]);
30310
+ const v1 = new THREE24.Vector3(...polygon3.vertices[0]);
30311
+ const v2 = new THREE24.Vector3(...polygon3.vertices[i]);
30312
+ const v3 = new THREE24.Vector3(...polygon3.vertices[i + 1]);
30132
30313
  const normal = new THREE24.Vector3().crossVectors(
30133
30314
  new THREE24.Vector3().subVectors(v2, v1),
30134
30315
  new THREE24.Vector3().subVectors(v3, v1)