Skip to content

Commit 79c5db7

Browse files
committed
setup simplifiedpathsolver
1 parent 6053104 commit 79c5db7

File tree

3 files changed

+108
-56
lines changed

3 files changed

+108
-56
lines changed

examples/construct-45-degree-path/construct45degreepath1.fixture.tsx

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,63 +15,9 @@ const Construct45DegreePathFixture: React.FC = () => {
1515
// Path colors
1616
const pathColors = ["#FF5733", "#33FF57", "#3357FF", "#F033FF"]
1717

18-
// Calculate all possible paths with one straight segment and one 45-degree segment
18+
// Update paths when points change
1919
useEffect(() => {
20-
const calculatePaths = () => {
21-
const result: Array<Array<Point>> = []
22-
const dx = Math.abs(pointB.x - pointA.x)
23-
const dy = Math.abs(pointB.y - pointA.y)
24-
const signX = pointB.x > pointA.x ? 1 : -1
25-
const signY = pointB.y > pointA.y ? 1 : -1
26-
27-
// Path 1: Horizontal then 45 degrees
28-
const midPoint1: Point = {
29-
x: pointB.x - signX * Math.abs(pointB.y - pointA.y),
30-
y: pointA.y,
31-
}
32-
// Check if midpoint is within bounds
33-
if (
34-
(midPoint1.x - pointA.x) * signX >= 0 &&
35-
(midPoint1.x - pointB.x) * signX <= 0
36-
) {
37-
result.push([pointA, midPoint1, pointB])
38-
}
39-
40-
// Path 2: Vertical then 45 degrees
41-
const midPoint2: Point = {
42-
x: pointA.x,
43-
y: pointB.y - signY * Math.abs(pointB.x - pointA.x),
44-
}
45-
// Check if midpoint is within bounds
46-
if (
47-
(midPoint2.y - pointA.y) * signY >= 0 &&
48-
(midPoint2.y - pointB.y) * signY <= 0
49-
) {
50-
result.push([pointA, midPoint2, pointB])
51-
}
52-
53-
// // Calculate 45-degree points
54-
const minDist = Math.min(dx, dy)
55-
56-
// // Path 3: 45 degrees then horizontal
57-
const midPoint3: Point = {
58-
x: pointA.x + signX * minDist,
59-
y: pointA.y + signY * minDist,
60-
}
61-
// Check if midpoint is within bounds
62-
if (
63-
(midPoint3.x - pointA.x) * signX >= 0 &&
64-
(midPoint3.x - pointB.x) * signX <= 0 &&
65-
(midPoint3.y - pointA.y) * signY >= 0 &&
66-
(midPoint3.y - pointB.y) * signY <= 0
67-
) {
68-
result.push([pointA, midPoint3, pointB])
69-
}
70-
71-
return result
72-
}
73-
74-
setPaths(calculatePaths())
20+
setPaths(calculate45DegreePaths(pointA, pointB))
7521
}, [pointA, pointB])
7622

7723
const handleDragMove = (e: any, point: "A" | "B") => {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { HighDensityIntraNodeRoute } from "lib/types/high-density-types"
2+
import { BaseSolver } from "../BaseSolver"
3+
import { Obstacle } from "lib/types"
4+
import { calculate45DegreePaths } from "lib/utils/calculate45DegreePaths"
5+
6+
interface Point {
7+
x: number
8+
y: number
9+
z: number
10+
}
11+
12+
export class SingleSimplifiedPathSolver extends BaseSolver {
13+
newRoute: HighDensityIntraNodeRoute["route"]
14+
newVias: HighDensityIntraNodeRoute["vias"]
15+
16+
headIndex = 0
17+
tailIndex = 0
18+
19+
constructor(
20+
public inputRoute: HighDensityIntraNodeRoute,
21+
public otherHdRoutes: HighDensityIntraNodeRoute[],
22+
public obstacles: Obstacle[],
23+
) {
24+
super()
25+
this.newRoute = []
26+
this.newVias = []
27+
}
28+
29+
isValidPath(pointsInRoute: Point[]): boolean {
30+
// check that the segments don't intersect with any obstacles or other
31+
// routes or vias
32+
// TODO
33+
}
34+
35+
_step() {
36+
// Each iteration, we're going to increase the head and make sure that
37+
// there's a compatible simplified path from the tail to the head
38+
// If there isn't a compatible simplified path, we add a segment to the new
39+
// route from [tail, tail + (head - tail) / 2] then start our next iteration
40+
// at tail = tail + Math.ceil((head - tail) / 2)
41+
// If there is a Z change between the tail and the head, we stop the
42+
// simplification for that segment (add to newRoute and newVias, set tail to
43+
// head)
44+
}
45+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
interface Point {
2+
x: number
3+
y: number
4+
}
5+
6+
export const calculate45DegreePaths = (
7+
pointA: Point,
8+
pointB: Point,
9+
): Array<Array<Point>> => {
10+
const result: Array<Array<Point>> = []
11+
const dx = Math.abs(pointB.x - pointA.x)
12+
const dy = Math.abs(pointB.y - pointA.y)
13+
const signX = pointB.x > pointA.x ? 1 : -1
14+
const signY = pointB.y > pointA.y ? 1 : -1
15+
16+
// Path 1: Horizontal then 45 degrees
17+
const midPoint1: Point = {
18+
x: pointB.x - signX * Math.abs(pointB.y - pointA.y),
19+
y: pointA.y,
20+
}
21+
// Check if midpoint is within bounds
22+
if (
23+
(midPoint1.x - pointA.x) * signX >= 0 &&
24+
(midPoint1.x - pointB.x) * signX <= 0
25+
) {
26+
result.push([pointA, midPoint1, pointB])
27+
}
28+
29+
// Path 2: Vertical then 45 degrees
30+
const midPoint2: Point = {
31+
x: pointA.x,
32+
y: pointB.y - signY * Math.abs(pointB.x - pointA.x),
33+
}
34+
// Check if midpoint is within bounds
35+
if (
36+
(midPoint2.y - pointA.y) * signY >= 0 &&
37+
(midPoint2.y - pointB.y) * signY <= 0
38+
) {
39+
result.push([pointA, midPoint2, pointB])
40+
}
41+
42+
// // Calculate 45-degree points
43+
const minDist = Math.min(dx, dy)
44+
45+
// // Path 3: 45 degrees then horizontal
46+
const midPoint3: Point = {
47+
x: pointA.x + signX * minDist,
48+
y: pointA.y + signY * minDist,
49+
}
50+
// Check if midpoint is within bounds
51+
if (
52+
(midPoint3.x - pointA.x) * signX >= 0 &&
53+
(midPoint3.x - pointB.x) * signX <= 0 &&
54+
(midPoint3.y - pointA.y) * signY >= 0 &&
55+
(midPoint3.y - pointB.y) * signY <= 0
56+
) {
57+
result.push([pointA, midPoint3, pointB])
58+
}
59+
60+
return result
61+
}

0 commit comments

Comments
 (0)