Example #1
0
        public static bool DoTest(Square square1, Square square2, Point start, Point end)
        {
            var line = square1.cut(square2);
            var r = (IsApproxEqual(line.Start, start) && IsApproxEqual(line.End, end)) || (IsApproxEqual(line.Start, end) && IsApproxEqual(line.End, start));

            if (!r)
            {
                PrintSquare(square1);
                PrintSquare(square2);
                PrintLine(line);
                Console.WriteLine(start.ToString());
                Console.WriteLine(end.ToString());
                Console.WriteLine();
                //return r;
            }

            return r;
        }
Example #2
0
 public static bool DoTestFull(Square s1, Square s2, Point start, Point end)
 {
     return DoTest(s1, s2, start, end) && DoTest(s2, s1, start, end);
 }
Example #3
0
        public bool Contains(Square other)
        {
            if (Left <= other.Left && Right >= other.Right && Top <= other.Top && Bottom >= other.Bottom)
            {
                return true;
            }

            return false;
        }
Example #4
0
        public Line75 cut(Square other)
        {
            /* Calculate where a line between each middle would collide with the edges of the squares */
            var p1 = Extend(Middle(), other.Middle(), Size);
            var p2 = Extend(Middle(), other.Middle(), -1 * Size);
            var p3 = Extend(other.Middle(), Middle(), other.Size);
            var p4 = Extend(other.Middle(), Middle(), -1 * other.Size);

            /* Of above points, find start and end of lines. Start is farthest left (with top most as a tie breaker)
             * and end is farthest right (with bottom most as a tie breaker */
            var start = p1;
            var end = p1;
            Point[] points = { p2, p3, p4 };

            for (var i = 0; i < points.Length; i++)
            {
                if (points[i].X < start.X || (points[i].X == start.X && points[i].Y < start.Y))
                {
                    start = points[i];
                }
                else if (points[i].X > end.X || (points[i].X == end.X && points[i].Y > end.Y))
                {
                    end = points[i];
                }
            }

            return new Line75(start, end);
        }
Example #5
0
 public static void PrintSquare(Square square)
 {
     Console.WriteLine(square.Left + "\t" + square.Top + "\t" + square.Size);
 }