@tscircuit/core 0.0.22 → 0.0.24
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.d.ts +273 -277
- package/dist/index.js +351 -67
- package/lib/Project.ts +1 -1
- package/lib/components/base-components/NormalComponent.ts +15 -0
- package/lib/components/base-components/PrimitiveComponent.ts +14 -11
- package/lib/components/base-components/Renderable.ts +2 -0
- package/lib/components/normal-components/Board.ts +3 -2
- package/lib/components/normal-components/Capacitor.ts +9 -2
- package/lib/components/normal-components/Resistor.ts +8 -2
- package/lib/components/primitive-components/Group.ts +6 -2
- package/lib/components/primitive-components/Net.ts +159 -0
- package/lib/components/primitive-components/Port.ts +17 -1
- package/lib/components/primitive-components/Trace.ts +153 -18
- package/lib/fiber/intrinsic-jsx.ts +1 -0
- package/lib/utils/getClosest.ts +29 -0
- package/package.json +2 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type PointLike =
|
|
2
|
+
| { getGlobalPcbPosition: () => { x: number; y: number } }
|
|
3
|
+
| { x: number; y: number }
|
|
4
|
+
|
|
5
|
+
const getDistance = (a: PointLike, b: PointLike) => {
|
|
6
|
+
const aPos = "getGlobalPcbPosition" in a ? a.getGlobalPcbPosition() : a
|
|
7
|
+
const bPos = "getGlobalPcbPosition" in b ? b.getGlobalPcbPosition() : b
|
|
8
|
+
return Math.sqrt((aPos.x - bPos.x) ** 2 + (aPos.y - bPos.y) ** 2)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getClosest<T extends PointLike, U extends PointLike>(
|
|
12
|
+
point: T,
|
|
13
|
+
candidates: U[],
|
|
14
|
+
): U {
|
|
15
|
+
if (candidates.length === 0)
|
|
16
|
+
throw new Error("No candidates given to getClosest method")
|
|
17
|
+
let closest: U = candidates[0]
|
|
18
|
+
let closestDist = Infinity
|
|
19
|
+
|
|
20
|
+
for (const candidate of candidates) {
|
|
21
|
+
const dist = getDistance(point, candidate)
|
|
22
|
+
if (dist < closestDist) {
|
|
23
|
+
closest = candidate
|
|
24
|
+
closestDist = dist
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return closest
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tscircuit/core",
|
|
3
3
|
"module": "index.ts",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.24",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"files": [
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@tscircuit/infgrid-ijump-astar": "^0.0.6",
|
|
35
|
-
"@tscircuit/props": "^0.0.
|
|
35
|
+
"@tscircuit/props": "^0.0.51",
|
|
36
36
|
"@tscircuit/soup": "^0.0.58",
|
|
37
37
|
"@tscircuit/soup-util": "0.0.18",
|
|
38
38
|
"footprinter": "^0.0.44",
|