Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class OutlineSegmentCandidatePointSolver extends BaseSolver {
packedComponents: PackedComponent[]
componentToPack: InputComponent
obstacles?: InputObstacle[]
bounds?: Bounds
globalBounds?: Bounds
}) {
super()
Expand All @@ -67,7 +68,7 @@ export class OutlineSegmentCandidatePointSolver extends BaseSolver {
this.packedComponents = params.packedComponents
this.componentToPack = params.componentToPack
this.obstacles = params.obstacles ?? []
this.globalBounds = params.globalBounds
this.globalBounds = params.globalBounds ?? params.bounds
}

override getConstructorParams(): ConstructorParameters<
Expand All @@ -83,6 +84,7 @@ export class OutlineSegmentCandidatePointSolver extends BaseSolver {
componentToPack: this.componentToPack,
obstacles: this.obstacles,
globalBounds: this.globalBounds,
bounds: this.globalBounds,
}
}

Expand Down Expand Up @@ -169,12 +171,22 @@ export class OutlineSegmentCandidatePointSolver extends BaseSolver {
Math.sign(this.outlineSegment[1].y - this.outlineSegment[0].y),
),
}
const viableBounds = {
let viableBounds = {
minX: largestRectBounds.minX - componentBounds.minX * segmentNormAbs.x,
minY: largestRectBounds.minY - componentBounds.minY * segmentNormAbs.y,
maxX: largestRectBounds.maxX - componentBounds.maxX * segmentNormAbs.x,
maxY: largestRectBounds.maxY - componentBounds.maxY * segmentNormAbs.y,
}

if (this.globalBounds) {
viableBounds = {
minX: Math.max(viableBounds.minX, this.globalBounds.minX),
minY: Math.max(viableBounds.minY, this.globalBounds.minY),
maxX: Math.min(viableBounds.maxX, this.globalBounds.maxX),
maxY: Math.min(viableBounds.maxY, this.globalBounds.maxY),
}
}

this.viableBounds = viableBounds

const viableBoundsWidth = viableBounds.maxX - viableBounds.minX
Expand Down
75 changes: 75 additions & 0 deletions tests/outline-segment-global-bounds.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { test, expect } from "bun:test"
import type { Point } from "@tscircuit/math-utils"
import type { InputComponent } from "../lib/types"
import { OutlineSegmentCandidatePointSolver } from "../lib/OutlineSegmentCandidatePointSolver/OutlineSegmentCandidatePointSolver"

// Helper to create a basic outline and component
const outline: [Point, Point][] = [
[
{ x: 0, y: 100 },
{ x: 400, y: 100 },
],
[
{ x: 400, y: 100 },
{ x: 400, y: 0 },
],
[
{ x: 400, y: 0 },
{ x: 0, y: 0 },
],
[
{ x: 0, y: 0 },
{ x: 0, y: 100 },
],
]

const component: InputComponent = {
componentId: "U1",
pads: [
{
padId: "P1",
networkId: "N1",
type: "rect",
offset: { x: 0, y: 0 },
size: { x: 10, y: 10 },
},
],
}

test("OutlineSegmentCandidatePointSolver respects globalBounds", () => {
const solver = new OutlineSegmentCandidatePointSolver({
outlineSegment: outline[0]!,
fullOutline: outline,
componentRotationDegrees: 0,
packStrategy: "minimum_sum_distance_to_network",
minGap: 1,
packedComponents: [],
componentToPack: component,
globalBounds: { minX: 50, minY: 0, maxX: 150, maxY: 200 },
})

solver.solve()

expect(solver.viableBounds).toBeDefined()
expect(solver.viableBounds!.minX).toBeGreaterThanOrEqual(50)
expect(solver.viableBounds!.maxX).toBeLessThanOrEqual(150)
})

test("OutlineSegmentCandidatePointSolver accepts bounds alias", () => {
const solver = new OutlineSegmentCandidatePointSolver({
outlineSegment: outline[0]!,
fullOutline: outline,
componentRotationDegrees: 0,
packStrategy: "minimum_sum_distance_to_network",
minGap: 1,
packedComponents: [],
componentToPack: component,
bounds: { minX: 60, minY: 0, maxX: 160, maxY: 200 },
})

solver.solve()

expect(solver.viableBounds).toBeDefined()
expect(solver.viableBounds!.minX).toBeGreaterThanOrEqual(60)
expect(solver.viableBounds!.maxX).toBeLessThanOrEqual(160)
})
46 changes: 23 additions & 23 deletions tests/repros/__snapshots__/repro05.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.