Skip to content
Open
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
695 changes: 407 additions & 288 deletions components/SolverDebugger3d.tsx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/fixtures/twoNodeExpansionFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import RBush from "rbush"
import type { RectDiffExpansionSolverInput } from "../solvers/RectDiffExpansionSolver/RectDiffExpansionSolver"
import type { SimpleRouteJson } from "../types/srj-types"
import type { XYRect } from "../rectdiff-types"
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { RTreeRect } from "../types/capacity-mesh-types"
import { buildZIndexMap } from "../solvers/RectDiffSeedingSolver/layers"

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/solvers/GapFillSolver/ExpandEdgesToEmptySpaceSolver.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BaseSolver } from "@tscircuit/solver-utils"
import type { CapacityMeshNode } from "lib/types/capacity-mesh-types"
import type { CapacityMeshNode } from "../../types/capacity-mesh-types"
import type { SegmentWithAdjacentEmptySpace } from "./FindSegmentsWithAdjacentEmptySpaceSolver"
import type { GraphicsObject } from "graphics-debug"
import RBush from "rbush"
import { EDGE_MAP, EDGES } from "./edge-constants"
import { getBoundsFromCorners } from "./getBoundsFromCorners"
import type { Bounds } from "@tscircuit/math-utils"
import { midpoint, segmentToBoxMinDistance } from "@tscircuit/math-utils"
import type { XYRect } from "lib/rectdiff-types"
import type { XYRect } from "../../rectdiff-types"

const EPS = 1e-4

Expand Down Expand Up @@ -212,6 +212,8 @@ export class ExpandEdgesToEmptySpaceSolver extends BaseSolver {
rects: [],
points: [],
lines: [],
infiniteLines: [],
polygons: [],
circles: [],
arrows: [],
texts: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseSolver } from "@tscircuit/solver-utils"
import Flatbush from "flatbush"
import type { GraphicsObject, NinePointAnchor } from "graphics-debug"
import type { CapacityMeshNode } from "lib/types/capacity-mesh-types"
import type { CapacityMeshNode } from "../../types/capacity-mesh-types"
import { projectToUncoveredSegments } from "./projectToUncoveredSegments"
import { EDGES } from "./edge-constants"
import { visuallyOffsetLine } from "./visuallyOffsetLine"
Expand Down Expand Up @@ -139,6 +139,8 @@ export class FindSegmentsWithAdjacentEmptySpaceSolver extends BaseSolver {
rects: [],
points: [],
lines: [],
infiniteLines: [],
polygons: [],
circles: [],
arrows: [],
texts: [],
Expand Down
8 changes: 6 additions & 2 deletions lib/solvers/GapFillSolver/GapFillSolverPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
definePipelineStep,
type PipelineStep,
} from "@tscircuit/solver-utils"
import type { CapacityMeshNode } from "lib/types/capacity-mesh-types"
import type { CapacityMeshNode } from "../../types/capacity-mesh-types"
import type { GraphicsObject } from "graphics-debug"
import { FindSegmentsWithAdjacentEmptySpaceSolver } from "./FindSegmentsWithAdjacentEmptySpaceSolver"
import { ExpandEdgesToEmptySpaceSolver } from "./ExpandEdgesToEmptySpaceSolver"
import type { XYRect } from "lib/rectdiff-types"
import type { XYRect } from "../../rectdiff-types"

