Beispiel #1
0
        public static float CalculateDistanceTo(this IRectangularF a, IRectangularF b)
        {
            var left   = b.Right() < a.Left;
            var right  = a.Right() < b.Left;
            var bottom = b.Bottom() < a.Top;
            var top    = a.Bottom() < b.Top;

            if (top && left)
            {
                return(CalculateDistanceTo(a.Left, a.Bottom(), b.Right(), b.Top));
            }
            else if (left && bottom)
            {
                return(CalculateDistanceTo(a.Left, a.Top, b.Right(), b.Bottom()));
            }
            else if (bottom && right)
            {
                return(CalculateDistanceTo(a.Right(), a.Top, b.Left, b.Bottom()));
            }
            else if (right && top)
            {
                return(CalculateDistanceTo(a.Right(), a.Bottom(), b.Left, b.Top));
            }
            else if (left)
            {
                return(a.Left - b.Right());
            }
            else if (right)
            {
                return(b.Left - a.Right());
            }
            else if (bottom)
            {
                return(a.Top - b.Bottom());
            }
            else if (top)
            {
                return(b.Top - a.Bottom());
            }
            else
            {
                return(0);
            }
        }
Beispiel #2
0
        public static float NumberOfPixelsThatOverlap(this IRectangularF rectangle, IRectangularF other)
        {
            var rectangleRight = rectangle.Right();
            var otherRight     = other.Right();

            var rectangleBottom = rectangle.Bottom();
            var otherBottom     = other.Bottom();

            var ret =
                Math.Max(0, Math.Min(rectangleRight, otherRight) - Math.Max(rectangle.Left, other.Left)) *
                Math.Max(0, Math.Min(rectangleBottom, otherBottom) - Math.Max(rectangle.Top, other.Top));

            ret = (float)Math.Round(ret, 4);
            return(ret);
        }
Beispiel #3
0
 public static ILocationF BottomRight(this IRectangularF rectangular) => LocationF.Create(rectangular.Right(), rectangular.Bottom());
Beispiel #4
0
 public static ILocationF BottomLeft(this IRectangularF rectangular) => LocationF.Create(rectangular.Left, rectangular.Bottom());