/// <summary> /// Gets geometric information for a edge and a route</summary> /// <param name="edge">Edge</param> /// <param name="route">Edge's route</param> /// <param name="startPoint">Calculated starting point for edge</param> /// <param name="endPoint">Calculated ending point for edge</param> /// <param name="circle">Calculated embedding circle for edge</param> /// <param name="moreThan180">Calculated sweep angle hint</param> /// <returns>True iff edge is straight line</returns> private bool GetEdgeGeometry( TEdge edge, int route, ref Vec2F startPoint, ref Vec2F endPoint, ref CircleF circle, ref bool moreThan180) { bool straightLine = false; if (edge.FromNode == edge.ToNode) { CircleF c = GetBoundary(edge.FromNode); circle = c; circle.Center.X -= circle.Radius; circle.Radius *= 0.85f; float offset = route * m_routeOffset / 2; circle.Center.X -= offset; circle.Radius += offset; CircleF.Intersect(circle, c, ref startPoint, ref endPoint); moreThan180 = true; } else { CircleF c1 = GetBoundary(edge.FromNode); CircleF c2 = GetBoundary(edge.ToNode); Vec2F d = Vec2F.Sub(c2.Center, c1.Center); float length = d.Length; if (length < c1.Radius + c2.Radius) { // overlapping nodes, don't try to draw arcs d = Vec2F.XAxis; straightLine = true; } else if (route == 0) { d *= 1.0f / length; straightLine = true; } else { Vec2F routePoint = c1.Center + d * 0.5f; float dLength = d.Length; Vec2F offset = d.Perp * (1.0f / dLength); routePoint -= offset * m_routeOffset * route; circle = new CircleF(c1.Center, routePoint, c2.Center); Vec2F dummy = new Vec2F(); CircleF.Intersect(circle, c1, ref startPoint, ref dummy); CircleF.Intersect(circle, c2, ref dummy, ref endPoint); Vec2F startToEnd = startPoint - endPoint; Vec2F centerToEnd = circle.Center - endPoint; moreThan180 = Vec2F.PerpDot(centerToEnd, startToEnd) < 0; } if (straightLine) { startPoint = Vec2F.Add(c1.Center, Vec2F.Mul(d, c1.Radius)); endPoint = Vec2F.Sub(c2.Center, Vec2F.Mul(d, c2.Radius)); } } return(straightLine); }