Пример #1
0
        /// <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);
        }
Пример #2
0
 /// <summary>
 /// Adds a vector and a scalar.
 /// </summary>
 /// <param name="v">A <see cref="Vec2F"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="Vec2F"/> instance containing the sum.</returns>
 public static Vec2F operator+(Vec2F v, float s)
 {
     return(Vec2F.Add(v, s));
 }
Пример #3
0
 /// <summary>
 /// Adds a vector and a scalar.
 /// </summary>
 /// <param name="v">A <see cref="Vec2F"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="Vec2F"/> instance containing the sum.</returns>
 public static Vec2F operator+(float s, Vec2F v)
 {
     return(Vec2F.Add(v, s));
 }
Пример #4
0
 /// <summary>
 /// Adds two vectors.
 /// </summary>
 /// <param name="u">A <see cref="Vec2F"/> instance.</param>
 /// <param name="v">A <see cref="Vec2F"/> instance.</param>
 /// <returns>A new <see cref="Vec2F"/> instance containing the sum.</returns>
 public static Vec2F operator+(Vec2F u, Vec2F v)
 {
     return(Vec2F.Add(u, v));
 }