@tscircuit/circuit-json-util 0.0.106 → 0.0.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,6 +35,8 @@ It reduces the amount of code to retrieve or join elements from circuit json, it
35
35
  | `getReadableNameForPcbSmtpad` | [`lib/readable-name-functions/get-readable-name-for-pcb-smtpad.ts`](./lib/readable-name-functions/get-readable-name-for-pcb-smtpad.ts) | Produces a readable label for a PCB SMT pad. |
36
36
  | `getReadableNameForPcbTrace` | [`lib/readable-name-functions/get-readable-name-for-pcb-trace.ts`](./lib/readable-name-functions/get-readable-name-for-pcb-trace.ts) | Produces a readable label for a PCB trace. |
37
37
  | `getBoundsOfPcbElements` | [`lib/get-bounds-of-pcb-elements.ts`](./lib/get-bounds-of-pcb-elements.ts) | Computes aggregate XY bounds for PCB elements. |
38
+ | `getPcbElementBounds` | [`lib/get-bounds-of-pcb-elements.ts`](./lib/get-bounds-of-pcb-elements.ts) | Computes the axis-aligned XY bounds of one PCB element. |
39
+ | `getPcbElementsWithinBounds` | [`lib/get-bounds-of-pcb-elements.ts`](./lib/get-bounds-of-pcb-elements.ts) | Selects PCB elements whose bounds intersect a region. |
38
40
  | `getBoardBounds` | [`lib/get-board-bounds.ts`](./lib/get-board-bounds.ts) | Computes board bounds/size from `width`+`height`+`center`, or from `outline` points. |
39
41
  | `getSchematicElementBounds` | [`lib/get-schematic-element-bounds.ts`](./lib/get-schematic-element-bounds.ts) | Computes the axis-aligned bounds of a schematic component, net label, or trace. |
40
42
  | `findBoundsAndCenter` | [`lib/find-bounds-and-center.ts`](./lib/find-bounds-and-center.ts) | Computes bounds and center for a set of points. |
package/dist/index.d.ts CHANGED
@@ -19274,20 +19274,25 @@ declare const getElementById: (soup: AnyCircuitElement[], id: string) => AnyCirc
19274
19274
 
19275
19275
  declare const getElementId: (elm: AnyCircuitElement) => string;
19276
19276
 
19277
- declare function getReadableNameForPcbTrace(soup: AnyCircuitElement[], pcb_trace_id: string): string;
19277
+ declare const getReadableNameForPcbPort: (soup: AnyCircuitElement[], pcb_port_id: string) => string;
19278
19278
 
19279
19279
  declare function getReadableNameForPcbSmtpad(soup: AnyCircuitElement[], pcb_smtpad_id: string): string;
19280
19280
 
19281
- declare const getReadableNameForPcbPort: (soup: AnyCircuitElement[], pcb_port_id: string) => string;
19281
+ declare function getReadableNameForPcbTrace(soup: AnyCircuitElement[], pcb_trace_id: string): string;
19282
19282
 
19283
19283
  declare const getReadableNameForElement: (soup: AnyCircuitElement[], elm: AnyCircuitElement | string) => string;
19284
19284
 
19285
- declare const getBoundsOfPcbElements: (elements: AnyCircuitElement[]) => {
19285
+ interface PcbBounds {
19286
19286
  minX: number;
19287
19287
  minY: number;
19288
19288
  maxX: number;
19289
19289
  maxY: number;
19290
- };
19290
+ }
19291
+ /** Returns the axis-aligned bounds of one drawable PCB element. */
19292
+ declare const getPcbElementBounds: (elm: AnyCircuitElement) => PcbBounds | null;
19293
+ declare const getBoundsOfPcbElements: (elements: AnyCircuitElement[]) => PcbBounds;
19294
+ /** Returns PCB elements whose axis-aligned bounds intersect the given bounds. */
19295
+ declare const getPcbElementsWithinBounds: (elements: AnyCircuitElement[], bounds: PcbBounds) => AnyCircuitElement[];
19291
19296
 
