@tscircuit/circuit-json-util 0.0.120 → 0.0.122

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as circuit_json from 'circuit-json';
2
- import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbPin1Location, Point as Point$2, PcbPlatedHole, PcbCopperPour, PcbSmtPad } from 'circuit-json';
2
+ import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbSolderPasteRect, PcbSolderPasteRotatedRect, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbPin1Location, Point as Point$2, PcbPlatedHole, PcbCopperPour, PcbSmtPad } from 'circuit-json';
3
3
  import * as zod from 'zod';
4
4
  import { Matrix } from 'transformation-matrix';
5
5
  import * as parsel from 'parsel-js';
@@ -12000,19 +12000,6 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
12000
12000
  subcircuit_id?: string | undefined;
12001
12001
  pcb_group_id?: string | undefined;
12002
12002
  pcb_smtpad_id?: string | undefined;
12003
- } | {
12004
- type: "pcb_solder_paste";
12005
- x: number;
12006
- y: number;
12007
- width: number;
12008
- height: number;
12009
- shape: "rect";
12010
- layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
12011
- pcb_solder_paste_id: string;
12012
- pcb_component_id?: string | undefined;
12013
- subcircuit_id?: string | undefined;
12014
- pcb_group_id?: string | undefined;
12015
- pcb_smtpad_id?: string | undefined;
12016
12003
  } | {
12017
12004
  type: "pcb_solder_paste";
12018
12005
  x: number;
@@ -12027,20 +12014,6 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
12027
12014
  subcircuit_id?: string | undefined;
12028
12015
  pcb_group_id?: string | undefined;
12029
12016
  pcb_smtpad_id?: string | undefined;
12030
- } | {
12031
- type: "pcb_solder_paste";
12032
- x: number;
12033
- y: number;
12034
- width: number;
12035
- height: number;
12036
- shape: "rotated_rect";
12037
- ccw_rotation: number;
12038
- layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
12039
- pcb_solder_paste_id: string;
12040
- pcb_component_id?: string | undefined;
12041
- subcircuit_id?: string | undefined;
12042
- pcb_group_id?: string | undefined;
12043
- pcb_smtpad_id?: string | undefined;
12044
12017
  } | {
12045
12018
  type: "pcb_solder_paste";
12046
12019
  x: number;
@@ -15199,7 +15172,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
15199
15172
  simulation_spice_subcircuit_id: string;
15200
15173
  spice_pin_to_source_port_map: Record<string, string>;
15201
15174
  subcircuit_source: string;
15202
- } | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon;
15175
+ } | PcbSolderPasteRect | PcbSolderPasteRotatedRect | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon;
15203
15176
  declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix) => ({
15204
15177
  message: string;
15205
15178
  type: "source_runtime_error";
@@ -16777,19 +16750,6 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16777
16750
  subcircuit_id?: string | undefined;
16778
16751
  pcb_group_id?: string | undefined;
16779
16752
  pcb_smtpad_id?: string | undefined;
16780
- } | {
16781
- type: "pcb_solder_paste";
16782
- x: number;
16783
- y: number;
16784
- width: number;
16785
- height: number;
16786
- shape: "rect";
16787
- layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
16788
- pcb_solder_paste_id: string;
16789
- pcb_component_id?: string | undefined;
16790
- subcircuit_id?: string | undefined;
16791
- pcb_group_id?: string | undefined;
16792
- pcb_smtpad_id?: string | undefined;
16793
16753
  } | {
16794
16754
  type: "pcb_solder_paste";
16795
16755
  x: number;
@@ -16804,20 +16764,6 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
16804
16764
  subcircuit_id?: string | undefined;
16805
16765
  pcb_group_id?: string | undefined;
16806
16766
  pcb_smtpad_id?: string | undefined;
16807
- } | {
16808
- type: "pcb_solder_paste";
16809
- x: number;
16810
- y: number;
16811
- width: number;
16812
- height: number;
16813
- shape: "rotated_rect";
16814
- ccw_rotation: number;
16815
- layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
16816
- pcb_solder_paste_id: string;
16817
- pcb_component_id?: string | undefined;
16818
- subcircuit_id?: string | undefined;
16819
- pcb_group_id?: string | undefined;
16820
- pcb_smtpad_id?: string | undefined;
16821
16767
  } | {
16822
16768
  type: "pcb_solder_paste";
16823
16769
  x: number;
@@ -19976,7 +19922,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
19976
19922
  simulation_spice_subcircuit_id: string;
19977
19923
  spice_pin_to_source_port_map: Record<string, string>;
19978
19924
  subcircuit_source: string;
19979
- } | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon)[];
19925
+ } | PcbSolderPasteRect | PcbSolderPasteRotatedRect | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon)[];
19980
19926
 
