示例#1
0
        /// <summary>
        /// Compares this rectangle to the specified rectangle.</summary>
        /// <param name="other"> other the other rectangle</param>
        /// <returns><c>true</c> if this rectangle equals <c>other</c>;
        /// <c>false</c> otherwise</returns>
        ///
        public override bool Equals(object other)
        {
            if (other == this)
            {
                return(true);
            }
            if (other == null)
            {
                return(false);
            }
            if (other.GetType() != this.GetType())
            {
                return(false);
            }
            RectHV that = (RectHV)other;

            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);
        }
示例#2
0
        // TODO: Add a window class to demo the Draw method

        /// <summary>
        /// Demo test for the <c>RectHVTest</c> data type.</summary>
        /// <param name="args">Place holder for user arguments</param>
        public static void MainTest(string[] args)
        {
            RectHV rec1 = new RectHV(50, 50, 300, 300);
            RectHV rec2 = new RectHV(150, 100, 400, 150);

            Point2D p1 = new Point2D(50, 500);
            Point2D p2 = new Point2D(400, 150);

            Console.WriteLine("Predicting rec1 intersects rec2: {0}", rec1.Intersects(rec2));
            Console.WriteLine("Predicting rec2 NOT contains p1 is {0}", !rec2.Contains(p1));
            Console.WriteLine("Predicting rec2 contains p2 is {0}", rec2.Contains(p2));

            Console.WriteLine("Distance from rectangle {0} to point {1} is {2}", rec1, p1, rec1.DistanceTo(p1));
            Console.WriteLine("Distance from rectangle {0} to point {1} is {2}", rec1, p2, rec1.DistanceTo(p2));
        }
示例#3
0
 /// <summary>
 /// Returns true if the two rectangles intersect.</summary>
 /// <param name="that">the other rectangle</param>
 /// <returns><c>true</c> if this rectangle intersect the argument
 /// rectangle at one or more points, including on the boundary</returns>
 ///
 public bool Intersects(RectHV that)
 {
     return(this.xmax >= that.xmin && this.ymax >= that.ymin &&
            that.xmax >= this.xmin && that.ymax >= this.ymin);
 }