@tscircuit/schematic-trace-solver 0.0.49 → 0.0.51
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 +133 -1
- package/dist/index.js +1084 -41
- package/lib/solvers/AvailableNetOrientationSolver/AvailableNetOrientationSolver.ts +682 -0
- package/lib/solvers/AvailableNetOrientationSolver/constants.ts +6 -0
- package/lib/solvers/AvailableNetOrientationSolver/geometry.ts +192 -0
- package/lib/solvers/AvailableNetOrientationSolver/traces.ts +43 -0
- package/lib/solvers/AvailableNetOrientationSolver/types.ts +44 -0
- package/lib/solvers/AvailableNetOrientationSolver/visualize.ts +123 -0
- package/lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts +30 -0
- package/lib/solvers/VccNetLabelCornerPlacementSolver/VccNetLabelCornerPlacementSolver.ts +268 -0
- package/lib/solvers/VccNetLabelCornerPlacementSolver/geometry.ts +59 -0
- package/lib/solvers/VccNetLabelCornerPlacementSolver/types.ts +37 -0
- package/lib/solvers/VccNetLabelCornerPlacementSolver/visualize.ts +114 -0
- package/package.json +1 -1
- package/tests/assets/example22.json +1 -1
- package/tests/examples/__snapshots__/example12.snap.svg +33 -30
- package/tests/examples/__snapshots__/example13.snap.svg +10 -4
- package/tests/examples/__snapshots__/example14.snap.svg +72 -66
- package/tests/examples/__snapshots__/example16.snap.svg +33 -27
- package/tests/examples/__snapshots__/example20.snap.svg +29 -23
- package/tests/examples/__snapshots__/example21.snap.svg +77 -65
- package/tests/examples/__snapshots__/example22.snap.svg +31 -25
- package/tests/examples/__snapshots__/example31.snap.svg +12 -12
package/dist/index.js
CHANGED
|
@@ -271,19 +271,19 @@ var doesPairCrossRestrictedCenterLines = (params) => {
|
|
|
271
271
|
chipMap
|
|
272
272
|
});
|
|
273
273
|
if (restrictedCenterLines.size === 0) return false;
|
|
274
|
-
const
|
|
274
|
+
const EPS8 = 1e-9;
|
|
275
275
|
const crossesSegment = (a, b) => {
|
|
276
276
|
for (const [, rcl] of restrictedCenterLines) {
|
|
277
277
|
if (rcl.axes.has("x") && typeof rcl.x === "number") {
|
|
278
|
-
if ((a.x - rcl.x) * (b.x - rcl.x) < -
|
|
278
|
+
if ((a.x - rcl.x) * (b.x - rcl.x) < -EPS8) return true;
|
|
279
279
|
}
|
|
280
280
|
if (rcl.axes.has("y") && typeof rcl.y === "number") {
|
|
281
|
-
if ((a.y - rcl.y) * (b.y - rcl.y) < -
|
|
281
|
+
if ((a.y - rcl.y) * (b.y - rcl.y) < -EPS8) return true;
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
return false;
|
|
285
285
|
};
|
|
286
|
-
if (Math.abs(p1.x - p2.x) <
|
|
286
|
+
if (Math.abs(p1.x - p2.x) < EPS8 || Math.abs(p1.y - p2.y) < EPS8) {
|
|
287
287
|
return crossesSegment({ x: p1.x, y: p1.y }, { x: p2.x, y: p2.y });
|
|
288
288
|
}
|
|
289
289
|
const elbowHV = { x: p2.x, y: p1.y };
|
|
@@ -810,8 +810,8 @@ var SchematicTraceSingleLineSolver2 = class extends BaseSolver {
|
|
|
810
810
|
if (!collision) {
|
|
811
811
|
const first = path[0];
|
|
812
812
|
const last = path[path.length - 1];
|
|
813
|
-
const
|
|
814
|
-
const samePoint = (p, q) => Math.abs(p.x - q.x) <
|
|
813
|
+
const EPS8 = 1e-9;
|
|
814
|
+
const samePoint = (p, q) => Math.abs(p.x - q.x) < EPS8 && Math.abs(p.y - q.y) < EPS8;
|
|
815
815
|
if (samePoint(first, { x: PA.x, y: PA.y }) && samePoint(last, { x: PB.x, y: PB.y })) {
|
|
816
816
|
this.solvedTracePath = path;
|
|
817
817
|
this.solved = true;
|
|
@@ -1010,13 +1010,13 @@ var applyJogToTerminalSegment = ({
|
|
|
1010
1010
|
segmentIndex: si,
|
|
1011
1011
|
offset,
|
|
1012
1012
|
JOG_SIZE,
|
|
1013
|
-
EPS:
|
|
1013
|
+
EPS: EPS8 = 1e-6
|
|
1014
1014
|
}) => {
|
|
1015
1015
|
if (si !== 0 && si !== pts.length - 2) return;
|
|
1016
1016
|
const start = pts[si];
|
|
1017
1017
|
const end = pts[si + 1];
|
|
1018
|
-
const isVertical3 = Math.abs(start.x - end.x) <
|
|
1019
|
-
const isHorizontal2 = Math.abs(start.y - end.y) <
|
|
1018
|
+
const isVertical3 = Math.abs(start.x - end.x) < EPS8;
|
|
1019
|
+
const isHorizontal2 = Math.abs(start.y - end.y) < EPS8;
|
|
1020
1020
|
if (!isVertical3 && !isHorizontal2) return;
|
|
1021
1021
|
const segDir = isVertical3 ? end.y > start.y ? 1 : -1 : end.x > start.x ? 1 : -1;
|
|
1022
1022
|
if (si === 0) {
|
|
@@ -1083,13 +1083,13 @@ var TraceOverlapIssueSolver = class extends BaseSolver {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
1085
|
_step() {
|
|
1086
|
-
const
|
|
1086
|
+
const EPS8 = 1e-6;
|
|
1087
1087
|
const offsets = this.overlappingTraceSegments.map((_, idx) => {
|
|
1088
1088
|
const n = Math.floor(idx / 2) + 1;
|
|
1089
1089
|
const signed = idx % 2 === 0 ? -n : n;
|
|
1090
1090
|
return signed * this.SHIFT_DISTANCE;
|
|
1091
1091
|
});
|
|
1092
|
-
const eq = (a, b) => Math.abs(a - b) <
|
|
1092
|
+
const eq = (a, b) => Math.abs(a - b) < EPS8;
|
|
1093
1093
|
const samePoint = (p, q) => !!p && !!q && eq(p.x, q.x) && eq(p.y, q.y);
|
|
1094
1094
|
this.overlappingTraceSegments.forEach((group, gidx) => {
|
|
1095
1095
|
const offset = offsets[gidx];
|
|
@@ -1115,13 +1115,13 @@ var TraceOverlapIssueSolver = class extends BaseSolver {
|
|
|
1115
1115
|
segmentIndex: si,
|
|
1116
1116
|
offset,
|
|
1117
1117
|
JOG_SIZE,
|
|
1118
|
-
EPS:
|
|
1118
|
+
EPS: EPS8
|
|
1119
1119
|
});
|
|
1120
1120
|
} else {
|
|
1121
1121
|
const start = pts[si];
|
|
1122
1122
|
const end = pts[si + 1];
|
|
1123
|
-
const isVertical3 = Math.abs(start.x - end.x) <
|
|
1124
|
-
const isHorizontal2 = Math.abs(start.y - end.y) <
|
|
1123
|
+
const isVertical3 = Math.abs(start.x - end.x) < EPS8;
|
|
1124
|
+
const isHorizontal2 = Math.abs(start.y - end.y) < EPS8;
|
|
1125
1125
|
if (!isVertical3 && !isHorizontal2) continue;
|
|
1126
1126
|
if (isVertical3) {
|
|
1127
1127
|
start.x += offset;
|
|
@@ -1218,7 +1218,7 @@ var TraceOverlapShiftSolver = class extends BaseSolver {
|
|
|
1218
1218
|
return islands;
|
|
1219
1219
|
}
|
|
1220
1220
|
findNextOverlapIssue() {
|
|
1221
|
-
const
|
|
1221
|
+
const EPS8 = 2e-3;
|
|
1222
1222
|
const netIds = Object.keys(this.traceNetIslands);
|
|
1223
1223
|
for (let i = 0; i < netIds.length; i++) {
|
|
1224
1224
|
for (let j = i + 1; j < netIds.length; j++) {
|
|
@@ -1236,7 +1236,7 @@ var TraceOverlapShiftSolver = class extends BaseSolver {
|
|
|
1236
1236
|
const minB = Math.min(b1, b2);
|
|
1237
1237
|
const maxB = Math.max(b1, b2);
|
|
1238
1238
|
const overlap = Math.min(maxA, maxB) - Math.max(minA, minB);
|
|
1239
|
-
return overlap >
|
|
1239
|
+
return overlap > EPS8;
|
|
1240
1240
|
};
|
|
1241
1241
|
for (let pa = 0; pa < pathsA.length; pa++) {
|
|
1242
1242
|
const pathA = pathsA[pa];
|
|
@@ -1244,8 +1244,8 @@ var TraceOverlapShiftSolver = class extends BaseSolver {
|
|
|
1244
1244
|
for (let sa = 0; sa < ptsA.length - 1; sa++) {
|
|
1245
1245
|
const a1 = ptsA[sa];
|
|
1246
1246
|
const a2 = ptsA[sa + 1];
|
|
1247
|
-
const aVert = Math.abs(a1.x - a2.x) <
|
|
1248
|
-
const aHorz = Math.abs(a1.y - a2.y) <
|
|
1247
|
+
const aVert = Math.abs(a1.x - a2.x) < EPS8;
|
|
1248
|
+
const aHorz = Math.abs(a1.y - a2.y) < EPS8;
|
|
1249
1249
|
if (!aVert && !aHorz) continue;
|
|
1250
1250
|
for (let pb = 0; pb < pathsB.length; pb++) {
|
|
1251
1251
|
const pathB = pathsB[pb];
|
|
@@ -1253,11 +1253,11 @@ var TraceOverlapShiftSolver = class extends BaseSolver {
|
|
|
1253
1253
|
for (let sb = 0; sb < ptsB.length - 1; sb++) {
|
|
1254
1254
|
const b1 = ptsB[sb];
|
|
1255
1255
|
const b2 = ptsB[sb + 1];
|
|
1256
|
-
const bVert = Math.abs(b1.x - b2.x) <
|
|
1257
|
-
const bHorz = Math.abs(b1.y - b2.y) <
|
|
1256
|
+
const bVert = Math.abs(b1.x - b2.x) < EPS8;
|
|
1257
|
+
const bHorz = Math.abs(b1.y - b2.y) < EPS8;
|
|
1258
1258
|
if (!bVert && !bHorz) continue;
|
|
1259
1259
|
if (aVert && bVert) {
|
|
1260
|
-
if (Math.abs(a1.x - b1.x) <
|
|
1260
|
+
if (Math.abs(a1.x - b1.x) < EPS8) {
|
|
1261
1261
|
if (overlaps1D(a1.y, a2.y, b1.y, b2.y)) {
|
|
1262
1262
|
const keyA = `${pa}:${sa}`;
|
|
1263
1263
|
const keyB = `${pb}:${sb}`;
|
|
@@ -1278,7 +1278,7 @@ var TraceOverlapShiftSolver = class extends BaseSolver {
|
|
|
1278
1278
|
}
|
|
1279
1279
|
}
|
|
1280
1280
|
} else if (aHorz && bHorz) {
|
|
1281
|
-
if (Math.abs(a1.y - b1.y) <
|
|
1281
|
+
if (Math.abs(a1.y - b1.y) < EPS8) {
|
|
1282
1282
|
if (overlaps1D(a1.x, a2.x, b1.x, b2.x)) {
|
|
1283
1283
|
const keyA = `${pa}:${sa}`;
|
|
1284
1284
|
const keyB = `${pb}:${sb}`;
|
|
@@ -1316,14 +1316,14 @@ var TraceOverlapShiftSolver = class extends BaseSolver {
|
|
|
1316
1316
|
return null;
|
|
1317
1317
|
}
|
|
1318
1318
|
findNextDiagonalSegment() {
|
|
1319
|
-
const
|
|
1319
|
+
const EPS8 = 2e-3;
|
|
1320
1320
|
for (const mspPairId in this.correctedTraceMap) {
|
|
1321
1321
|
const tracePath = this.correctedTraceMap[mspPairId].tracePath;
|
|
1322
1322
|
for (let i = 0; i < tracePath.length - 1; i++) {
|
|
1323
1323
|
const p1 = tracePath[i];
|
|
1324
1324
|
const p2 = tracePath[i + 1];
|
|
1325
|
-
const isHorizontal2 = Math.abs(p1.y - p2.y) <
|
|
1326
|
-
const isVertical3 = Math.abs(p1.x - p2.x) <
|
|
1325
|
+
const isHorizontal2 = Math.abs(p1.y - p2.y) < EPS8;
|
|
1326
|
+
const isVertical3 = Math.abs(p1.x - p2.x) < EPS8;
|
|
1327
1327
|
if (!isHorizontal2 && !isVertical3) {
|
|
1328
1328
|
return { mspPairId, tracePath, i, p1, p2 };
|
|
1329
1329
|
}
|
|
@@ -1337,13 +1337,13 @@ var TraceOverlapShiftSolver = class extends BaseSolver {
|
|
|
1337
1337
|
return false;
|
|
1338
1338
|
}
|
|
1339
1339
|
const { mspPairId, tracePath, i, p1, p2 } = diagonalInfo;
|
|
1340
|
-
const
|
|
1340
|
+
const EPS8 = 2e-3;
|
|
1341
1341
|
const p0 = i > 0 ? tracePath[i - 1] : null;
|
|
1342
1342
|
const p3 = i + 2 < tracePath.length ? tracePath[i + 2] : null;
|
|
1343
|
-
const prevIsVertical = p0 ? Math.abs(p0.x - p1.x) <
|
|
1344
|
-
const prevIsHorizontal = p0 ? Math.abs(p0.y - p1.y) <
|
|
1345
|
-
const nextIsVertical = p3 ? Math.abs(p2.x - p3.x) <
|
|
1346
|
-
const nextIsHorizontal = p3 ? Math.abs(p2.y - p3.y) <
|
|
1343
|
+
const prevIsVertical = p0 ? Math.abs(p0.x - p1.x) < EPS8 : false;
|
|
1344
|
+
const prevIsHorizontal = p0 ? Math.abs(p0.y - p1.y) < EPS8 : false;
|
|
1345
|
+
const nextIsVertical = p3 ? Math.abs(p2.x - p3.x) < EPS8 : false;
|
|
1346
|
+
const nextIsHorizontal = p3 ? Math.abs(p2.y - p3.y) < EPS8 : false;
|
|
1347
1347
|
const elbow1 = { x: p1.x, y: p2.y };
|
|
1348
1348
|
const elbow2 = { x: p2.x, y: p1.y };
|
|
1349
1349
|
let score1 = 0;
|
|
@@ -1507,24 +1507,24 @@ function getRectBounds(center, w, h) {
|
|
|
1507
1507
|
}
|
|
1508
1508
|
|
|
1509
1509
|
// lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/collisions.ts
|
|
1510
|
-
function segmentIntersectsRect2(p1, p2, rect,
|
|
1511
|
-
const isVert = Math.abs(p1.x - p2.x) <
|
|
1512
|
-
const isHorz = Math.abs(p1.y - p2.y) <
|
|
1510
|
+
function segmentIntersectsRect2(p1, p2, rect, EPS8 = 1e-9) {
|
|
1511
|
+
const isVert = Math.abs(p1.x - p2.x) < EPS8;
|
|
1512
|
+
const isHorz = Math.abs(p1.y - p2.y) < EPS8;
|
|
1513
1513
|
if (!isVert && !isHorz) return false;
|
|
1514
1514
|
if (isVert) {
|
|
1515
1515
|
const x = p1.x;
|
|
1516
|
-
if (x < rect.minX -
|
|
1516
|
+
if (x < rect.minX - EPS8 || x > rect.maxX + EPS8) return false;
|
|
1517
1517
|
const segMinY = Math.min(p1.y, p2.y);
|
|
1518
1518
|
const segMaxY = Math.max(p1.y, p2.y);
|
|
1519
1519
|
const overlap = Math.min(segMaxY, rect.maxY) - Math.max(segMinY, rect.minY);
|
|
1520
|
-
return overlap >
|
|
1520
|
+
return overlap > EPS8;
|
|
1521
1521
|
} else {
|
|
1522
1522
|
const y = p1.y;
|
|
1523
|
-
if (y < rect.minY -
|
|
1523
|
+
if (y < rect.minY - EPS8 || y > rect.maxY + EPS8) return false;
|
|
1524
1524
|
const segMinX = Math.min(p1.x, p2.x);
|
|
1525
1525
|
const segMaxX = Math.max(p1.x, p2.x);
|
|
1526
1526
|
const overlap = Math.min(segMaxX, rect.maxX) - Math.max(segMinX, rect.minX);
|
|
1527
|
-
return overlap >
|
|
1527
|
+
return overlap > EPS8;
|
|
1528
1528
|
}
|
|
1529
1529
|
}
|
|
1530
1530
|
function rectIntersectsAnyTrace(bounds, inputTraceMap, hostPathId, hostSegIndex) {
|
|
@@ -1902,14 +1902,14 @@ var SingleNetLabelPlacementSolver = class extends BaseSolver {
|
|
|
1902
1902
|
};
|
|
1903
1903
|
let bestCandidate = null;
|
|
1904
1904
|
let bestScore = -Infinity;
|
|
1905
|
-
const
|
|
1905
|
+
const EPS8 = 1e-6;
|
|
1906
1906
|
for (const curr of tracesToScan) {
|
|
1907
1907
|
const pts = curr.tracePath.slice();
|
|
1908
1908
|
for (let si = 0; si < pts.length - 1; si++) {
|
|
1909
1909
|
const a = pts[si];
|
|
1910
1910
|
const b = pts[si + 1];
|
|
1911
|
-
const isH = Math.abs(a.y - b.y) <
|
|
1912
|
-
const isV = Math.abs(a.x - b.x) <
|
|
1911
|
+
const isH = Math.abs(a.y - b.y) < EPS8;
|
|
1912
|
+
const isV = Math.abs(a.x - b.x) < EPS8;
|
|
1913
1913
|
if (!isH && !isV) continue;
|
|
1914
1914
|
const segmentAllowed = isH ? ["y+", "y-"] : ["x+", "x-"];
|
|
1915
1915
|
const candidateOrients = orientations.filter(
|
|
@@ -5345,6 +5345,1023 @@ var Example28Solver = class extends BaseSolver {
|
|
|
5345
5345
|
}
|
|
5346
5346
|
};
|
|
5347
5347
|
|
|
5348
|
+
// lib/solvers/AvailableNetOrientationSolver/constants.ts
|
|
5349
|
+
var LABEL_SEARCH_STEP = 0.05;
|
|
5350
|
+
var WICK_CLEARANCE = 1e-3;
|
|
5351
|
+
var EPS6 = 1e-9;
|
|
5352
|
+
var TRACE_BOUNDARY_TOLERANCE = WICK_CLEARANCE + EPS6;
|
|
5353
|
+
var CANDIDATE_SELECTED_COLOR2 = "blue";
|
|
5354
|
+
var CANDIDATE_REJECTED_COLOR2 = "red";
|
|
5355
|
+
|
|
5356
|
+
// lib/solvers/AvailableNetOrientationSolver/geometry.ts
|
|
5357
|
+
var isYOrientation = (orientation) => orientation === "y+" || orientation === "y-";
|
|
5358
|
+
var isXOrientation = (orientation) => orientation === "x+" || orientation === "x-";
|
|
5359
|
+
var rectsOverlap = (a, b) => Math.min(a.maxX, b.maxX) - Math.max(a.minX, b.minX) > EPS6 && Math.min(a.maxY, b.maxY) - Math.max(a.minY, b.minY) > EPS6;
|
|
5360
|
+
var rangesOverlap = (minA, maxA, minB, maxB) => Math.min(maxA, maxB) - Math.max(minA, minB) > EPS6;
|
|
5361
|
+
var traceCrossesBoundsInterior = (bounds, traceMap) => {
|
|
5362
|
+
for (const trace of Object.values(traceMap)) {
|
|
5363
|
+
const points = trace.tracePath;
|
|
5364
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
5365
|
+
if (segmentCrossesBoundsInterior(points[i], points[i + 1], bounds)) {
|
|
5366
|
+
return true;
|
|
5367
|
+
}
|
|
5368
|
+
}
|
|
5369
|
+
}
|
|
5370
|
+
return false;
|
|
5371
|
+
};
|
|
5372
|
+
var segmentCrossesBoundsInterior = (p1, p2, bounds) => {
|
|
5373
|
+
const interiorBounds = {
|
|
5374
|
+
minX: bounds.minX + TRACE_BOUNDARY_TOLERANCE,
|
|
5375
|
+
minY: bounds.minY + TRACE_BOUNDARY_TOLERANCE,
|
|
5376
|
+
maxX: bounds.maxX - TRACE_BOUNDARY_TOLERANCE,
|
|
5377
|
+
maxY: bounds.maxY - TRACE_BOUNDARY_TOLERANCE
|
|
5378
|
+
};
|
|
5379
|
+
if (interiorBounds.minX >= interiorBounds.maxX || interiorBounds.minY >= interiorBounds.maxY) {
|
|
5380
|
+
return false;
|
|
5381
|
+
}
|
|
5382
|
+
if (sameX(p1, p2)) {
|
|
5383
|
+
if (p1.x <= interiorBounds.minX + EPS6 || p1.x >= interiorBounds.maxX - EPS6) {
|
|
5384
|
+
return false;
|
|
5385
|
+
}
|
|
5386
|
+
return rangesOverlap(
|
|
5387
|
+
Math.min(p1.y, p2.y),
|
|
5388
|
+
Math.max(p1.y, p2.y),
|
|
5389
|
+
interiorBounds.minY,
|
|
5390
|
+
interiorBounds.maxY
|
|
5391
|
+
);
|
|
5392
|
+
}
|
|
5393
|
+
if (sameY(p1, p2)) {
|
|
5394
|
+
if (p1.y <= interiorBounds.minY + EPS6 || p1.y >= interiorBounds.maxY - EPS6) {
|
|
5395
|
+
return false;
|
|
5396
|
+
}
|
|
5397
|
+
return rangesOverlap(
|
|
5398
|
+
Math.min(p1.x, p2.x),
|
|
5399
|
+
Math.max(p1.x, p2.x),
|
|
5400
|
+
interiorBounds.minX,
|
|
5401
|
+
interiorBounds.maxX
|
|
5402
|
+
);
|
|
5403
|
+
}
|
|
5404
|
+
return false;
|
|
5405
|
+
};
|
|
5406
|
+
var tracePathCrossesAnyTrace = (tracePath, traceMap) => {
|
|
5407
|
+
for (const trace of Object.values(traceMap)) {
|
|
5408
|
+
const points = trace.tracePath;
|
|
5409
|
+
for (let i = 0; i < tracePath.length - 1; i++) {
|
|
5410
|
+
for (let j = 0; j < points.length - 1; j++) {
|
|
5411
|
+
if (segmentsStrictlyCross(
|
|
5412
|
+
tracePath[i],
|
|
5413
|
+
tracePath[i + 1],
|
|
5414
|
+
points[j],
|
|
5415
|
+
points[j + 1]
|
|
5416
|
+
)) {
|
|
5417
|
+
return true;
|
|
5418
|
+
}
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
}
|
|
5422
|
+
return false;
|
|
5423
|
+
};
|
|
5424
|
+
var segmentsStrictlyCross = (a1, a2, b1, b2) => {
|
|
5425
|
+
if (sameX(a1, a2) && sameY(b1, b2)) {
|
|
5426
|
+
return a1.x > Math.min(b1.x, b2.x) + EPS6 && a1.x < Math.max(b1.x, b2.x) - EPS6 && b1.y > Math.min(a1.y, a2.y) + EPS6 && b1.y < Math.max(a1.y, a2.y) - EPS6;
|
|
5427
|
+
}
|
|
5428
|
+
if (sameY(a1, a2) && sameX(b1, b2)) {
|
|
5429
|
+
return b1.x > Math.min(a1.x, a2.x) + EPS6 && b1.x < Math.max(a1.x, a2.x) - EPS6 && a1.y > Math.min(b1.y, b2.y) + EPS6 && a1.y < Math.max(b1.y, b2.y) - EPS6;
|
|
5430
|
+
}
|
|
5431
|
+
return false;
|
|
5432
|
+
};
|
|
5433
|
+
var getSideDistances = (point, bounds) => [
|
|
5434
|
+
["left", Math.abs(point.x - bounds.minX)],
|
|
5435
|
+
["right", Math.abs(point.x - bounds.maxX)],
|
|
5436
|
+
["bottom", Math.abs(point.y - bounds.minY)],
|
|
5437
|
+
["top", Math.abs(point.y - bounds.maxY)]
|
|
5438
|
+
];
|
|
5439
|
+
var getConnectorTracePath = (source, target, orientation) => simplifyOrthogonalPath(
|
|
5440
|
+
isYOrientation(orientation) ? [source, { x: target.x, y: source.y }, target] : [source, { x: source.x, y: target.y }, target]
|
|
5441
|
+
);
|
|
5442
|
+
var simplifyOrthogonalPath = (path) => {
|
|
5443
|
+
const deduped = path.filter(
|
|
5444
|
+
(point, index) => index === 0 || !pointsEqual(point, path[index - 1])
|
|
5445
|
+
);
|
|
5446
|
+
if (deduped.length < 3) return deduped;
|
|
5447
|
+
const simplified = [deduped[0]];
|
|
5448
|
+
for (let i = 1; i < deduped.length - 1; i++) {
|
|
5449
|
+
const prev = simplified[simplified.length - 1];
|
|
5450
|
+
const point = deduped[i];
|
|
5451
|
+
const next = deduped[i + 1];
|
|
5452
|
+
if (sameX(prev, point) && sameX(point, next) || sameY(prev, point) && sameY(point, next)) {
|
|
5453
|
+
continue;
|
|
5454
|
+
}
|
|
5455
|
+
simplified.push(point);
|
|
5456
|
+
}
|
|
5457
|
+
simplified.push(deduped[deduped.length - 1]);
|
|
5458
|
+
return simplified;
|
|
5459
|
+
};
|
|
5460
|
+
var pointsEqual = (a, b) => sameX(a, b) && sameY(a, b);
|
|
5461
|
+
var sameX = (a, b) => Math.abs(a.x - b.x) <= EPS6;
|
|
5462
|
+
var sameY = (a, b) => Math.abs(a.y - b.y) <= EPS6;
|
|
5463
|
+
var getMaxSearchDistance = (inputProblem) => {
|
|
5464
|
+
const maxChipWidth = Math.max(
|
|
5465
|
+
...inputProblem.chips.map((chip) => chip.width),
|
|
5466
|
+
1
|
|
5467
|
+
);
|
|
5468
|
+
return maxChipWidth * 3;
|
|
5469
|
+
};
|
|
5470
|
+
|
|
5471
|
+
// lib/solvers/AvailableNetOrientationSolver/traces.ts
|
|
5472
|
+
var getPinMap = (inputProblem) => {
|
|
5473
|
+
const pinMap = {};
|
|
5474
|
+
for (const chip of inputProblem.chips) {
|
|
5475
|
+
for (const pin of chip.pins) {
|
|
5476
|
+
pinMap[pin.pinId] = { ...pin, chipId: chip.chipId };
|
|
5477
|
+
}
|
|
5478
|
+
}
|
|
5479
|
+
return pinMap;
|
|
5480
|
+
};
|
|
5481
|
+
var getTracePins = (label, pinMap) => {
|
|
5482
|
+
const pins = label.pinIds.flatMap((pinId) => {
|
|
5483
|
+
const pin = pinMap[pinId];
|
|
5484
|
+
return pin ? [pin] : [];
|
|
5485
|
+
});
|
|
5486
|
+
if (pins.length >= 2) return [pins[0], pins[1]];
|
|
5487
|
+
if (pins.length === 1) return [pins[0], pins[0]];
|
|
5488
|
+
const syntheticPin = {
|
|
5489
|
+
pinId: `${label.globalConnNetId}-netlabel-anchor`,
|
|
5490
|
+
x: label.anchorPoint.x,
|
|
5491
|
+
y: label.anchorPoint.y,
|
|
5492
|
+
chipId: "available-net-orientation"
|
|
5493
|
+
};
|
|
5494
|
+
return [syntheticPin, syntheticPin];
|
|
5495
|
+
};
|
|
5496
|
+
var toNetLabelPlacementPatch = (candidate) => ({
|
|
5497
|
+
orientation: candidate.orientation,
|
|
5498
|
+
anchorPoint: candidate.anchorPoint,
|
|
5499
|
+
center: candidate.center,
|
|
5500
|
+
width: candidate.width,
|
|
5501
|
+
height: candidate.height
|
|
5502
|
+
});
|
|
5503
|
+
|
|
5504
|
+
// lib/solvers/AvailableNetOrientationSolver/visualize.ts
|
|
5505
|
+
var visualizeAvailableNetOrientationSolver = (params) => {
|
|
5506
|
+
const graphics = visualizeInputProblem(params.inputProblem);
|
|
5507
|
+
ensureGraphicsArrays(graphics);
|
|
5508
|
+
drawTraces2(graphics, params.traces);
|
|
5509
|
+
drawNetLabels2(graphics, params.outputNetLabelPlacements);
|
|
5510
|
+
drawCurrentLabel(graphics, params.currentLabel, params.solved);
|
|
5511
|
+
drawCurrentCandidates2(graphics, params.currentCandidateResults, params.solved);
|
|
5512
|
+
return graphics;
|
|
5513
|
+
};
|
|
5514
|
+
var drawTraces2 = (graphics, traces) => {
|
|
5515
|
+
for (const trace of traces) {
|
|
5516
|
+
graphics.lines.push({
|
|
5517
|
+
points: trace.tracePath,
|
|
5518
|
+
strokeColor: "purple"
|
|
5519
|
+
});
|
|
5520
|
+
}
|
|
5521
|
+
};
|
|
5522
|
+
var drawNetLabels2 = (graphics, labels) => {
|
|
5523
|
+
for (const label of labels) {
|
|
5524
|
+
graphics.rects.push({
|
|
5525
|
+
center: label.center,
|
|
5526
|
+
width: label.width,
|
|
5527
|
+
height: label.height,
|
|
5528
|
+
fill: getColorFromString(label.globalConnNetId, 0.35),
|
|
5529
|
+
strokeColor: getColorFromString(label.globalConnNetId, 0.9),
|
|
5530
|
+
label: `netId: ${label.netId}
|
|
5531
|
+
globalConnNetId: ${label.globalConnNetId}`
|
|
5532
|
+
});
|
|
5533
|
+
graphics.points.push({
|
|
5534
|
+
x: label.anchorPoint.x,
|
|
5535
|
+
y: label.anchorPoint.y,
|
|
5536
|
+
color: getColorFromString(label.globalConnNetId, 0.9),
|
|
5537
|
+
label: `anchorPoint
|
|
5538
|
+
orientation: ${label.orientation}`
|
|
5539
|
+
});
|
|
5540
|
+
}
|
|
5541
|
+
};
|
|
5542
|
+
var drawCurrentLabel = (graphics, currentLabel, solved) => {
|
|
5543
|
+
if (!currentLabel || solved) return;
|
|
5544
|
+
graphics.rects.push({
|
|
5545
|
+
center: currentLabel.center,
|
|
5546
|
+
width: currentLabel.width,
|
|
5547
|
+
height: currentLabel.height,
|
|
5548
|
+
fill: "rgba(255, 0, 0, 0.2)",
|
|
5549
|
+
strokeColor: CANDIDATE_REJECTED_COLOR2,
|
|
5550
|
+
label: `available orientation target
|
|
5551
|
+
${currentLabel.netId ?? currentLabel.globalConnNetId}`
|
|
5552
|
+
});
|
|
5553
|
+
};
|
|
5554
|
+
var drawCurrentCandidates2 = (graphics, candidates, solved) => {
|
|
5555
|
+
if (solved) return;
|
|
5556
|
+
for (const candidate of candidates) {
|
|
5557
|
+
const color = candidate.selected ? CANDIDATE_SELECTED_COLOR2 : CANDIDATE_REJECTED_COLOR2;
|
|
5558
|
+
const distanceLabel = candidate.distance === void 0 ? "" : `
|
|
5559
|
+
distance: ${candidate.distance.toFixed(3)}`;
|
|
5560
|
+
const outwardDistanceLabel = candidate.outwardDistance === void 0 || candidate.outwardDistance === 0 ? "" : `
|
|
5561
|
+
outward distance: ${candidate.outwardDistance.toFixed(3)}`;
|
|
5562
|
+
graphics.rects.push({
|
|
5563
|
+
center: candidate.center,
|
|
5564
|
+
width: candidate.width,
|
|
5565
|
+
height: candidate.height,
|
|
5566
|
+
fill: candidate.selected ? "rgba(0, 0, 255, 0.2)" : "rgba(255, 0, 0, 0.15)",
|
|
5567
|
+
strokeColor: color,
|
|
5568
|
+
strokeDash: candidate.selected ? void 0 : "4 2",
|
|
5569
|
+
label: `${candidate.selected ? "selected" : candidate.status} available orientation
|
|
5570
|
+
phase: ${candidate.phase}
|
|
5571
|
+
orientation: ${candidate.orientation}${distanceLabel}${outwardDistanceLabel}`
|
|
5572
|
+
});
|
|
5573
|
+
graphics.points.push({
|
|
5574
|
+
x: candidate.anchorPoint.x,
|
|
5575
|
+
y: candidate.anchorPoint.y,
|
|
5576
|
+
color,
|
|
5577
|
+
label: `candidate anchor
|
|
5578
|
+
${candidate.phase}
|
|
5579
|
+
${candidate.orientation}`
|
|
5580
|
+
});
|
|
5581
|
+
}
|
|
5582
|
+
};
|
|
5583
|
+
var ensureGraphicsArrays = (graphics) => {
|
|
5584
|
+
if (!graphics.lines) graphics.lines = [];
|
|
5585
|
+
if (!graphics.points) graphics.points = [];
|
|
5586
|
+
if (!graphics.rects) graphics.rects = [];
|
|
5587
|
+
if (!graphics.circles) graphics.circles = [];
|
|
5588
|
+
if (!graphics.texts) graphics.texts = [];
|
|
5589
|
+
};
|
|
5590
|
+
|
|
5591
|
+
// lib/solvers/AvailableNetOrientationSolver/AvailableNetOrientationSolver.ts
|
|
5592
|
+
var AvailableNetOrientationSolver = class extends BaseSolver {
|
|
5593
|
+
inputProblem;
|
|
5594
|
+
traces;
|
|
5595
|
+
netLabelPlacements;
|
|
5596
|
+
outputNetLabelPlacements;
|
|
5597
|
+
queuedLabelIndices = [];
|
|
5598
|
+
currentLabelIndex = null;
|
|
5599
|
+
currentLabel = null;
|
|
5600
|
+
currentCandidateResults = [];
|
|
5601
|
+
traceMap;
|
|
5602
|
+
chipObstacleSpatialIndex;
|
|
5603
|
+
maxSearchDistance;
|
|
5604
|
+
pinMap;
|
|
5605
|
+
constructor(params) {
|
|
5606
|
+
super();
|
|
5607
|
+
this.inputProblem = params.inputProblem;
|
|
5608
|
+
this.traces = [...params.traces];
|
|
5609
|
+
this.netLabelPlacements = params.netLabelPlacements;
|
|
5610
|
+
this.outputNetLabelPlacements = [...params.netLabelPlacements];
|
|
5611
|
+
this.traceMap = Object.fromEntries(
|
|
5612
|
+
this.traces.map((trace) => [trace.mspPairId, trace])
|
|
5613
|
+
);
|
|
5614
|
+
this.pinMap = getPinMap(params.inputProblem);
|
|
5615
|
+
this.chipObstacleSpatialIndex = params.inputProblem._chipObstacleSpatialIndex ?? new ChipObstacleSpatialIndex(params.inputProblem.chips);
|
|
5616
|
+
this.maxSearchDistance = getMaxSearchDistance(params.inputProblem);
|
|
5617
|
+
this.queuedLabelIndices = this.getProcessableLabelIndices();
|
|
5618
|
+
this.setCurrentLabel(this.queuedLabelIndices[0] ?? null);
|
|
5619
|
+
}
|
|
5620
|
+
getConstructorParams() {
|
|
5621
|
+
return {
|
|
5622
|
+
inputProblem: this.inputProblem,
|
|
5623
|
+
traces: this.traces,
|
|
5624
|
+
netLabelPlacements: this.netLabelPlacements
|
|
5625
|
+
};
|
|
5626
|
+
}
|
|
5627
|
+
_step() {
|
|
5628
|
+
const labelIndex = this.queuedLabelIndices.shift();
|
|
5629
|
+
if (labelIndex === void 0) {
|
|
5630
|
+
this.finish();
|
|
5631
|
+
return;
|
|
5632
|
+
}
|
|
5633
|
+
this.processLabel(labelIndex);
|
|
5634
|
+
}
|
|
5635
|
+
getOutput() {
|
|
5636
|
+
return {
|
|
5637
|
+
traces: this.traces,
|
|
5638
|
+
netLabelPlacements: this.outputNetLabelPlacements
|
|
5639
|
+
};
|
|
5640
|
+
}
|
|
5641
|
+
getProcessableLabelIndices() {
|
|
5642
|
+
const indices = [];
|
|
5643
|
+
for (let i = 0; i < this.outputNetLabelPlacements.length; i++) {
|
|
5644
|
+
if (this.shouldProcessLabel(this.outputNetLabelPlacements[i], i)) {
|
|
5645
|
+
indices.push(i);
|
|
5646
|
+
}
|
|
5647
|
+
}
|
|
5648
|
+
return indices;
|
|
5649
|
+
}
|
|
5650
|
+
shouldProcessLabel(label, labelIndex) {
|
|
5651
|
+
const orientations = this.getAvailableOrientations(label);
|
|
5652
|
+
if (orientations.length === 0) return false;
|
|
5653
|
+
return !(orientations.includes(label.orientation) && this.isLabelPlacementValid(label, labelIndex));
|
|
5654
|
+
}
|
|
5655
|
+
processLabel(labelIndex) {
|
|
5656
|
+
const label = this.outputNetLabelPlacements[labelIndex];
|
|
5657
|
+
this.setCurrentLabel(labelIndex);
|
|
5658
|
+
this.currentCandidateResults = [];
|
|
5659
|
+
const candidate = this.findCorrectedCandidate(label, labelIndex);
|
|
5660
|
+
if (!candidate) return;
|
|
5661
|
+
this.applyCandidate(label, candidate, labelIndex);
|
|
5662
|
+
}
|
|
5663
|
+
applyCandidate(label, candidate, labelIndex) {
|
|
5664
|
+
this.outputNetLabelPlacements[labelIndex] = {
|
|
5665
|
+
...label,
|
|
5666
|
+
...toNetLabelPlacementPatch(candidate)
|
|
5667
|
+
};
|
|
5668
|
+
this.addConnectorTrace(label, candidate, labelIndex);
|
|
5669
|
+
}
|
|
5670
|
+
addConnectorTrace(label, candidate, labelIndex) {
|
|
5671
|
+
const tracePath = getConnectorTracePath(
|
|
5672
|
+
label.anchorPoint,
|
|
5673
|
+
candidate.anchorPoint,
|
|
5674
|
+
candidate.orientation
|
|
5675
|
+
);
|
|
5676
|
+
if (tracePath.length < 2) return;
|
|
5677
|
+
const mspPairId = `available-net-orientation-${labelIndex}-${label.netId ?? label.globalConnNetId}`;
|
|
5678
|
+
const connectorTrace = {
|
|
5679
|
+
mspPairId,
|
|
5680
|
+
dcConnNetId: label.dcConnNetId ?? label.globalConnNetId,
|
|
5681
|
+
globalConnNetId: label.globalConnNetId,
|
|
5682
|
+
userNetId: label.netId,
|
|
5683
|
+
pins: getTracePins(label, this.pinMap),
|
|
5684
|
+
tracePath,
|
|
5685
|
+
mspConnectionPairIds: [mspPairId],
|
|
5686
|
+
pinIds: label.pinIds
|
|
5687
|
+
};
|
|
5688
|
+
this.traces.push(connectorTrace);
|
|
5689
|
+
this.traceMap[mspPairId] = connectorTrace;
|
|
5690
|
+
}
|
|
5691
|
+
finish() {
|
|
5692
|
+
this.currentLabelIndex = null;
|
|
5693
|
+
this.currentLabel = null;
|
|
5694
|
+
this.currentCandidateResults = [];
|
|
5695
|
+
this.solved = true;
|
|
5696
|
+
}
|
|
5697
|
+
setCurrentLabel(labelIndex) {
|
|
5698
|
+
this.currentLabelIndex = labelIndex;
|
|
5699
|
+
this.currentLabel = labelIndex === null ? null : this.outputNetLabelPlacements[labelIndex];
|
|
5700
|
+
}
|
|
5701
|
+
findCorrectedCandidate(label, labelIndex) {
|
|
5702
|
+
const orientations = this.getAvailableOrientations(label);
|
|
5703
|
+
const rotatedCandidate = this.findValidRotatedCandidate(
|
|
5704
|
+
label,
|
|
5705
|
+
labelIndex,
|
|
5706
|
+
orientations
|
|
5707
|
+
);
|
|
5708
|
+
return rotatedCandidate ?? this.findValidShiftedCandidate(label, orientations[0], labelIndex);
|
|
5709
|
+
}
|
|
5710
|
+
findValidRotatedCandidate(label, labelIndex, orientations) {
|
|
5711
|
+
for (const orientation of orientations) {
|
|
5712
|
+
const candidate = this.createCandidate(
|
|
5713
|
+
label,
|
|
5714
|
+
this.getSearchStartAnchor(label, orientation),
|
|
5715
|
+
orientation
|
|
5716
|
+
);
|
|
5717
|
+
const result = this.evaluateCandidate(
|
|
5718
|
+
candidate,
|
|
5719
|
+
label,
|
|
5720
|
+
labelIndex,
|
|
5721
|
+
"rotate"
|
|
5722
|
+
);
|
|
5723
|
+
this.currentCandidateResults.push(result);
|
|
5724
|
+
if (result.status === "valid") {
|
|
5725
|
+
result.selected = true;
|
|
5726
|
+
return result;
|
|
5727
|
+
}
|
|
5728
|
+
}
|
|
5729
|
+
return null;
|
|
5730
|
+
}
|
|
5731
|
+
getAvailableOrientations(label) {
|
|
5732
|
+
const effectiveNetId = label.netId ?? label.globalConnNetId;
|
|
5733
|
+
return this.inputProblem.availableNetLabelOrientations[effectiveNetId] ?? [];
|
|
5734
|
+
}
|
|
5735
|
+
findValidShiftedCandidate(label, orientation, labelIndex) {
|
|
5736
|
+
const direction = dir(orientation);
|
|
5737
|
+
const initialBaseAnchor = this.getSearchStartAnchor(label, orientation);
|
|
5738
|
+
const outwardDirection = this.getPerpendicularOutwardDirection(
|
|
5739
|
+
label.anchorPoint,
|
|
5740
|
+
orientation
|
|
5741
|
+
);
|
|
5742
|
+
const maxSearchDistance = this.getSearchDistanceLimit(label, orientation);
|
|
5743
|
+
const maxOutwardDistance = outwardDirection.x === 0 && outwardDirection.y === 0 ? 0 : this.maxSearchDistance;
|
|
5744
|
+
for (let outwardDistance = 0; outwardDistance <= maxOutwardDistance + EPS6; outwardDistance += LABEL_SEARCH_STEP) {
|
|
5745
|
+
const baseAnchor = {
|
|
5746
|
+
x: initialBaseAnchor.x + outwardDirection.x * outwardDistance,
|
|
5747
|
+
y: initialBaseAnchor.y + outwardDirection.y * outwardDistance
|
|
5748
|
+
};
|
|
5749
|
+
const candidate = this.findValidCandidateInShiftColumn({
|
|
5750
|
+
label,
|
|
5751
|
+
labelIndex,
|
|
5752
|
+
orientation,
|
|
5753
|
+
direction,
|
|
5754
|
+
baseAnchor,
|
|
5755
|
+
maxSearchDistance,
|
|
5756
|
+
outwardDistance
|
|
5757
|
+
});
|
|
5758
|
+
if (candidate) return candidate;
|
|
5759
|
+
}
|
|
5760
|
+
return null;
|
|
5761
|
+
}
|
|
5762
|
+
findValidCandidateInShiftColumn(params) {
|
|
5763
|
+
const {
|
|
5764
|
+
label,
|
|
5765
|
+
labelIndex,
|
|
5766
|
+
orientation,
|
|
5767
|
+
direction,
|
|
5768
|
+
baseAnchor,
|
|
5769
|
+
maxSearchDistance,
|
|
5770
|
+
outwardDistance
|
|
5771
|
+
} = params;
|
|
5772
|
+
for (let distance3 = LABEL_SEARCH_STEP; distance3 <= maxSearchDistance + EPS6; distance3 += LABEL_SEARCH_STEP) {
|
|
5773
|
+
const anchorPoint = {
|
|
5774
|
+
x: baseAnchor.x + direction.x * distance3,
|
|
5775
|
+
y: baseAnchor.y + direction.y * distance3
|
|
5776
|
+
};
|
|
5777
|
+
const candidate = this.createCandidate(label, anchorPoint, orientation);
|
|
5778
|
+
const result = this.evaluateCandidate(
|
|
5779
|
+
candidate,
|
|
5780
|
+
label,
|
|
5781
|
+
labelIndex,
|
|
5782
|
+
"shift",
|
|
5783
|
+
distance3,
|
|
5784
|
+
outwardDistance
|
|
5785
|
+
);
|
|
5786
|
+
this.currentCandidateResults.push(result);
|
|
5787
|
+
if (result.status === "valid") {
|
|
5788
|
+
result.selected = true;
|
|
5789
|
+
return result;
|
|
5790
|
+
}
|
|
5791
|
+
if (result.status === "trace-collision") break;
|
|
5792
|
+
}
|
|
5793
|
+
return null;
|
|
5794
|
+
}
|
|
5795
|
+
evaluateCandidate(candidate, label, labelIndex, phase, distance3, outwardDistance) {
|
|
5796
|
+
return {
|
|
5797
|
+
...candidate,
|
|
5798
|
+
phase,
|
|
5799
|
+
distance: distance3,
|
|
5800
|
+
outwardDistance,
|
|
5801
|
+
selected: false,
|
|
5802
|
+
status: this.getCandidateStatus(candidate, label, labelIndex)
|
|
5803
|
+
};
|
|
5804
|
+
}
|
|
5805
|
+
getSearchStartAnchor(label, orientation) {
|
|
5806
|
+
const anchorPoint = this.getWickOffsetAnchor(label.anchorPoint, orientation);
|
|
5807
|
+
const { width, height } = getDimsForOrientation({
|
|
5808
|
+
orientation,
|
|
5809
|
+
netLabelWidth: this.getNetLabelWidth(label)
|
|
5810
|
+
});
|
|
5811
|
+
return this.getSideOffsetAnchor({
|
|
5812
|
+
anchorPoint,
|
|
5813
|
+
labelAnchorPoint: label.anchorPoint,
|
|
5814
|
+
orientation,
|
|
5815
|
+
width,
|
|
5816
|
+
height
|
|
5817
|
+
});
|
|
5818
|
+
}
|
|
5819
|
+
getWickOffsetAnchor(anchorPoint, orientation) {
|
|
5820
|
+
const direction = dir(orientation);
|
|
5821
|
+
return {
|
|
5822
|
+
x: anchorPoint.x + direction.x * WICK_CLEARANCE,
|
|
5823
|
+
y: anchorPoint.y + direction.y * WICK_CLEARANCE
|
|
5824
|
+
};
|
|
5825
|
+
}
|
|
5826
|
+
getSideOffsetAnchor(params) {
|
|
5827
|
+
const { anchorPoint, labelAnchorPoint, orientation, width, height } = params;
|
|
5828
|
+
const chipSide = this.getChipSideForPoint(labelAnchorPoint);
|
|
5829
|
+
if (isYOrientation(orientation) && chipSide === "left") {
|
|
5830
|
+
return {
|
|
5831
|
+
x: anchorPoint.x - width / 2 - WICK_CLEARANCE,
|
|
5832
|
+
y: anchorPoint.y
|
|
5833
|
+
};
|
|
5834
|
+
}
|
|
5835
|
+
if (isYOrientation(orientation) && chipSide === "right") {
|
|
5836
|
+
return {
|
|
5837
|
+
x: anchorPoint.x + width / 2 + WICK_CLEARANCE,
|
|
5838
|
+
y: anchorPoint.y
|
|
5839
|
+
};
|
|
5840
|
+
}
|
|
5841
|
+
if (isXOrientation(orientation) && chipSide === "bottom") {
|
|
5842
|
+
return {
|
|
5843
|
+
x: anchorPoint.x,
|
|
5844
|
+
y: anchorPoint.y - height / 2 - WICK_CLEARANCE
|
|
5845
|
+
};
|
|
5846
|
+
}
|
|
5847
|
+
if (isXOrientation(orientation) && chipSide === "top") {
|
|
5848
|
+
return {
|
|
5849
|
+
x: anchorPoint.x,
|
|
5850
|
+
y: anchorPoint.y + height / 2 + WICK_CLEARANCE
|
|
5851
|
+
};
|
|
5852
|
+
}
|
|
5853
|
+
return anchorPoint;
|
|
5854
|
+
}
|
|
5855
|
+
getSearchDistanceLimit(label, orientation) {
|
|
5856
|
+
const { width, height } = getDimsForOrientation({
|
|
5857
|
+
orientation,
|
|
5858
|
+
netLabelWidth: this.getNetLabelWidth(label)
|
|
5859
|
+
});
|
|
5860
|
+
const labelLength = orientation === "y+" || orientation === "y-" ? height : width;
|
|
5861
|
+
return Math.min(this.maxSearchDistance, labelLength * 2);
|
|
5862
|
+
}
|
|
5863
|
+
createCandidate(label, anchorPoint, orientation) {
|
|
5864
|
+
const { width, height } = getDimsForOrientation({
|
|
5865
|
+
orientation,
|
|
5866
|
+
netLabelWidth: this.getNetLabelWidth(label)
|
|
5867
|
+
});
|
|
5868
|
+
return {
|
|
5869
|
+
orientation,
|
|
5870
|
+
anchorPoint,
|
|
5871
|
+
width,
|
|
5872
|
+
height,
|
|
5873
|
+
center: getCenterFromAnchor(anchorPoint, orientation, width, height)
|
|
5874
|
+
};
|
|
5875
|
+
}
|
|
5876
|
+
getNetLabelWidth(label) {
|
|
5877
|
+
if (!label.netId) return void 0;
|
|
5878
|
+
return this.inputProblem.netConnections.find(
|
|
5879
|
+
(connection) => connection.netId === label.netId
|
|
5880
|
+
)?.netLabelWidth;
|
|
5881
|
+
}
|
|
5882
|
+
isLabelPlacementValid(label, labelIndex) {
|
|
5883
|
+
return this.isCandidateValidWithOffset(
|
|
5884
|
+
{
|
|
5885
|
+
orientation: label.orientation,
|
|
5886
|
+
anchorPoint: label.anchorPoint,
|
|
5887
|
+
center: label.center,
|
|
5888
|
+
width: label.width,
|
|
5889
|
+
height: label.height
|
|
5890
|
+
},
|
|
5891
|
+
labelIndex
|
|
5892
|
+
);
|
|
5893
|
+
}
|
|
5894
|
+
isCandidateValidWithOffset(candidate, labelIndex) {
|
|
5895
|
+
const bounds = this.getOffsetCollisionBounds(candidate);
|
|
5896
|
+
return this.getBoundsStatus(bounds, labelIndex) === "valid";
|
|
5897
|
+
}
|
|
5898
|
+
getCandidateStatus(candidate, label, labelIndex) {
|
|
5899
|
+
const boundsStatus = this.getBoundsStatus(
|
|
5900
|
+
getRectBounds(candidate.center, candidate.width, candidate.height),
|
|
5901
|
+
labelIndex
|
|
5902
|
+
);
|
|
5903
|
+
if (boundsStatus !== "valid") return boundsStatus;
|
|
5904
|
+
if (tracePathCrossesAnyTrace(
|
|
5905
|
+
getConnectorTracePath(
|
|
5906
|
+
label.anchorPoint,
|
|
5907
|
+
candidate.anchorPoint,
|
|
5908
|
+
candidate.orientation
|
|
5909
|
+
),
|
|
5910
|
+
this.traceMap
|
|
5911
|
+
)) {
|
|
5912
|
+
return "trace-collision";
|
|
5913
|
+
}
|
|
5914
|
+
return "valid";
|
|
5915
|
+
}
|
|
5916
|
+
getBoundsStatus(bounds, labelIndex) {
|
|
5917
|
+
if (this.chipObstacleSpatialIndex.getChipsInBounds(bounds).length > 0) {
|
|
5918
|
+
return "chip-collision";
|
|
5919
|
+
}
|
|
5920
|
+
if (this.sharesChipBoundary(bounds)) {
|
|
5921
|
+
return "chip-collision";
|
|
5922
|
+
}
|
|
5923
|
+
if (traceCrossesBoundsInterior(bounds, this.traceMap)) {
|
|
5924
|
+
return "trace-collision";
|
|
5925
|
+
}
|
|
5926
|
+
if (this.intersectsAnyOtherNetLabel(bounds, labelIndex)) {
|
|
5927
|
+
return "netlabel-collision";
|
|
5928
|
+
}
|
|
5929
|
+
return "valid";
|
|
5930
|
+
}
|
|
5931
|
+
getOffsetCollisionBounds(candidate) {
|
|
5932
|
+
const direction = dir(candidate.orientation);
|
|
5933
|
+
const collisionTestOffset = 1e-4;
|
|
5934
|
+
const testCenter = {
|
|
5935
|
+
x: candidate.center.x + direction.x * collisionTestOffset,
|
|
5936
|
+
y: candidate.center.y + direction.y * collisionTestOffset
|
|
5937
|
+
};
|
|
5938
|
+
return getRectBounds(testCenter, candidate.width, candidate.height);
|
|
5939
|
+
}
|
|
5940
|
+
intersectsAnyOtherNetLabel(bounds, labelIndex) {
|
|
5941
|
+
for (let i = 0; i < this.outputNetLabelPlacements.length; i++) {
|
|
5942
|
+
if (i === labelIndex) continue;
|
|
5943
|
+
const label = this.outputNetLabelPlacements[i];
|
|
5944
|
+
const otherBounds = getRectBounds(label.center, label.width, label.height);
|
|
5945
|
+
if (rectsOverlap(bounds, otherBounds)) return true;
|
|
5946
|
+
}
|
|
5947
|
+
return false;
|
|
5948
|
+
}
|
|
5949
|
+
sharesChipBoundary(bounds) {
|
|
5950
|
+
for (const chip of this.chipObstacleSpatialIndex.chips) {
|
|
5951
|
+
const chipBounds = chip.bounds;
|
|
5952
|
+
const adjacentToVerticalSide = Math.abs(bounds.minX - chipBounds.maxX) <= WICK_CLEARANCE + EPS6 || Math.abs(bounds.maxX - chipBounds.minX) <= WICK_CLEARANCE + EPS6;
|
|
5953
|
+
const adjacentToHorizontalSide = Math.abs(bounds.minY - chipBounds.maxY) <= WICK_CLEARANCE + EPS6 || Math.abs(bounds.maxY - chipBounds.minY) <= WICK_CLEARANCE + EPS6;
|
|
5954
|
+
if (adjacentToVerticalSide && rangesOverlap(
|
|
5955
|
+
bounds.minY,
|
|
5956
|
+
bounds.maxY,
|
|
5957
|
+
chipBounds.minY,
|
|
5958
|
+
chipBounds.maxY
|
|
5959
|
+
)) {
|
|
5960
|
+
return true;
|
|
5961
|
+
}
|
|
5962
|
+
if (adjacentToHorizontalSide && rangesOverlap(
|
|
5963
|
+
bounds.minX,
|
|
5964
|
+
bounds.maxX,
|
|
5965
|
+
chipBounds.minX,
|
|
5966
|
+
chipBounds.maxX
|
|
5967
|
+
)) {
|
|
5968
|
+
return true;
|
|
5969
|
+
}
|
|
5970
|
+
}
|
|
5971
|
+
return false;
|
|
5972
|
+
}
|
|
5973
|
+
getChipSideForPoint(point) {
|
|
5974
|
+
const containingSide = this.getContainingChipSide(point);
|
|
5975
|
+
if (containingSide) return containingSide;
|
|
5976
|
+
const side = this.getOutsideChipSide(point);
|
|
5977
|
+
if (side) return side;
|
|
5978
|
+
return this.getNearestChipSide(point);
|
|
5979
|
+
}
|
|
5980
|
+
getPerpendicularOutwardDirection(point, orientation) {
|
|
5981
|
+
const chipSide = this.getChipSideForPoint(point);
|
|
5982
|
+
if (isYOrientation(orientation) && chipSide === "left") {
|
|
5983
|
+
return { x: -1, y: 0 };
|
|
5984
|
+
}
|
|
5985
|
+
if (isYOrientation(orientation) && chipSide === "right") {
|
|
5986
|
+
return { x: 1, y: 0 };
|
|
5987
|
+
}
|
|
5988
|
+
if (isXOrientation(orientation) && chipSide === "bottom") {
|
|
5989
|
+
return { x: 0, y: -1 };
|
|
5990
|
+
}
|
|
5991
|
+
if (isXOrientation(orientation) && chipSide === "top") {
|
|
5992
|
+
return { x: 0, y: 1 };
|
|
5993
|
+
}
|
|
5994
|
+
return { x: 0, y: 0 };
|
|
5995
|
+
}
|
|
5996
|
+
getContainingChipSide(point) {
|
|
5997
|
+
let nearestSide = null;
|
|
5998
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
5999
|
+
for (const chip of this.chipObstacleSpatialIndex.chips) {
|
|
6000
|
+
const bounds = chip.bounds;
|
|
6001
|
+
if (point.x < bounds.minX - EPS6 || point.x > bounds.maxX + EPS6 || point.y < bounds.minY - EPS6 || point.y > bounds.maxY + EPS6) {
|
|
6002
|
+
continue;
|
|
6003
|
+
}
|
|
6004
|
+
for (const [side, distance3] of getSideDistances(point, bounds)) {
|
|
6005
|
+
if (distance3 < nearestDistance) {
|
|
6006
|
+
nearestSide = side;
|
|
6007
|
+
nearestDistance = distance3;
|
|
6008
|
+
}
|
|
6009
|
+
}
|
|
6010
|
+
}
|
|
6011
|
+
return nearestSide;
|
|
6012
|
+
}
|
|
6013
|
+
getOutsideChipSide(point) {
|
|
6014
|
+
let nearestSide = null;
|
|
6015
|
+
let nearestDistanceSq = Number.POSITIVE_INFINITY;
|
|
6016
|
+
for (const chip of this.chipObstacleSpatialIndex.chips) {
|
|
6017
|
+
const bounds = chip.bounds;
|
|
6018
|
+
const dx = point.x < bounds.minX - EPS6 ? bounds.minX - point.x : point.x > bounds.maxX + EPS6 ? point.x - bounds.maxX : 0;
|
|
6019
|
+
const dy = point.y < bounds.minY - EPS6 ? bounds.minY - point.y : point.y > bounds.maxY + EPS6 ? point.y - bounds.maxY : 0;
|
|
6020
|
+
if (dx === 0 && dy === 0) continue;
|
|
6021
|
+
const distanceSq = dx ** 2 + dy ** 2;
|
|
6022
|
+
if (distanceSq >= nearestDistanceSq) continue;
|
|
6023
|
+
nearestDistanceSq = distanceSq;
|
|
6024
|
+
if (dx > 0) {
|
|
6025
|
+
nearestSide = point.x < bounds.minX ? "left" : "right";
|
|
6026
|
+
} else {
|
|
6027
|
+
nearestSide = point.y < bounds.minY ? "bottom" : "top";
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
return nearestSide;
|
|
6031
|
+
}
|
|
6032
|
+
getNearestChipSide(point) {
|
|
6033
|
+
let nearestSide = null;
|
|
6034
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
6035
|
+
for (const chip of this.chipObstacleSpatialIndex.chips) {
|
|
6036
|
+
for (const [side, distance3] of getSideDistances(point, chip.bounds)) {
|
|
6037
|
+
if (distance3 < nearestDistance) {
|
|
6038
|
+
nearestSide = side;
|
|
6039
|
+
nearestDistance = distance3;
|
|
6040
|
+
}
|
|
6041
|
+
}
|
|
6042
|
+
}
|
|
6043
|
+
return nearestSide;
|
|
6044
|
+
}
|
|
6045
|
+
visualize() {
|
|
6046
|
+
return visualizeAvailableNetOrientationSolver({
|
|
6047
|
+
inputProblem: this.inputProblem,
|
|
6048
|
+
traces: this.traces,
|
|
6049
|
+
outputNetLabelPlacements: this.outputNetLabelPlacements,
|
|
6050
|
+
currentLabel: this.currentLabel,
|
|
6051
|
+
currentCandidateResults: this.currentCandidateResults,
|
|
6052
|
+
solved: this.solved
|
|
6053
|
+
});
|
|
6054
|
+
}
|
|
6055
|
+
};
|
|
6056
|
+
|
|
6057
|
+
// lib/solvers/VccNetLabelCornerPlacementSolver/geometry.ts
|
|
6058
|
+
var EPS7 = 1e-6;
|
|
6059
|
+
var isTraceLine = (trace) => getUniquePinCount(trace.pinIds) >= 2;
|
|
6060
|
+
var rectsOverlap2 = (a, b) => Math.min(a.maxX, b.maxX) - Math.max(a.minX, b.minX) > EPS7 && Math.min(a.maxY, b.maxY) - Math.max(a.minY, b.minY) > EPS7;
|
|
6061
|
+
var getTraceCorners = (path) => {
|
|
6062
|
+
const corners = [];
|
|
6063
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
6064
|
+
const previousPoint = path[i - 1];
|
|
6065
|
+
const cornerPoint = path[i];
|
|
6066
|
+
const nextPoint = path[i + 1];
|
|
6067
|
+
if (isTraceCorner(previousPoint, cornerPoint, nextPoint)) {
|
|
6068
|
+
corners.push(cornerPoint);
|
|
6069
|
+
}
|
|
6070
|
+
}
|
|
6071
|
+
return corners;
|
|
6072
|
+
};
|
|
6073
|
+
var tracePathContainsPoint = (path, point) => {
|
|
6074
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
6075
|
+
if (isPointOnSegment(point, path[i], path[i + 1])) return true;
|
|
6076
|
+
}
|
|
6077
|
+
return false;
|
|
6078
|
+
};
|
|
6079
|
+
var getDistance2 = (a, b) => Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
6080
|
+
var getUniquePinCount = (pinIds) => new Set(pinIds).size;
|
|
6081
|
+
var isTraceCorner = (a, b, c) => getSegmentOrientation2(a, b) !== getSegmentOrientation2(b, c);
|
|
6082
|
+
var isPointOnSegment = (point, start, end) => {
|
|
6083
|
+
if (getSegmentOrientation2(start, end) === "horizontal") {
|
|
6084
|
+
return Math.abs(point.y - start.y) <= EPS7 && point.x >= Math.min(start.x, end.x) - EPS7 && point.x <= Math.max(start.x, end.x) + EPS7;
|
|
6085
|
+
}
|
|
6086
|
+
return Math.abs(point.x - start.x) <= EPS7 && point.y >= Math.min(start.y, end.y) - EPS7 && point.y <= Math.max(start.y, end.y) + EPS7;
|
|
6087
|
+
};
|
|
6088
|
+
var getSegmentOrientation2 = (a, b) => Math.abs(a.y - b.y) <= EPS7 ? "horizontal" : "vertical";
|
|
6089
|
+
|
|
6090
|
+
// lib/solvers/VccNetLabelCornerPlacementSolver/visualize.ts
|
|
6091
|
+
var CANDIDATE_SELECTED_COLOR3 = "blue";
|
|
6092
|
+
var CANDIDATE_REJECTED_COLOR3 = "red";
|
|
6093
|
+
var visualizeVccNetLabelCornerPlacementSolver = (state) => {
|
|
6094
|
+
const graphics = visualizeInputProblem(state.inputProblem);
|
|
6095
|
+
ensureGraphicsArrays2(graphics);
|
|
6096
|
+
drawTraces3(graphics, state.traces);
|
|
6097
|
+
drawNetLabels3(graphics, state.outputNetLabelPlacements);
|
|
6098
|
+
if (!state.solved) {
|
|
6099
|
+
drawCurrentLabel2(graphics, state.currentLabel);
|
|
6100
|
+
drawCurrentCandidates3(graphics, state.currentCandidateResults);
|
|
6101
|
+
}
|
|
6102
|
+
return graphics;
|
|
6103
|
+
};
|
|
6104
|
+
var drawTraces3 = (graphics, traces) => {
|
|
6105
|
+
for (const trace of traces) {
|
|
6106
|
+
graphics.lines.push({
|
|
6107
|
+
points: trace.tracePath,
|
|
6108
|
+
strokeColor: "purple"
|
|
6109
|
+
});
|
|
6110
|
+
}
|
|
6111
|
+
};
|
|
6112
|
+
var drawNetLabels3 = (graphics, labels) => {
|
|
6113
|
+
for (const label of labels) {
|
|
6114
|
+
graphics.rects.push({
|
|
6115
|
+
center: label.center,
|
|
6116
|
+
width: label.width,
|
|
6117
|
+
height: label.height,
|
|
6118
|
+
fill: getColorFromString(label.globalConnNetId, 0.35),
|
|
6119
|
+
strokeColor: getColorFromString(label.globalConnNetId, 0.9),
|
|
6120
|
+
label: `netId: ${label.netId}
|
|
6121
|
+
globalConnNetId: ${label.globalConnNetId}`
|
|
6122
|
+
});
|
|
6123
|
+
graphics.points.push({
|
|
6124
|
+
x: label.anchorPoint.x,
|
|
6125
|
+
y: label.anchorPoint.y,
|
|
6126
|
+
color: getColorFromString(label.globalConnNetId, 0.9),
|
|
6127
|
+
label: `anchorPoint
|
|
6128
|
+
orientation: ${label.orientation}`
|
|
6129
|
+
});
|
|
6130
|
+
}
|
|
6131
|
+
};
|
|
6132
|
+
var drawCurrentLabel2 = (graphics, currentLabel) => {
|
|
6133
|
+
if (!currentLabel) return;
|
|
6134
|
+
graphics.rects.push({
|
|
6135
|
+
center: currentLabel.center,
|
|
6136
|
+
width: currentLabel.width,
|
|
6137
|
+
height: currentLabel.height,
|
|
6138
|
+
fill: "rgba(255, 0, 0, 0.2)",
|
|
6139
|
+
strokeColor: CANDIDATE_REJECTED_COLOR3,
|
|
6140
|
+
label: `trace-line VCC target
|
|
6141
|
+
${currentLabel.netId ?? currentLabel.globalConnNetId}`
|
|
6142
|
+
});
|
|
6143
|
+
};
|
|
6144
|
+
var drawCurrentCandidates3 = (graphics, candidates) => {
|
|
6145
|
+
for (const candidate of candidates) {
|
|
6146
|
+
const color = candidate.selected ? CANDIDATE_SELECTED_COLOR3 : CANDIDATE_REJECTED_COLOR3;
|
|
6147
|
+
graphics.rects.push({
|
|
6148
|
+
center: candidate.center,
|
|
6149
|
+
width: candidate.width,
|
|
6150
|
+
height: candidate.height,
|
|
6151
|
+
fill: candidate.selected ? "rgba(0, 0, 255, 0.2)" : "rgba(255, 0, 0, 0.15)",
|
|
6152
|
+
strokeColor: color,
|
|
6153
|
+
strokeDash: candidate.selected ? void 0 : "4 2",
|
|
6154
|
+
label: `${candidate.selected ? "selected" : candidate.status} trace corner
|
|
6155
|
+
trace: ${candidate.traceId}
|
|
6156
|
+
distance: ${candidate.distance.toFixed(3)}`
|
|
6157
|
+
});
|
|
6158
|
+
graphics.points.push({
|
|
6159
|
+
...candidate.anchorPoint,
|
|
6160
|
+
color,
|
|
6161
|
+
label: `candidate anchor
|
|
6162
|
+
${candidate.status}`
|
|
6163
|
+
});
|
|
6164
|
+
}
|
|
6165
|
+
};
|
|
6166
|
+
var ensureGraphicsArrays2 = (graphics) => {
|
|
6167
|
+
if (!graphics.lines) graphics.lines = [];
|
|
6168
|
+
if (!graphics.points) graphics.points = [];
|
|
6169
|
+
if (!graphics.rects) graphics.rects = [];
|
|
6170
|
+
if (!graphics.circles) graphics.circles = [];
|
|
6171
|
+
if (!graphics.texts) graphics.texts = [];
|
|
6172
|
+
};
|
|
6173
|
+
|
|
6174
|
+
// lib/solvers/VccNetLabelCornerPlacementSolver/VccNetLabelCornerPlacementSolver.ts
|
|
6175
|
+
var VccNetLabelCornerPlacementSolver = class extends BaseSolver {
|
|
6176
|
+
inputProblem;
|
|
6177
|
+
traces;
|
|
6178
|
+
netLabelPlacements;
|
|
6179
|
+
outputNetLabelPlacements;
|
|
6180
|
+
queuedLabelIndices = [];
|
|
6181
|
+
currentLabelIndex = null;
|
|
6182
|
+
currentLabel = null;
|
|
6183
|
+
currentCandidateResults = [];
|
|
6184
|
+
queuedCornerCandidates = [];
|
|
6185
|
+
shouldAdvanceToNextLabel = false;
|
|
6186
|
+
traceMap;
|
|
6187
|
+
constructor(params) {
|
|
6188
|
+
super();
|
|
6189
|
+
this.inputProblem = params.inputProblem;
|
|
6190
|
+
this.traces = params.traces;
|
|
6191
|
+
this.netLabelPlacements = params.netLabelPlacements;
|
|
6192
|
+
this.outputNetLabelPlacements = [...params.netLabelPlacements];
|
|
6193
|
+
this.traceMap = Object.fromEntries(
|
|
6194
|
+
params.traces.map((trace) => [trace.mspPairId, trace])
|
|
6195
|
+
);
|
|
6196
|
+
this.queuedLabelIndices = this.getProcessableLabelIndices();
|
|
6197
|
+
this.prepareNextLabel();
|
|
6198
|
+
}
|
|
6199
|
+
getConstructorParams() {
|
|
6200
|
+
return {
|
|
6201
|
+
inputProblem: this.inputProblem,
|
|
6202
|
+
traces: this.traces,
|
|
6203
|
+
netLabelPlacements: this.netLabelPlacements
|
|
6204
|
+
};
|
|
6205
|
+
}
|
|
6206
|
+
_step() {
|
|
6207
|
+
if (this.shouldAdvanceToNextLabel) {
|
|
6208
|
+
this.advanceToNextLabel();
|
|
6209
|
+
return;
|
|
6210
|
+
}
|
|
6211
|
+
const label = this.currentLabel;
|
|
6212
|
+
const labelIndex = this.currentLabelIndex;
|
|
6213
|
+
if (label === null || labelIndex === null) {
|
|
6214
|
+
this.finish();
|
|
6215
|
+
return;
|
|
6216
|
+
}
|
|
6217
|
+
const candidate = this.queuedCornerCandidates.shift();
|
|
6218
|
+
if (!candidate) {
|
|
6219
|
+
this.shouldAdvanceToNextLabel = true;
|
|
6220
|
+
return;
|
|
6221
|
+
}
|
|
6222
|
+
const result = this.evaluateCornerCandidate(label, labelIndex, candidate);
|
|
6223
|
+
this.currentCandidateResults.push(result);
|
|
6224
|
+
if (result.status !== "valid") return;
|
|
6225
|
+
result.selected = true;
|
|
6226
|
+
this.applyCandidate(labelIndex, label, result);
|
|
6227
|
+
this.shouldAdvanceToNextLabel = true;
|
|
6228
|
+
}
|
|
6229
|
+
getOutput() {
|
|
6230
|
+
return {
|
|
6231
|
+
netLabelPlacements: this.outputNetLabelPlacements
|
|
6232
|
+
};
|
|
6233
|
+
}
|
|
6234
|
+
getProcessableLabelIndices() {
|
|
6235
|
+
const labelIndices = [];
|
|
6236
|
+
for (let i = 0; i < this.outputNetLabelPlacements.length; i++) {
|
|
6237
|
+
const label = this.outputNetLabelPlacements[i];
|
|
6238
|
+
if (!this.shouldProcessLabel(label)) continue;
|
|
6239
|
+
labelIndices.push(i);
|
|
6240
|
+
}
|
|
6241
|
+
return labelIndices;
|
|
6242
|
+
}
|
|
6243
|
+
prepareNextLabel() {
|
|
6244
|
+
const labelIndex = this.queuedLabelIndices.shift();
|
|
6245
|
+
if (labelIndex === void 0) {
|
|
6246
|
+
this.clearCurrentLabel();
|
|
6247
|
+
return false;
|
|
6248
|
+
}
|
|
6249
|
+
const label = this.outputNetLabelPlacements[labelIndex];
|
|
6250
|
+
this.currentLabelIndex = labelIndex;
|
|
6251
|
+
this.currentLabel = label;
|
|
6252
|
+
this.currentCandidateResults = [];
|
|
6253
|
+
this.queuedCornerCandidates = this.getCornerCandidatesForLabel(label);
|
|
6254
|
+
return true;
|
|
6255
|
+
}
|
|
6256
|
+
advanceToNextLabel() {
|
|
6257
|
+
this.shouldAdvanceToNextLabel = false;
|
|
6258
|
+
if (!this.prepareNextLabel()) this.finish();
|
|
6259
|
+
}
|
|
6260
|
+
clearCurrentLabel() {
|
|
6261
|
+
this.currentLabelIndex = null;
|
|
6262
|
+
this.currentLabel = null;
|
|
6263
|
+
this.currentCandidateResults = [];
|
|
6264
|
+
this.queuedCornerCandidates = [];
|
|
6265
|
+
}
|
|
6266
|
+
finish() {
|
|
6267
|
+
this.clearCurrentLabel();
|
|
6268
|
+
this.solved = true;
|
|
6269
|
+
}
|
|
6270
|
+
evaluateCornerCandidate(label, labelIndex, candidate) {
|
|
6271
|
+
const center = getCenterFromAnchor(
|
|
6272
|
+
candidate.anchorPoint,
|
|
6273
|
+
label.orientation,
|
|
6274
|
+
label.width,
|
|
6275
|
+
label.height
|
|
6276
|
+
);
|
|
6277
|
+
const bounds = getRectBounds(center, label.width, label.height);
|
|
6278
|
+
return {
|
|
6279
|
+
...candidate,
|
|
6280
|
+
center,
|
|
6281
|
+
width: label.width,
|
|
6282
|
+
height: label.height,
|
|
6283
|
+
status: this.getCandidateStatus(bounds, labelIndex),
|
|
6284
|
+
selected: false
|
|
6285
|
+
};
|
|
6286
|
+
}
|
|
6287
|
+
getCandidateStatus(bounds, labelIndex) {
|
|
6288
|
+
if (this.intersectsAnyChip(bounds)) return "chip-collision";
|
|
6289
|
+
if (traceCrossesBoundsInterior(bounds, this.traceMap)) {
|
|
6290
|
+
return "trace-collision";
|
|
6291
|
+
}
|
|
6292
|
+
if (this.intersectsAnyOtherNetLabel(bounds, labelIndex)) {
|
|
6293
|
+
return "netlabel-collision";
|
|
6294
|
+
}
|
|
6295
|
+
return "valid";
|
|
6296
|
+
}
|
|
6297
|
+
applyCandidate(labelIndex, label, candidate) {
|
|
6298
|
+
this.outputNetLabelPlacements[labelIndex] = {
|
|
6299
|
+
...label,
|
|
6300
|
+
anchorPoint: candidate.anchorPoint,
|
|
6301
|
+
center: candidate.center
|
|
6302
|
+
};
|
|
6303
|
+
}
|
|
6304
|
+
shouldProcessLabel(label) {
|
|
6305
|
+
return label.netId === "VCC" && this.getCornerCandidatesForLabel(label).length > 0;
|
|
6306
|
+
}
|
|
6307
|
+
intersectsAnyChip(bounds) {
|
|
6308
|
+
return this.inputProblem.chips.some(
|
|
6309
|
+
(chip) => rectsOverlap2(bounds, getRectBounds(chip.center, chip.width, chip.height))
|
|
6310
|
+
);
|
|
6311
|
+
}
|
|
6312
|
+
intersectsAnyOtherNetLabel(bounds, labelIndex) {
|
|
6313
|
+
return this.outputNetLabelPlacements.some((label, index) => {
|
|
6314
|
+
if (index === labelIndex) return false;
|
|
6315
|
+
return rectsOverlap2(
|
|
6316
|
+
bounds,
|
|
6317
|
+
getRectBounds(label.center, label.width, label.height)
|
|
6318
|
+
);
|
|
6319
|
+
});
|
|
6320
|
+
}
|
|
6321
|
+
getCornerCandidatesForLabel(label) {
|
|
6322
|
+
const candidates = [];
|
|
6323
|
+
const seenCornerKeys = /* @__PURE__ */ new Set();
|
|
6324
|
+
for (const trace of this.getTraceLinesForLabel(label)) {
|
|
6325
|
+
for (const anchorPoint of getTraceCorners(trace.tracePath)) {
|
|
6326
|
+
const key = `${anchorPoint.x}:${anchorPoint.y}`;
|
|
6327
|
+
if (seenCornerKeys.has(key)) continue;
|
|
6328
|
+
seenCornerKeys.add(key);
|
|
6329
|
+
candidates.push({
|
|
6330
|
+
anchorPoint,
|
|
6331
|
+
traceId: trace.mspPairId,
|
|
6332
|
+
distance: getDistance2(anchorPoint, label.anchorPoint)
|
|
6333
|
+
});
|
|
6334
|
+
}
|
|
6335
|
+
}
|
|
6336
|
+
return candidates.sort((a, b) => a.distance - b.distance);
|
|
6337
|
+
}
|
|
6338
|
+
getTraceLinesForLabel(label) {
|
|
6339
|
+
return this.traces.filter(
|
|
6340
|
+
(trace) => isTraceLine(trace) && this.isTraceForLabel(trace, label)
|
|
6341
|
+
);
|
|
6342
|
+
}
|
|
6343
|
+
isTraceForLabel(trace, label) {
|
|
6344
|
+
if (!tracePathContainsPoint(trace.tracePath, label.anchorPoint)) {
|
|
6345
|
+
return false;
|
|
6346
|
+
}
|
|
6347
|
+
const traceIds = new Set(label.mspConnectionPairIds);
|
|
6348
|
+
if (traceIds.size > 0) {
|
|
6349
|
+
return traceIds.has(trace.mspPairId);
|
|
6350
|
+
}
|
|
6351
|
+
return trace.globalConnNetId === label.globalConnNetId;
|
|
6352
|
+
}
|
|
6353
|
+
visualize() {
|
|
6354
|
+
return visualizeVccNetLabelCornerPlacementSolver({
|
|
6355
|
+
inputProblem: this.inputProblem,
|
|
6356
|
+
traces: this.traces,
|
|
6357
|
+
outputNetLabelPlacements: this.outputNetLabelPlacements,
|
|
6358
|
+
currentLabel: this.currentLabel,
|
|
6359
|
+
currentCandidateResults: this.currentCandidateResults,
|
|
6360
|
+
solved: this.solved
|
|
6361
|
+
});
|
|
6362
|
+
}
|
|
6363
|
+
};
|
|
6364
|
+
|
|
5348
6365
|
// lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts
|
|
5349
6366
|
function definePipelineStep(solverName, solverClass, getConstructorParams, opts = {}) {
|
|
5350
6367
|
return {
|
|
@@ -5366,6 +6383,8 @@ var SchematicTracePipelineSolver = class extends BaseSolver {
|
|
|
5366
6383
|
traceLabelOverlapAvoidanceSolver;
|
|
5367
6384
|
traceCleanupSolver;
|
|
5368
6385
|
example28Solver;
|
|
6386
|
+
availableNetOrientationSolver;
|
|
6387
|
+
vccNetLabelCornerPlacementSolver;
|
|
5369
6388
|
startTimeOfPhase;
|
|
5370
6389
|
endTimeOfPhase;
|
|
5371
6390
|
timeSpentOnPhase;
|
|
@@ -5511,7 +6530,31 @@ var SchematicTracePipelineSolver = class extends BaseSolver {
|
|
|
5511
6530
|
netLabelPlacements: instance.netLabelPlacementSolver.netLabelPlacements
|
|
5512
6531
|
}
|
|
5513
6532
|
];
|
|
5514
|
-
})
|
|
6533
|
+
}),
|
|
6534
|
+
definePipelineStep(
|
|
6535
|
+
"availableNetOrientationSolver",
|
|
6536
|
+
AvailableNetOrientationSolver,
|
|
6537
|
+
(instance) => [
|
|
6538
|
+
{
|
|
6539
|
+
inputProblem: instance.inputProblem,
|
|
6540
|
+
traces: instance.example28Solver.outputTraces,
|
|
6541
|
+
netLabelPlacements: instance.example28Solver.outputNetLabelPlacements
|
|
6542
|
+
}
|
|
6543
|
+
]
|
|
6544
|
+
),
|
|
6545
|
+
definePipelineStep(
|
|
6546
|
+
"vccNetLabelCornerPlacementSolver",
|
|
6547
|
+
VccNetLabelCornerPlacementSolver,
|
|
6548
|
+
(instance) => {
|
|
6549
|
+
return [
|
|
6550
|
+
{
|
|
6551
|
+
inputProblem: instance.inputProblem,
|
|
6552
|
+
traces: instance.availableNetOrientationSolver.traces,
|
|
6553
|
+
netLabelPlacements: instance.availableNetOrientationSolver.outputNetLabelPlacements
|
|
6554
|
+
}
|
|
6555
|
+
];
|
|
6556
|
+
}
|
|
6557
|
+
)
|
|
5515
6558
|
];
|
|
5516
6559
|
constructor(inputProblem) {
|
|
5517
6560
|
super();
|