1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
            if (startIsVertex != null)
            {
                Vector2 a = p.GetPreviousVertexPositionFromHandle(startIsVertex.Value);
                Vector2 b = p.GetVertexPositionFromHandle(startIsVertex.Value);
                Vector2 c = p.GetNextVertexPositionFromHandle(startIsVertex.Value);
                Vector2 x = end;
                return GeometryHelper.Area2(a, b, x) >= 0 && GeometryHelper.Area2(x, b, c) >= 0;
            }
            else if (endIsVertex != null)
            {
                Vector2 a = p.GetPreviousVertexPositionFromHandle(endIsVertex.Value);
                Vector2 b = p.GetVertexPositionFromHandle(endIsVertex.Value);
                Vector2 c = p.GetNextVertexPositionFromHandle(endIsVertex.Value);
                Vector2 x = start;
                return GeometryHelper.Area2(a, b, x) >= 0 && GeometryHelper.Area2(x, b, c) >= 0;
            }


        public static float Area2(Vector2 a, Vector2 b, Vector2 c)
        {
            return (b.X - a.X) * (c.Y - a.Y) - (c.X - a.X) * (b.Y - a.Y);
        }