@tscircuit/pcb-viewer 1.11.234 → 1.11.235
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 +122 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
8696
|
-
|
|
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
|
|
10292
|
+
const distance5 = Math.sqrt(
|
|
10286
10293
|
(point.x - hole.x) ** 2 + (point.y - hole.y) ** 2
|
|
10287
10294
|
);
|
|
10288
|
-
return
|
|
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);
|
|
@@ -11386,6 +11393,9 @@ var ElementOverlayBox = ({
|
|
|
11386
11393
|
)) });
|
|
11387
11394
|
};
|
|
11388
11395
|
|
|
11396
|
+
// src/components/MouseElementTracker.tsx
|
|
11397
|
+
import { distance as distance4 } from "circuit-json";
|
|
11398
|
+
|
|
11389
11399
|
// src/lib/util/if-sets-match-exactly.ts
|
|
11390
11400
|
function ifSetsMatchExactly(set1, set2) {
|
|
11391
11401
|
if (set1.size !== set2.size) return false;
|
|
@@ -11395,16 +11405,16 @@ function ifSetsMatchExactly(set1, set2) {
|
|
|
11395
11405
|
// node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
|
|
11396
11406
|
function pointToSegmentDistance2(p, v, w) {
|
|
11397
11407
|
const l2 = (w.x - v.x) ** 2 + (w.y - v.y) ** 2;
|
|
11398
|
-
if (l2 === 0) return
|
|
11408
|
+
if (l2 === 0) return distance3(p, v);
|
|
11399
11409
|
let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
|
|
11400
11410
|
t = Math.max(0, Math.min(1, t));
|
|
11401
11411
|
const projection = {
|
|
11402
11412
|
x: v.x + t * (w.x - v.x),
|
|
11403
11413
|
y: v.y + t * (w.y - v.y)
|
|
11404
11414
|
};
|
|
11405
|
-
return
|
|
11415
|
+
return distance3(p, projection);
|
|
11406
11416
|
}
|
|
11407
|
-
function
|
|
11417
|
+
function distance3(p1, p2) {
|
|
11408
11418
|
const dx = p1.x - p2.x;
|
|
11409
11419
|
const dy = p1.y - p2.y;
|
|
11410
11420
|
return Math.sqrt(dx * dx + dy * dy);
|
|
@@ -11412,19 +11422,85 @@ function distance2(p1, p2) {
|
|
|
11412
11422
|
|
|
11413
11423
|
// src/components/MouseElementTracker.tsx
|
|
11414
11424
|
import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
11425
|
+
var getPolygonBoundingBox = (points) => {
|
|
11426
|
+
if (points.length === 0) return null;
|
|
11427
|
+
let minX = points[0].x;
|
|
11428
|
+
let minY = points[0].y;
|
|
11429
|
+
let maxX = points[0].x;
|
|
11430
|
+
let maxY = points[0].y;
|
|
11431
|
+
for (const point of points) {
|
|
11432
|
+
if (point.x < minX) minX = point.x;
|
|
11433
|
+
if (point.y < minY) minY = point.y;
|
|
11434
|
+
if (point.x > maxX) maxX = point.x;
|
|
11435
|
+
if (point.y > maxY) maxY = point.y;
|
|
11436
|
+
}
|
|
11437
|
+
return {
|
|
11438
|
+
center: {
|
|
11439
|
+
x: (minX + maxX) / 2,
|
|
11440
|
+
y: (minY + maxY) / 2
|
|
11441
|
+
},
|
|
11442
|
+
width: maxX - minX,
|
|
11443
|
+
height: maxY - minY
|
|
11444
|
+
};
|
|
11445
|
+
};
|
|
11446
|
+
var isPointInsidePolygon = (point, polygon) => {
|
|
11447
|
+
if (polygon.length < 3) return false;
|
|
11448
|
+
let isInside = false;
|
|
11449
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
11450
|
+
const xi = polygon[i].x;
|
|
11451
|
+
const yi = polygon[i].y;
|
|
11452
|
+
const xj = polygon[j].x;
|
|
11453
|
+
const yj = polygon[j].y;
|
|
11454
|
+
const intersects = yi > point.y !== yj > point.y && point.x < (xj - xi) * (point.y - yi) / (yj - yi || Number.EPSILON) + xi;
|
|
11455
|
+
if (intersects) {
|
|
11456
|
+
isInside = !isInside;
|
|
11457
|
+
}
|
|
11458
|
+
}
|
|
11459
|
+
return isInside;
|
|
11460
|
+
};
|
|
11415
11461
|
var getPrimitivesUnderPoint = (primitives, rwPoint, transform) => {
|
|
11416
11462
|
const newMousedPrimitives = [];
|
|
11417
11463
|
for (const primitive of primitives) {
|
|
11418
11464
|
if (!primitive._element) continue;
|
|
11419
11465
|
if ("x1" in primitive && primitive._element?.type === "pcb_trace") {
|
|
11420
|
-
const
|
|
11466
|
+
const distance5 = pointToSegmentDistance2(
|
|
11421
11467
|
{ x: rwPoint.x, y: rwPoint.y },
|
|
11422
11468
|
{ x: primitive.x1, y: primitive.y1 },
|
|
11423
11469
|
{ x: primitive.x2, y: primitive.y2 }
|
|
11424
11470
|
);
|
|
11425
11471
|
const lineWidth = primitive.width || 0.5;
|
|
11426
11472
|
const detectionThreshold = Math.max(lineWidth * 25, 2) / transform.a;
|
|
11427
|
-
if (
|
|
11473
|
+
if (distance5 < detectionThreshold) {
|
|
11474
|
+
newMousedPrimitives.push(primitive);
|
|
11475
|
+
}
|
|
11476
|
+
continue;
|
|
11477
|
+
}
|
|
11478
|
+
if (primitive.pcb_drawing_type === "polygon") {
|
|
11479
|
+
const points = primitive.points.map((point) => ({
|
|
11480
|
+
x: distance4.parse(point.x),
|
|
11481
|
+
y: distance4.parse(point.y)
|
|
11482
|
+
}));
|
|
11483
|
+
const boundingBox = getPolygonBoundingBox(points);
|
|
11484
|
+
if (!boundingBox) continue;
|
|
11485
|
+
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) {
|
|
11486
|
+
continue;
|
|
11487
|
+
}
|
|
11488
|
+
if (isPointInsidePolygon(rwPoint, points)) {
|
|
11489
|
+
newMousedPrimitives.push(primitive);
|
|
11490
|
+
}
|
|
11491
|
+
continue;
|
|
11492
|
+
}
|
|
11493
|
+
if (primitive.pcb_drawing_type === "polygon_with_arcs") {
|
|
11494
|
+
const points = primitive.brep_shape.outer_ring.vertices.map((v) => ({
|
|
11495
|
+
x: distance4.parse(v.x),
|
|
11496
|
+
y: distance4.parse(v.y)
|
|
11497
|
+
}));
|
|
11498
|
+
const boundingBox = getPolygonBoundingBox(points);
|
|
11499
|
+
if (!boundingBox) continue;
|
|
11500
|
+
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) {
|
|
11501
|
+
continue;
|
|
11502
|
+
}
|
|
11503
|
+
if (isPointInsidePolygon(rwPoint, points)) {
|
|
11428
11504
|
newMousedPrimitives.push(primitive);
|
|
11429
11505
|
}
|
|
11430
11506
|
continue;
|
|
@@ -11462,12 +11538,32 @@ var MouseElementTracker = ({
|
|
|
11462
11538
|
if (primitive._element?.type === "pcb_via") continue;
|
|
11463
11539
|
if (primitive._element?.type === "pcb_component") continue;
|
|
11464
11540
|
if (primitive?.layer === "drill") continue;
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
|
|
11468
|
-
)
|
|
11469
|
-
|
|
11470
|
-
|
|
11541
|
+
let basePoint = null;
|
|
11542
|
+
let w = 0;
|
|
11543
|
+
let h = 0;
|
|
11544
|
+
if (primitive.pcb_drawing_type === "polygon") {
|
|
11545
|
+
const boundingBox = getPolygonBoundingBox(primitive.points);
|
|
11546
|
+
if (!boundingBox) continue;
|
|
11547
|
+
basePoint = boundingBox.center;
|
|
11548
|
+
w = boundingBox.width;
|
|
11549
|
+
h = boundingBox.height;
|
|
11550
|
+
} else if (primitive.pcb_drawing_type === "polygon_with_arcs") {
|
|
11551
|
+
const points = primitive.brep_shape.outer_ring.vertices.map((v) => ({
|
|
11552
|
+
x: v.x,
|
|
11553
|
+
y: v.y
|
|
11554
|
+
}));
|
|
11555
|
+
const boundingBox = getPolygonBoundingBox(points);
|
|
11556
|
+
if (!boundingBox) continue;
|
|
11557
|
+
basePoint = boundingBox.center;
|
|
11558
|
+
w = boundingBox.width;
|
|
11559
|
+
h = boundingBox.height;
|
|
11560
|
+
} else if ("x" in primitive && "y" in primitive) {
|
|
11561
|
+
basePoint = { x: primitive.x, y: primitive.y };
|
|
11562
|
+
w = "w" in primitive ? primitive.w : "r" in primitive ? primitive.r * 2 : 0;
|
|
11563
|
+
h = "h" in primitive ? primitive.h : "r" in primitive ? primitive.r * 2 : 0;
|
|
11564
|
+
}
|
|
11565
|
+
if (!basePoint) continue;
|
|
11566
|
+
const screenPos = applyToPoint12(transform, basePoint);
|
|
11471
11567
|
const screenSize = {
|
|
11472
11568
|
w: w * transform.a,
|
|
11473
11569
|
h: h * transform.a
|
|
@@ -11477,6 +11573,10 @@ var MouseElementTracker = ({
|
|
|
11477
11573
|
).length;
|
|
11478
11574
|
highlightedPrimitives2.push({
|
|
11479
11575
|
...primitive,
|
|
11576
|
+
x: basePoint.x,
|
|
11577
|
+
y: basePoint.y,
|
|
11578
|
+
w,
|
|
11579
|
+
h,
|
|
11480
11580
|
screen_x: screenPos.x,
|
|
11481
11581
|
screen_y: screenPos.y,
|
|
11482
11582
|
screen_w: screenSize.w,
|
|
@@ -11820,11 +11920,11 @@ var RatsNestOverlay = ({ transform, soup, children }) => {
|
|
|
11820
11920
|
connectedIds.forEach((id) => {
|
|
11821
11921
|
const pos = getElementPosition(id);
|
|
11822
11922
|
if (pos) {
|
|
11823
|
-
const
|
|
11923
|
+
const distance5 = Math.sqrt(
|
|
11824
11924
|
(sourcePoint.x - pos.x) ** 2 + (sourcePoint.y - pos.y) ** 2
|
|
11825
11925
|
);
|
|
11826
|
-
if (
|
|
11827
|
-
minDistance =
|
|
11926
|
+
if (distance5 < minDistance && distance5 > 0) {
|
|
11927
|
+
minDistance = distance5;
|
|
11828
11928
|
nearestPoint = pos;
|
|
11829
11929
|
}
|
|
11830
11930
|
}
|
|
@@ -11909,7 +12009,7 @@ import { css as css3 } from "@emotion/css";
|
|
|
11909
12009
|
// package.json
|
|
11910
12010
|
var package_default = {
|
|
11911
12011
|
name: "@tscircuit/pcb-viewer",
|
|
11912
|
-
version: "1.11.
|
|
12012
|
+
version: "1.11.234",
|
|
11913
12013
|
main: "dist/index.js",
|
|
11914
12014
|
type: "module",
|
|
11915
12015
|
repository: "tscircuit/pcb-viewer",
|