Exemplo n.º 1
0
        public static 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(points);
        }
Exemplo 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public void AddPoints(IEnumerable <PolygonPoint> list)
        {
            foreach (PolygonPoint point2 in list)
            {
                point2.Previous = this._last;
                if (this._last != null)
                {
                    point2.Next     = this._last.Next;
                    this._last.Next = point2;
                }
                this._last = point2;
                this._points.Add(point2);
            }
            PolygonPoint point = (PolygonPoint)this._points[0];

            this._last.Next = point;
            point.Previous  = this._last;
        }
Exemplo 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;
        }
        public static Polygon RandomCircleSweep2(double scale, int vertexCount)
        {
            PolygonPoint point;

            PolygonPoint[] points;
            double         radius = scale / 4;

            points = new PolygonPoint[vertexCount];
            for (int i = 0; i < vertexCount; i++)
            {
                do
                {
                    radius += scale / 5 * (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(points));
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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);
 }