@tscircuit/circuit-json-util 0.0.117 → 0.0.119

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
@@ -831,7 +831,12 @@ cjuIndexed.unparsed = cjuIndexed;
831
831
  var cju_indexed_default = cjuIndexed;
832
832
 
833
833
  // lib/transform-soup-elements.ts
834
- import { applyToPoint, decomposeTSR } from "transformation-matrix";
834
+ import {
835
+ applyToPoint,
836
+ compose,
837
+ decomposeTSR,
838
+ rotateDEG
839
+ } from "transformation-matrix";
835
840
 
836
841
  // lib/direction-to-vec.ts
837
842
  var directionToVec = (direction) => {
@@ -989,27 +994,55 @@ var transformSchematicElement = (elm, matrix) => {
989
994
  var transformSchematicElements = (elms, matrix) => {
990
995
  return elms.map((elm) => transformSchematicElement(elm, matrix));
991
996
  };
997
+ var transformPcbSoldermaskOpening = (opening, matrix) => {
998
+ if (opening.shape === "polygon") {
999
+ opening.points = opening.points.map((point) => applyToPoint(matrix, point));
1000
+ return opening;
1001
+ }
1002
+ const center = applyToPoint(matrix, { x: opening.x, y: opening.y });
1003
+ opening.x = center.x;
1004
+ opening.y = center.y;
1005
+ if (opening.shape === "circle") return opening;
1006
+ 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;
1009
+ if (Math.abs(transformedRotation) < 1e-8) {
1010
+ Object.assign(opening, { shape: "rect" });
1011
+ Reflect.deleteProperty(opening, "ccw_rotation");
1012
+ } else {
1013
+ Object.assign(opening, {
1014
+ shape: "rotated_rect",
1015
+ ccw_rotation: transformedRotation
1016
+ });
1017
+ }
1018
+ return opening;
1019
+ };
992
1020
  var transformPCBElement = (elm, matrix) => {
1021
+ if (elm.type === "pcb_soldermask_opening") {
1022
+ return transformPcbSoldermaskOpening(elm, matrix);
1023
+ }
1024
+ if ((elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste") && elm.shape === "polygon") {
1025
+ elm.points = elm.points.map((point) => applyToPoint(matrix, point));
1026
+ if (elm.type === "pcb_solder_paste" && elm.holes) {
1027
+ elm.holes = elm.holes.map(
1028
+ (hole) => hole.map((point) => applyToPoint(matrix, point))
1029
+ );
1030
+ }
1031
+ return elm;
1032
+ }
993
1033
  const tsr = decomposeTSR(matrix);
994
1034
  const flipPadWidthHeight = Math.abs(getQuarterTurns(tsr.rotation.angle)) % 2 === 1;
995
1035
  const rotationDegrees = tsr.rotation.angle / Math.PI * 180;
996
1036
  const isFlipped = tsr.scale.sy < 0;
997
1037
  if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste" || elm.type === "pcb_port") {
998
1038
  const { x, y } = applyToPoint(matrix, {
999
- x: Number(elm.x),
1000
- y: Number(elm.y)
1039
+ x: elm.x,
1040
+ y: elm.y
1001
1041
  });
1002
1042
  elm.x = x;
1003
1043
  elm.y = y;
1004
- if (elm.type === "pcb_smtpad" && elm.shape === "polygon" && Array.isArray(elm.points)) {
1005
- elm.points = elm.points.map((point) => {
1006
- const tp = applyToPoint(matrix, { x: point.x, y: point.y });
1007
- return {
1008
- x: tp.x,
1009
- y: tp.y
1010
- };
1011
- });
1012
- }
1044
+ } else if (elm.type === "pcb_keepout" && elm.shape === "outline") {
1045
+ elm.outline = elm.outline.map((point) => applyToPoint(matrix, point));
1013
1046
  } else if (elm.type === "pcb_keepout" || elm.type === "pcb_board") {
1014
1047
  elm.center = applyToPoint(matrix, elm.center);
1015
1048
  } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text" || elm.type === "pcb_note_text") {
@@ -2907,9 +2940,9 @@ import {
2907
2940
  Polygon,
2908
2941
  Segment
2909
2942
  } from "@flatten-js/core";
2910
- import { compose, rotate, translate as translate5 } from "transformation-matrix";
2943
+ import { compose as compose2, rotate, translate as translate5 } from "transformation-matrix";
2911
2944
  var placePolygon = (polygon, center, degrees = 0) => {
2912
- const { a, b, c, d, e, f } = compose(
2945
+ const { a, b, c, d, e, f } = compose2(
2913
2946
  translate5(center.x, center.y),
2914
2947
  rotate(degrees * Math.PI / 180)
2915
2948
  );