@tscircuit/core 0.0.1194 → 0.0.1195

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.
Files changed (2) hide show
  1. package/dist/index.js +133 -35
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2784,6 +2784,19 @@ var getObstaclesFromCircuitJson = (soup, connMap) => {
2784
2784
  connectedTo: withNetId([element.pcb_smtpad_id])
2785
2785
  });
2786
2786
  }
2787
+ } else if (element.shape === "pill" || element.shape === "rotated_pill") {
2788
+ obstacles.push({
2789
+ type: "rect",
2790
+ layers: [element.layer],
2791
+ center: {
2792
+ x: element.x,
2793
+ y: element.y
2794
+ },
2795
+ width: element.width,
2796
+ height: element.height,
2797
+ ...element.shape === "rotated_pill" ? { ccwRotationDegrees: element.ccw_rotation } : {},
2798
+ connectedTo: withNetId([element.pcb_smtpad_id])
2799
+ });
2787
2800
  }
2788
2801
  } else if (element.type === "pcb_keepout") {
2789
2802
  if (element.shape === "circle") {
@@ -2871,6 +2884,19 @@ var getObstaclesFromCircuitJson = (soup, connMap) => {
2871
2884
  height: element.hole_height,
2872
2885
  connectedTo: []
2873
2886
  });
2887
+ } else if (element.hole_shape === "pill" || element.hole_shape === "rotated_pill") {
2888
+ obstacles.push({
2889
+ type: "rect",
2890
+ layers: EVERY_LAYER,
2891
+ center: {
2892
+ x: element.x,
2893
+ y: element.y
2894
+ },
2895
+ width: element.hole_width,
2896
+ height: element.hole_height,
2897
+ ...element.hole_shape === "rotated_pill" ? { ccwRotationDegrees: element.ccw_rotation } : {},
2898
+ connectedTo: []
2899
+ });
2874
2900
  } else if (element.hole_shape === "rect") {
2875
2901
  obstacles.push({
2876
2902
  type: "rect",
@@ -2938,7 +2964,7 @@ var getObstaclesFromCircuitJson = (soup, connMap) => {
2938
2964
  height: element.rect_pad_height,
2939
2965
  connectedTo: withNetId([element.pcb_plated_hole_id])
2940
2966
  });
2941
- } else if (element.shape === "oval" || element.shape === "pill") {
2967
+ } else if (element.shape === "oval") {
2942
2968
  obstacles.push({
2943
2969
  // @ts-ignore
2944
2970
  type: "oval",
@@ -2951,6 +2977,19 @@ var getObstaclesFromCircuitJson = (soup, connMap) => {
2951
2977
  height: element.outer_height,
2952
2978
  connectedTo: withNetId([element.pcb_plated_hole_id])
2953
2979
  });
2980
+ } else if (element.shape === "pill") {
2981
+ obstacles.push({
2982
+ type: "rect",
2983
+ layers: EVERY_LAYER,
2984
+ center: {
2985
+ x: element.x,
2986
+ y: element.y
2987
+ },
2988
+ width: element.outer_width,
2989
+ height: element.outer_height,
2990
+ ccwRotationDegrees: element.ccw_rotation,
2991
+ connectedTo: withNetId([element.pcb_plated_hole_id])
2992
+ });
2954
2993
  } else if (element.shape === "hole_with_polygon_pad") {
2955
2994
  if ("pad_outline" in element && element.pad_outline && element.pad_outline.length > 0) {
2956
2995
  const xs = element.pad_outline.map((p) => element.x + p.x);
@@ -7719,6 +7758,29 @@ import {
7719
7758
  distance as distance5
7720
7759
  } from "circuit-json";
7721
7760
  import { applyToPoint as applyToPoint15, decomposeTSR as decomposeTSR6 } from "transformation-matrix";
7761
+
7762
+ // lib/utils/pcb/get-axis-aligned-size-from-rotated-rect.ts
7763
+ function getAxisAlignedSizeFromRotatedRect({
7764
+ width,
7765
+ height,
7766
+ ccwRotationDegrees
7767
+ }) {
7768
+ const angleRad = ccwRotationDegrees * Math.PI / 180;
7769
+ const cosAngle = Math.cos(angleRad);
7770
+ const sinAngle = Math.sin(angleRad);
7771
+ const w2 = width / 2;
7772
+ const h2 = height / 2;
7773
+ const xExtent = Math.abs(w2 * cosAngle) + Math.abs(h2 * sinAngle);
7774
+ const yExtent = Math.abs(w2 * sinAngle) + Math.abs(h2 * cosAngle);
7775
+ return {
7776
+ width: xExtent * 2,
7777
+ height: yExtent * 2,
7778
+ xExtent,
7779
+ yExtent
7780
+ };
7781
+ }
7782
+
7783
+ // lib/components/primitive-components/SmtPad.ts
7722
7784
  var SmtPad = class extends PrimitiveComponent2 {
7723
7785
  pcb_smtpad_id = null;
7724
7786
  matchedPort = null;
@@ -7738,12 +7800,11 @@ var SmtPad = class extends PrimitiveComponent2 {
7738
7800
  return { width: props.width, height: props.height };
7739
7801
  }
7740
7802
  if (props.shape === "rotated_rect") {
7741
- const rotationDegrees = props.ccwRotation ?? 0;
7742
- const angleRad = rotationDegrees * Math.PI / 180;
7743
- const cosAngle = Math.cos(angleRad);
7744
- const sinAngle = Math.sin(angleRad);
7745
- const width = Math.abs(props.width * cosAngle) + Math.abs(props.height * sinAngle);
7746
- const height = Math.abs(props.width * sinAngle) + Math.abs(props.height * cosAngle);
7803
+ const { width, height } = getAxisAlignedSizeFromRotatedRect({
7804
+ width: props.width,
7805
+ height: props.height,
7806
+ ccwRotationDegrees: props.ccwRotation ?? 0
7807
+ });
7747
7808
  return { width, height };
7748
7809
  }
7749
7810
  if (props.shape === "polygon") {
@@ -7962,23 +8023,44 @@ var SmtPad = class extends PrimitiveComponent2 {
7962
8023
  pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
7963
8024
  });
7964
8025
  } else if (props.shape === "pill") {
7965
- pcb_smtpad = db.pcb_smtpad.insert({
7966
- pcb_component_id,
7967
- pcb_port_id: this.matchedPort?.pcb_port_id,
7968
- // port likely isn't matched
7969
- layer: maybeFlipLayer(props.layer ?? "top"),
7970
- shape: "pill",
7971
- x: position.x,
7972
- y: position.y,
7973
- radius: props.radius,
7974
- height: props.height,
7975
- width: props.width,
7976
- port_hints: portHints,
7977
- is_covered_with_solder_mask: isCoveredWithSolderMask,
7978
- soldermask_margin: soldermaskMargin,
7979
- subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
7980
- pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
7981
- });
8026
+ if (finalRotationDegrees !== 0) {
8027
+ pcb_smtpad = db.pcb_smtpad.insert({
8028
+ pcb_component_id,
8029
+ pcb_port_id: this.matchedPort?.pcb_port_id,
8030
+ // port likely isn't matched
8031
+ layer: maybeFlipLayer(props.layer ?? "top"),
8032
+ shape: "rotated_pill",
8033
+ x: position.x,
8034
+ y: position.y,
8035
+ radius: props.radius,
8036
+ height: props.height,
8037
+ width: props.width,
8038
+ ccw_rotation: finalRotationDegrees,
8039
+ port_hints: portHints,
8040
+ is_covered_with_solder_mask: isCoveredWithSolderMask,
8041
+ soldermask_margin: soldermaskMargin,
8042
+ subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
8043
+ pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
8044
+ });
8045
+ } else {
8046
+ pcb_smtpad = db.pcb_smtpad.insert({
8047
+ pcb_component_id,
8048
+ pcb_port_id: this.matchedPort?.pcb_port_id,
8049
+ // port likely isn't matched
8050
+ layer: maybeFlipLayer(props.layer ?? "top"),
8051
+ shape: "pill",
8052
+ x: position.x,
8053
+ y: position.y,
8054
+ radius: props.radius,
8055
+ height: props.height,
8056
+ width: props.width,
8057
+ port_hints: portHints,
8058
+ is_covered_with_solder_mask: isCoveredWithSolderMask,
8059
+ soldermask_margin: soldermaskMargin,
8060
+ subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
8061
+ pcb_group_id: this.getGroup()?.pcb_group_id ?? void 0
8062
+ });
8063
+ }
7982
8064
  }
7983
8065
  if (pcb_smtpad) {
7984
8066
  this.pcb_smtpad_id = pcb_smtpad.pcb_smtpad_id;
@@ -8008,13 +8090,11 @@ var SmtPad = class extends PrimitiveComponent2 {
8008
8090
  };
8009
8091
  }
8010
8092
  if (smtpad.shape === "rotated_rect") {
8011
- const angleRad = smtpad.ccw_rotation * Math.PI / 180;
8012
- const cosAngle = Math.cos(angleRad);
8013
- const sinAngle = Math.sin(angleRad);
8014
- const w2 = smtpad.width / 2;
8015
- const h2 = smtpad.height / 2;
8016
- const xExtent = Math.abs(w2 * cosAngle) + Math.abs(h2 * sinAngle);
8017
- const yExtent = Math.abs(w2 * sinAngle) + Math.abs(h2 * cosAngle);
8093
+ const { width, height, xExtent, yExtent } = getAxisAlignedSizeFromRotatedRect({
8094
+ width: smtpad.width,
8095
+ height: smtpad.height,
8096
+ ccwRotationDegrees: smtpad.ccw_rotation
8097
+ });
8018
8098
  return {
8019
8099
  center: { x: smtpad.x, y: smtpad.y },
8020
8100
  bounds: {
@@ -8023,8 +8103,8 @@ var SmtPad = class extends PrimitiveComponent2 {
8023
8103
  top: smtpad.y - yExtent,
8024
8104
  bottom: smtpad.y + yExtent
8025
8105
  },
8026
- width: xExtent * 2,
8027
- height: yExtent * 2
8106
+ width,
8107
+ height
8028
8108
  };
8029
8109
  }
8030
8110
  if (smtpad.shape === "circle") {
@@ -8075,6 +8155,24 @@ var SmtPad = class extends PrimitiveComponent2 {
8075
8155
  height: smtpad.height
8076
8156
  };
8077
8157
  }
8158
+ if (smtpad.shape === "rotated_pill") {
8159
+ const { width, height, xExtent, yExtent } = getAxisAlignedSizeFromRotatedRect({
8160
+ width: smtpad.width,
8161
+ height: smtpad.height,
8162
+ ccwRotationDegrees: smtpad.ccw_rotation
8163
+ });
8164
+ return {
8165
+ center: { x: smtpad.x, y: smtpad.y },
8166
+ bounds: {
8167
+ left: smtpad.x - xExtent,
8168
+ right: smtpad.x + xExtent,
8169
+ top: smtpad.y - yExtent,
8170
+ bottom: smtpad.y + yExtent
8171
+ },
8172
+ width,
8173
+ height
8174
+ };
8175
+ }
8078
8176
  throw new Error(
8079
8177
  `circuitJson bounds calculation not implemented for shape "${smtpad.shape}"`
8080
8178
  );
@@ -8102,7 +8200,7 @@ var SmtPad = class extends PrimitiveComponent2 {
8102
8200
  const { db } = this.root;
8103
8201
  if (!this.pcb_smtpad_id) return;
8104
8202
  const pad = db.pcb_smtpad.get(this.pcb_smtpad_id);
8105
- if (pad.shape === "rect" || pad.shape === "circle" || pad.shape === "rotated_rect" || pad.shape === "pill") {
8203
+ if (pad.shape === "rect" || pad.shape === "circle" || pad.shape === "rotated_rect" || pad.shape === "pill" || pad.shape === "rotated_pill") {
8106
8204
  this._setPositionFromLayout({ x: pad.x + deltaX, y: pad.y + deltaY });
8107
8205
  } else if (pad.shape === "polygon") {
8108
8206
  db.pcb_smtpad.update(this.pcb_smtpad_id, {
@@ -20025,7 +20123,7 @@ import { identity as identity5 } from "transformation-matrix";
20025
20123
  var package_default = {
20026
20124
  name: "@tscircuit/core",
20027
20125
  type: "module",
20028
- version: "0.0.1193",
20126
+ version: "0.0.1194",
20029
20127
  types: "dist/index.d.ts",
20030
20128
  main: "dist/index.js",
20031
20129
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1194",
4
+ "version": "0.0.1195",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",