@tscircuit/core 0.0.1110 → 0.0.1111

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 +131 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18642,7 +18642,7 @@ import { identity as identity5 } from "transformation-matrix";
18642
18642
  var package_default = {
18643
18643
  name: "@tscircuit/core",
18644
18644
  type: "module",
18645
- version: "0.0.1109",
18645
+ version: "0.0.1110",
18646
18646
  types: "dist/index.d.ts",
18647
18647
  main: "dist/index.js",
18648
18648
  module: "dist/index.js",
@@ -22127,6 +22127,131 @@ import {
22127
22127
  convertCircuitJsonToInputProblem
22128
22128
  } from "@tscircuit/copper-pour-solver";
22129
22129
  import { getFullConnectivityMapFromCircuitJson as getFullConnectivityMapFromCircuitJson4 } from "circuit-json-to-connectivity-map";
22130
+
22131
+ // lib/components/primitive-components/CopperPour/utils/mark-trace-segments-inside-copper-pour.ts
22132
+ var EPSILON = 1e-9;
22133
+ var isWireRoutePoint = (routePoint) => routePoint.route_type === "wire";
22134
+ var isPointOnSegment = (p, a, b) => {
22135
+ const cross2 = (p.y - a.y) * (b.x - a.x) - (p.x - a.x) * (b.y - a.y);
22136
+ if (Math.abs(cross2) > EPSILON) return false;
22137
+ const dot = (p.x - a.x) * (b.x - a.x) + (p.y - a.y) * (b.y - a.y);
22138
+ if (dot < -EPSILON) return false;
22139
+ const squaredLength = (b.x - a.x) ** 2 + (b.y - a.y) ** 2;
22140
+ if (dot - squaredLength > EPSILON) return false;
22141
+ return true;
22142
+ };
22143
+ var isPointInRing = (point6, ring) => {
22144
+ if (ring.length < 3) return false;
22145
+ let inside = false;
22146
+ let previous = ring[ring.length - 1];
22147
+ for (const current of ring) {
22148
+ if (isPointOnSegment(point6, previous, current)) return true;
22149
+ const intersects = current.y > point6.y !== previous.y > point6.y && point6.x < (previous.x - current.x) * (point6.y - current.y) / (previous.y - current.y) + current.x;
22150
+ if (intersects) inside = !inside;
22151
+ previous = current;
22152
+ }
22153
+ return inside;
22154
+ };
22155
+ var isPointInRectPour = (p, pour) => {
22156
+ const { center, width, height } = pour;
22157
+ const rotationRad = (pour.rotation ?? 0) * Math.PI / 180;
22158
+ const cosR = Math.cos(-rotationRad);
22159
+ const sinR = Math.sin(-rotationRad);
22160
+ const dx = p.x - center.x;
22161
+ const dy = p.y - center.y;
22162
+ const localX = dx * cosR - dy * sinR;
22163
+ const localY = dx * sinR + dy * cosR;
22164
+ return Math.abs(localX) <= width / 2 + EPSILON && Math.abs(localY) <= height / 2 + EPSILON;
22165
+ };
22166
+ var isPointInBrepPour = (p, pour) => {
22167
+ const outerRing = pour.brep_shape.outer_ring.vertices.map((v) => ({
22168
+ x: v.x,
22169
+ y: v.y
22170
+ }));
22171
+ if (!isPointInRing(p, outerRing)) return false;
22172
+ for (const innerRing of pour.brep_shape.inner_rings) {
22173
+ const points = innerRing.vertices.map((v) => ({ x: v.x, y: v.y }));
22174
+ if (isPointInRing(p, points)) return false;
22175
+ }
22176
+ return true;
22177
+ };
22178
+ var isPointInCopperPour = (point6, pour) => {
22179
+ if (pour.shape === "rect") {
22180
+ return isPointInRectPour(point6, pour);
22181
+ }
22182
+ if (pour.shape === "brep") {
22183
+ return isPointInBrepPour(point6, pour);
22184
+ }
22185
+ return false;
22186
+ };
22187
+ var isTraceConnectedToSourceNet = (trace, sourceNetId, sourceTraceById) => {
22188
+ if (trace.source_trace_id === sourceNetId) return true;
22189
+ if (!trace.source_trace_id) return false;
22190
+ const sourceTrace = sourceTraceById.get(trace.source_trace_id);
22191
+ if (!sourceTrace) return false;
22192
+ return sourceTrace.connected_source_net_ids.includes(sourceNetId);
22193
+ };
22194
+ var isSegmentFullyInsideCopperPour = (start, end, pour) => {
22195
+ const dx = end.x - start.x;
22196
+ const dy = end.y - start.y;
22197
+ const length7 = Math.hypot(dx, dy);
22198
+ if (length7 <= EPSILON) return false;
22199
+ const samples = [0, 0.25, 0.5, 0.75, 1];
22200
+ return samples.every(
22201
+ (t) => isPointInCopperPour(
22202
+ {
22203
+ x: start.x + dx * t,
22204
+ y: start.y + dy * t
22205
+ },
22206
+ pour
22207
+ )
22208
+ );
22209
+ };
22210
+ var markTraceSegmentsInsideCopperPour = ({
22211
+ db,
22212
+ copperPour
22213
+ }) => {
22214
+ if (!copperPour.source_net_id) return;
22215
+ const sourceTraceById = new Map(
22216
+ db.source_trace.list().map((sourceTrace) => [sourceTrace.source_trace_id, sourceTrace])
22217
+ );
22218
+ for (const trace of db.pcb_trace.list()) {
22219
+ if (!isTraceConnectedToSourceNet(
22220
+ trace,
22221
+ copperPour.source_net_id,
22222
+ sourceTraceById
22223
+ )) {
22224
+ continue;
22225
+ }
22226
+ let routeChanged = false;
22227
+ const nextRoute = trace.route.map((routePoint) => ({ ...routePoint }));
22228
+ for (let i = 0; i < nextRoute.length - 1; i++) {
22229
+ const fromRoutePoint = nextRoute[i];
22230
+ const toRoutePoint = nextRoute[i + 1];
22231
+ if (!fromRoutePoint || !toRoutePoint) continue;
22232
+ if (!isWireRoutePoint(fromRoutePoint) || !isWireRoutePoint(toRoutePoint))
22233
+ continue;
22234
+ if (fromRoutePoint.layer !== copperPour.layer || toRoutePoint.layer !== copperPour.layer)
22235
+ continue;
22236
+ if (isSegmentFullyInsideCopperPour(
22237
+ { x: fromRoutePoint.x, y: fromRoutePoint.y },
22238
+ { x: toRoutePoint.x, y: toRoutePoint.y },
22239
+ copperPour
22240
+ )) {
22241
+ fromRoutePoint.is_inside_copper_pour = true;
22242
+ fromRoutePoint.copper_pour_id = copperPour.pcb_copper_pour_id;
22243
+ toRoutePoint.is_inside_copper_pour = true;
22244
+ toRoutePoint.copper_pour_id = copperPour.pcb_copper_pour_id;
22245
+ routeChanged = true;
22246
+ }
22247
+ }
22248
+ if (routeChanged) {
22249
+ db.pcb_trace.update(trace.pcb_trace_id, { route: nextRoute });
22250
+ }
22251
+ }
22252
+ };
22253
+
22254
+ // lib/components/primitive-components/CopperPour/CopperPour.ts
22130
22255
  var CopperPour = class extends PrimitiveComponent2 {
22131
22256
  isPcbPrimitive = true;
22132
22257
  get config() {
@@ -22179,7 +22304,7 @@ var CopperPour = class extends PrimitiveComponent2 {
22179
22304
  const { brep_shapes } = solver.getOutput();
22180
22305
  const coveredWithSolderMask = props.coveredWithSolderMask ?? false;
22181
22306
  for (const brep_shape of brep_shapes) {
22182
- db.pcb_copper_pour.insert({
22307
+ const insertedPour = db.pcb_copper_pour.insert({
22183
22308
  shape: "brep",
22184
22309
  layer: props.layer,
22185
22310
  brep_shape,
@@ -22187,6 +22312,10 @@ var CopperPour = class extends PrimitiveComponent2 {
22187
22312
  subcircuit_id: subcircuit?.subcircuit_id ?? void 0,
22188
22313
  covered_with_solder_mask: coveredWithSolderMask
22189
22314
  });
22315
+ markTraceSegmentsInsideCopperPour({
22316
+ db,
22317
+ copperPour: insertedPour
22318
+ });
22190
22319
  }
22191
22320
  });
22192
22321
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1110",
4
+ "version": "0.0.1111",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",