Inheritance: TriangulationPoint
Ejemplo n.º 1
0
        public static Polygon.Polygon RandomCircleSweep(double scale, int vertexCount)
        {
            PolygonPoint point;
            PolygonPoint[] points;
            double radius = scale/4;

            points = new PolygonPoint[vertexCount];
            for (int i = 0; i < vertexCount; i++)
            {
                do
                {
                    if (i%250 == 0)
                    {
                        radius += scale/2*(0.5 - RNG.NextDouble());
                    }
                    else if (i%50 == 0)
                    {
                        radius += scale/5*(0.5 - RNG.NextDouble());
                    }
                    else
                    {
                        radius += 25*scale/vertexCount*(0.5 - RNG.NextDouble());
                    }
                    radius = radius > scale/2 ? scale/2 : radius;
                    radius = radius < scale/10 ? scale/10 : radius;
                } while (radius < scale/10 || radius > scale/2);
                point = new PolygonPoint(radius*Math.Cos((PI_2*i)/vertexCount),
                                         radius*Math.Sin((PI_2*i)/vertexCount));
                points[i] = point;
            }
            return new Polygon.Polygon(points);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes a point from the polygon.
        /// </summary>
        /// <param name="p"></param>
        public void RemovePoint(PolygonPoint p)
        {
            PolygonPoint next, prev;

            next          = p.Next;
            prev          = p.Previous;
            prev.Next     = next;
            next.Previous = prev;
            _points.Remove(p);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Removes a point from the polygon.  Note this can be a somewhat expensive operation
        /// as it must recalculate the bounding area from scratch.
        /// </summary>
        /// <param name="p"></param>
        public void RemovePoint(PolygonPoint p)
        {
            PolygonPoint next = p.Next;
            PolygonPoint prev = p.Previous;

            prev.Next     = next;
            next.Previous = prev;
            MPoints.Remove(p);

            BoundingBox = new Rect2D();
            foreach (var point2D in MPoints)
            {
                BoundingBox = BoundingBox.AddPoint(point2D);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Inserts newPoint after point.
        /// </summary>
        /// <param name="point">The point to insert after in the polygon</param>
        /// <param name="newPoint">The point to insert into the polygon</param>
        public void InsertPointAfter(PolygonPoint point, PolygonPoint newPoint)
        {
            // Validate that
            int index = _points.IndexOf(point);

            if (index == -1)
            {
                throw new ArgumentException(
                          "Tried to insert a point into a Polygon after a point not belonging to the Polygon", "point");
            }
            newPoint.Next       = point.Next;
            newPoint.Previous   = point;
            point.Next.Previous = newPoint;
            point.Next          = newPoint;
            _points.Insert(index + 1, newPoint);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Inserts list (after last point in polygon?)
        /// </summary>
        /// <param name="list"></param>
        public void AddPoints(IEnumerable <PolygonPoint> list)
        {
            PolygonPoint first;

            foreach (PolygonPoint p in list)
            {
                p.Previous = _last;
                if (_last != null)
                {
                    p.Next     = _last.Next;
                    _last.Next = p;
                }
                _last = p;
                _points.Add(p);
            }
            first          = (PolygonPoint)_points[0];
            _last.Next     = first;
            first.Previous = _last;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Removes a point from the polygon.
        /// </summary>
        /// <param name="p"></param>
        public void RemovePoint(PolygonPoint p)
        {
            PolygonPoint next, prev;

            next = p.Next;
            prev = p.Previous;
            prev.Next = next;
            next.Previous = prev;
            _points.Remove(p);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds a point after the last in the polygon.
 /// </summary>
 /// <param name="p">The point to add</param>
 public void AddPoint(PolygonPoint p)
 {
     p.Previous = _last;
     p.Next = _last.Next;
     _last.Next = p;
     _points.Add(p);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Inserts list (after last point in polygon?)
 /// </summary>
 /// <param name="list"></param>
 public void AddPoints(IEnumerable<PolygonPoint> list)
 {
     PolygonPoint first;
     foreach (PolygonPoint p in list)
     {
         p.Previous = _last;
         if (_last != null)
         {
             p.Next = _last.Next;
             _last.Next = p;
         }
         _last = p;
         _points.Add(p);
     }
     first = (PolygonPoint) _points[0];
     _last.Next = first;
     first.Previous = _last;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Inserts newPoint after point.
 /// </summary>
 /// <param name="point">The point to insert after in the polygon</param>
 /// <param name="newPoint">The point to insert into the polygon</param>
 public void InsertPointAfter(PolygonPoint point, PolygonPoint newPoint)
 {
     // Validate that 
     int index = _points.IndexOf(point);
     if (index == -1)
         throw new ArgumentException(
             "Tried to insert a point into a Polygon after a point not belonging to the Polygon", "point");
     newPoint.Next = point.Next;
     newPoint.Previous = point;
     point.Next.Previous = newPoint;
     point.Next = newPoint;
     _points.Insert(index + 1, newPoint);
 }
Ejemplo n.º 10
0
 public void Add(PolygonPoint p)
 {
     Add(p, -1, true);
 }