Skip to content
Merged
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,7 +56,10 @@ export class RectDiffExpansionSolver extends BaseSolver {
for (const placement of this.input.placed) {
for (const z of placement.zLayers) {
const placedIndex = this.placedIndexByLayer[z]
if (placedIndex) placedIndex.insert(rectToTree(placement.rect))
if (placedIndex)
placedIndex.insert(
rectToTree(placement.rect, { zLayers: placement.zLayers }),
)
}
}
}
Expand Down Expand Up @@ -104,8 +107,8 @@ export class RectDiffExpansionSolver extends BaseSolver {
for (const z of p.zLayers) {
const tree = this.placedIndexByLayer[z]
if (tree) {
tree.remove(rectToTree(oldRect), sameTreeRect)
tree.insert(rectToTree(expanded))
tree.remove(rectToTree(oldRect, { zLayers: p.zLayers }), sameTreeRect)
tree.insert(rectToTree(expanded, { zLayers: p.zLayers }))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export const buildObstacleIndexesByLayer = (params: {
)

const insertObstacle = (rect: XYRect, z: number) => {
const treeRect = {
const treeRect: RTreeRect = {
...rect,
minX: rect.x,
minY: rect.y,
maxX: rect.x + rect.width,
maxY: rect.y + rect.height,
zLayers: [z],
}
obstacleIndexByLayer[z]?.insert(treeRect)
}
Expand Down
9 changes: 2 additions & 7 deletions lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { resizeSoftOverlaps } from "../../utils/resizeSoftOverlaps"
import { getColorForZLayer } from "lib/utils/getColorForZLayer"
import RBush from "rbush"
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import { rectToTree } from "lib/utils/rectToTree"

export type RectDiffSeedingSolverInput = {
simpleRouteJson: SimpleRouteJson
Expand Down Expand Up @@ -258,13 +259,7 @@ export class RectDiffSeedingSolver extends BaseSolver {
for (const z of attempt.layers) {
const idx = this.placedIndexByLayer[z]
if (idx) {
idx.insert({
...rect,
minX: rect.x,
minY: rect.y,
maxX: rect.x + rect.width,
maxY: rect.y + rect.height,
})
idx.insert(rectToTree(rect, { zLayers: placed.zLayers }))
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/types/capacity-mesh-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ export type RTreeRect = XYRect & {
minY: number
maxX: number
maxY: number
zLayers: number[]
}
3 changes: 3 additions & 0 deletions lib/utils/expandRectFromSeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export function expandRectFromSeed(params: {
const initialH = Math.max(minSide, minReq.height)
const blockers: XYRect[] = []
const seen = new Set<string>()
const totalLayers = placedIndexByLayer.length

// Ignore the existing placement we are expanding so it doesn't self-block.

Expand All @@ -232,6 +233,8 @@ export function expandRectFromSeed(params: {
const placedLayer = placedIndexByLayer[z]
if (placedLayer) {
for (const entry of placedLayer.search(query)) {
const isFullStack = entry.zLayers.length >= totalLayers
if (!isFullStack) continue
const rect = toRect(entry)
if (
isSelfRect({
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/rectToTree.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { XYRect } from "lib/rectdiff-types"
import type { RTreeRect } from "lib/types/capacity-mesh-types"

export const rectToTree = (rect: XYRect): RTreeRect => ({
export const rectToTree = (
rect: XYRect,
opts: { zLayers: number[] },
): RTreeRect => ({
...rect,
minX: rect.x,
minY: rect.y,
maxX: rect.x + rect.width,
maxY: rect.y + rect.height,
zLayers: opts.zLayers,
})
24 changes: 8 additions & 16 deletions lib/utils/resizeSoftOverlaps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { Placed3D, XYRect } from "../rectdiff-types"
import type { Placed3D } from "../rectdiff-types"
import { overlaps, subtractRect2D, EPS } from "./rectdiff-geometry"
import type RBush from "rbush"
import { rectToTree } from "./rectToTree"

export function resizeSoftOverlaps(
params: {
Expand Down Expand Up @@ -57,13 +58,6 @@ export function resizeSoftOverlaps(
}

// Remove fully overlapped nodes and keep indexes in sync
const rectToTree = (rect: XYRect): RTreeRect => ({
...rect,
minX: rect.x,
minY: rect.y,
maxX: rect.x + rect.width,
maxY: rect.y + rect.height,
})
const sameRect = (a: RTreeRect, b: RTreeRect) =>
a.minX === b.minX &&
a.minY === b.minY &&
Expand All @@ -77,7 +71,11 @@ export function resizeSoftOverlaps(
if (params.placedIndexByLayer) {
for (const z of rem.zLayers) {
const tree = params.placedIndexByLayer[z]
if (tree) tree.remove(rectToTree(rem.rect), sameRect)
if (tree)
tree.remove(
rectToTree(rem.rect, { zLayers: rem.zLayers }),
sameRect,
)
}
}
})
Expand All @@ -89,13 +87,7 @@ export function resizeSoftOverlaps(
if (params.placedIndexByLayer) {
const idx = params.placedIndexByLayer[z]
if (idx) {
idx.insert({
...p.rect,
minX: p.rect.x,
minY: p.rect.y,
maxX: p.rect.x + p.rect.width,
maxY: p.rect.y + p.rect.height,
})
idx.insert(rectToTree(p.rect, { zLayers: p.zLayers.slice() }))
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.