예제 #1
0
        // unit testing of the methods (optional)
        public static void InternalMain()
        {
            //List<Point2D>

            PointSET set = new PointSET();

            set.insert(new Point2D(.2, .2));
            set.insert(new Point2D(.1, .2));
            set.insert(new Point2D(.3, .2));
            set.insert(new Point2D(.3, .3));
            set.insert(new Point2D(.4, .4));

            RectHV rect = new RectHV(0, 0, .2, 1);

            var iterator = set.range(rect);

            while (iterator.MoveNext())
            {
                Point2D p = iterator.Current;
                DisplayPoint(p);
            }

            var n = set.nearest(new Point2D(0, 0));

            DisplayPoint(n);

            Console.Read();
        }
예제 #2
0
        public IEnumerator <Point2D> range(RectHV rect)
        {
            var l = new List <Point2D>();

            range(this.root, rect, l);
            return(l.GetEnumerator());
        }
예제 #3
0
        public void range(Node <Point2D, V> temp, RectHV rect, List <Point2D> t)
        {
            if (temp == null)
            {
                return;
            }

            if (rect.Contains(temp.Key))
            {
                t.Add(temp.Key);
            }

            IComparer <Point2D> comparer = (IComparer <Point2D>) new XPoint2DComparer();

            if (temp.depth % 2 == 1)
            {
                comparer = (IComparer <Point2D>) new YPoint2DComparer();
            }

            if (temp.depth % 2 == 1)
            {
                if (rect.ContainsInY(temp.Key) > 0)
                {
                    range(temp.left, rect, t);
                }
                else if (rect.ContainsInY(temp.Key) < 0)
                {
                    range(temp.right, rect, t);
                }
                else
                {
                    range(temp.left, rect, t);
                    range(temp.right, rect, t);
                }
            }
            else
            {
                if (rect.ContainsInX(temp.Key) > 0)
                {
                    range(temp.left, rect, t);
                }
                else if (rect.ContainsInX(temp.Key) < 0)
                {
                    range(temp.right, rect, t);
                }
                else
                {
                    range(temp.left, rect, t);
                    range(temp.right, rect, t);
                }
            }
        }
예제 #4
0
        //public void draw()                         // draw all points to standard draw

        // all points that are inside the rectangle (or on the boundary)
        public IEnumerator <Point2D> range(RectHV rect)
        {
            List <Point2D> inRangePoints = new List <Point2D>();

            foreach (var p in set)
            {
                if (rect.Contains(p))
                {
                    inRangePoints.Add(p);
                }
            }
            return(inRangePoints.GetEnumerator());
        }
예제 #5
0
 // does this rectangle intersect that rectangle (at one or more points)?
 public bool Intersects(RectHV that)
 {
     return((this.Contains(new Point2D(xmin(), ymin()))) || (this.Contains(new Point2D(xmax(), ymax()))) ||
            (that.Contains(new Point2D(that.xmin(), that.ymin()))) || (that.Contains(new Point2D(that.xmax(), that.ymax()))));
 }