public static Vertices LineSegmentPolygonIntersect(ref Point2D point1, ref Point2D point2, Polygon polygon)
        {
            Vertices intersectionPoints = new Vertices();
            int count = polygon.Vertices.Count - (polygon.isClosed() ? 0 : 1);

            for (int i = 0; i < count; i++)
            {
                Point2D point;
                if (LineIntersect(polygon.Vertices[i], polygon.Vertices[polygon.Vertices.NextIndex(i)], point1, point2, true, true, out point))
                {
                    intersectionPoints.Add(point);
                }
            }
            return intersectionPoints;
        }