@tscircuit/pcb-viewer 1.11.234 → 1.11.236

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
@@ -7043,8 +7043,13 @@ function getExpandedStroke(strokeInput, defaultWidth) {
7043
7043
  }
7044
7044
 
7045
7045
  // src/lib/convert-element-to-primitive.ts
7046
+ import { distance as distance2 } from "circuit-json";
7046
7047
  var globalPcbDrawingObjectCount = 0;
7047
7048
  var getNewPcbDrawingObjectId = (prefix) => `${prefix}_${globalPcbDrawingObjectCount++}`;
7049
+ var normalizePolygonPoints = (points) => (points ?? []).map((point) => ({
7050
+ x: distance2.parse(point.x),
7051
+ y: distance2.parse(point.y)
7052
+ }));
7048
7053
  var convertElementToPrimitives = (element, allElements) => {
7049
7054
  const _parent_pcb_component = "pcb_component_id" in element ? allElements.find(
7050
7055
  (elm) => elm.type === "pcb_component" && elm.pcb_component_id === element.pcb_component_id
@@ -7174,7 +7179,7 @@ var convertElementToPrimitives = (element, allElements) => {
7174
7179
  {
7175
7180
  _pcb_drawing_object_id: `polygon_${globalPcbDrawingObjectCount++}`,
7176
7181
  pcb_drawing_type: "polygon",
7177
- points,
7182
+ points: normalizePolygonPoints(points),
7178
7183
  layer: layer || "top",
7179
7184
  _element: element,
7180
7185
  _parent_pcb_component,
@@ -7724,7 +7729,7 @@ var convertElementToPrimitives = (element, allElements) => {
7724
7729
  "pcb_copper_pour_polygon"
7725
7730
  ),
7726
7731
  pcb_drawing_type: "polygon",
7727
- points,
7732
+ points: normalizePolygonPoints(points),
7728
7733
  layer,
7729
7734
  _element: element
7730
7735
  }
@@ -7925,7 +7930,7 @@ var convertElementToPrimitives = (element, allElements) => {
7925
7930
  {
7926
7931
  _pcb_drawing_object_id: getNewPcbDrawingObjectId("pcb_cutout_polygon"),
7927
7932
  pcb_drawing_type: "polygon",
7928
- points: cutoutElement.points,
7933
+ points: normalizePolygonPoints(cutoutElement.points),
7929
7934
  layer: "drill",
7930
7935
  _element: element,
7931
7936
  _parent_pcb_component,
@@ -8692,8 +8697,10 @@ var Drawer = class {
8692
8697
  ctx.closePath();
8693
8698
  ctx.fill("evenodd");
8694
8699
  const lineWidth = scaleOnly(this.transform, this.aperture.size);
8695
- ctx.lineWidth = lineWidth;
8696
- ctx.stroke();
8700
+ if (lineWidth > 0) {
8701
+ ctx.lineWidth = lineWidth;
8702
+ ctx.stroke();
8703
+ }
8697
8704
  }
8698
8705
  /* NOTE: This is not gerber compatible */
8699
8706
  debugText(text, x, y) {
@@ -10282,10 +10289,10 @@ var isInsideOfSmtpad = (elm, point, padding = 0) => {
10282
10289
  };
10283
10290
  var isInsideOfPlatedHole = (hole, point, padding = 0) => {
10284
10291
  if (hole.shape === "circle") {
10285
- const distance3 = Math.sqrt(
10292
+ const distance5 = Math.sqrt(
10286
10293
  (point.x - hole.x) ** 2 + (point.y - hole.y) ** 2
10287
10294
  );
10288
- return distance3 <= hole.outer_diameter / 2 + padding;
10295
+ return distance5 <= hole.outer_diameter / 2 + padding;
10289
10296
  } else if (hole.shape === "circular_hole_with_rect_pad") {
10290
10297
  const dx = Math.abs(point.x - hole.x);
10291
10298
  const dy = Math.abs(point.y - hole.y);
@@ -11297,6 +11304,10 @@ var HighlightedPrimitiveBoxWithText = ({
11297
11304
  }
11298
11305
  );
11299
11306
  }
11307
+ const label = getTextForHighlightedPrimitive(primitive);
11308
+ if (label.trim().length === 0) {
11309
+ return null;
11310
+ }
11300
11311
  return /* @__PURE__ */ jsx11(
11301
11312
  "div",
11302
11313
  {
@@ -11348,7 +11359,7 @@ var HighlightedPrimitiveBoxWithText = ({
11348
11359
  minWidth: "45px",
11349
11360
  textAlign: "center"
11350
11361
  },
11351
- children: getTextForHighlightedPrimitive(primitive)
11362
+ children: label
11352
11363
  }
11353
11364
  )
11354
11365
  }
@@ -11386,6 +11397,9 @@ var ElementOverlayBox = ({
11386
11397
  )) });
11387
11398
  };
11388
11399
 
11400
+ // src/components/MouseElementTracker.tsx
11401
+ import { distance as distance4 } from "circuit-json";
11402
+
11389
11403
  // src/lib/util/if-sets-match-exactly.ts
11390
11404
  function ifSetsMatchExactly(set1, set2) {
11391
11405
  if (set1.size !== set2.size) return false;
@@ -11395,16 +11409,16 @@ function ifSetsMatchExactly(set1, set2) {
11395
11409
  // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
11396
11410
  function pointToSegmentDistance2(p, v, w) {
11397
11411
  const l2 = (w.x - v.x) ** 2 + (w.y - v.y) ** 2;
11398
- if (l2 === 0) return distance2(p, v);
11412
+ if (l2 === 0) return distance3(p, v);
11399
11413
  let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
11400
11414
  t = Math.max(0, Math.min(1, t));
11401
11415
  const projection = {
11402
11416
  x: v.x + t * (w.x - v.x),
11403
11417
  y: v.y + t * (w.y - v.y)
11404
11418
  };
11405
- return distance2(p, projection);
11419
+ return distance3(p, projection);
11406
11420
  }
11407
- function distance2(p1, p2) {
11421
+ function distance3(p1, p2) {
11408
11422
  const dx = p1.x - p2.x;
11409
11423
  const dy = p1.y - p2.y;
11410
11424
  return Math.sqrt(dx * dx + dy * dy);
@@ -11412,19 +11426,85 @@ function distance2(p1, p2) {
11412
11426
 
11413
11427
  // src/components/MouseElementTracker.tsx
11414
11428
  import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
11429
+ var getPolygonBoundingBox = (points) => {
11430
+ if (points.length === 0) return null;
11431
+ let minX = points[0].x;
11432
+ let minY = points[0].y;
11433
+ let maxX = points[0].x;
11434
+ let maxY = points[0].y;
11435
+ for (const point of points) {
11436
+ if (point.x < minX) minX = point.x;
11437
+ if (point.y < minY) minY = point.y;
11438
+ if (point.x > maxX) maxX = point.x;
11439
+ if (point.y > maxY) maxY = point.y;
11440
+ }
11441
+ return {
11442
+ center: {
11443
+ x: (minX + maxX) / 2,
11444
+ y: (minY + maxY) / 2
11445
+ },
11446
+ width: maxX - minX,
11447
+ height: maxY - minY
11448
+ };
11449
+ };
11450
+ var isPointInsidePolygon = (point, polygon) => {
11451
+ if (polygon.length < 3) return false;
11452
+ let isInside = false;
11453
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
11454
+ const xi = polygon[i].x;
11455
+ const yi = polygon[i].y;
11456
+ const xj = polygon[j].x;
11457
+ const yj = polygon[j].y;
11458
+ const intersects = yi > point.y !== yj > point.y && point.x < (xj - xi) * (point.y - yi) / (yj - yi || Number.EPSILON) + xi;
11459
+ if (intersects) {
11460
+ isInside = !isInside;
11461
+ }
11462
+ }
11463
+ return isInside;
11464
+ };
11415
11465
  var getPrimitivesUnderPoint = (primitives, rwPoint, transform) => {
11416
11466
  const newMousedPrimitives = [];
11417
11467
  for (const primitive of primitives) {
11418
11468
  if (!primitive._element) continue;
11419
11469
  if ("x1" in primitive && primitive._element?.type === "pcb_trace") {
11420
- const distance3 = pointToSegmentDistance2(
11470
+ const distance5 = pointToSegmentDistance2(
11421
11471
  { x: rwPoint.x, y: rwPoint.y },
11422
11472
  { x: primitive.x1, y: primitive.y1 },
11423
11473
  { x: primitive.x2, y: primitive.y2 }
11424
11474
  );
11425
11475
  const lineWidth = primitive.width || 0.5;
11426
11476
  const detectionThreshold = Math.max(lineWidth * 25, 2) / transform.a;
11427
- if (distance3 < detectionThreshold) {
11477
+ if (distance5 < detectionThreshold) {
11478
+ newMousedPrimitives.push(primitive);
11479
+ }
11480
+ continue;
11481
+ }
11482
+ if (primitive.pcb_drawing_type === "polygon") {
11483
+ const points = primitive.points.map((point) => ({
11484
+ x: distance4.parse(point.x),
11485
+ y: distance4.parse(point.y)
11486
+ }));
11487
+ const boundingBox = getPolygonBoundingBox(points);
11488
+ if (!boundingBox) continue;
11489
+ if (rwPoint.x < boundingBox.center.x - boundingBox.width / 2 || rwPoint.x > boundingBox.center.x + boundingBox.width / 2 || rwPoint.y < boundingBox.center.y - boundingBox.height / 2 || rwPoint.y > boundingBox.center.y + boundingBox.height / 2) {
11490
+ continue;
11491
+ }
11492
+ if (isPointInsidePolygon(rwPoint, points)) {
11493
+ newMousedPrimitives.push(primitive);
11494
+ }
11495
+ continue;
11496
+ }
11497
+ if (primitive.pcb_drawing_type === "polygon_with_arcs") {
11498
+ const points = primitive.brep_shape.outer_ring.vertices.map((v) => ({
11499
+ x: distance4.parse(v.x),
11500
+ y: distance4.parse(v.y)
11501
+ }));
11502
+ const boundingBox = getPolygonBoundingBox(points);
11503
+ if (!boundingBox) continue;
11504
+ if (rwPoint.x < boundingBox.center.x - boundingBox.width / 2 || rwPoint.x > boundingBox.center.x + boundingBox.width / 2 || rwPoint.y < boundingBox.center.y - boundingBox.height / 2 || rwPoint.y > boundingBox.center.y + boundingBox.height / 2) {
11505
+ continue;
11506
+ }
11507
+ if (isPointInsidePolygon(rwPoint, points)) {
11428
11508
  newMousedPrimitives.push(primitive);
11429
11509
  }
11430
11510
  continue;
@@ -11462,12 +11542,32 @@ var MouseElementTracker = ({
11462
11542
  if (primitive._element?.type === "pcb_via") continue;
11463
11543
  if (primitive._element?.type === "pcb_component") continue;
11464
11544
  if (primitive?.layer === "drill") continue;
11465
- const screenPos = applyToPoint12(
11466
- transform,
11467
- primitive
11468
- );
11469
- const w = "w" in primitive ? primitive.w : "r" in primitive ? primitive.r * 2 : 0;
11470
- const h = "h" in primitive ? primitive.h : "r" in primitive ? primitive.r * 2 : 0;
11545
+ let basePoint = null;
11546
+ let w = 0;
11547
+ let h = 0;
11548
+ if (primitive.pcb_drawing_type === "polygon") {
11549
+ const boundingBox = getPolygonBoundingBox(primitive.points);
11550
+ if (!boundingBox) continue;
11551
+ basePoint = boundingBox.center;
11552
+ w = boundingBox.width;
11553
+ h = boundingBox.height;
11554
+ } else if (primitive.pcb_drawing_type === "polygon_with_arcs") {
11555
+ const points = primitive.brep_shape.outer_ring.vertices.map((v) => ({
11556
+ x: v.x,
11557
+ y: v.y
11558
+ }));
11559
+ const boundingBox = getPolygonBoundingBox(points);
11560
+ if (!boundingBox) continue;
11561
+ basePoint = boundingBox.center;
11562
+ w = boundingBox.width;
11563
+ h = boundingBox.height;
11564
+ } else if ("x" in primitive && "y" in primitive) {
11565
+ basePoint = { x: primitive.x, y: primitive.y };
11566
+ w = "w" in primitive ? primitive.w : "r" in primitive ? primitive.r * 2 : 0;
11567
+ h = "h" in primitive ? primitive.h : "r" in primitive ? primitive.r * 2 : 0;
11568
+ }
11569
+ if (!basePoint) continue;
11570
+ const screenPos = applyToPoint12(transform, basePoint);
11471
11571
  const screenSize = {
11472
11572
  w: w * transform.a,
11473
11573
  h: h * transform.a
@@ -11477,6 +11577,10 @@ var MouseElementTracker = ({
11477
11577
  ).length;
11478
11578
  highlightedPrimitives2.push({
11479
11579
  ...primitive,
11580
+ x: basePoint.x,
11581
+ y: basePoint.y,
11582
+ w,
11583
+ h,
11480
11584
  screen_x: screenPos.x,
11481
11585
  screen_y: screenPos.y,
11482
11586
  screen_w: screenSize.w,
@@ -11820,11 +11924,11 @@ var RatsNestOverlay = ({ transform, soup, children }) => {
11820
11924
  connectedIds.forEach((id) => {
11821
11925
  const pos = getElementPosition(id);
11822
11926
  if (pos) {
11823
- const distance3 = Math.sqrt(
11927
+ const distance5 = Math.sqrt(
11824
11928
  (sourcePoint.x - pos.x) ** 2 + (sourcePoint.y - pos.y) ** 2
11825
11929
  );
11826
- if (distance3 < minDistance && distance3 > 0) {
11827
- minDistance = distance3;
11930
+ if (distance5 < minDistance && distance5 > 0) {
11931
+ minDistance = distance5;
11828
11932
  nearestPoint = pos;
11829
11933
  }
11830
11934
  }
@@ -11909,7 +12013,7 @@ import { css as css3 } from "@emotion/css";
11909
12013
  // package.json
11910
12014
  var package_default = {
11911
12015
  name: "@tscircuit/pcb-viewer",
11912
- version: "1.11.233",
12016
+ version: "1.11.235",
11913
12017
  main: "dist/index.js",
11914
12018
  type: "module",
11915
12019
  repository: "tscircuit/pcb-viewer",