calculate-packing 0.0.55 → 0.0.57
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 +44 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3110,12 +3110,30 @@ var convertCircuitJsonToPackOutput = (circuitJson, opts = {}) => {
|
|
|
3110
3110
|
return `unnamed${unnamedCounter++}`;
|
|
3111
3111
|
};
|
|
3112
3112
|
const topLevelNodes = tree.childNodes ?? [];
|
|
3113
|
+
const collectRelativeToGroupAnchorComponents = (node) => {
|
|
3114
|
+
const relativeComponents2 = [];
|
|
3115
|
+
if (node.nodeType === "component") {
|
|
3116
|
+
const pcbComponent = node.otherChildElements.find(
|
|
3117
|
+
(e) => e.type === "pcb_component"
|
|
3118
|
+
);
|
|
3119
|
+
if (pcbComponent && pcbComponent.position_mode === "relative_to_group_anchor") {
|
|
3120
|
+
relativeComponents2.push(pcbComponent);
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
for (const child of node.childNodes ?? []) {
|
|
3124
|
+
relativeComponents2.push(...collectRelativeToGroupAnchorComponents(child));
|
|
3125
|
+
}
|
|
3126
|
+
return relativeComponents2;
|
|
3127
|
+
};
|
|
3113
3128
|
for (const node of topLevelNodes) {
|
|
3114
3129
|
if (node.nodeType === "component") {
|
|
3115
3130
|
const pcbComponent = node.otherChildElements.find(
|
|
3116
3131
|
(e) => e.type === "pcb_component"
|
|
3117
3132
|
);
|
|
3118
3133
|
if (!pcbComponent) continue;
|
|
3134
|
+
if (pcbComponent.position_mode === "relative_to_group_anchor") {
|
|
3135
|
+
continue;
|
|
3136
|
+
}
|
|
3119
3137
|
let shouldAddInnerObstaclesForComp = opts.shouldAddInnerObstacles;
|
|
3120
3138
|
if (pcbComponent.obstructs_within_bounds === false) {
|
|
3121
3139
|
shouldAddInnerObstaclesForComp = false;
|
|
@@ -3146,6 +3164,32 @@ var convertCircuitJsonToPackOutput = (circuitJson, opts = {}) => {
|
|
|
3146
3164
|
);
|
|
3147
3165
|
}
|
|
3148
3166
|
}
|
|
3167
|
+
const relativeComponents = topLevelNodes.flatMap(
|
|
3168
|
+
(node) => collectRelativeToGroupAnchorComponents(node)
|
|
3169
|
+
);
|
|
3170
|
+
for (const pcbComponent of relativeComponents) {
|
|
3171
|
+
const padInfos = extractPadInfos(pcbComponent, db, getNetworkId);
|
|
3172
|
+
if (padInfos.length === 0) continue;
|
|
3173
|
+
let minX = Infinity;
|
|
3174
|
+
let minY = Infinity;
|
|
3175
|
+
let maxX = -Infinity;
|
|
3176
|
+
let maxY = -Infinity;
|
|
3177
|
+
for (const pad of padInfos) {
|
|
3178
|
+
minX = Math.min(minX, pad.absoluteCenter.x - pad.size.x / 2);
|
|
3179
|
+
maxX = Math.max(maxX, pad.absoluteCenter.x + pad.size.x / 2);
|
|
3180
|
+
minY = Math.min(minY, pad.absoluteCenter.y - pad.size.y / 2);
|
|
3181
|
+
maxY = Math.max(maxY, pad.absoluteCenter.y + pad.size.y / 2);
|
|
3182
|
+
}
|
|
3183
|
+
const center = { x: (minX + maxX) / 2, y: (minY + maxY) / 2 };
|
|
3184
|
+
const width = maxX - minX;
|
|
3185
|
+
const height = maxY - minY;
|
|
3186
|
+
packOutput.obstacles.push({
|
|
3187
|
+
obstacleId: pcbComponent.pcb_component_id,
|
|
3188
|
+
absoluteCenter: center,
|
|
3189
|
+
width,
|
|
3190
|
+
height
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3149
3193
|
for (const element of elementsOutsideTree) {
|
|
3150
3194
|
if (element.type === "pcb_plated_hole" && element.shape === "circular_hole_with_rect_pad") {
|
|
3151
3195
|
const { rect_pad_height, rect_pad_width, x, y } = element;
|
package/package.json
CHANGED