This commit is contained in:
Mayank Mohapatra 2025-02-23 16:53:22 +00:00
parent 9731ae66b5
commit 3a0bab35c3
5 changed files with 213 additions and 176 deletions

View file

@ -104,6 +104,43 @@ func createCircularArc(edge *d2graph.Edge) {
edge.Route = path edge.Route = path
edge.IsCurve = true edge.IsCurve = true
// Adjust the last segment to ensure proper arrowhead direction
if len(edge.Route) >= 2 {
lastIndex := len(edge.Route) - 1
lastPoint := edge.Route[lastIndex]
secondLastPoint := edge.Route[lastIndex-1]
// Calculate tangent direction (perpendicular to radius vector)
tangentX := -lastPoint.Y
tangentY := lastPoint.X
mag := math.Hypot(tangentX, tangentY)
if mag > 0 {
tangentX /= mag
tangentY /= mag
}
const MIN_SEGMENT_LEN = 10.0
// Calculate current segment direction
dx := lastPoint.X - secondLastPoint.X
dy := lastPoint.Y - secondLastPoint.Y
segLength := math.Hypot(dx, dy)
if segLength > 0 {
currentDirX := dx / segLength
currentDirY := dy / segLength
// Check if we need to adjust the direction
if segLength < MIN_SEGMENT_LEN || (currentDirX*tangentX+currentDirY*tangentY) < 0.999 {
// Create new point along tangent direction
adjustLength := MIN_SEGMENT_LEN // Now float64
if segLength >= MIN_SEGMENT_LEN {
adjustLength = segLength // Both are float64 now
}
newSecondLastX := lastPoint.X - tangentX*adjustLength
newSecondLastY := lastPoint.Y - tangentY*adjustLength
edge.Route[lastIndex-1] = geo.NewPoint(newSecondLastX, newSecondLastY)
}
}
}
} }

View file

@ -864,8 +864,8 @@
"y": -37.47600173950195 "y": -37.47600173950195
}, },
{ {
"x": 197.02099609375, "x": 195.6020050048828,
"y": -34.3849983215332 "y": -42.86199951171875
}, },
{ {
"x": 197.2519989013672, "x": 197.2519989013672,
@ -1228,8 +1228,8 @@
"y": 197.53700256347656 "y": 197.53700256347656
}, },
{ {
"x": 28.18000030517578, "x": 36.4109992980957,
"y": 198.00399780273438 "y": 196.90499877929688
}, },
{ {
"x": 26.5, "x": 26.5,
@ -1592,8 +1592,8 @@
"y": 37.47600173950195 "y": 37.47600173950195
}, },
{ {
"x": -197.02099609375, "x": -195.6020050048828,
"y": 34.3849983215332 "y": 42.86199951171875
}, },
{ {
"x": -197.2519989013672, "x": -197.2519989013672,
@ -1972,8 +1972,8 @@
"y": 111.8030014038086 "y": 111.8030014038086
}, },
{ {
"x": 701.875, "x": 704.7830200195312,
"y": 115.77300262451172 "y": 107.5770034790039
}, },
{ {
"x": 701.4329833984375, "x": 701.4329833984375,
@ -2336,8 +2336,8 @@
"y": 186.90899658203125 "y": 186.90899658203125
}, },
{ {
"x": 364.3710021972656, "x": 370.2919921875,
"y": 183.8260040283203 "y": 190.46800231933594
}, },
{ {
"x": 363.6419982910156, "x": 363.6419982910156,
@ -2740,8 +2740,8 @@
"y": 196.45700073242188 "y": 196.45700073242188
}, },
{ {
"x": 1003.2860107421875, "x": 1008.4110107421875,
"y": 197.53700256347656 "y": 196.89300537109375
}, },
{ {
"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: 26 KiB

View file

@ -864,8 +864,8 @@
"y": -25.47599983215332 "y": -25.47599983215332
}, },
{ {
"x": 209.02099609375, "x": 207.6020050048828,
"y": -22.385000228881836 "y": -30.86199951171875
}, },
{ {
"x": 209.2519989013672, "x": 209.2519989013672,
@ -1228,8 +1228,8 @@
"y": 209.53700256347656 "y": 209.53700256347656
}, },
{ {
"x": 40.18000030517578, "x": 48.4109992980957,
"y": 210.00399780273438 "y": 208.90499877929688
}, },
{ {
"x": 38.5, "x": 38.5,
@ -1592,8 +1592,8 @@
"y": 49.47600173950195 "y": 49.47600173950195
}, },
{ {
"x": -185.02099609375, "x": -183.6020050048828,
"y": 46.3849983215332 "y": 54.86199951171875
}, },
{ {
"x": -185.2519989013672, "x": -185.2519989013672,
@ -1972,8 +1972,8 @@
"y": 123.8030014038086 "y": 123.8030014038086
}, },
{ {
"x": 674.375, "x": 677.2830200195312,
"y": 127.77300262451172 "y": 119.5770034790039
}, },
{ {
"x": 673.9329833984375, "x": 673.9329833984375,
@ -2336,8 +2336,8 @@
"y": 198.90899658203125 "y": 198.90899658203125
}, },
{ {
"x": 336.8710021972656, "x": 342.7919921875,
"y": 195.8260040283203 "y": 202.46800231933594
}, },
{ {
"x": 336.1419982910156, "x": 336.1419982910156,
@ -2740,8 +2740,8 @@
"y": 208.45700073242188 "y": 208.45700073242188
}, },
{ {
"x": 936.197021484375, "x": 941.3209838867188,
"y": 209.53700256347656 "y": 208.89300537109375
}, },
{ {
"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: 26 KiB