Exemplo n.º 1
0
        public void Constructor(string locationStr, string sizeStr)
        {
            var location = Vector2.Parse(locationStr);
            var size     = SizeD.Parse(sizeStr);

            var rect = new RectangleAA2(location, size);

            Assert.AreEqual(location, rect.Location);
            Assert.AreEqual(size.Width, rect.Width);
            Assert.AreEqual(size.Height, rect.Height);
        }
Exemplo n.º 2
0
        [TestCase("40, 50", "10, 10", "(10, 20),(60, 70)", true)]  // Above the line
        public void CollisionWithLine2(string locationStr, string sizeStr, string lineStr, bool expectedCollision)
        {
            var location = Vector2.Parse(locationStr);
            var size     = SizeD.Parse(sizeStr);
            var rect     = new RectangleAA2(location, size);

            var line = LineSegment2.Parse(lineStr);


            var hasCollision = rect.HasCollision(line);

            Assert.AreEqual(expectedCollision, hasCollision);
        }
Exemplo n.º 3
0
        public void LocationRotation(string locationStr, string sizeStr, string rotationStr)
        {
            var location = Vector2.Parse(locationStr);
            var size     = SizeD.Parse(sizeStr);
            var rotation = Angle.Parse(rotationStr);

            var rect = new Rectangle2(location, size, rotation);

            Assert.AreEqual(location, rect.Location);
            Assert.AreEqual(size.Width, rect.Width, GeometrySettings.DEFAULT_TOLERANCE);
            Assert.AreEqual(size.Height, rect.Height, GeometrySettings.DEFAULT_TOLERANCE);
            Assert.AreEqual(rotation, rect.Rotation);
        }
Exemplo n.º 4
0
        [TestCase("(10,10) (90,90)", "(30,30)", " (50,40)", "(30,30),(70,70)")]  // Diagonal Line with two intersections
        // [TestCase("(25, 567.521681),(355.95663, 567.521681)", "(167.97, 555.5)", "(45, 24)", "(11,11)")] // Case from real data

        public void InterceptRect(string line1Str, string rectLocationStr, string rectSizeStr, string expectedIntersections)
        {
            var line1 = LineSegment2.Parse(line1Str);
            var rect  = new AARectangle(Vector2.Parse(rectLocationStr), SizeD.Parse(rectSizeStr));

            var expectedInters = Vector2.ParseAll(expectedIntersections);

            var actual = line1.RectIntersection(rect);

            Assert.AreEqual(expectedInters.Length, actual.Count); // Expected number of intersections
            // Check each point
            if (expectedInters.Length == actual.Count)
            {
                foreach (var p in actual)
                {
                    Assert.True(expectedInters.Contains(p));
                }
            }
        }