This commit is contained in:
Mayank Mohapatra 2025-02-22 11:00:58 +00:00
parent 85c1ea10f4
commit 6736a70389
5 changed files with 237 additions and 176 deletions

View file

@ -65,6 +65,47 @@ func positionObjects(objects []*d2graph.Object, radius float64) {
}
}
// func createCircularArc(edge *d2graph.Edge) {
// if edge.Src == nil || edge.Dst == nil {
// return
// }
// srcCenter := edge.Src.Center()
// dstCenter := edge.Dst.Center()
// srcAngle := math.Atan2(srcCenter.Y, srcCenter.X)
// dstAngle := math.Atan2(dstCenter.Y, dstCenter.X)
// if dstAngle < srcAngle {
// dstAngle += 2 * math.Pi
// }
// arcRadius := math.Hypot(srcCenter.X, srcCenter.Y)
// path := make([]*geo.Point, 0, ARC_STEPS+1)
// for i := 0; i <= ARC_STEPS; i++ {
// t := float64(i) / float64(ARC_STEPS)
// angle := srcAngle + t*(dstAngle-srcAngle)
// x := arcRadius * math.Cos(angle)
// y := arcRadius * math.Sin(angle)
// path = append(path, geo.NewPoint(x, y))
// }
// path[0] = srcCenter
// path[len(path)-1] = dstCenter
// // Clamp endpoints to the boundaries of the source and destination boxes.
// _, newSrc := clampPointOutsideBox(edge.Src.Box, path, 0)
// _, newDst := clampPointOutsideBoxReverse(edge.Dst.Box, path, len(path)-1)
// path[0] = newSrc
// path[len(path)-1] = newDst
// // Trim redundant path points that fall inside node boundaries.
// path = trimPathPoints(path, edge.Src.Box)
// path = trimPathPoints(path, edge.Dst.Box)
// edge.Route = path
// edge.IsCurve = true
// }
// createCircularArc creates a circular arc path for the edge and adjusts the last segment to align with the tangent direction.
func createCircularArc(edge *d2graph.Edge) {
if edge.Src == nil || edge.Dst == nil {
return
@ -102,6 +143,26 @@ func createCircularArc(edge *d2graph.Edge) {
path = trimPathPoints(path, edge.Src.Box)
path = trimPathPoints(path, edge.Dst.Box)
// Adjust the last segment to align with the tangent direction at the destination
if len(path) >= 2 {
last := path[len(path)-1]
// Calculate tangent direction (perpendicular to radius vector)
tangentX := -last.Y
tangentY := last.X
tangentLength := math.Hypot(tangentX, tangentY)
if tangentLength > 0 {
// Normalize tangent direction
tangentDir := geo.NewPoint(tangentX/tangentLength, tangentY/tangentLength)
// Move second-to-last point along the tangent direction
delta := 10.0
newSecondLast := geo.NewPoint(
last.X-delta*tangentDir.X,
last.Y-delta*tangentDir.Y,
)
path[len(path)-2] = newSecondLast
}
}
edge.Route = path
edge.IsCurve = true
}

View file

@ -864,8 +864,8 @@
"y": -37.47600173950195
},
{
"x": 197.02099609375,
"y": -34.3849983215332
"x": 195.6020050048828,
"y": -42.86199951171875
},
{
"x": 197.2519989013672,
@ -1228,8 +1228,8 @@
"y": 197.53700256347656
},
{
"x": 28.18000030517578,
"y": 198.00399780273438
"x": 36.4109992980957,
"y": 196.90499877929688
},
{
"x": 26.5,
@ -1592,8 +1592,8 @@
"y": 37.47600173950195
},
{
"x": -197.02099609375,
"y": 34.3849983215332
"x": -195.6020050048828,
"y": 42.86199951171875
},
{
"x": -197.2519989013672,
@ -1972,8 +1972,8 @@
"y": 111.8030014038086
},
{
"x": 701.875,
"y": 115.77300262451172
"x": 704.7830200195312,
"y": 107.5770034790039
},
{
"x": 701.4329833984375,
@ -2336,8 +2336,8 @@
"y": 186.90899658203125
},
{
"x": 364.3710021972656,
"y": 183.8260040283203
"x": 370.2919921875,
"y": 190.46800231933594
},
{
"x": 363.6419982910156,
@ -2740,8 +2740,8 @@
"y": 196.45700073242188
},
{
"x": 1003.2860107421875,
"y": 197.53700256347656
"x": 1008.4110107421875,
"y": 196.89300537109375
},
{
"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
},
{
"x": 209.02099609375,
"y": -22.385000228881836
"x": 207.6020050048828,
"y": -30.86199951171875
},
{
"x": 209.2519989013672,
@ -1228,8 +1228,8 @@
"y": 209.53700256347656
},
{
"x": 40.18000030517578,
"y": 210.00399780273438
"x": 48.4109992980957,
"y": 208.90499877929688
},
{
"x": 38.5,
@ -1592,8 +1592,8 @@
"y": 49.47600173950195
},
{
"x": -185.02099609375,
"y": 46.3849983215332
"x": -183.6020050048828,
"y": 54.86199951171875
},
{
"x": -185.2519989013672,
@ -1972,8 +1972,8 @@
"y": 123.8030014038086
},
{
"x": 674.375,
"y": 127.77300262451172
"x": 677.2830200195312,
"y": 119.5770034790039
},
{
"x": 673.9329833984375,
@ -2336,8 +2336,8 @@
"y": 198.90899658203125
},
{
"x": 336.8710021972656,
"y": 195.8260040283203
"x": 342.7919921875,
"y": 202.46800231933594
},
{
"x": 336.1419982910156,
@ -2740,8 +2740,8 @@
"y": 208.45700073242188
},
{
"x": 936.197021484375,
"y": 209.53700256347656
"x": 941.3209838867188,
"y": 208.89300537109375
},
{
"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