@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.
@@ -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.22",
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.49",
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",