public Polygon2DDiviser(Polygon2D parent)
 {
     Parent = parent;
     SubDivision = new Polygon2DCollection();
     Divisers = new LineSegment2DCollection();
     InnerPoints = new Point2DCollection();
     SubDivision.Add(Parent);
 }
Example #2
0
        public Polygon2D(Polygon2D polygon)
        {
            Vertices = new Point2DCollection();

            Vertices.Clone(polygon.Vertices);

            SetStatus();
        }
        public void Clone(Point2DCollection point2DCollection)
        {
            this.Capacity = point2DCollection.Capacity;

            this.Points = new Point2D[Capacity];

            point2DCollection.Points.CopyTo(this.Points, 0);

            CurrentCount = point2DCollection.Count;
        }
        public void Union(Point2DCollection point2DCollection)
        {
            Capacity += point2DCollection.Capacity;

            Point2D[] points = new Point2D[Capacity];

            this.Points.CopyTo(points, 0);
            point2DCollection.Points.CopyTo(points, this.Count);

            this.Points = points;

            CurrentCount += point2DCollection.Count;
        }
        public Polygon2DLinkMaker(Polygon2D polygon, int a, int b)
            : base(polygon)
        {
            if (!polygon.isRegular)
            {
                throw (new ArgumentException());
            }

            FirstPoint = polygon.GetPoint(a);
            LastPoint = polygon.GetPoint(b);
            LinkDivisers = new Point2DCollection();
            //Partitions = new Polygon2DCollection();
            //Partitions.Add(polygon);
        }
        /// <summary>
        /// Convert this line segment to a path. Instert some new points.
        /// </summary>
        /// <param name="ExtraPoints">the number of extra points to insert.</param>
        /// <returns>the path.</returns>
        public Point2DCollection ToPath(int ExtraPoints)
        {
            if (ExtraPoints < 0)
            {
                throw (new ArgumentException());
            }

            Point2DCollection points = new Point2DCollection();

            points.Add(this.FirstPoint);
            for (int i = 1; i <= ExtraPoints; i++)
            {
                double d = (double) i / (double) (ExtraPoints + 1);

                points.Add(this.GetPoint(d));
            }

            points.Add(this.LastPoint);
            return points;
        }
        /// <summary>
        /// Divide a sub polygon by a line segment.
        /// </summary>
        /// <param name="lineSegment">the line segment.</param>
        /// <param name="poly">the polygon to divide.</param>
        /// <returns>one of the sub polygon divided from the polygon.</returns>
        internal Polygon2D DividedBy(LineSegment2D lineSegment, Polygon2D poly)
        {
            if (poly.isDiagonal(lineSegment))
            {
                int a = poly.HasVertex(lineSegment.FirstPoint);
                int b = poly.HasVertex(lineSegment.LastPoint);

                if (a > b)
                {
                    int tmp = a;
                    a = b;
                    b = tmp;
                }

                Point2DCollection p2 = new Point2DCollection(b - a + 1);
                Point2DCollection p1 = new Point2DCollection(poly.VertexCount - p2.Size + 2);

                for (int i = 0; i < poly.VertexCount; i++)
                {
                    if (i <= a || i >= b)
                    {
                        p1.Add(poly.GetPoint(i));
                    }
                    if (i >= a && i <= b)
                    {
                        p2.Add(poly.GetPoint(i));
                    }
                }

                if (p1.Count > p2.Count)
                {
                    SubDivision.Add(new Polygon2D(p1));
                    return new Polygon2D(p2);
                }
                else
                {
                    SubDivision.Add(new Polygon2D(p2));
                    return new Polygon2D(p1);
                }
            }
            else if (lineSegment.Intersects(poly))
            {
                Point2DCollection Points = new Point2DCollection(2);

                for (int i = 0; i < poly.VertexCount; i++)
                {
                    LineSegment2D border = poly.GetEdge(i);

                    Point2D p = lineSegment.GetIntersectPoint(border);

                    if (p.isRegular)
                    {
                        Points.DistinctAdd(p);
                    }
                }

                Debug.Assert(Points.Count == 2);

                if (poly.HasVertex(Points[0]) == Polygon2D.NoSuchPoint)
                {
                    poly.Add(Points[0], poly.OnEdge(Points[0]));
                    Parent.AddInner(Points[0]);
                    this.InnerPoints.DistinctAdd(Points[0]);
                }

                if (poly.HasVertex(Points[1]) == Polygon2D.NoSuchPoint)
                {
                    poly.Add(Points[1], poly.OnEdge(Points[1]));
                    Parent.AddInner(Points[1]);
                    this.InnerPoints.DistinctAdd(Points[1]);
                }

                LineSegment2D line = new LineSegment2D(Points[0], Points[1]);

                return DividedBy(line, poly);
            }
            else
            {
                return poly;
            }
        }
        /// <summary>
        /// Divide a polygon by a path.(point2DCollection)
        /// </summary>
        /// <param name="path">the path.</param>
        /// <param name="polygon">the polygon to divide.</param>
        public void DividedBy(Point2DCollection path, Polygon2D polygon)
        {
            int a = polygon.HasVertex(path.FirstPoint);
            int b = polygon.HasVertex(path.LastPoint);

            if (a == Polygon2D.NoSuchPoint || b == Polygon2D.NoSuchPoint)
            {
                throw (new ArgumentException());
            }

            if (a > b)
            {
                int tmp = a;

                a = b;
                b = tmp;
            }

            Point2DCollection p2 = new Point2DCollection();
            Point2DCollection p1 = new Point2DCollection();

            for (int i = 0; i < polygon.VertexCount; i++)
            {
                if (i <= a || i >= b)
                {
                    p1.Add(polygon.GetPoint(i));
                }

                if (i >= a && i <= b)
                {
                    p2.Add(polygon.GetPoint(i));
                }
            }

            for (int i = 1; i < path.Count - 1; i++)
            {
                p1.Add(path[i], a + i);
                p2.Add(path[i], 0);
                Parent.AddInner(path[i]);
            }

            if (p1.Count > p2.Count)
            {
                SubDivision.Add(new Polygon2D(p1));
                SubDivision.Add(new Polygon2D(p2));
            }
            else
            {
                SubDivision.Add(new Polygon2D(p2));
                SubDivision.Add(new Polygon2D(p1));
            }
        }
        public void Union(Point2DCollection point2DCollection)
        {
            Capacity += point2DCollection.Capacity;

            Point2D[] points = new Point2D[Capacity];

            this.Points.CopyTo(points, 0);
            point2DCollection.Points.CopyTo(points, this.Count);

            this.Points = points;

            CurrentCount += point2DCollection.Count;
        }
        public void Clone(Point2DCollection point2DCollection)
        {
            this.Capacity = point2DCollection.Capacity;

            this.Points = new Point2D[Capacity];

            point2DCollection.Points.CopyTo(this.Points, 0);

            CurrentCount = point2DCollection.Count;
        }
Example #11
0
        private Polygon2D FlipArea(GhostTriangle2D a, GhostTriangle2D b, Polygon2D poly)
        {
            if (!isNeighbor(a, b))
            {
                throw (new ArgumentException());
            }

            Map(a, b);

            Point2DCollection points = new Point2DCollection(4);

            points.Add(poly.GetPoint(a.C));
            points.Add(poly.GetPoint(a.A));
            points.Add(poly.GetPoint(b.C));
            points.Add(poly.GetPoint(b.B));

            Polygon2D polygon = new Polygon2D(points);
            return polygon;
        }
Example #12
0
        public Polygon2D(Point2DCollection points)
        {
            Vertices = points;

            SetStatus();
        }
Example #13
0
 public Polygon2D()
 {
     Vertices = new Point2DCollection();
 }