@tscircuit/core 0.0.2326 → 0.0.2327

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 +67 -47
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -159602,7 +159602,7 @@ var RoutingPhasePreparationError = class extends Error {
159602
159602
  var package_default = {
159603
159603
  name: "@tscircuit/core",
159604
159604
  type: "module",
159605
- version: "0.0.2325",
159605
+ version: "0.0.2326",
159606
159606
  types: "dist/index.d.ts",
159607
159607
  main: "dist/index.js",
159608
159608
  module: "dist/index.js",
@@ -172043,7 +172043,11 @@ import {
172043
172043
  // lib/components/primitive-components/CopperPour/utils/mark-trace-segments-inside-copper-pour.ts
172044
172044
  var EPSILON30 = 1e-9;
172045
172045
  var isWireRoutePoint = (routePoint) => routePoint.route_type === "wire";
172046
+ var getWirePointKey = (point12) => `${point12.layer}:${point12.x}:${point12.y}`;
172046
172047
  var isPointOnSegment4 = (p2, a2, b2) => {
172048
+ if (Math.hypot(b2.x - a2.x, b2.y - a2.y) <= EPSILON30) {
172049
+ return Math.hypot(p2.x - a2.x, p2.y - a2.y) <= EPSILON30;
172050
+ }
172047
172051
  const cross5 = (p2.y - a2.y) * (b2.x - a2.x) - (p2.x - a2.x) * (b2.y - a2.y);
172048
172052
  if (Math.abs(cross5) > EPSILON30) return false;
172049
172053
  const dot2 = (p2.x - a2.x) * (b2.x - a2.x) + (p2.y - a2.y) * (b2.y - a2.y);
@@ -172076,16 +172080,7 @@ var isPointInRectPour = (p2, pour) => {
172076
172080
  return Math.abs(localX) <= width / 2 + EPSILON30 && Math.abs(localY) <= height / 2 + EPSILON30;
172077
172081
  };
172078
172082
  var isPointInBrepPour = (p2, pour) => {
172079
- const outerRing = pour.brep_shape.outer_ring.vertices.map((v2) => ({
172080
- x: v2.x,
172081
- y: v2.y
172082
- }));
172083
- if (!isPointInRing2(p2, outerRing)) return false;
172084
- for (const innerRing of pour.brep_shape.inner_rings) {
172085
- const points = innerRing.vertices.map((v2) => ({ x: v2.x, y: v2.y }));
172086
- if (isPointInRing2(p2, points)) return false;
172087
- }
172088
- return true;
172083
+ return isPointInRing2(p2, pour.brep_shape.outer_ring.vertices) && !pour.brep_shape.inner_rings.some((ring2) => isPointInRing2(p2, ring2.vertices));
172089
172084
  };
172090
172085
  var isPointInCopperPour = (point12, pour) => {
172091
172086
  if (pour.shape === "rect") {
@@ -172108,55 +172103,80 @@ var isSegmentFullyInsideCopperPour = (start, end, pour) => {
172108
172103
  const dy2 = end.y - start.y;
172109
172104
  const length9 = Math.hypot(dx2, dy2);
172110
172105
  if (length9 <= EPSILON30) return false;
172111
- const samples = [0, 0.25, 0.5, 0.75, 1];
172112
- return samples.every(
172113
- (t48) => isPointInCopperPour(
172114
- {
172115
- x: start.x + dx2 * t48,
172116
- y: start.y + dy2 * t48
172117
- },
172118
- pour
172119
- )
172106
+ if (!isPointInCopperPour(start, pour) || !isPointInCopperPour(end, pour)) {
172107
+ return false;
172108
+ }
172109
+ if (pour.shape === "rect") return true;
172110
+ if (pour.shape !== "brep") return false;
172111
+ for (const ring2 of [
172112
+ pour.brep_shape.outer_ring,
172113
+ ...pour.brep_shape.inner_rings
172114
+ ]) {
172115
+ const vertices = ring2.vertices;
172116
+ for (let edgeIndex = 0; edgeIndex < vertices.length; edgeIndex++) {
172117
+ if (doesTraceSegmentTouchPourBoundaryEdge(
172118
+ start,
172119
+ end,
172120
+ vertices[edgeIndex],
172121
+ vertices[(edgeIndex + 1) % vertices.length]
172122
+ ))
172123
+ return false;
172124
+ }
172125
+ }
172126
+ return true;
172127
+ };
172128
+ var doesTraceSegmentTouchPourBoundaryEdge = (traceStart, traceEnd, boundaryStart, boundaryEnd) => {
172129
+ if (isPointOnSegment4(traceStart, boundaryStart, boundaryEnd) || isPointOnSegment4(traceEnd, boundaryStart, boundaryEnd) || isPointOnSegment4(boundaryStart, traceStart, traceEnd) || isPointOnSegment4(boundaryEnd, traceStart, traceEnd))
172130
+ return true;
172131
+ const side = (start, end, point12) => (end.x - start.x) * (point12.y - start.y) - (end.y - start.y) * (point12.x - start.x);
172132
+ const oppositeSides = (first, second) => first > EPSILON30 && second < -EPSILON30 || first < -EPSILON30 && second > EPSILON30;
172133
+ return oppositeSides(
172134
+ side(traceStart, traceEnd, boundaryStart),
172135
+ side(traceStart, traceEnd, boundaryEnd)
172136
+ ) && oppositeSides(
172137
+ side(boundaryStart, boundaryEnd, traceStart),
172138
+ side(boundaryStart, boundaryEnd, traceEnd)
172120
172139
  );
172121
172140
  };
172122
172141
  var markTraceSegmentsInsideCopperPour = ({
172123
172142
  db: db2,
172124
172143
  copperPour
172125
172144
  }) => {
172126
- if (!copperPour.source_net_id) return;
172145
+ const sourceNetId = copperPour.source_net_id;
172146
+ if (!sourceNetId) return;
172127
172147
  const sourceTraceById = new Map(
172128
172148
  db2.source_trace.list().map((sourceTrace) => [sourceTrace.source_trace_id, sourceTrace])
172129
172149
  );
172130
- for (const trace of db2.pcb_trace.list()) {
172131
- if (!isTraceConnectedToSourceNet(
172132
- trace,
172133
- copperPour.source_net_id,
172134
- sourceTraceById
172135
- )) {
172136
- continue;
172150
+ const traceCoverage = db2.pcb_trace.list().filter(
172151
+ (trace) => isTraceConnectedToSourceNet(trace, sourceNetId, sourceTraceById)
172152
+ ).map((trace) => ({
172153
+ trace,
172154
+ coveredSegments: trace.route.slice(0, -1).map((from, segmentIndex) => {
172155
+ const to = trace.route[segmentIndex + 1];
172156
+ return isWireRoutePoint(from) && isWireRoutePoint(to) && from.layer === copperPour.layer && to.layer === copperPour.layer && isSegmentFullyInsideCopperPour(from, to, copperPour);
172157
+ })
172158
+ }));
172159
+ const exposedPoints = /* @__PURE__ */ new Set();
172160
+ for (const { trace, coveredSegments } of traceCoverage) {
172161
+ for (const [routeIndex, point12] of trace.route.entries()) {
172162
+ const coveredBefore = routeIndex === 0 || coveredSegments[routeIndex - 1];
172163
+ const coveredAfter = routeIndex === trace.route.length - 1 || coveredSegments[routeIndex];
172164
+ if (isWireRoutePoint(point12) && (!coveredBefore || !coveredAfter)) {
172165
+ exposedPoints.add(getWirePointKey(point12));
172166
+ }
172137
172167
  }
172168
+ }
172169
+ for (const { trace, coveredSegments } of traceCoverage) {
172138
172170
  let routeChanged = false;
172139
- const nextRoute = trace.route.map((routePoint) => ({ ...routePoint }));
172140
- for (let i2 = 0; i2 < nextRoute.length - 1; i2++) {
172141
- const fromRoutePoint = nextRoute[i2];
172142
- const toRoutePoint = nextRoute[i2 + 1];
172143
- if (!fromRoutePoint || !toRoutePoint) continue;
172144
- if (!isWireRoutePoint(fromRoutePoint) || !isWireRoutePoint(toRoutePoint))
172145
- continue;
172146
- if (fromRoutePoint.layer !== copperPour.layer || toRoutePoint.layer !== copperPour.layer)
172147
- continue;
172148
- if (isSegmentFullyInsideCopperPour(
172149
- { x: fromRoutePoint.x, y: fromRoutePoint.y },
172150
- { x: toRoutePoint.x, y: toRoutePoint.y },
172151
- copperPour
172152
- )) {
172153
- fromRoutePoint.is_inside_copper_pour = true;
172154
- fromRoutePoint.copper_pour_id = copperPour.pcb_copper_pour_id;
172155
- toRoutePoint.is_inside_copper_pour = true;
172156
- toRoutePoint.copper_pour_id = copperPour.pcb_copper_pour_id;
172171
+ const nextRoute = trace.route.map((routePoint) => {
172172
+ const point12 = { ...routePoint };
172173
+ if (isWireRoutePoint(point12) && coveredSegments.length > 0 && !exposedPoints.has(getWirePointKey(point12))) {
172174
+ point12.is_inside_copper_pour = true;
172175
+ point12.copper_pour_id = copperPour.pcb_copper_pour_id;
172157
172176
  routeChanged = true;
172158
172177
  }
172159
- }
172178
+ return point12;
172179
+ });
172160
172180
  if (routeChanged) {
172161
172181
  db2.pcb_trace.update(trace.pcb_trace_id, { route: nextRoute });
172162
172182
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.2326",
4
+ "version": "0.0.2327",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",