try
This commit is contained in:
parent
be5ba61297
commit
85c1ea10f4
1 changed files with 31 additions and 51 deletions
|
|
@ -73,52 +73,32 @@ func createCircularArc(edge *d2graph.Edge) {
|
||||||
srcCenter := edge.Src.Center()
|
srcCenter := edge.Src.Center()
|
||||||
dstCenter := edge.Dst.Center()
|
dstCenter := edge.Dst.Center()
|
||||||
|
|
||||||
// Calculate the radius based on the distance from origin to the centers
|
|
||||||
srcRadius := math.Hypot(srcCenter.X, srcCenter.Y)
|
|
||||||
dstRadius := math.Hypot(dstCenter.X, dstCenter.Y)
|
|
||||||
|
|
||||||
// Use average radius for more consistent arcs
|
|
||||||
|
|
||||||
|
|
||||||
// Calculate angles but preserve relative positioning
|
|
||||||
srcAngle := math.Atan2(srcCenter.Y, srcCenter.X)
|
srcAngle := math.Atan2(srcCenter.Y, srcCenter.X)
|
||||||
dstAngle := math.Atan2(dstCenter.Y, dstCenter.X)
|
dstAngle := math.Atan2(dstCenter.Y, dstCenter.X)
|
||||||
|
|
||||||
// Ensure we take the shorter path around the circle
|
|
||||||
if dstAngle < srcAngle {
|
if dstAngle < srcAngle {
|
||||||
if srcAngle - dstAngle > math.Pi {
|
|
||||||
dstAngle += 2 * math.Pi
|
dstAngle += 2 * math.Pi
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if dstAngle - srcAngle > math.Pi {
|
arcRadius := math.Hypot(srcCenter.X, srcCenter.Y)
|
||||||
srcAngle += 2 * math.Pi
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
path := make([]*geo.Point, 0, ARC_STEPS+1)
|
path := make([]*geo.Point, 0, ARC_STEPS+1)
|
||||||
for i := 0; i <= ARC_STEPS; i++ {
|
for i := 0; i <= ARC_STEPS; i++ {
|
||||||
t := float64(i) / float64(ARC_STEPS)
|
t := float64(i) / float64(ARC_STEPS)
|
||||||
angle := srcAngle + t*(dstAngle-srcAngle)
|
angle := srcAngle + t*(dstAngle-srcAngle)
|
||||||
|
x := arcRadius * math.Cos(angle)
|
||||||
// Use interpolated radius for smoother transition
|
y := arcRadius * math.Sin(angle)
|
||||||
radius := srcRadius + t*(dstRadius-srcRadius)
|
|
||||||
|
|
||||||
x := radius * math.Cos(angle)
|
|
||||||
y := radius * math.Sin(angle)
|
|
||||||
path = append(path, geo.NewPoint(x, y))
|
path = append(path, geo.NewPoint(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure exact endpoints
|
|
||||||
path[0] = srcCenter
|
path[0] = srcCenter
|
||||||
path[len(path)-1] = dstCenter
|
path[len(path)-1] = dstCenter
|
||||||
|
|
||||||
// Clamp endpoints to the boundaries of the source and destination boxes
|
// Clamp endpoints to the boundaries of the source and destination boxes.
|
||||||
_, newSrc := clampPointOutsideBox(edge.Src.Box, path, 0)
|
_, newSrc := clampPointOutsideBox(edge.Src.Box, path, 0)
|
||||||
_, newDst := clampPointOutsideBoxReverse(edge.Dst.Box, path, len(path)-1)
|
_, newDst := clampPointOutsideBoxReverse(edge.Dst.Box, path, len(path)-1)
|
||||||
path[0] = newSrc
|
path[0] = newSrc
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue