@tscircuit/checks 0.0.162 → 0.0.163
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 +9 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -200,6 +200,7 @@ function getDistanceBetweenPoints(pointA, pointB) {
|
|
|
200
200
|
return Math.sqrt((pointB.x - pointA.x) ** 2 + (pointB.y - pointA.y) ** 2);
|
|
201
201
|
}
|
|
202
202
|
var POINT_ON_SEGMENT_TOLERANCE_MM = 1e-9;
|
|
203
|
+
var POINT_IN_PAD_TOLERANCE_MM = 1e-9;
|
|
203
204
|
function isPointOnSegment(point, segment) {
|
|
204
205
|
const crossProduct = (point.y - segment.start.y) * (segment.end.x - segment.start.x) - (point.x - segment.start.x) * (segment.end.y - segment.start.y);
|
|
205
206
|
if (Math.abs(crossProduct) > POINT_ON_SEGMENT_TOLERANCE_MM) return false;
|
|
@@ -222,12 +223,12 @@ function isPointInPolygon(point, polygon) {
|
|
|
222
223
|
function isPointInPad(point, pad) {
|
|
223
224
|
if (pad.type === "pcb_smtpad") {
|
|
224
225
|
if (pad.shape === "circle") {
|
|
225
|
-
return getDistanceBetweenPoints(point, pad) <= pad.radius;
|
|
226
|
+
return getDistanceBetweenPoints(point, pad) <= pad.radius + POINT_IN_PAD_TOLERANCE_MM;
|
|
226
227
|
}
|
|
227
228
|
if (pad.shape === "rect") {
|
|
228
229
|
const halfWidth = pad.width / 2;
|
|
229
230
|
const halfHeight = pad.height / 2;
|
|
230
|
-
return Math.abs(point.x - pad.x) <= halfWidth && Math.abs(point.y - pad.y) <= halfHeight;
|
|
231
|
+
return Math.abs(point.x - pad.x) <= halfWidth + POINT_IN_PAD_TOLERANCE_MM && Math.abs(point.y - pad.y) <= halfHeight + POINT_IN_PAD_TOLERANCE_MM;
|
|
231
232
|
}
|
|
232
233
|
if (pad.shape === "rotated_rect") {
|
|
233
234
|
return isPointInPolygon(point, getPolygonPointsForPad(pad));
|
|
@@ -235,12 +236,12 @@ function isPointInPad(point, pad) {
|
|
|
235
236
|
if (pad.shape === "pill" || pad.shape === "rotated_pill") {
|
|
236
237
|
if (pad.shape === "rotated_pill") {
|
|
237
238
|
const pill2 = getPillCenterLineForPad(pad);
|
|
238
|
-
return pointToSegmentDistance(point, pill2.start, pill2.end) <= pill2.radius;
|
|
239
|
+
return pointToSegmentDistance(point, pill2.start, pill2.end) <= pill2.radius + POINT_IN_PAD_TOLERANCE_MM;
|
|
239
240
|
}
|
|
240
241
|
const halfWidth = pad.width / 2;
|
|
241
242
|
const halfHeight = pad.height / 2;
|
|
242
243
|
const radius = pad.radius;
|
|
243
|
-
if (Math.abs(point.x - pad.x) <= halfWidth - radius && Math.abs(point.y - pad.y) <= halfHeight) {
|
|
244
|
+
if (Math.abs(point.x - pad.x) <= halfWidth - radius + POINT_IN_PAD_TOLERANCE_MM && Math.abs(point.y - pad.y) <= halfHeight + POINT_IN_PAD_TOLERANCE_MM) {
|
|
244
245
|
return true;
|
|
245
246
|
}
|
|
246
247
|
const cornerX = Math.max(
|
|
@@ -251,7 +252,8 @@ function isPointInPad(point, pad) {
|
|
|
251
252
|
Math.abs(point.y - pad.y) - (halfHeight - radius),
|
|
252
253
|
0
|
|
253
254
|
);
|
|
254
|
-
|
|
255
|
+
const radiusWithTolerance = radius + POINT_IN_PAD_TOLERANCE_MM;
|
|
256
|
+
return cornerX * cornerX + cornerY * cornerY <= radiusWithTolerance * radiusWithTolerance;
|
|
255
257
|
}
|
|
256
258
|
if (pad.shape === "polygon") {
|
|
257
259
|
return isPointInPolygon(point, pad.points);
|
|
@@ -259,13 +261,13 @@ function isPointInPad(point, pad) {
|
|
|
259
261
|
}
|
|
260
262
|
if (pad.type === "pcb_plated_hole") {
|
|
261
263
|
if (pad.shape === "circle") {
|
|
262
|
-
return getDistanceBetweenPoints(point, pad) <= pad.outer_diameter / 2;
|
|
264
|
+
return getDistanceBetweenPoints(point, pad) <= pad.outer_diameter / 2 + POINT_IN_PAD_TOLERANCE_MM;
|
|
263
265
|
}
|
|
264
266
|
if ("rect_pad_width" in pad && "rect_pad_height" in pad) {
|
|
265
267
|
return isPointInPolygon(point, getPolygonPointsForPad(pad));
|
|
266
268
|
}
|
|
267
269
|
if (pad.shape === "oval" || pad.shape === "pill") {
|
|
268
|
-
return Math.abs(point.x - pad.x) <= pad.outer_width / 2 && Math.abs(point.y - pad.y) <= pad.outer_height / 2;
|
|
270
|
+
return Math.abs(point.x - pad.x) <= pad.outer_width / 2 + POINT_IN_PAD_TOLERANCE_MM && Math.abs(point.y - pad.y) <= pad.outer_height / 2 + POINT_IN_PAD_TOLERANCE_MM;
|
|
269
271
|
}
|
|
270
272
|
}
|
|
271
273
|
return false;
|