19292
19297
  interface BoardBounds {
19293
19298
  minX: number;
@@ -19464,4 +19469,4 @@ type DrcLike = {
19464
19469
  };
19465
19470
  declare const categorizeErrorOrWarning: (value: string | DrcLike) => DrcCategory;
19466
19471
 
19467
- export { type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getStringFromCircuitJsonTree, oppositeDirection, oppositeSide, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
19472
+ export { type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbBounds, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPcbElementBounds, getPcbElementsWithinBounds, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getStringFromCircuitJsonTree, oppositeDirection, oppositeSide, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
package/dist/index.js CHANGED
@@ -1210,42 +1210,6 @@ var getElementById = (soup, id) => {
1210
1210
  return soup.find((elm) => getElementId(elm) === id) ?? null;
1211
1211
  };
1212
1212
 
1213
- // lib/readable-name-functions/get-readable-name-for-pcb-trace.ts
1214
- function getReadableNameForPcbTrace(soup, pcb_trace_id) {
1215
- const pcbTrace = cju(soup).pcb_trace.get(pcb_trace_id);
1216
- if (!pcbTrace) {
1217
- return `trace[${pcb_trace_id}]`;
1218
- }
1219
- const connectedPcbPortIds = pcbTrace.route.flatMap((point) => [point.start_pcb_port_id, point.end_pcb_port_id]).filter(Boolean);
1220
- if (connectedPcbPortIds.length === 0) {
1221
- return `trace[${pcb_trace_id}]`;
1222
- }
1223
- function getComponentAndPortInfo(pcb_port_id) {
1224
- const pcbPort = cju(soup).pcb_port.get(pcb_port_id);
1225
- if (!pcbPort) return null;
1226
- const pcbComponent = pcbPort.pcb_component_id ? cju(soup).pcb_component.get(pcbPort.pcb_component_id) : void 0;
1227
- if (!pcbComponent) return null;
1228
- const sourceComponent = cju(soup).source_component.get(
1229
- pcbComponent.source_component_id
1230
- );
1231
- if (!sourceComponent) return null;
1232
- const sourcePort = cju(soup).source_port.get(pcbPort.source_port_id);
1233
- const portHint = sourcePort?.port_hints ? sourcePort.port_hints[1] : "";
1234
- return {
1235
- componentName: sourceComponent.name,
1236
- portHint
1237
- };
1238
- }
1239
- const selectorParts = connectedPcbPortIds.map((portId) => {
1240
- const info = getComponentAndPortInfo(portId);
1241
- if (info) {
1242
- return `.${info.componentName} > port.${info.portHint}`;
1243
- }
1244
- return `port[${portId}]`;
1245
- });
1246
- return `trace[${selectorParts.join(", ")}]`;
1247
- }
1248
-
1249
1213
  // lib/readable-name-functions/get-readable-name-for-pcb-port.ts
1250
1214
  var getReadableNameForPcbPort = (soup, pcb_port_id) => {
1251
1215
  const pcbPort = cju(soup).pcb_port.get(pcb_port_id);
@@ -1286,6 +1250,42 @@ function getReadableNameForPcbSmtpad(soup, pcb_smtpad_id) {
1286
1250
  return getReadableNameForPcbPort(soup, pcbSmtpad.pcb_port_id);
1287
1251
  }
1288
1252
 
1253
+ // lib/readable-name-functions/get-readable-name-for-pcb-trace.ts
1254
+ function getReadableNameForPcbTrace(soup, pcb_trace_id) {
1255
+ const pcbTrace = cju(soup).pcb_trace.get(pcb_trace_id);
1256
+ if (!pcbTrace) {
1257
+ return `trace[${pcb_trace_id}]`;
1258
+ }
1259
+ const connectedPcbPortIds = pcbTrace.route.flatMap((point) => [point.start_pcb_port_id, point.end_pcb_port_id]).filter(Boolean);
1260
+ if (connectedPcbPortIds.length === 0) {
1261
+ return `trace[${pcb_trace_id}]`;
1262
+ }
1263
+ function getComponentAndPortInfo(pcb_port_id) {
1264
+ const pcbPort = cju(soup).pcb_port.get(pcb_port_id);
1265
+ if (!pcbPort) return null;
1266
+ const pcbComponent = pcbPort.pcb_component_id ? cju(soup).pcb_component.get(pcbPort.pcb_component_id) : void 0;
1267
+ if (!pcbComponent) return null;
1268
+ const sourceComponent = cju(soup).source_component.get(
1269
+ pcbComponent.source_component_id
1270
+ );
1271
+ if (!sourceComponent) return null;
1272
+ const sourcePort = cju(soup).source_port.get(pcbPort.source_port_id);
1273
+ const portHint = sourcePort?.port_hints ? sourcePort.port_hints[1] : "";
1274
+ return {
1275
+ componentName: sourceComponent.name,
1276
+ portHint
1277
+ };
1278
+ }
1279
+ const selectorParts = connectedPcbPortIds.map((portId) => {
1280
+ const info = getComponentAndPortInfo(portId);
1281
+ if (info) {
1282
+ return `.${info.componentName} > port.${info.portHint}`;
1283
+ }
1284
+ return `port[${portId}]`;
1285
+ });
1286
+ return `trace[${selectorParts.join(", ")}]`;
1287
+ }
1288
+
1289
1289
  // lib/readable-name-functions/get-readable-name-for-element.ts
1290
1290
  var getReadableNameForElement = (soup, elm) => {
1291
1291
  if (typeof elm === "string") {
@@ -1378,155 +1378,160 @@ var getRotatedPillBounds = (x, y, width, height, rotationDegrees) => {
1378
1378
  maxY: y + halfHeight
1379
1379
  };
1380
1380
  };
1381
- var getBoundsOfPcbElements = (elements) => {
1382
- let minX = Number.POSITIVE_INFINITY;
1383
- let minY = Number.POSITIVE_INFINITY;
1384
- let maxX = Number.NEGATIVE_INFINITY;
1385
- let maxY = Number.NEGATIVE_INFINITY;
1386
- for (const elm of elements) {
1387
- if (!elm.type.startsWith("pcb_")) continue;
1388
- if (elm.type === "pcb_smtpad" && elm.shape === "polygon" && Array.isArray(elm.points)) {
1389
- for (const point of elm.points) {
1390
- minX = Math.min(minX, point.x);
1391
- minY = Math.min(minY, point.y);
1392
- maxX = Math.max(maxX, point.x);
1393
- maxY = Math.max(maxY, point.y);
1394
- }
1395
- continue;
1396
- }
1397
- if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
1398
- const holeBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
1399
- minX = Math.min(minX, holeBounds.minX);
1400
- minY = Math.min(minY, holeBounds.minY);
1401
- maxX = Math.max(maxX, holeBounds.maxX);
1402
- maxY = Math.max(maxY, holeBounds.maxY);
1403
- continue;
1404
- }
1405
- if (elm.type === "pcb_plated_hole") {
1406
- let platedHoleBounds;
1407
- if ("outer_diameter" in elm && typeof elm.outer_diameter === "number") {
1408
- platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.outer_diameter);
1409
- } else if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
1410
- platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
1411
- }
1412
- if ((elm.shape === "oval" || elm.shape === "pill") && typeof elm.outer_width === "number" && typeof elm.outer_height === "number") {
1413
- const getOuterBounds = elm.shape === "pill" ? getRotatedPillBounds : getRotatedOvalBounds;
1414
- platedHoleBounds = getOuterBounds(
1415
- elm.x,
1416
- elm.y,
1417
- elm.outer_width,
1418
- elm.outer_height,
1419
- elm.ccw_rotation ?? 0
1420
- );
1421
- }
1422
- if ("rect_pad_width" in elm && typeof elm.rect_pad_width === "number" && "rect_pad_height" in elm && typeof elm.rect_pad_height === "number") {
1423
- const rectBounds = getRotatedRectBounds(
1424
- elm.x,
1425
- elm.y,
1426
- elm.rect_pad_width,
1427
- elm.rect_pad_height,
1428
- "rect_ccw_rotation" in elm ? elm.rect_ccw_rotation ?? 0 : 0
1429
- );
1430
- platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, rectBounds) : rectBounds;
1431
- }
1432
- if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
1433
- const drillBounds = getCircleBounds(
1434
- elm.x + ("hole_offset_x" in elm ? elm.hole_offset_x ?? 0 : 0),
1435
- elm.y + ("hole_offset_y" in elm ? elm.hole_offset_y ?? 0 : 0),
1436
- elm.hole_diameter
1437
- );
1438
- platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
1439
- }
1440
- if (platedHoleBounds) {
1441
- minX = Math.min(minX, platedHoleBounds.minX);
1442
- minY = Math.min(minY, platedHoleBounds.minY);
1443
- maxX = Math.max(maxX, platedHoleBounds.maxX);
1444
- maxY = Math.max(maxY, platedHoleBounds.maxY);
1445
- continue;
1446
- }
1381
+ var getBoundsFromPoints = (points) => {
1382
+ if (points.length === 0) return null;
1383
+ return {
1384
+ minX: Math.min(...points.map((point) => point.x)),
1385
+ minY: Math.min(...points.map((point) => point.y)),
1386
+ maxX: Math.max(...points.map((point) => point.x)),
1387
+ maxY: Math.max(...points.map((point) => point.y))
1388
+ };
1389
+ };
1390
+ var getRoutePoints = (route) => {
1391
+ if (!Array.isArray(route)) return [];
1392
+ return route.flatMap((point) => {
1393
+ if (!point || typeof point !== "object") return [];
1394
+ if ("x" in point && "y" in point && typeof point.x === "number" && typeof point.y === "number") {
1395
+ return [{ x: point.x, y: point.y }];
1396
+ }
1397
+ if ("start" in point && "end" in point) {
1398
+ const positions = [point.start, point.end];
1399
+ return positions.filter(
1400
+ (position) => Boolean(
1401
+ position && typeof position === "object" && "x" in position && "y" in position && typeof position.x === "number" && typeof position.y === "number"
1402
+ )
1403
+ );
1447
1404
  }
1448
- let centerX;
1449
- let centerY;
1450
- let width;
1451
- let height;
1452
- if ("x" in elm && "y" in elm) {
1453
- centerX = Number(elm.x);
1454
- centerY = Number(elm.y);
1455
- }
1456
- if ("outer_diameter" in elm) {
1457
- width = Number(elm.outer_diameter);
1458
- height = Number(elm.outer_diameter);
1459
- }
1460
- if ("width" in elm) {
1461
- width = Number(elm.width);
1462
- }
1463
- if ("height" in elm) {
1464
- height = Number(elm.height);
1465
- }
1466
- if ("center" in elm) {
1467
- centerX = elm.center.x;
1468
- centerY = elm.center.y;
1469
- }
1470
- const rotation = typeof elm.rotation === "number" ? elm.rotation : 0;
1471
- if (centerX !== void 0 && centerY !== void 0) {
1472
- minX = Math.min(minX, centerX);
1473
- minY = Math.min(minY, centerY);
1474
- maxX = Math.max(maxX, centerX);
1475
- maxY = Math.max(maxY, centerY);
1476
- if (width !== void 0 && height !== void 0) {
1477
- if (rotation) {
1478
- const rotatedBounds = getRotatedRectBounds(
1479
- centerX,
1480
- centerY,
1481
- width,
1482
- height,
1483
- rotation
1484
- );
1485
- minX = Math.min(minX, rotatedBounds.minX);
1486
- minY = Math.min(minY, rotatedBounds.minY);
1487
- maxX = Math.max(maxX, rotatedBounds.maxX);
1488
- maxY = Math.max(maxY, rotatedBounds.maxY);
1489
- } else {
1490
- minX = Math.min(minX, centerX - width / 2);
1491
- minY = Math.min(minY, centerY - height / 2);
1492
- maxX = Math.max(maxX, centerX + width / 2);
1493
- maxY = Math.max(maxY, centerY + height / 2);
1494
- }
1495
- }
1496
- if ("radius" in elm) {
1497
- minX = Math.min(minX, centerX - elm.radius);
1498
- minY = Math.min(minY, centerY - elm.radius);
1499
- maxX = Math.max(maxX, centerX + elm.radius);
1500
- maxY = Math.max(maxY, centerY + elm.radius);
1501
- }
1502
- } else if (elm.type === "pcb_trace") {
1503
- for (const point of elm.route) {
1504
- const positions = "x" in point ? [point] : [point.start, point.end];
1505
- for (const { x, y } of positions) {
1506
- minX = Math.min(minX, x);
1507
- minY = Math.min(minY, y);
1508
- maxX = Math.max(maxX, x);
1509
- maxY = Math.max(maxY, y);
1510
- }
1511
- }
1512
- } else if (elm.type === "pcb_courtyard_outline") {
1513
- for (const point of elm.outline) {
1514
- minX = Math.min(minX, point.x);
1515
- minY = Math.min(minY, point.y);
1516
- maxX = Math.max(maxX, point.x);
1517
- maxY = Math.max(maxY, point.y);
1518
- }
1519
- } else if (elm.type === "pcb_courtyard_polygon") {
1520
- for (const point of elm.points) {
1521
- minX = Math.min(minX, point.x);
1522
- minY = Math.min(minY, point.y);
1523
- maxX = Math.max(maxX, point.x);
1524
- maxY = Math.max(maxY, point.y);
1525
- }
1405
+ return [];
1406
+ });
1407
+ };
1408
+ var getPcbElementBounds = (elm) => {
1409
+ if (!elm.type.startsWith("pcb_")) return null;
1410
+ if (elm.type === "pcb_smtpad" && elm.shape === "polygon" && Array.isArray(elm.points)) {
1411
+ return getBoundsFromPoints(elm.points);
1412
+ }
1413
+ if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
1414
+ return getCircleBounds(elm.x, elm.y, elm.hole_diameter);
1415
+ }
1416
+ if (elm.type === "pcb_plated_hole") {
1417
+ let platedHoleBounds;
1418
+ if ("outer_diameter" in elm && typeof elm.outer_diameter === "number") {
1419
+ platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.outer_diameter);
1420
+ } else if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
1421
+ platedHoleBounds = getCircleBounds(elm.x, elm.y, elm.hole_diameter);
1422
+ }
1423
+ if ((elm.shape === "oval" || elm.shape === "pill") && typeof elm.outer_width === "number" && typeof elm.outer_height === "number") {
1424
+ const getOuterBounds = elm.shape === "pill" ? getRotatedPillBounds : getRotatedOvalBounds;
1425
+ platedHoleBounds = getOuterBounds(
1426
+ elm.x,
1427
+ elm.y,
1428
+ elm.outer_width,
1429
+ elm.outer_height,
1430
+ elm.ccw_rotation ?? 0
1431
+ );
1432
+ }
1433
+ if ("rect_pad_width" in elm && typeof elm.rect_pad_width === "number" && "rect_pad_height" in elm && typeof elm.rect_pad_height === "number") {
1434
+ const rectBounds = getRotatedRectBounds(
1435
+ elm.x,
1436
+ elm.y,
1437
+ elm.rect_pad_width,
1438
+ elm.rect_pad_height,
1439
+ "rect_ccw_rotation" in elm ? elm.rect_ccw_rotation ?? 0 : 0
1440
+ );
1441
+ platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, rectBounds) : rectBounds;
1442
+ }
1443
+ if ("hole_diameter" in elm && typeof elm.hole_diameter === "number") {
1444
+ const drillBounds = getCircleBounds(
1445
+ elm.x + ("hole_offset_x" in elm ? elm.hole_offset_x ?? 0 : 0),
1446
+ elm.y + ("hole_offset_y" in elm ? elm.hole_offset_y ?? 0 : 0),
1447
+ elm.hole_diameter
1448
+ );
1449
+ platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
1526
1450
  }
1451
+ if (platedHoleBounds) return platedHoleBounds;
1527
1452
  }
1528
- return { minX, minY, maxX, maxY };
1453
+ const elementRecord = elm;
1454
+ const routeBounds = getBoundsFromPoints(getRoutePoints(elementRecord.route));
1455
+ if (routeBounds) return routeBounds;
1456
+ const outlineBounds = getBoundsFromPoints(
1457
+ getRoutePoints(elementRecord.outline)
1458
+ );
1459
+ if (outlineBounds) return outlineBounds;
1460
+ const pointsBounds = getBoundsFromPoints(getRoutePoints(elementRecord.points));
1461
+ if (pointsBounds) return pointsBounds;
1462
+ let centerX;
1463
+ let centerY;
1464
+ let width;
1465
+ let height;
1466
+ if ("x" in elm && "y" in elm) {
1467
+ centerX = Number(elm.x);
1468
+ centerY = Number(elm.y);
1469
+ }
1470
+ if ("outer_diameter" in elm) {
1471
+ width = Number(elm.outer_diameter);
1472
+ height = Number(elm.outer_diameter);
1473
+ }
1474
+ if ("width" in elm) {
1475
+ width = Number(elm.width);
1476
+ }
1477
+ if ("height" in elm) {
1478
+ height = Number(elm.height);
1479
+ }
1480
+ if ("center" in elm && elm.center && typeof elm.center === "object" && "x" in elm.center && "y" in elm.center) {
1481
+ centerX = Number(elm.center.x);
1482
+ centerY = Number(elm.center.y);
1483
+ }
1484
+ let rotation = 0;
1485
+ if ("rotation" in elm && typeof elm.rotation === "number") {
1486
+ rotation = elm.rotation;
1487
+ }
1488
+ if ("ccw_rotation" in elm && typeof elm.ccw_rotation === "number") {
1489
+ rotation = elm.ccw_rotation;
1490
+ }
1491
+ if (centerX !== void 0 && centerY !== void 0) {
1492
+ if (width !== void 0 && height !== void 0) {
1493
+ return rotation ? getRotatedRectBounds(centerX, centerY, width, height, rotation) : {
1494
+ minX: centerX - width / 2,
1495
+ minY: centerY - height / 2,
1496
+ maxX: centerX + width / 2,
1497
+ maxY: centerY + height / 2
1498
+ };
1499
+ }
1500
+ if ("radius" in elm && typeof elm.radius === "number") {
1501
+ return getCircleBounds(centerX, centerY, elm.radius * 2);
1502
+ }
1503
+ return { minX: centerX, minY: centerY, maxX: centerX, maxY: centerY };
1504
+ }
1505
+ const anchoredPoint = [elementRecord.anchor_position, elementRecord.position].filter(
1506
+ (position) => Boolean(
1507
+ position && typeof position === "object" && "x" in position && "y" in position && typeof position.x === "number" && typeof position.y === "number"
1508
+ )
1509
+ ).at(0);
1510
+ return anchoredPoint ? {
1511
+ minX: anchoredPoint.x,
1512
+ minY: anchoredPoint.y,
1513
+ maxX: anchoredPoint.x,
1514
+ maxY: anchoredPoint.y
1515
+ } : null;
1529
1516
  };