type GapFillSolverInput = {
meshNodes: CapacityMeshNode[]
Expand Down Expand Up @@ -73,6 +73,8 @@ export class GapFillSolverPipeline extends BasePipelineSolver<GapFillSolverInput
rects: [],
points: [],
lines: [],
infiniteLines: [],
polygons: [],
circles: [],
arrows: [],
texts: [],
Expand Down Expand Up @@ -103,6 +105,8 @@ export class GapFillSolverPipeline extends BasePipelineSolver<GapFillSolverInput
rects: [],
points: [],
lines: [],
infiniteLines: [],
polygons: [],
circles: [],
arrows: [],
texts: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BaseSolver } from "@tscircuit/solver-utils"
import type { GraphicsObject } from "graphics-debug"
import type { CapacityMeshNode } from "lib/types/capacity-mesh-types"
import type { XYRect } from "lib/rectdiff-types"
import type { Obstacle, SimpleRouteJson } from "lib/types/srj-types"
import type { CapacityMeshNode } from "../../types/capacity-mesh-types"
import type { XYRect } from "../../rectdiff-types"
import type { Obstacle, SimpleRouteJson } from "../../types/srj-types"
import { obstacleToXYRect, obstacleZs } from "../RectDiffSeedingSolver/layers"
import { getColorForZLayer } from "lib/utils/getColorForZLayer"
import { subtractRect2D, overlaps, EPS } from "lib/utils/rectdiff-geometry"
import { padRect } from "lib/utils/padRect"
import { getColorForZLayer } from "../../utils/getColorForZLayer"
import { subtractRect2D, overlaps, EPS } from "../../utils/rectdiff-geometry"
import { padRect } from "../../utils/padRect"

type OuterLayerContainmentMergeSolverInput = {
meshNodes: CapacityMeshNode[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { BaseSolver } from "@tscircuit/solver-utils"
import type { GraphicsObject } from "graphics-debug"
import type { CapacityMeshNode, RTreeRect } from "lib/types/capacity-mesh-types"
import type {
CapacityMeshNode,
RTreeRect,
} from "../../types/capacity-mesh-types"
import { expandRectFromSeed } from "../../utils/expandRectFromSeed"
import { finalizeRects } from "../../utils/finalizeRects"
import { resizeSoftOverlaps } from "../../utils/resizeSoftOverlaps"
import { rectsToMeshNodes } from "./rectsToMeshNodes"
import type { XYRect, Candidate3D, Placed3D } from "../../rectdiff-types"
import type { Obstacle } from "lib/types/srj-types"
import type { Obstacle } from "../../types/srj-types"
import RBush from "rbush"
import { rectToTree } from "../../utils/rectToTree"
import { sameTreeRect } from "../../utils/sameTreeRect"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import type {
Obstacle,
SimpleRouteConnection,
SimpleRouteJson,
} from "lib/types/srj-types"
import type { GridFill3DOptions, XYRect } from "lib/rectdiff-types"
import type { CapacityMeshNode, RTreeRect } from "lib/types/capacity-mesh-types"
import { RectDiffSeedingSolver } from "lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver"
import { RectDiffExpansionSolver } from "lib/solvers/RectDiffExpansionSolver/RectDiffExpansionSolver"
} from "../../types/srj-types"
import type { GridFill3DOptions, XYRect } from "../../rectdiff-types"
import type {
CapacityMeshNode,
RTreeRect,
} from "../../types/capacity-mesh-types"
import { RectDiffSeedingSolver } from "../RectDiffSeedingSolver/RectDiffSeedingSolver"
import { RectDiffExpansionSolver } from "../RectDiffExpansionSolver/RectDiffExpansionSolver"
import type { GraphicsObject } from "graphics-debug"
import RBush from "rbush"
import { buildObstacleIndexesByLayer } from "./buildObstacleIndexes"
Expand Down
18 changes: 11 additions & 7 deletions lib/solvers/RectDiffGridSolverPipeline/buildObstacleIndexes.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { SimpleRouteJson } from "lib/types/srj-types"
import type { SimpleRouteJson } from "../../types/srj-types"
import RBush from "rbush"
import { computeInverseRects } from "lib/solvers/RectDiffSeedingSolver/computeInverseRects"
import { computeInverseRects } from "../RectDiffSeedingSolver/computeInverseRects"
import {
buildZIndexMap,
obstacleToXYRect,
obstacleZs,
} from "lib/solvers/RectDiffSeedingSolver/layers"
import type { XYRect } from "lib/rectdiff-types"
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import { padRect } from "lib/utils/padRect"
} from "../RectDiffSeedingSolver/layers"
import type { XYRect } from "../../rectdiff-types"
import type { RTreeRect } from "../../types/capacity-mesh-types"
import { padRect } from "../../utils/padRect"

