Beispiel #1
0
        WhichEdgesAreClose(ref Rectangle area1, ref Rectangle area2, int distance)
        {
            RectangleEdges result = RectangleEdges.None;

            if ((Math.Abs(area1.Top - area2.Top) <= distance ||
                 Math.Abs(area1.Top - area2.Bottom) <= distance) &&
                RangesCollide(area1.Left, area1.Right, area1.Left, area1.Right))
            {
                result |= RectangleEdges.Top;
            }

            if ((Math.Abs(area1.Bottom - area2.Bottom) <= distance ||
                 Math.Abs(area1.Bottom - area2.Top) <= distance) &&
                RangesCollide(area1.Left, area1.Right, area1.Left, area1.Right))
            {
                result |= RectangleEdges.Bottom;
            }

            if ((Math.Abs(area1.Left - area2.Left) <= distance ||
                 Math.Abs(area1.Left - area2.Right) <= distance) &&
                RangesCollide(area1.Top, area1.Bottom, area1.Top, area1.Bottom))
            {
                result |= RectangleEdges.Left;
            }

            if ((Math.Abs(area1.Right - area2.Right) <= distance ||
                 Math.Abs(area1.Right - area2.Left) <= distance) &&
                RangesCollide(area1.Top, area1.Bottom, area1.Top, area1.Bottom))
            {
                result |= RectangleEdges.Right;
            }

            return(null);
        }
Beispiel #2
0
 public static Thickness <Points> CollapseEdges(this Thickness <Points> self, RectangleEdges edges)
 {
     return(self.With(
                left: edges.HasFlag(RectangleEdges.Left) ? Optional.Some <Points>(0) : Optional.None(),
                top: edges.HasFlag(RectangleEdges.Top) ? Optional.Some <Points>(0) : Optional.None(),
                right: edges.HasFlag(RectangleEdges.Right) ? Optional.Some <Points>(0) : Optional.None(),
                bottom: edges.HasFlag(RectangleEdges.Bottom) ? Optional.Some <Points>(0) : Optional.None()));
 }
Beispiel #3
0
 public static Thickness <Points> CollapseEdgesExcept(this Thickness <Points> self, RectangleEdges edges)
 {
     return(self.CollapseEdges(~edges));
 }
 public static void ClingToEdges(ref Rectangle areaToClingTo, ref Rectangle area, RectangleEdges edge, RectangleEdges edgeToClingTo)
 {
     if ((edge & RectangleEdges.Top) == RectangleEdges.Top)
     {
         area.Y = areaToClingTo.Y;
     }
     if ((edge & RectangleEdges.Bottom) == RectangleEdges.Bottom)
     {
         area.Y = areaToClingTo.Y + areaToClingTo.Height - area.Height;
     }
     if ((edge & RectangleEdges.Left) == RectangleEdges.Left)
     {
         area.X = areaToClingTo.X;
     }
     if ((edge & RectangleEdges.Right) == RectangleEdges.Right)
     {
         area.X = areaToClingTo.X + areaToClingTo.Width - area.Width;
     }
 }
Beispiel #5
0
 public static void ClingToEdges(ref Rectangle areaToClingTo, ref Rectangle area, RectangleEdges edge, RectangleEdges edgeToClingTo)
 {
     if ((edge & RectangleEdges.Top) == RectangleEdges.Top)
     {
         area.Y = areaToClingTo.Y;
     }
     if ((edge & RectangleEdges.Bottom) == RectangleEdges.Bottom)
     {
         area.Y = areaToClingTo.Y + areaToClingTo.Height - area.Height;
     }
     if ((edge & RectangleEdges.Left) == RectangleEdges.Left)
     {
         area.X = areaToClingTo.X;
     }
     if ((edge & RectangleEdges.Right) == RectangleEdges.Right)
     {
         area.X = areaToClingTo.X + areaToClingTo.Width - area.Width;
     }
 }