Beispiel #1
0
        public void TestEquality(string lineAStr, string lineBStr)
        {
            var lineA = LineSegment2.Parse(lineAStr);
            var lineB = LineSegment2.Parse(lineBStr);

            Assert.AreEqual(lineA, lineB);
        }
Beispiel #2
0
        [TestCase("(10,10) (10,100)", "(0,303) (0,500)", true)]  // Two vert lines
        public void IsParallelTo(string line1Str, string line2Str, bool expected)
        {
            var line1 = LineSegment2.Parse(line1Str);
            var line2 = LineSegment2.Parse(line2Str);

            Assert.AreEqual(expected, line1.IsParallelTo(line2));
        }
Beispiel #3
0
        public void TesthasOverlap(string line1Str, string line2Str, bool expectedOverlap)
        {
            var line1      = LineSegment2.Parse(line1Str);
            var line2      = LineSegment2.Parse(line2Str);
            var hasOverlap = line1.HasOverlap(line2);

            Assert.AreEqual(expectedOverlap, hasOverlap);
        }
Beispiel #4
0
        [TestCase("(6,56497115745559, -13,4350288425444), (20, -1,77635683940025E-15)", "(0, 0), (20, 0)", false)] // // A line touches another - no proper intersection
        public void TestProperIntersection(string line1Str, string line2Str, bool expectedProperIntersection)
        {
            var line1 = LineSegment2.Parse(line1Str);
            var line2 = LineSegment2.Parse(line2Str);
            var properIntersection = line1.IsIntersectionProper(line2);

            Assert.AreEqual(expectedProperIntersection, properIntersection);
        }
Beispiel #5
0
        [TestCase("(10, 20),(60, 70)", "(35,30),(45,40)")]    // two parallel but nonaxial non overlapping lines
        public void TestNoOverlap(string line1Str, string line2Str)
        {
            var line1 = LineSegment2.Parse(line1Str);
            var line2 = LineSegment2.Parse(line2Str);

            var overlap = line1.HasOverlap(line2);

            Assert.AreEqual(false, overlap);
        }
Beispiel #6
0
        public void TestLineCollisions(string line1Str, string line2Str, bool expectedCollision)
        {
            var line1 = LineSegment2.Parse(line1Str);
            var line2 = LineSegment2.Parse(line2Str);

            var collides = line1.HasCollision(line2);

            Assert.AreEqual(expectedCollision, collides);
        }
Beispiel #7
0
        public void TestOverlap(string line1Str, string line2Str, string expectedOverlapStr)
        {
            var line1           = LineSegment2.Parse(line1Str);
            var line2           = LineSegment2.Parse(line2Str);
            var expectedOverlap = LineSegment2.Parse(expectedOverlapStr);

            var overlap = line1.GetOverlapSegment(line2);

            Assert.AreEqual(expectedOverlap, overlap);
        }
Beispiel #8
0
        public void InterceptRectNo()
        {
            var line1 = LineSegment2.Parse("(10, 5000)(2000, 5000)");
            var rect  = new AARectangle(new Vector2(30, 30), new SizeD(50, 40));

            var actual = line1.RectIntersection(rect);

            Assert.AreEqual(false, line1.HasRectIntersection(rect));
            Assert.AreEqual(0, actual.Count);
        }
Beispiel #9
0
        public void TestEqualityInList(string lineAStr, string lineBStr)
        {
            var lineA = LineSegment2.Parse(lineAStr);
            var lineB = LineSegment2.Parse(lineBStr);

            var list = new List <LineSegment2>();

            list.Add(lineA);

            Assert.IsTrue(list.Contains(lineB));
        }
Beispiel #10
0
        [TestCase("(25, 567.52168),(355.95663, 567.52168)", "(212.97, 555.5),(212.97, 579.5)", "(212.97, 567.52168)")] // Specail real world case
        public void IntersectLine(string line1Str, string line2Str, string expectedIntersection)
        {
            IGeometry line1 = LineSegment2.Parse(line1Str);
            IGeometry line2 = LineSegment2.Parse(line2Str);

            var expected = Vector2.Parse(expectedIntersection);

            var intersection = line1.Intersect(line2);

            Assert.AreEqual(expected, intersection.First());
        }
Beispiel #11
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);
        }
Beispiel #12
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));
                }
            }
        }
Beispiel #13
0
        [TestCase("(10,10) (100,10)", 90)]  // Horizontal
        public void Parse(string sp, double expected)
        {
            var l1 = LineSegment2.Parse(sp);

            Assert.AreEqual(expected, l1.Length);
        }