Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (obj == (object)this)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (obj.GetType() != this.GetType())
            {
                return(false);
            }
            RectHV that = (RectHV)obj;

            if (this.Xmin != that.Xmin)
            {
                return(false);
            }
            if (this.Ymin != that.Ymin)
            {
                return(false);
            }
            if (this.Xmax != that.Xmax)
            {
                return(false);
            }
            if (this.Ymax != that.Ymax)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        private void FindRangeRecursive(Node x, RectHV rect, Queue <Point2D> acc, bool isVertical)
        {
            if (rect.contains(x.p))
            {
                acc.Enqueue(x.p);
            }

            RectHV line = isVertical ? new RectHV(x.p.X, x.rect.Ymin, x.p.X, x.rect.Ymax) :
                          new RectHV(x.rect.Xmin, x.p.Y, x.rect.Xmax, x.p.Y);

            if (rect.Intersects(line))
            {
                //both subtrees
                if (null != x.lb)
                {
                    FindRangeRecursive(x.lb, rect, acc, !isVertical);
                }
                if (null != x.rt)
                {
                    FindRangeRecursive(x.rt, rect, acc, !isVertical);
                }
            }
            else
            {
                //just one subtree
                if (null != x.lb && rect.Intersects(x.lb.rect))
                {
                    FindRangeRecursive(x.lb, rect, acc, !isVertical);
                }
                else if (null != x.rt)
                {
                    FindRangeRecursive(x.rt, rect, acc, !isVertical);
                }
            }
        }
Ejemplo n.º 3
0
        public IEnumerable <Point2D> Range(RectHV rect)
        {
            Queue <Point2D> acc = new Queue <Point2D>();

            if (!IsEmpty)
            {
                FindRangeRecursive(root, rect, acc, true);
            }
            return(acc);
        }
Ejemplo n.º 4
0
 public bool Intersects(RectHV that)
 {
     return(this.Xmax >= that.Xmin && this.Ymax >= that.Ymin &&
            that.Xmax >= this.Xmin && that.Ymax >= this.Ymin);
 }