static void Main(string[] args)
        {
            try
            {
                if (!args.Any())
                {
                    throw new ArgumentException("Error: no file provided");
                }

                var content = InputReader.ReadFile(args[0]);

                var jsonRectangles = Parser.ParseJson(content);

                var rectangles = RectangleListBuilder.BuildRectangles(jsonRectangles);

                var intersections = IntersectionCalculator.CalculateIntersections(rectangles);

                ResultWriter.Display(rectangles, intersections);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.Message);
                }
            }
        }
Exemplo n.º 2
0
        public void CalculateIntersections4RectangleNoIntersectionTest()
        {
            var rectangles = new List <Rectangle>()
            {
                new Rectangle()
                {
                    X = 10, Y = 10, Width = 10, Height = 10
                },
                new Rectangle()
                {
                    X = 100, Y = 100, Width = 10, Height = 10
                },
                new Rectangle()
                {
                    X = 1000, Y = 1000, Width = 10, Height = 10
                },
                new Rectangle()
                {
                    X = 10000, Y = 10000, Width = 10, Height = 10
                },
            };

            var expectedResult = new List <RectangleIntersection>();
            var result         = IntersectionCalculator.CalculateIntersections(rectangles);

            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 3
0
        public void CalculateIntersections10EqualRectanglesTest()
        {
            var rectangles = new List <Rectangle>()
            {
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 101, Width = 250, Height = 80
                }
            };

            var expectedCount = 1013;

            var result = IntersectionCalculator.CalculateIntersections(rectangles);

            Assert.AreEqual(result.Count, expectedCount);

            for (int i = 0; i < expectedCount; i++)
            {
                Assert.AreEqual(result[i].Intersection.X, 100);
                Assert.AreEqual(result[i].Intersection.Y, 101);
                Assert.AreEqual(result[i].Intersection.Width, 250);
                Assert.AreEqual(result[i].Intersection.Height, 80);
            }
        }
Exemplo n.º 4
0
        public void CalculateIntersections0RectangleTest()
        {
            var rectangles = new List <Rectangle>();

            var expectedResult = new List <RectangleIntersection>();
            var result         = IntersectionCalculator.CalculateIntersections(rectangles);

            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 5
0
        public void CalculateIntersections4EqualRectanglesTest()
        {
            var rectangles = new List <Rectangle>()
            {
                new Rectangle()
                {
                    X = 100, Y = 100, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 100, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 100, Width = 250, Height = 80
                },
                new Rectangle()
                {
                    X = 100, Y = 100, Width = 250, Height = 80
                }
            };

            var expectedResult = new List <RectangleIntersection>()
            {
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        1, 2
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        1, 3
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        1, 4
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        2, 3
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        2, 4
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        1, 2, 3
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        1, 2, 4
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        3, 4
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        1, 3, 4
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        2, 3, 4
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
                new RectangleIntersection()
                {
                    RectangleIndexes = new List <int>()
                    {
                        1, 2, 3, 4
                    },
                    Intersection = new Rectangle()
                    {
                        X = 100, Y = 100, Width = 250, Height = 80
                    }
                },
            };

            var result = IntersectionCalculator.CalculateIntersections(rectangles);

            Assert.AreEqual(expectedResult.Count, result.Count);

            for (int i = 0; i < expectedResult.Count; i++)
            {
                Assert.AreEqual(IsEqual(expectedResult[i], result[i]), true);
            }
        }