export const buildObstacleIndexesByLayer = (params: {
srj: SimpleRouteJson
Expand Down Expand Up @@ -71,7 +71,11 @@ export const buildObstacleIndexesByLayer = (params: {
) {
obstacle.zLayers = zLayers
}
for (const z of zLayers) insertObstacle(rect, z)
for (const z of zLayers) {
const isOuterLayer = z === 0 || z === layerCount - 1
if (isOuterLayer && obstacle.isCopperPour) continue
insertObstacle(rect, z)
}
}

return { obstacleIndexByLayer, layerNames, zIndexByName }
Expand Down
8 changes: 4 additions & 4 deletions lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { computeCandidates3D } from "./computeCandidates3D"
import { computeEdgeCandidates3D } from "./computeEdgeCandidates3D"
import { longestFreeSpanAroundZ } from "./longestFreeSpanAroundZ"
import { allLayerNode } from "../../utils/buildHardPlacedByLayer"
import { isFullyOccupiedAtPoint } from "lib/utils/isFullyOccupiedAtPoint"
import { isFullyOccupiedAtPoint } from "../../utils/isFullyOccupiedAtPoint"
import { resizeSoftOverlaps } from "../../utils/resizeSoftOverlaps"
import { getColorForZLayer } from "lib/utils/getColorForZLayer"
import { getColorForZLayer } from "../../utils/getColorForZLayer"
import RBush from "rbush"
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import { rectToTree } from "lib/utils/rectToTree"
import type { RTreeRect } from "../../types/capacity-mesh-types"
import { rectToTree } from "../../utils/rectToTree"

export type RectDiffSeedingSolverInput = {
simpleRouteJson: SimpleRouteJson
Expand Down
2 changes: 1 addition & 1 deletion lib/solvers/RectDiffSeedingSolver/computeCandidates3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EPS, distancePointToRectEdges } from "../../utils/rectdiff-geometry"
import { isFullyOccupiedAtPoint } from "../../utils/isFullyOccupiedAtPoint"
import { longestFreeSpanAroundZ } from "./longestFreeSpanAroundZ"
import type RBush from "rbush"
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { RTreeRect } from "../../types/capacity-mesh-types"
const quantize = (value: number, precision = 1e-6) =>
Math.round(value / precision) * precision

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EPS, distancePointToRectEdges } from "../../utils/rectdiff-geometry"
import { isFullyOccupiedAtPoint } from "../../utils/isFullyOccupiedAtPoint"
import { longestFreeSpanAroundZ } from "./longestFreeSpanAroundZ"
import type RBush from "rbush"
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { RTreeRect } from "../../types/capacity-mesh-types"
const quantize = (value: number, precision = 1e-6) =>
Math.round(value / precision) * precision

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { RTreeRect } from "../../types/capacity-mesh-types"
import type { XYRect } from "../../rectdiff-types"
import { clamp, containsPoint } from "../../utils/rectdiff-geometry"
import type RBush from "rbush"
Expand Down
2 changes: 1 addition & 1 deletion lib/types/capacity-mesh-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { XYRect } from "lib/rectdiff-types"
import type { XYRect } from "../rectdiff-types"

export type CapacityMeshNodeId = string

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/expandRectFromSeed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type RBush from "rbush"
import type { XYRect } from "../rectdiff-types"
import { EPS, gt, gte, lt, lte, overlaps } from "./rectdiff-geometry"
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { RTreeRect } from "../types/capacity-mesh-types"
import { isSelfRect } from "./isSelfRect"
import {
searchStripDown,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/finalizeRects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Obstacle } from "lib/types/srj-types"
import type { Obstacle } from "../types/srj-types"
import type { Placed3D, Rect3d, XYRect } from "../rectdiff-types"
import {
obstacleToXYRect,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isFullyOccupiedAtPoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { RTreeRect } from "../types/capacity-mesh-types"
import RBush from "rbush"

export type OccupancyParams = {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isSelfRect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { XYRect } from "lib/rectdiff-types"
import type { XYRect } from "../rectdiff-types"

const EPS = 1e-9

Expand Down
4 changes: 2 additions & 2 deletions lib/utils/rectToTree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { XYRect } from "lib/rectdiff-types"
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { XYRect } from "../rectdiff-types"
import type { RTreeRect } from "../types/capacity-mesh-types"

export const rectToTree = (
rect: XYRect,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/renderObstacleClearance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SimpleRouteJson } from "lib/types/srj-types"
import type { SimpleRouteJson } from "../types/srj-types"
import type { GraphicsObject } from "graphics-debug"

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/resizeSoftOverlaps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { RTreeRect } from "../types/capacity-mesh-types"
import type { Placed3D } from "../rectdiff-types"
import { overlaps, subtractRect2D, EPS } from "./rectdiff-geometry"
import type RBush from "rbush"
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/sameTreeRect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RTreeRect } from "lib/types/capacity-mesh-types"
import type { RTreeRect } from "../types/capacity-mesh-types"

export const sameTreeRect = (a: RTreeRect, b: RTreeRect) =>
a.minX === b.minX &&
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/searchStrip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { XYRect } from "lib/rectdiff-types"
import type { XYRect } from "../rectdiff-types"

export const searchStripRight = ({
rect,
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
"name": "@tscircuit/rectdiff",
"version": "0.0.25",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./lib/index.ts",
"types": "./lib/index.ts",
"exports": {
".": "./lib/index.ts"
},
"scripts": {
"start": "cosmos",
"build": "tsup-node ./lib/index.ts --format esm --dts",
Expand All @@ -16,7 +19,7 @@
"@biomejs/biome": "^2.3.5",
"@react-hook/resize-observer": "^2.0.2",
"@tscircuit/math-utils": "^0.0.29",
"@tscircuit/solver-utils": "^0.0.9",
"@tscircuit/solver-utils": "^0.0.16",
"@types/bun": "latest",
"@types/rbush": "^4.0.0",
"@types/react": "^18",
Expand All @@ -25,7 +28,7 @@
"@vitejs/plugin-react": "^4",
"biome": "^0.3.3",
"bun-match-svg": "^0.0.14",
"graphics-debug": "^0.0.76",
"graphics-debug": "^0.0.90",
"rbush": "^4.0.1",
"react": "18",
"react-cosmos": "^6.2.3",
Expand Down
21 changes: 21 additions & 0 deletions pages/arduino-uno-bottom-inner2-power-ground-pours.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import simpleRouteJson from "../test-assets/arduino-uno-bottom-inner2-power-ground-pours.json"
import { RectDiffPipeline } from "../lib/RectDiffPipeline"
import { useMemo } from "react"
import { SolverDebugger3d } from "../components/SolverDebugger3d"

export default () => {
const solver = useMemo(
() =>
new RectDiffPipeline({
simpleRouteJson: simpleRouteJson.simple_route_json,
}),
[],
)

return (
<SolverDebugger3d
solver={solver}
simpleRouteJson={simpleRouteJson.simple_route_json}
/>
)
}
26 changes: 26 additions & 0 deletions pages/bugreport46-ac4337-arduino-uno-inner-pours.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useMemo } from "react"
import { SolverDebugger3d } from "../components/SolverDebugger3d"
import { RectDiffPipeline } from "../lib/RectDiffPipeline"
import bugreport46 from "../test-assets/bugreport46-ac4337-arduino-uno-inner-pours.json"
import type { SimpleRouteJson } from "../lib/types/srj-types"

export const bugreport46ArduinoUnoInnerPoursSrj =
(bugreport46 as { simple_route_json?: SimpleRouteJson }).simple_route_json ??
(bugreport46 as SimpleRouteJson)

export default () => {
const solver = useMemo(
() =>
new RectDiffPipeline({
simpleRouteJson: bugreport46ArduinoUnoInnerPoursSrj,
}),
[],
)

return (
<SolverDebugger3d
solver={solver}
simpleRouteJson={bugreport46ArduinoUnoInnerPoursSrj}
/>
)
}
Loading