easyeda 0.0.341 → 0.0.342

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/main.cjs CHANGED
@@ -1026,7 +1026,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
1026
1026
  var package_default = {
1027
1027
  name: "easyeda",
1028
1028
  type: "module",
1029
- version: "0.0.340",
1029
+ version: "0.0.341",
1030
1030
  files: [
1031
1031
  "dist"
1032
1032
  ],
@@ -7353,8 +7353,9 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
7353
7353
  }
7354
7354
  const h = Math.sqrt(radius * radius - distance3 * distance3 / 4);
7355
7355
  const angle = Math.atan2(dy, dx);
7356
- const centerX = midX + h * Math.sin(angle) * (sweepFlag ? -1 : 1);
7357
- const centerY = midY - h * Math.cos(angle) * (sweepFlag ? -1 : 1);
7356
+ const centerDirection = (sweepFlag ? -1 : 1) * (largeArcFlag ? -1 : 1);
7357
+ const centerX = midX + h * Math.sin(angle) * centerDirection;
7358
+ const centerY = midY - h * Math.cos(angle) * centerDirection;
7358
7359
  const startAngle = Math.atan2(startY - centerY, startX - centerX);
7359
7360
  let endAngle = Math.atan2(endY - centerY, endX - centerX);
7360
7361
  if (sweepFlag && endAngle > startAngle) {
@@ -7387,6 +7388,71 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
7387
7388
  // lib/utils/easyeda-unit-to-mm.ts
7388
7389
  var mil10ToMm = (value) => value * 10 * 0.0254;
7389
7390
 
7391
+ // lib/utils/get-silkscreen-arc-path.ts
7392
+ var classifySemicircle = (arc, silkscreenTracks) => {
7393
+ const chord = {
7394
+ x: arc.end.x - arc.start.x,
7395
+ y: arc.end.y - arc.start.y
7396
+ };
7397
+ const chordLength = Math.hypot(chord.x, chord.y);
7398
+ const isSemicircle = !arc.largeArc && Math.abs(chordLength - 2 * arc.radiusX) <= Math.max(1e-6, arc.radiusX * 1e-4);
7399
+ if (!isSemicircle) return null;
7400
+ const endpointTolerance = Math.max(0.05, arc.radiusX * 0.02);
7401
+ const isNearEndpoint = (point2) => Math.hypot(point2.x - arc.start.x, point2.y - arc.start.y) <= endpointTolerance || Math.hypot(point2.x - arc.end.x, point2.y - arc.end.y) <= endpointTolerance;
7402
+ let hasConnectedSegment = false;
7403
+ for (const track of silkscreenTracks) {
7404
+ if (track.layer !== arc.layer) continue;
7405
+ for (const [pointIndex, point2] of track.points.entries()) {
7406
+ if (!isNearEndpoint(point2)) continue;
7407
+ const neighbors = [
7408
+ track.points[pointIndex - 1],
7409
+ track.points[pointIndex + 1]
7410
+ ];
7411
+ for (const neighbor of neighbors) {
7412
+ if (!neighbor) continue;
7413
+ hasConnectedSegment = true;
7414
+ const segment = {
7415
+ x: neighbor.x - point2.x,
7416
+ y: neighbor.y - point2.y
7417
+ };
7418
+ const segmentLength = Math.hypot(segment.x, segment.y);
7419
+ if (segmentLength === 0) continue;
7420
+ const normalizedDot = Math.abs(segment.x * chord.x + segment.y * chord.y) / (segmentLength * chordLength);
7421
+ if (normalizedDot < 0.25) return "end_cap";
7422
+ }
7423
+ }
7424
+ }
7425
+ return hasConnectedSegment ? "notch" : null;
7426
+ };
7427
+ var distanceFromRouteMidpoint = (route, point2) => {
7428
+ const midpoint2 = route[Math.floor(route.length / 2)];
7429
+ return Math.hypot(midpoint2.x - point2.x, midpoint2.y - point2.y);
7430
+ };
7431
+ var getSilkscreenArcPath = (arc, footprintCenter, silkscreenTracks) => {
7432
+ const generateArcPath = (sweepFlag2) => generateArcFromSweep(
7433
+ arc.start.x,
7434
+ arc.start.y,
7435
+ arc.end.x,
7436
+ arc.end.y,
7437
+ arc.radiusX,
7438
+ arc.largeArc,
7439
+ sweepFlag2
7440
+ );
7441
+ const sweepFlag = arc.sweepDirection === "CW";
7442
+ const arcPath = generateArcPath(sweepFlag);
7443
+ const semicircleRole = classifySemicircle(arc, silkscreenTracks);
7444
+ if (!semicircleRole) return arcPath;
7445
+ const oppositeArcPath = generateArcPath(!sweepFlag);
7446
+ const arcDistance = distanceFromRouteMidpoint(arcPath, footprintCenter);
7447
+ const oppositeDistance = distanceFromRouteMidpoint(
7448
+ oppositeArcPath,
7449
+ footprintCenter
7450
+ );
7451
+ const originalArcIsInward = arcDistance <= oppositeDistance;
7452
+ const shouldBowInward = semicircleRole === "notch";
7453
+ return originalArcIsInward === shouldBowInward ? arcPath : oppositeArcPath;
7454
+ };
7455
+
7390
7456
  // lib/utils/get-polarized-pin-metadata.ts
7391
7457
  var getPinLabelValues = (labels) => {
7392
7458
  if (typeof labels === "string") return [labels];
@@ -7849,16 +7915,8 @@ var getSideFromLayer = (layer) => {
7849
7915
  if (layer === 4 || layer === 14) return "bottom";
7850
7916
  return "top";
7851
7917
  };
7852
- var handleSilkscreenArc = (arc, index) => {
7853
- const arcPath = generateArcFromSweep(
7854
- arc.start.x,
7855
- arc.start.y,
7856
- arc.end.x,
7857
- arc.end.y,
7858
- arc.radiusX,
7859
- arc.largeArc,
7860
- arc.sweepDirection === "CW"
7861
- );
7918
+ var handleSilkscreenArc = (arc, index, footprintCenter, silkscreenTracks) => {
7919
+ const arcPath = getSilkscreenArcPath(arc, footprintCenter, silkscreenTracks);
7862
7920
  return pcb_silkscreen_path.parse({
7863
7921
  type: "pcb_silkscreen_path",
7864
7922
  pcb_silkscreen_path_id: `pcb_silkscreen_arc_${index + 1}`,
@@ -8208,6 +8266,9 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
8208
8266
  circuitElements.push(handleCutout(sr, index));
8209
8267
  });
8210
8268
  let hasFoundDesignator = false;
8269
+ const silkscreenTracks = easyEdaJson.packageDetail.dataStr.shape.filter(
8270
+ (shape) => shape.type === "TRACK" && isSilkscreenLayer(shape.layer)
8271
+ );
8211
8272
  easyEdaJson.packageDetail.dataStr.shape.forEach((shape, index) => {
8212
8273
  if (shape.type === "TRACK") {
8213
8274
  if (isSilkscreenLayer(shape.layer)) {
@@ -8226,7 +8287,14 @@ var convertEasyEdaJsonToCircuitJson = (easyEdaJson, {
8226
8287
  circuitElements.push(handleRect(shape, index));
8227
8288
  } else if (shape.type === "ARC") {
8228
8289
  if (!isCourtyardLayer(shape.layer)) {
8229
- circuitElements.push(handleSilkscreenArc(shape, index));
8290
+ circuitElements.push(
8291
+ handleSilkscreenArc(
8292
+ shape,
8293
+ index,
8294
+ easyEdaJson.packageDetail.dataStr.head,
8295
+ silkscreenTracks
8296
+ )
8297
+ );
8230
8298
  }
8231
8299
  } else if (shape.type === "TEXT") {
8232
8300
  if (isCourtyardLayer(shape.layer)) return;