This commit is contained in:
Mayank Mohapatra 2025-02-22 13:50:35 +00:00
parent 6ec83ff541
commit a9a27821c4
5 changed files with 219 additions and 180 deletions

View file

@ -99,13 +99,52 @@ func createCircularArc(edge *d2graph.Edge) {
path[len(path)-1] = newDst path[len(path)-1] = newDst
// Trim redundant path points that fall inside node boundaries. // Trim redundant path points that fall inside node boundaries.
path = trimPathPoints(path, edge.Src.Box) // path = trimPathPoints(path, edge.Src.Box)
path = trimPathPoints(path, edge.Dst.Box) // path = trimPathPoints(path, edge.Dst.Box)
edge.Route = path // edge.Route = path
edge.IsCurve = true // edge.IsCurve = true
// }
path = trimPathPoints(path, edge.Src.Box)
path = trimPathPoints(path, edge.Dst.Box)
// Adjust the last two points to align the arrow direction with the arc's tangent
if len(path) >= 2 {
dstPoint := path[len(path)-1]
prevPoint := path[len(path)-2]
// Calculate the vector between the last two points
dx := dstPoint.X - prevPoint.X
dy := dstPoint.Y - prevPoint.Y
// Calculate the perpendicular vector (rotated 90 degrees counter-clockwise)
// This gives us the center direction of the circular arc
centerDirX := -dy
centerDirY := dx
// Normalize the center direction vector
centerLength := math.Hypot(centerDirX, centerDirY)
if centerLength > 0 {
centerDirX /= centerLength
centerDirY /= centerLength
}
// Calculate the tangent direction (perpendicular to center direction)
tangentX := -centerDirY
tangentY := centerDirX
// Adjust the penultimate point to create proper arrow alignment
step := 10.0
newPrevX := dstPoint.X - tangentX*step
newPrevY := dstPoint.Y - tangentY*step
// Update the path with the adjusted point
path[len(path)-2] = geo.NewPoint(newPrevX, newPrevY)
} }
edge.Route = path
edge.IsCurve = true
}
// clampPointOutsideBox walks forward along the path until it finds a point outside the box, // clampPointOutsideBox walks forward along the path until it finds a point outside the box,
// then replaces the point with a precise intersection. // then replaces the point with a precise intersection.

View file

@ -864,8 +864,8 @@
"y": -37.47600173950195 "y": -37.47600173950195
}, },
{ {
"x": 197.02099609375, "x": 198.8939971923828,
"y": -34.3849983215332 "y": -23.135000228881836
}, },
{ {
"x": 197.2519989013672, "x": 197.2519989013672,
@ -1228,8 +1228,8 @@
"y": 197.53700256347656 "y": 197.53700256347656
}, },
{ {
"x": 28.18000030517578, "x": 16.589000701904297,
"y": 198.00399780273438 "y": 199.56100463867188
}, },
{ {
"x": 26.5, "x": 26.5,
@ -1592,8 +1592,8 @@
"y": 37.47600173950195 "y": 37.47600173950195
}, },
{ {
"x": -197.02099609375, "x": -198.8939971923828,
"y": 34.3849983215332 "y": 23.135000228881836
}, },
{ {
"x": -197.2519989013672, "x": -197.2519989013672,
@ -1972,8 +1972,8 @@
"y": 111.8030014038086 "y": 111.8030014038086
}, },
{ {
"x": 701.875, "x": 698.0460205078125,
"y": 115.77300262451172 "y": 126.40799713134766
}, },
{ {
"x": 701.4329833984375, "x": 701.4329833984375,
@ -2336,8 +2336,8 @@
"y": 186.90899658203125 "y": 186.90899658203125
}, },
{ {
"x": 364.3710021972656, "x": 357.02899169921875,
"y": 183.8260040283203 "y": 175.4980010986328
}, },
{ {
"x": 363.6419982910156, "x": 363.6419982910156,
@ -2740,8 +2740,8 @@
"y": 196.45700073242188 "y": 196.45700073242188
}, },
{ {
"x": 1003.2860107421875, "x": 988.5989990234375,
"y": 197.53700256347656 "y": 199.6269989013672
}, },
{ {
"x": 998.5, "x": 998.5,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -864,8 +864,8 @@
"y": -25.47599983215332 "y": -25.47599983215332
}, },
{ {
"x": 209.02099609375, "x": 210.8939971923828,
"y": -22.385000228881836 "y": -11.135000228881836
}, },
{ {
"x": 209.2519989013672, "x": 209.2519989013672,
@ -1228,8 +1228,8 @@
"y": 209.53700256347656 "y": 209.53700256347656
}, },
{ {
"x": 40.18000030517578, "x": 28.589000701904297,
"y": 210.00399780273438 "y": 211.56100463867188
}, },
{ {
"x": 38.5, "x": 38.5,
@ -1592,8 +1592,8 @@
"y": 49.47600173950195 "y": 49.47600173950195
}, },
{ {
"x": -185.02099609375, "x": -186.8939971923828,
"y": 46.3849983215332 "y": 35.1349983215332
}, },
{ {
"x": -185.2519989013672, "x": -185.2519989013672,
@ -1972,8 +1972,8 @@
"y": 123.8030014038086 "y": 123.8030014038086
}, },
{ {
"x": 674.375, "x": 670.5460205078125,
"y": 127.77300262451172 "y": 138.4080047607422
}, },
{ {
"x": 673.9329833984375, "x": 673.9329833984375,
@ -2336,8 +2336,8 @@
"y": 198.90899658203125 "y": 198.90899658203125
}, },
{ {
"x": 336.8710021972656, "x": 329.52899169921875,
"y": 195.8260040283203 "y": 187.4980010986328
}, },
{ {
"x": 336.1419982910156, "x": 336.1419982910156,
@ -2740,8 +2740,8 @@
"y": 208.45700073242188 "y": 208.45700073242188
}, },
{ {
"x": 936.197021484375, "x": 921.5089721679688,
"y": 209.53700256347656 "y": 211.6269989013672
}, },
{ {
"x": 931.4099731445312, "x": 931.4099731445312,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 25 KiB