@tscircuit/find-convex-regions 0.0.1
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/README.md +44 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +1963 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @tscircuit/find-convex-regions
|
|
2
|
+
|
|
3
|
+
Use `ConvexRegionsSolver` to compute convex regions from your own bounds and vias.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { ConvexRegionsSolver } from "@tscircuit/find-convex-regions"
|
|
9
|
+
|
|
10
|
+
const bounds = { minX: 0, maxX: 450, minY: 0, maxY: 450 }
|
|
11
|
+
|
|
12
|
+
const vias = [
|
|
13
|
+
{ center: { x: 120, y: 150 }, diameter: 30 },
|
|
14
|
+
{ center: { x: 250, y: 100 }, diameter: 25 },
|
|
15
|
+
{ center: { x: 200, y: 280 }, diameter: 35 },
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
const solver = new ConvexRegionsSolver({
|
|
19
|
+
bounds,
|
|
20
|
+
vias,
|
|
21
|
+
clearance: 8,
|
|
22
|
+
concavityTolerance: 0,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
solver.solve()
|
|
26
|
+
|
|
27
|
+
const output = solver.getOutput()
|
|
28
|
+
if (!output) throw new Error("Failed to compute convex regions")
|
|
29
|
+
|
|
30
|
+
console.log(output.regions)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Input Shape
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
type Point = { x: number; y: number }
|
|
37
|
+
type Via = { center: Point; diameter: number }
|
|
38
|
+
type Bounds = { minX: number; maxX: number; minY: number; maxY: number }
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- `bounds`: your board/area rectangle.
|
|
42
|
+
- `vias`: your own keepouts (bring your own vias).
|
|
43
|
+
- `clearance`: extra radius added around each via.
|
|
44
|
+
- `concavityTolerance`: `0` for strict convex regions; higher values allow shallow concavity when merging.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import * as _tscircuit_solver_utils from '@tscircuit/solver-utils';
|
|
2
|
+
import { BaseSolver, BasePipelineSolver } from '@tscircuit/solver-utils';
|
|
3
|
+
import { GraphicsObject } from 'graphics-debug';
|
|
4
|
+
|
|
5
|
+
type Point = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
type Via = {
|
|
10
|
+
center: Point;
|
|
11
|
+
diameter: number;
|
|
12
|
+
};
|
|
13
|
+
type Bounds = {
|
|
14
|
+
minX: number;
|
|
15
|
+
maxX: number;
|
|
16
|
+
minY: number;
|
|
17
|
+
maxY: number;
|
|
18
|
+
};
|
|
19
|
+
type Triangle = [number, number, number];
|
|
20
|
+
type ConvexRegionsComputeInput = {
|
|
21
|
+
bounds: Bounds;
|
|
22
|
+
vias: Via[];
|
|
23
|
+
clearance: number;
|
|
24
|
+
concavityTolerance: number;
|
|
25
|
+
};
|
|
26
|
+
type ConvexRegionsComputeResult = {
|
|
27
|
+
pts: Point[];
|
|
28
|
+
validTris: Triangle[];
|
|
29
|
+
regions: Point[][];
|
|
30
|
+
hulls: Point[][];
|
|
31
|
+
depths: number[];
|
|
32
|
+
};
|
|
33
|
+
type RegionPort = {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
region: number;
|
|
37
|
+
};
|
|
38
|
+
type GeneratePointsStageOutput = {
|
|
39
|
+
pts: Point[];
|
|
40
|
+
};
|
|
41
|
+
type TriangulateStageInput = GeneratePointsStageOutput & {
|
|
42
|
+
bounds: Bounds;
|
|
43
|
+
vias: Via[];
|
|
44
|
+
clearance: number;
|
|
45
|
+
};
|
|
46
|
+
type TriangulateStageOutput = GeneratePointsStageOutput & {
|
|
47
|
+
validTris: Triangle[];
|
|
48
|
+
};
|
|
49
|
+
type MergeCellsStageInput = TriangulateStageOutput & {
|
|
50
|
+
concavityTolerance: number;
|
|
51
|
+
};
|
|
52
|
+
type MergeCellsStageOutput = TriangulateStageOutput & {
|
|
53
|
+
cells: number[][];
|
|
54
|
+
depths: number[];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
declare class BuildRegionsSolver extends BaseSolver {
|
|
58
|
+
private readonly input;
|
|
59
|
+
private output;
|
|
60
|
+
constructor(input: MergeCellsStageOutput);
|
|
61
|
+
_step(): void;
|
|
62
|
+
getConstructorParams(): [MergeCellsStageOutput];
|
|
63
|
+
getOutput(): ConvexRegionsComputeResult | null;
|
|
64
|
+
visualize(): GraphicsObject;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare const buildRegionsFromCells: (merged: MergeCellsStageOutput) => {
|
|
68
|
+
regions: Point[][];
|
|
69
|
+
hulls: Point[][];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
declare class GeneratePointsSolver extends BaseSolver {
|
|
73
|
+
private readonly input;
|
|
74
|
+
private output;
|
|
75
|
+
constructor(input: ConvexRegionsComputeInput);
|
|
76
|
+
_step(): void;
|
|
77
|
+
getConstructorParams(): [ConvexRegionsComputeInput];
|
|
78
|
+
getOutput(): GeneratePointsStageOutput | null;
|
|
79
|
+
visualize(): GraphicsObject;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare class MergeCellsSolver extends BaseSolver {
|
|
83
|
+
private readonly input;
|
|
84
|
+
private output;
|
|
85
|
+
constructor(input: MergeCellsStageInput);
|
|
86
|
+
_step(): void;
|
|
87
|
+
getConstructorParams(): [MergeCellsStageInput];
|
|
88
|
+
getOutput(): MergeCellsStageOutput | null;
|
|
89
|
+
visualize(): GraphicsObject;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class TriangulateSolver extends BaseSolver {
|
|
93
|
+
private readonly input;
|
|
94
|
+
private output;
|
|
95
|
+
constructor(input: TriangulateStageInput);
|
|
96
|
+
_step(): void;
|
|
97
|
+
getConstructorParams(): [TriangulateStageInput];
|
|
98
|
+
getOutput(): TriangulateStageOutput | null;
|
|
99
|
+
visualize(): GraphicsObject;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare class ConvexRegionsSolver extends BasePipelineSolver<ConvexRegionsComputeInput> {
|
|
103
|
+
pipelineDef: (_tscircuit_solver_utils.PipelineStep<GeneratePointsSolver> | _tscircuit_solver_utils.PipelineStep<TriangulateSolver> | _tscircuit_solver_utils.PipelineStep<MergeCellsSolver> | _tscircuit_solver_utils.PipelineStep<BuildRegionsSolver>)[];
|
|
104
|
+
getConstructorParams(): [ConvexRegionsComputeInput];
|
|
105
|
+
getOutput(): ConvexRegionsComputeResult | null;
|
|
106
|
+
visualize(): GraphicsObject;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare const computeConvexRegions: (input: ConvexRegionsComputeInput) => ConvexRegionsComputeResult;
|
|
110
|
+
|
|
111
|
+
declare const computeRegionPorts: (regions: Point[][], bounds: Bounds, vias: Via[], clearance: number) => RegionPort[];
|
|
112
|
+
|
|
113
|
+
declare const concavityDepth: (ring: number[], pts: Point[]) => number;
|
|
114
|
+
|
|
115
|
+
declare const cross: (o: Point, a: Point, b: Point) => number;
|
|
116
|
+
|
|
117
|
+
declare const delaunay: (rawPoints: Point[]) => Triangle[];
|
|
118
|
+
|
|
119
|
+
declare const dist2: (a: Point, b: Point) => number;
|
|
120
|
+
|
|
121
|
+
declare const filterTris: (triangles: Triangle[], pts: Point[], bounds: Bounds, vias: Via[], clearance: number) => Triangle[];
|
|
122
|
+
|
|
123
|
+
declare const genPoints: (bounds: Bounds, vias: Via[], clearance: number) => Point[];
|
|
124
|
+
|
|
125
|
+
declare const hullIdx: (indices: number[], pts: Point[]) => number[];
|
|
126
|
+
|
|
127
|
+
declare const inFreeSpace: (px: number, py: number, bounds: Bounds, vias: Via[], clearance: number) => boolean;
|
|
128
|
+
|
|
129
|
+
declare const isDefined: <T>(value: T | undefined) => value is T;
|
|
130
|
+
|
|
131
|
+
declare const mergeCells: (triangles: Triangle[], pts: Point[], concavityTolerance: number) => {
|
|
132
|
+
cells: number[][];
|
|
133
|
+
depths: number[];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
declare const polyArea: (ring: Point[]) => number;
|
|
137
|
+
|
|
138
|
+
declare const ptSegDist: (p: Point, a: Point, b: Point) => number;
|
|
139
|
+
|
|
140
|
+
declare const regionPath: (region: Point[]) => string;
|
|
141
|
+
|
|
142
|
+
declare const stitchRings: (ringA: number[], ringB: number[]) => number[] | null;
|
|
143
|
+
|
|
144
|
+
export { type Bounds, BuildRegionsSolver, type ConvexRegionsComputeInput, type ConvexRegionsComputeResult, ConvexRegionsSolver, GeneratePointsSolver, type GeneratePointsStageOutput, MergeCellsSolver, type MergeCellsStageInput, type MergeCellsStageOutput, type Point, type RegionPort, type Triangle, TriangulateSolver, type TriangulateStageInput, type TriangulateStageOutput, type Via, buildRegionsFromCells, computeConvexRegions, computeRegionPorts, concavityDepth, cross, delaunay, dist2, filterTris, genPoints, hullIdx, inFreeSpace, isDefined, mergeCells, polyArea, ptSegDist, regionPath, stitchRings };
|