Esempio n. 1
0
        public static void FillPolygon(VectorGroup points, Color color,
                                       bool isCurved = false)
        {
            var normalizedPoints = NormalizeCoords(points);

            if (isCurved)
            {
                currentGraphics.FillClosedCurve(new SolidBrush(color), normalizedPoints);
            }
            else
            {
                currentGraphics.FillPolygon(new SolidBrush(color), normalizedPoints);
            }
        }
Esempio n. 2
0
        public static void DrawPolygon(VectorGroup points, Color color, bool isCurved =
                                       false, float stroke = 1)
        {
            var normalizedPoints = NormalizeCoords(points);

            if (isCurved)
            {
                currentGraphics.DrawClosedCurve(new Pen(color, stroke), normalizedPoints);
            }
            else
            {
                currentGraphics.DrawPolygon(new Pen(color, stroke), normalizedPoints);
            }
        }
Esempio n. 3
0
        public bool IsIntersectsByBounding(VectorGroup other)
        {
            float Area(Vector a, Vector b, Vector c)
            {
                return((b.X - a.X) * (c.Y - a.Y) - (b.Y - a.Y) * (c.X - a.X));
            }

            void Swap(ref float a, ref float b)
            {
                var t = a;

                a = b;
                b = t;
            }

            bool SubIntersect(float a, float b, float c, float d)
            {
                if (a > b)
                {
                    Swap(ref a, ref b);
                }
                if (c > d)
                {
                    Swap(ref c, ref d);
                }
                return(Max(a, c) <= Min(b, d));
            }

            bool Intersect(Vector a, Vector b, Vector c, Vector d)
            {
                return(SubIntersect(a.X, b.X, c.X, d.X) &&
                       SubIntersect(a.Y, b.Y, c.Y, d.Y) &&
                       Area(a, b, c) * Area(a, b, d) <= 0 &&
                       Area(c, d, a) * Area(c, d, b) <= 0);
            }

            for (int i = 0; i < points.Length - 1; i++)
            {
                for (int j = 0; j < other.points.Length - 1; j++)
                {
                    if (Intersect(points[i], points[i + 1], other.points[j], other.points[j + 1]))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 4
0
 private static PointF[] NormalizeCoords(VectorGroup group) =>
 group.Select(p => new PointF(p.X, Height - p.Y)).ToArray();
Esempio n. 5
0
        public static void MarkSlip(VectorGroup points)
        {
            var normalizedPoints = NormalizeCoords(points);

            slipsG.FillPolygon(new SolidBrush(Color.LightGray), normalizedPoints);
        }