Пример #1
0
 public void MoveVertexWithRestrictions(PolyPoint point, Vector delta)
 {
     point.FromVector(point.GetVector() + delta);
     if (point.PreviousEdge.EnactedRestriction != Edge.Restriction.None)
     {
         EnactRestriction(point.PreviousEdge.RelatedEdge, Direction.Forward);
     }
     if (point.NextEdge.EnactedRestriction != Edge.Restriction.None)
     {
         EnactRestriction(point.NextEdge.RelatedEdge, Direction.Backwards);
     }
 }
Пример #2
0
 public PolyPoint GetOpposite(PolyPoint p)
 {
     if (p == Next)
     {
         return(Previous);
     }
     if (p == Previous)
     {
         return(Next);
     }
     throw new Exception("Edge doesn't contain this point");
 }
Пример #3
0
        public static Edge Link(PolyPoint p1, PolyPoint p2)
        {
            if (p1.Parent != p2.Parent)
            {
                throw new Exception("Cannot link points in different polygons");
            }
            Edge e = new Edge(p1.Parent);

            e.Previous  = p1;
            e.Next      = p2;
            p1.NextEdge = p2.PreviousEdge = e;
            return(e);
        }
Пример #4
0
        public Polygon(Point[] points, Color color)
        {
            First = new PolyPoint(points[0].X, points[0].Y, this);
            PolyPoint p = First;

            for (int i = 1; i < points.Length; i++)
            {
                Edge.Link(p, new PolyPoint(points[i].X, points[i].Y, this));
                p = p.Next;
            }
            Edge.Link(p, First);
            this.color = color;
            PointCount = points.Length;
            relationNumbersUsedList = new List <bool>();
        }
Пример #5
0
 public bool Remove(PolyPoint polyPoint)
 {
     if (PointCount <= 3)
     {
         return(false);
     }
     if (polyPoint == First)
     {
         First = polyPoint.Next;
     }
     polyPoint.PreviousEdge.ClearRestriction();
     polyPoint.NextEdge.ClearRestriction();
     Edge.Join(polyPoint.PreviousEdge, polyPoint.NextEdge);
     PointCount--;
     return(true);
 }
Пример #6
0
        public Figures.PolyPoint SelectPoint(int x, int y)
        {
            int minDist = Int32.MaxValue;

            Figures.PolyPoint res = null;
            foreach (Figures.Polygon polygon in Polygons)
            {
                var(dist, p) = polygon.TrySelectPoint(x, y, distanceLimit);
                if (p != null && dist < minDist)
                {
                    minDist = dist;
                    res     = p;
                }
            }
            return(res);
        }
Пример #7
0
 public void AddPointBetween(PolyPoint p1, PolyPoint p2)
 {
     if (p1.Parent != this || p2.Parent != this)
     {
         throw new Exception($"This polygon is not the owner of {p1}, {p2}");
     }
     if (p2.Next == p1)
     {
         PolyPoint buff = p2;
         p2 = p1;
         p1 = buff;
     }
     if (p1.Next != p2)
     {
         throw new Exception($"These points aren't adjacent");
     }
     p1.NextEdge.ClearRestriction();
     Edge.Split(p1.NextEdge, new PolyPoint((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, this));
     PointCount++;
     return;
 }
Пример #8
0
        public (int dist, PolyPoint p) TrySelectPoint(int x, int y, int distanceLimit)
        {
            PolyPoint res     = null;
            PolyPoint point   = First;
            int       minDist = Int32.MaxValue;

            do
            {
                int xDist = Math.Abs((int)point.X - x);
                int yDist = Math.Abs((int)point.Y - y);
                if (xDist + yDist < distanceLimit)
                {
                    if (res == null || xDist + yDist < minDist)
                    {
                        res     = point;
                        minDist = xDist + yDist;
                    }
                }
                point = point.Next;
            } while (point != First);
            return(minDist, res);
        }
Пример #9
0
        public void Draw(MemoryBitmap bitmap)
        {
            PolyPoint point = First;

            do
            {
                bitmap.DrawPoint((int)point.X, (int)point.Y, color, Helper.pointSize);
                bitmap.DrawLine(point, point.Next, color);
                point = point.Next;
            } while (point != First);
            if (DrawLabels)
            {
                do
                {
                    if (point.NextEdge.EnactedRestriction != Edge.Restriction.None)
                    {
                        Helper.DrawRestrictionLabel(point.NextEdge, bitmap);
                    }
                    point = point.Next;
                } while (point != First);
            }
        }
Пример #10
0
 public static (Edge e1, Edge e2) Split(Edge e, PolyPoint splittingPoint)
 {
     return(Link(e.Previous, splittingPoint), Link(splittingPoint, e.Next));
 }
Пример #11
0
        public void DrawLine(Figures.PolyPoint p1, Figures.PolyPoint p2, Color color)
        {
            int x0 = (int)p1.X, y0 = (int)p1.Y, x1 = (int)p2.X, y1 = (int)p2.Y;

            DrawLine(x0, y0, x1, y1, color);
        }