Ejemplo n.º 1
0
        /// Intersection
        ///
        /// Sets the rectangle to the intersection of two rectangles.
        /// Returns true if there is any intersection between the two rectangles.
        /// If there is no intersection, the rectangle is set to 0, 0, 0, 0.
        /// Either of the input rectangles may be the same as destination rectangle.
        ///
        public bool Intersection(Rect2D r1, Rect2D r2)
        {
            if (!TriangulationUtil.RectsIntersect(r1, r2))
            {
                Left = Right = Top = Bottom = 0.0;
                return(false);
            }

            Left   = (r1.Left > r2.Left) ? r1.Left : r2.Left;
            Top    = (r1.Top < r2.Top) ? r1.Top : r2.Top;
            Right  = (r1.Right < r2.Right) ? r1.Right : r2.Right;
            Bottom = (r1.Bottom > r2.Bottom) ? r1.Bottom : r2.Bottom;

            return(true);
        }
Ejemplo n.º 2
0
 /// Union
 ///
 /// Sets the rectangle to the union of two rectangles r1 and r2.
 /// If either rect is empty, it is ignored. If both are empty, the rectangle
 /// is set to r1.
 /// Either of the input rectangle references may refer to the destination rectangle.
 ///
 public void Union(Rect2D r1, Rect2D r2)
 {
     if ((r2.Right == r2.Left) || (r2.Bottom == r2.Top))
     {
         Set(r1);
     }
     else if ((r1.Right == r1.Left) || (r1.Bottom == r1.Top))
     {
         Set(r2);
     }
     else
     {
         Left   = (r1.Left < r2.Left) ? r1.Left : r2.Left;
         Top    = (r1.Top > r2.Top) ? r1.Top : r2.Top;
         Right  = (r1.Right > r2.Right) ? r1.Right : r2.Right;
         Bottom = (r1.Bottom < r2.Bottom) ? r1.Bottom : r2.Bottom;
     }
 }
Ejemplo n.º 3
0
        public bool Equals(Rect2D r, double epsilon)
        {
            if (!MathUtil.AreValuesEqual(MinX, r.MinX, epsilon))
            {
                return(false);
            }
            if (!MathUtil.AreValuesEqual(MaxX, r.MaxX))
            {
                return(false);
            }
            if (!MathUtil.AreValuesEqual(MinY, r.MinY, epsilon))
            {
                return(false);
            }
            if (!MathUtil.AreValuesEqual(MaxY, r.MaxY, epsilon))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
 public bool ContainsInclusive(Rect2D r, double epsilon)
 {
     return(((Left - epsilon) <= r.Left) && ((Right + epsilon) >= r.Right) && ((Top - epsilon) <= r.Top) && ((Bottom + epsilon) >= r.Bottom));
 }
Ejemplo n.º 5
0
 public bool ContainsInclusive(Rect2D r)
 {
     return((Left <= r.Left) && (Right >= r.Right) && (Top <= r.Top) && (Bottom >= r.Bottom));
 }
Ejemplo n.º 6
0
 public bool Contains(Rect2D r)
 {
     return((Left < r.Left) && (Right > r.Right) && (Top < r.Top) && (Bottom > r.Bottom));
 }
Ejemplo n.º 7
0
 public bool Equals(Rect2D r)
 {
     return(Equals(r, MathUtil.EPSILON));
 }