calculate-packing 0.0.18 → 0.0.19
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 +65 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -132,6 +132,69 @@ var rotatePoint = (point, angle, origin = { x: 0, y: 0 }) => {
|
|
|
132
132
|
};
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
+
// lib/math/cross.ts
|
|
136
|
+
var cross = (O, A, B) => (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
|
|
137
|
+
|
|
138
|
+
// lib/geometry/simplify-collinear-segments.ts
|
|
139
|
+
function simplifyCollinearSegments(outline, tolerance = 1e-10) {
|
|
140
|
+
if (outline.length <= 1) {
|
|
141
|
+
return outline;
|
|
142
|
+
}
|
|
143
|
+
const simplified = [];
|
|
144
|
+
let currentSegmentStart = outline[0][0];
|
|
145
|
+
let currentSegmentEnd = outline[0][1];
|
|
146
|
+
for (let i = 1; i < outline.length; i++) {
|
|
147
|
+
const nextSegment = outline[i];
|
|
148
|
+
const [nextStart, nextEnd] = nextSegment;
|
|
149
|
+
const connectionTolerance = 1e-10;
|
|
150
|
+
const isConnected = Math.abs(currentSegmentEnd.x - nextStart.x) < connectionTolerance && Math.abs(currentSegmentEnd.y - nextStart.y) < connectionTolerance;
|
|
151
|
+
if (!isConnected) {
|
|
152
|
+
simplified.push([currentSegmentStart, currentSegmentEnd]);
|
|
153
|
+
currentSegmentStart = nextStart;
|
|
154
|
+
currentSegmentEnd = nextEnd;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const crossProduct = cross(currentSegmentStart, currentSegmentEnd, nextEnd);
|
|
158
|
+
if (Math.abs(crossProduct) < tolerance) {
|
|
159
|
+
currentSegmentEnd = nextEnd;
|
|
160
|
+
} else {
|
|
161
|
+
simplified.push([currentSegmentStart, currentSegmentEnd]);
|
|
162
|
+
currentSegmentStart = nextStart;
|
|
163
|
+
currentSegmentEnd = nextEnd;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (outline.length > 2) {
|
|
167
|
+
const firstSegment = simplified[0];
|
|
168
|
+
const lastSegmentCandidate = [
|
|
169
|
+
currentSegmentStart,
|
|
170
|
+
currentSegmentEnd
|
|
171
|
+
];
|
|
172
|
+
if (firstSegment && simplified.length > 0) {
|
|
173
|
+
const connectionTolerance = 1e-10;
|
|
174
|
+
const isLastConnectedToFirst = Math.abs(currentSegmentEnd.x - firstSegment[0].x) < connectionTolerance && Math.abs(currentSegmentEnd.y - firstSegment[0].y) < connectionTolerance;
|
|
175
|
+
if (isLastConnectedToFirst) {
|
|
176
|
+
const crossProduct = cross(
|
|
177
|
+
currentSegmentStart,
|
|
178
|
+
currentSegmentEnd,
|
|
179
|
+
firstSegment[1]
|
|
180
|
+
);
|
|
181
|
+
if (Math.abs(crossProduct) < tolerance) {
|
|
182
|
+
simplified[0] = [currentSegmentStart, firstSegment[1]];
|
|
183
|
+
} else {
|
|
184
|
+
simplified.push(lastSegmentCandidate);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
simplified.push(lastSegmentCandidate);
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
simplified.push(lastSegmentCandidate);
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
simplified.push([currentSegmentStart, currentSegmentEnd]);
|
|
194
|
+
}
|
|
195
|
+
return simplified;
|
|
196
|
+
}
|
|
197
|
+
|
|
135
198
|
// lib/constructOutlinesFromPackedComponents.ts
|
|
136
199
|
var createPadPolygons = (component, minGap) => {
|
|
137
200
|
return component.pads.map((pad) => {
|
|
@@ -185,7 +248,8 @@ var constructOutlinesFromPackedComponents = (components, opts = {}) => {
|
|
|
185
248
|
]);
|
|
186
249
|
edge = edge.next;
|
|
187
250
|
} while (edge !== face.first);
|
|
188
|
-
|
|
251
|
+
const simplifiedOutline = simplifyCollinearSegments(outline);
|
|
252
|
+
outlines.push(simplifiedOutline);
|
|
189
253
|
}
|
|
190
254
|
return outlines;
|
|
191
255
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "calculate-packing",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.19",
|
|
6
6
|
"description": "Calculate a packing layout with support for different strategy configurations",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "cosmos",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"react-dom": "^19.1.0",
|
|
35
35
|
"tscircuit": "^0.0.562",
|
|
36
36
|
"tsup": "^8.5.0",
|
|
37
|
-
"vite": "^7.
|
|
37
|
+
"vite": "^7.1.2"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"typescript": "^5",
|