This commit is contained in:
Mayank Mohapatra 2025-02-22 13:35:53 +00:00
parent 36ccdb62bd
commit a8526432df
5 changed files with 207 additions and 227 deletions

View file

@ -65,46 +65,6 @@ 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
// }
func createCircularArc(edge *d2graph.Edge) {
if edge.Src == nil || edge.Dst == nil {
return
@ -115,14 +75,9 @@ func createCircularArc(edge *d2graph.Edge) {
srcAngle := math.Atan2(srcCenter.Y, srcCenter.X)
dstAngle := math.Atan2(dstCenter.Y, dstCenter.X)
diff := dstAngle - srcAngle
if math.Abs(diff) > math.Pi {
if diff > 0 {
dstAngle -= 2 * math.Pi
} else {
if dstAngle < srcAngle {
dstAngle += 2 * math.Pi
}
}
arcRadius := math.Hypot(srcCenter.X, srcCenter.Y)
@ -144,11 +99,36 @@ func createCircularArc(edge *d2graph.Edge) {
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)
// path = trimPathPoints(path, edge.Src.Box)
// path = trimPathPoints(path, edge.Dst.Box)
edge.Route = path
edge.IsCurve = true
// edge.Route = path
// 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 at the destination.
if len(path) >= 2 {
dstPoint := path[len(path)-1]
// Calculate the tangent direction at the destination point (counter-clockwise)
tangentX := -dstPoint.Y
tangentY := dstPoint.X
// Normalize the tangent vector
length := math.Hypot(tangentX, tangentY)
if length > 0 {
tangentX /= length
tangentY /= length
}
// Adjust the penultimate point to be a small step back along the tangent direction
step := 10.0
prevX := dstPoint.X - tangentX*step
prevY := dstPoint.Y - tangentY*step
path[len(path)-2] = geo.NewPoint(prevX, prevY)
}
edge.Route = path
edge.IsCurve = true
}
// clampPointOutsideBox walks forward along the path until it finds a point outside the box,

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