1517
+ var getBoundsOfPcbElements = (elements) => {
1518
+ let bounds = {
1519
+ minX: Number.POSITIVE_INFINITY,
1520
+ minY: Number.POSITIVE_INFINITY,
1521
+ maxX: Number.NEGATIVE_INFINITY,
1522
+ maxY: Number.NEGATIVE_INFINITY
1523
+ };
1524
+ for (const element of elements) {
1525
+ const elementBounds = getPcbElementBounds(element);
1526
+ if (elementBounds) bounds = mergeBounds(bounds, elementBounds);
1527
+ }
1528
+ return bounds;
1529
+ };
1530
+ var getPcbElementsWithinBounds = (elements, bounds) => elements.filter((element) => {
1531
+ const elementBounds = getPcbElementBounds(element);
1532
+ if (!elementBounds) return false;
1533
+ return elementBounds.minX <= bounds.maxX && elementBounds.maxX >= bounds.minX && elementBounds.minY <= bounds.maxY && elementBounds.maxY >= bounds.minY;
1534
+ });
1530
1535
 
1531
1536
  // lib/get-board-bounds.ts
1532
1537
  var getBoardBounds = (board) => {
@@ -2772,6 +2777,8 @@ export {
2772
2777
  getElementId,
2773
2778
  getElementRenderLayers,
2774
2779
  getMinimumFlexContainer,
2780
+ getPcbElementBounds,
2781
+ getPcbElementsWithinBounds,
2775
2782
  getPrimaryId,
2776
2783
  getReadableNameForElement,
2777
2784
  getReadableNameForPcbPort,