@tscircuit/checks 0.0.206 → 0.0.207

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/index.js CHANGED
@@ -1264,10 +1264,58 @@ function getReadableNameForFootprintPad(circuitJson, pad, ordinal) {
1264
1264
  return `${padKind} #${ordinal + 1} at ${location}`;
1265
1265
  }
1266
1266
 
1267
+ // lib/copper-pour-connectivity/create-copper-polygon-contact-tester.ts
1268
+ import {
1269
+ Box
1270
+ } from "@flatten-js/core";
1271
+ function createCopperPolygonContactTester(tolerance) {
1272
+ const cache = /* @__PURE__ */ new WeakMap();
1273
+ const getGeometry = (polygon) => {
1274
+ let geometry = cache.get(polygon);
1275
+ if (!geometry) {
1276
+ geometry = {
1277
+ box: polygon.box,
1278
+ facePoints: [...polygon.faces].map((face) => face.first.start),
1279
+ edges: [...polygon.edges].map((edge) => edge.shape),
1280
+ edgeIndex: polygon.edges
1281
+ };
1282
+ cache.set(polygon, geometry);
1283
+ }
1284
+ return geometry;
1285
+ };
1286
+ return (a, b) => {
1287
+ if (a.isEmpty() || b.isEmpty()) return false;
1288
+ const ga = getGeometry(a);
1289
+ const gb = getGeometry(b);
1290
+ if (ga.box.xmin > gb.box.xmax + tolerance || ga.box.xmax < gb.box.xmin - tolerance || ga.box.ymin > gb.box.ymax + tolerance || ga.box.ymax < gb.box.ymin - tolerance)
1291
+ return false;
1292
+ if (ga.facePoints.some(
1293
+ (point2) => gb.box.contains(point2) && b.contains(point2)
1294
+ ) || gb.facePoints.some((point2) => ga.box.contains(point2) && a.contains(point2)))
1295
+ return true;
1296
+ const [small, large] = ga.edges.length <= gb.edges.length ? [ga, gb] : [gb, ga];
1297
+ for (const edge of small.edges) {
1298
+ const box = edge.box;
1299
+ const queryBox = new Box(
1300
+ box.xmin - tolerance,
1301
+ box.ymin - tolerance,
1302
+ box.xmax + tolerance,
1303
+ box.ymax + tolerance
1304
+ );
1305
+ const candidates = large.edgeIndex.search(
1306
+ queryBox
1307
+ );
1308
+ for (const candidate of candidates) {
1309
+ if (edge.distanceTo(candidate.shape)[0] <= tolerance) return true;
1310
+ }
1311
+ }
1312
+ return false;
1313
+ };
1314
+ }
1315
+
1267
1316
  // lib/copper-pour-connectivity/get-copper-pour-connectivity.ts
1268
1317
  import {
1269
1318
  getPrimaryId,
1270
- copperPolygonsTouch,
1271
1319
  getPlatedHolePolygon,
1272
1320
  getPourPolygon,
1273
1321
  getSmtPadPolygon,
@@ -1277,6 +1325,7 @@ import {
1277
1325
  function getCopperPourConnectivity(circuitJson, connectivity) {
1278
1326
  const scale = 1e6;
1279
1327
  const tolerance = 1e-7 * scale;
1328
+ const copperPolygonsTouch = createCopperPolygonContactTester(tolerance);
1280
1329
  const conductors = [];
1281
1330
  const pouredNets = /* @__PURE__ */ new Set();
1282
1331
  const netForId = (id) => connectivity.getNetConnectedToId(id);
@@ -1380,11 +1429,7 @@ function getCopperPourConnectivity(circuitJson, connectivity) {
1380
1429
  (layer) => conductors[j].layers.includes(layer)
1381
1430
  ))
1382
1431
  continue;
1383
- if (copperPolygonsTouch(
1384
- conductors[i].polygon,
1385
- conductors[j].polygon,
1386
- tolerance
1387
- ))
1432
+ if (copperPolygonsTouch(conductors[i].polygon, conductors[j].polygon))
1388
1433
  parent[find(j)] = find(i);
1389
1434
  }
1390
1435
  }