19981
19927
  declare const directionToVec: (direction: "up" | "down" | "left" | "right") => {
19982
19928
  x: number;
package/dist/index.js CHANGED
@@ -994,6 +994,31 @@ var transformSchematicElement = (elm, matrix) => {
994
994
  var transformSchematicElements = (elms, matrix) => {
995
995
  return elms.map((elm) => transformSchematicElement(elm, matrix));
996
996
  };
997
+ var getTransformedRectRotation = (rotation, matrix) => {
998
+ const isReflected = matrix.a * matrix.d - matrix.b * matrix.c < 0;
999
+ return decomposeTSR(compose(matrix, rotateDEG(rotation)), false, isReflected).rotation.angle * 180 / Math.PI;
1000
+ };
1001
+ var transformPcbSolderPasteRectangle = (paste, matrix) => {
1002
+ const center = applyToPoint(matrix, { x: paste.x, y: paste.y });
1003
+ paste.x = center.x;
1004
+ paste.y = center.y;
1005
+ const rotation = getTransformedRectRotation(
1006
+ paste.shape === "rotated_rect" ? paste.ccw_rotation : 0,
1007
+ matrix
1008
+ );
1009
+ const quarterTurns = Math.round(rotation / 90);
1010
+ if (Math.abs(rotation - quarterTurns * 90) < 1e-8) {
1011
+ if (Math.abs(quarterTurns) % 2 === 1) {
1012
+ ;
1013
+ [paste.width, paste.height] = [paste.height, paste.width];
1014
+ }
1015
+ Object.assign(paste, { shape: "rect" });
1016
+ Reflect.deleteProperty(paste, "ccw_rotation");
1017
+ } else {
1018
+ Object.assign(paste, { shape: "rotated_rect", ccw_rotation: rotation });
1019
+ }
1020
+ return paste;
1021
+ };
997
1022
  var transformPcbSoldermaskOpening = (opening, matrix) => {
998
1023
  if (opening.shape === "polygon") {
999
1024
  opening.points = opening.points.map((point) => applyToPoint(matrix, point));
@@ -1004,8 +1029,7 @@ var transformPcbSoldermaskOpening = (opening, matrix) => {
1004
1029
  opening.y = center.y;
1005
1030
  if (opening.shape === "circle") return opening;
1006
1031
  const rectRotation = opening.shape === "rotated_rect" ? opening.ccw_rotation : 0;
1007
- const isReflected = matrix.a * matrix.d - matrix.b * matrix.c < 0;
1008
- const transformedRotation = decomposeTSR(compose(matrix, rotateDEG(rectRotation)), false, isReflected).rotation.angle * 180 / Math.PI;
1032
+ const transformedRotation = getTransformedRectRotation(rectRotation, matrix);
1009
1033
  if (Math.abs(transformedRotation) < 1e-8) {
1010
1034
  Object.assign(opening, { shape: "rect" });
1011
1035
  Reflect.deleteProperty(opening, "ccw_rotation");
@@ -1021,6 +1045,9 @@ var transformPCBElement = (elm, matrix) => {
1021
1045
  if (elm.type === "pcb_soldermask_opening") {
1022
1046
  return transformPcbSoldermaskOpening(elm, matrix);
1023
1047
  }
1048
+ if (elm.type === "pcb_solder_paste" && (elm.shape === "rect" || elm.shape === "rotated_rect")) {
1049
+ return transformPcbSolderPasteRectangle(elm, matrix);
1050
+ }
1024
1051
  if ((elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste") && elm.shape === "polygon") {
1025
1052
  elm.points = elm.points.map((point) => applyToPoint(matrix, point));
1026
1053
  if (elm.type === "pcb_solder_paste" && elm.holes) {
@@ -1136,7 +1163,7 @@ var transformPCBElements = (elms, matrix) => {
1136
1163
  let transformedElms = elms.map((elm) => transformPCBElement(elm, matrix));
1137
1164
  if (flipPadWidthHeight) {
1138
1165
  transformedElms = transformedElms.map((elm) => {
1139
- if ((elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste") && (elm.shape === "rect" || elm.shape === "pill")) {
1166
+ if (elm.type === "pcb_smtpad" && (elm.shape === "rect" || elm.shape === "pill") || elm.type === "pcb_solder_paste" && elm.shape === "pill") {
1140
1167
  ;
1141
1168
  [elm.width, elm.height] = [elm.height, elm.width];
1142
1169
  }
@@ -2938,7 +2965,8 @@ import {
2938
2965
  ORIENTATION,
2939
2966
  Point,
2940
2967
  Polygon,
2941
- Segment
2968
+ Segment,
2969
+ Utils
2942
2970
  } from "@flatten-js/core";
2943
2971
  import { compose as compose2, rotate, translate as translate5 } from "transformation-matrix";
2944
2972
  var placePolygon = (polygon, center, degrees = 0) => {
@@ -3100,7 +3128,7 @@ var getTraceSegmentPolygon = (start, end, startWidth, endWidth = startWidth) =>
3100
3128
  const length = Math.hypot(end.x - start.x, end.y - start.y);
3101
3129
  const r1 = startWidth / 2;
3102
3130
  const r2 = endWidth / 2;
3103
- if (length <= Math.abs(r2 - r1))
3131
+ if (Utils.EQ_0(length) || length <= Math.abs(r2 - r1))
3104
3132
  return circlePolygon(r1 >= r2 ? start : end, Math.max(r1, r2));
3105
3133
  const angle = Math.atan2(end.y - start.y, end.x - start.x);
3106
3134
  const tangent = Math.acos((r1 - r2) / length);