示例#1
0
        /// <summary>
        /// Compares two regions.
        /// </summary>
        /// <param name="rect1">The first region.</param>
        /// <param name="rect2">The second region.</param>
        public static bool IsEqual(Rect rect1, Rect rect2)
        {
            double DiffX  = Math.Abs(rect2.X - rect1.X);
            double DiffY  = Math.Abs(rect2.Y - rect1.Y);
            double DiffCX = Math.Abs(rect2.Width - rect1.Width);
            double DiffCY = Math.Abs(rect2.Height - rect1.Height);

            return(RegionHelper.IsZero(DiffX) && RegionHelper.IsZero(DiffY) && RegionHelper.IsZero(DiffCX) && RegionHelper.IsZero(DiffCY));
        }
示例#2
0
        /// <summary>
        /// Compares two sizes. Stretched sizes are never equal, even to themselves.
        /// </summary>
        /// <param name="size1">The first size.</param>
        /// <param name="size2">The second size.</param>
        public static bool IsEqual(Size size1, Size size2)
        {
            double DiffCX = size1.Width.IsFloating && size2.Width.IsFloating ? 0 : Math.Abs((size2.Width - size1.Width).Draw);
            double DiffCY = size1.Height.IsFloating && size2.Height.IsFloating ? 0 : Math.Abs((size2.Height - size1.Height).Draw);

            Debug.Assert(!double.IsNaN(DiffCX) && !double.IsNaN(DiffCY));

            return(RegionHelper.IsZero(DiffCX) && RegionHelper.IsZero(DiffCY));
        }
示例#3
0
        /// <summary>
        /// Returns the union of the visible surface of two rectangles.
        /// </summary>
        /// <param name="rect1">The first rectangle.</param>
        /// <param name="rect2">The second rectangle.</param>
        public static Rect VisibleUnion(Rect rect1, Rect rect2)
        {
            Debug.Assert(RegionHelper.IsFixed(rect1));
            Debug.Assert(RegionHelper.IsFixed(rect2));

            GetUnionX(rect1, rect2, out double UnionX, out double UnionCX);
            GetUnionY(rect1, rect2, out double UnionY, out double UnionCY);

            return(new Rect(UnionX, UnionY, UnionCX - UnionX, UnionCY - UnionY));
        }
示例#4
0
        /// <summary>
        /// Returns the union of the visible surface of two rectangles.
        /// </summary>
        /// <param name="rect1">The first rectangle.</param>
        /// <param name="rect2">The second rectangle.</param>
        public static Rect VisibleUnion(Rect rect1, Rect rect2)
        {
            Debug.Assert(RegionHelper.IsFixed(rect1));
            Debug.Assert(RegionHelper.IsFixed(rect2));

            double UnionX;
            double UnionY;
            double UnionCX;
            double UnionCY;

            if (rect1.Width > 0 && rect2.Width > 0)
            {
                UnionX  = rect1.X < rect2.X ? rect1.X : rect2.X;
                UnionCX = rect1.X + rect1.Width > rect2.X + rect2.Width ? rect1.X + rect1.Width : rect2.X + rect2.Width;
            }
            else if (rect1.Width > 0)
            {
                UnionX  = rect1.X;
                UnionCX = rect1.X + rect1.Width;
            }
            else if (rect2.Width > 0)
            {
                UnionX  = rect2.X;
                UnionCX = rect2.X + rect2.Width;
            }
            else
            {
                UnionX  = rect1.X < rect2.X ? rect1.X : rect2.X;
                UnionCX = UnionX;
            }

            if (rect1.Height > 0 && rect2.Height > 0)
            {
                UnionY  = rect1.Y < rect2.Y ? rect1.Y : rect2.Y;
                UnionCY = rect1.Y + rect1.Height > rect2.Y + rect2.Height ? rect1.Y + rect1.Height : rect2.Y + rect2.Height;
            }
            else if (rect1.Height > 0)
            {
                UnionY  = rect1.Y;
                UnionCY = rect1.Y + rect1.Height;
            }
            else if (rect2.Height > 0)
            {
                UnionY  = rect2.Y;
                UnionCY = rect2.Y + rect2.Height;
            }
            else
            {
                UnionY  = rect1.Y < rect2.Y ? rect1.Y : rect2.Y;
                UnionCY = UnionY;
            }

            return(new Rect(UnionX, UnionY, UnionCX - UnionX, UnionCY - UnionY));
        }