예제 #1
0
        public void GetNodesBetweenPointsReturnPointsInCorrectOrder1()
        {
            PointGeo start = new PointGeo(1, 1);
            PointGeo middle1 = new PointGeo(1, 1.5);
            PointGeo middle2 = new PointGeo(1, 1.6);
            PointGeo middle3 = new PointGeo(1, 1.7);
            PointGeo end = new PointGeo(1, 2);
            Polyline<IPointGeo> line = new Polyline<IPointGeo>();
            line.Nodes.Add(start);
            line.Nodes.Add(middle1);
            line.Nodes.Add(middle2);
            line.Nodes.Add(middle3);
            line.Nodes.Add(end);

            var result = Topology.GetNodesBetweenPoints(new PointGeo(1, 1.1), new PointGeo(1, 1.9), line).ToList();
            Assert.Equal(3, result.Count());
            Assert.Equal(middle1, result[0]);
            Assert.Equal(middle2, result[1]);
            Assert.Equal(middle3, result[2]);

            result = Topology.GetNodesBetweenPoints(new PointGeo(1, 1.9), new PointGeo(1, 1.1), line).ToList();
            Assert.Equal(3, result.Count());
            Assert.Equal(middle3, result[0]);
            Assert.Equal(middle2, result[1]);
            Assert.Equal(middle1, result[2]);
        }
예제 #2
0
        public void SegmentEqualsReturnsFalseForNull()
        {
            PointGeo startPoint = new PointGeo(21, 34);
            PointGeo endPoint = new PointGeo(26, 31);

            Segment<PointGeo> target = new Segment<PointGeo>(startPoint, endPoint);

            Assert.False(target.Equals(null));
        }
예제 #3
0
        public void NodeConstructorSetsPositionAndInitializeProperties()
        {
            PointGeo position = new PointGeo(12.8, 45.9);

            Node target = new Node(position);

            Assert.Equal(position, target.MapPoint);
            Assert.NotNull(target.Connections);
        }
예제 #4
0
        public void PointGeoConstructorSetsLatitudeAndLongitude()
        {
            double lat = 10.1;
            double lon = 12.8;

            PointGeo target = new PointGeo(lat, lon);

            Assert.Equal(lat, target.Latitude);
            Assert.Equal(lon, target.Longitude);
        }
예제 #5
0
        public void SegmentEqualsReturnsTrueForSegmentsWithTheSameEndPoints()
        {
            PointGeo startPoint = new PointGeo(21, 34);
            PointGeo endPoint = new PointGeo(26, 31);

            Segment<PointGeo> target = new Segment<PointGeo>(startPoint, endPoint);
            Segment<PointGeo> theSame = new Segment<PointGeo>(startPoint, endPoint);

            Assert.True(target.Equals(theSame));
        }
예제 #6
0
        public void SegmentConstructorSetsStartAndEndPoint()
        {
            PointGeo startPoint = new PointGeo(21, 34);
            PointGeo endPoint = new PointGeo(26, 31);

            Segment<PointGeo> target = new Segment<PointGeo>(startPoint, endPoint);

            Assert.Equal(startPoint, target.StartPoint);
            Assert.Equal(endPoint, target.EndPoint);
        }
예제 #7
0
        public void CalculationsGetDistanceReturnsDistanceFromLineSegmentForPointProjetedToSegment()
        {
            PointGeo orgin = new PointGeo(1, 1);
            PointGeo end = new PointGeo(2, 2);
            Segment<IPointGeo> segment = new Segment<IPointGeo>(orgin, end);

            PointGeo testPoint = new PointGeo(1, 2);

            Assert.Equal(Calculations.GetDistance2D(testPoint, new PointGeo(1.5,1.5)), Calculations.GetDistance2D(testPoint, segment));
        }
예제 #8
0
        public void PolylineNodesCountReturnsCorrectValue()
        {
            PointGeo p1 = new PointGeo(1, 2);
            PointGeo p2 = new PointGeo(3, 4);

            Polyline<PointGeo> target = new Polyline<PointGeo>();
            target.Nodes.Add(p1);
            target.Nodes.Add(p2);

            Assert.Equal(2, target.NodesCount);
        }
예제 #9
0
        public void SegmentEqualsReturnsFalseForSegmentsWithTheDifferentEndPoints()
        {
            PointGeo startPoint = new PointGeo(21, 34);
            PointGeo startPoint2 = new PointGeo(21.1, 34.1);

            PointGeo endPoint = new PointGeo(26, 31);

            Segment<PointGeo> target = new Segment<PointGeo>(startPoint, endPoint);
            Segment<PointGeo> other = new Segment<PointGeo>(startPoint2, endPoint);

            Assert.False(target.Equals(other));
        }
예제 #10
0
        public void AddVertexThrowsExceptionWhenAddingDuplicateNode()
        {
            PointGeo p1 = new PointGeo(1.0, 1.0);
            PointGeo p2 = new PointGeo(2.0, 1.0);
            PointGeo p3 = new PointGeo(2.0, 2.0);
            PointGeo p4 = new PointGeo(1.0, 2.0);
            List<IPointGeo> nodes = new List<IPointGeo>(new IPointGeo[] { p1, p2, p3, p4 });

            Polygon<PointGeo> target = new Polygon<PointGeo>(nodes);

            Assert.Throws<ArgumentException>(delegate { target.AddVertex(p2); });
        }
예제 #11
0
        public void CalculationsGetDistanceReturnsDistanceFromSegmentEndForPointProjetedOutsideSegment()
        {
            PointGeo orgin = new PointGeo(1, 1);
            PointGeo end = new PointGeo(2, 2);
            Segment<IPointGeo> segment = new Segment<IPointGeo>(orgin, end);

            PointGeo testPoint1 = new PointGeo(0, 0);
            PointGeo testPoint2 = new PointGeo(2, 3);

            Assert.Equal(Calculations.GetDistance2D(testPoint1, new PointGeo(1, 1)), Calculations.GetDistance2D(testPoint1, segment));
            Assert.Equal(Calculations.GetDistance2D(testPoint2, new PointGeo(2, 2)), Calculations.GetDistance2D(testPoint2, segment));
        }
예제 #12
0
        public void PolygonConstructorAcceptsCollectionOfVertices()
        {
            PointGeo p1 = new PointGeo(1.0, 1.0);
            PointGeo p2 = new PointGeo(2.0, 1.0);
            PointGeo p3 = new PointGeo(2.0, 2.0);
            PointGeo p4 = new PointGeo(1.0, 2.0);
            List<IPointGeo> nodes = new List<IPointGeo>(new IPointGeo[] { p1, p2, p3, p4 });

            Polygon<PointGeo> target = new Polygon<PointGeo>(nodes);

            CompareVerticesLists(nodes, target.Vertices);
        }
예제 #13
0
        public void PolylineLengthReturnsLengthOfThePolyline()
        {
            PointGeo p1 = new PointGeo(1, 2);
            PointGeo p2 = new PointGeo(3, 4);

            IPolyline<IPointGeo> target = new Polyline<IPointGeo>();
            target.Nodes.Add(p1);
            target.Nodes.Add(p2);

            double expectedLength = Calculations.GetLength(target);

            Assert.InRange(target.Length, expectedLength - Calculations.EpsLength, expectedLength + Calculations.EpsLength);
        }
예제 #14
0
        public void BBoxCornersReturnsCorners()
        {
            BBox target = new BBox() { North = 10, South = 8, East = 9, West = 7 };

            PointGeo corner1 = new PointGeo(10, 9);
            PointGeo corner2 = new PointGeo(10, 7);
            PointGeo corner3 = new PointGeo(8, 9);
            PointGeo corner4 = new PointGeo(8, 7);

            Assert.Contains(corner1, target.Corners);
            Assert.Contains(corner2, target.Corners);
            Assert.Contains(corner3, target.Corners);
            Assert.Contains(corner4, target.Corners);
        }
예제 #15
0
        public void PolygonAddVertexAddsVertexToTheEnd()
        {
            PointGeo p1 = new PointGeo(1.0, 1.0);
            PointGeo p2 = new PointGeo(2.0, 1.0);
            PointGeo p3 = new PointGeo(2.0, 2.0);
            PointGeo p4 = new PointGeo(1.0, 2.0);
            List<IPointGeo> nodes = new List<IPointGeo>(new IPointGeo[] { p1, p2, p3});

            Polygon<PointGeo> target = new Polygon<PointGeo>(nodes);
            target.AddVertex(p4);

            nodes.Add(p4);
            CompareVerticesLists(nodes, target.Vertices);
        }
예제 #16
0
        public void BBoxConstructorIEnumerableSetsBound()
        {
            PointGeo p1 = new PointGeo(15, 10, -100);
            PointGeo p2 = new PointGeo(-15, -10, 1000);

            BBox target = new BBox(new IPointGeo[] { p1, p2 });

            Assert.Equal(15, target.North);
            Assert.Equal(-15, target.South);
            Assert.Equal(10, target.East);
            Assert.Equal(-10, target.West);

            Assert.Equal(-100, target.MinElevation);
            Assert.Equal(1000, target.MaxElevation);
        }
예제 #17
0
        public void PolygonBoundingBoxReturnsCorrectData()
        {
            PointGeo p1 = new PointGeo(1.0, 1.0);
            PointGeo p2 = new PointGeo(2.0, 1.0);
            PointGeo p3 = new PointGeo(2.0, 2.0);
            PointGeo p4 = new PointGeo(1.0, 2.0);
            List<IPointGeo> nodes = new List<IPointGeo>(new IPointGeo[] { p1, p2, p3, p4 });

            Polygon<PointGeo> target = new Polygon<PointGeo>(nodes);

            Assert.Equal(2, target.BoundingBox.North);
            Assert.Equal(1, target.BoundingBox.South);
            Assert.Equal(2, target.BoundingBox.East);
            Assert.Equal(1, target.BoundingBox.West);
        }
예제 #18
0
        public void BBoxExtendToCoverInflatesBBox()
        {
            PointGeo p1 = new PointGeo(12.1, 18.3, 100);
            PointGeo p2 = new PointGeo(-12.9, -34.3, 500);

            BBox target = new BBox();
            target.ExtendToCover(p1);
            target.ExtendToCover(p2);

            Assert.Equal(12.1, target.North);
            Assert.Equal(-12.9, target.South);
            Assert.Equal(18.3, target.East);
            Assert.Equal(-34.3, target.West);

            Assert.Equal(100, target.MinElevation);
            Assert.Equal(500, target.MaxElevation);
        }
예제 #19
0
        public void CalculationsGetDistanceReturnsDistanceFromPolyline()
        {
            PointGeo pt1 = new PointGeo(1, 1);
            PointGeo pt2 = new PointGeo(2, 2);
            PointGeo pt3 = new PointGeo(2, 3);

            Polyline<IPointGeo> line = new Polyline<IPointGeo>();
            line.Nodes.Add(pt1);
            line.Nodes.Add(pt2);
            line.Nodes.Add(pt3);

            PointGeo testPoint1 = new PointGeo(2, 1);
            PointGeo testPoint2 = new PointGeo(2, 2.5);
            PointGeo testPoint3 = new PointGeo(1, 3.5);

            Assert.Equal(Calculations.GetDistance2D(testPoint1, new PointGeo(1.5, 1.5)), Calculations.GetDistance2D(testPoint1, line));
            Assert.Equal(0, Calculations.GetDistance2D(testPoint2, line));
            Assert.Equal(Calculations.GetDistance2D(testPoint3, new PointGeo(2, 3)), Calculations.GetDistance2D(testPoint3, line));
        }
예제 #20
0
 public PointGeo ToSpherical()
 {
     PointGeo result = new PointGeo();
     result.Latitude = Calculations.ToDegrees( Math.PI / 2 - Math.Acos(Z));
     result.Longitude = Calculations.ToDegrees(Math.Atan2(Y, X));
     return result;
 }
예제 #21
0
        public void GetPathLengthSegmentReturnsDistanceBetweenPoints()
        {
            PointGeo segmentOrigin = new PointGeo(10, 10);
            PointGeo segmentEnd = new PointGeo(10, 11);

            PointGeo from = new PointGeo(10, 10.5);
            PointGeo to = new PointGeo(10, 10.6);
            double exceptedLength = Calculations.GetDistance2D(from, to);

            Segment<IPointGeo> target = new Segment<IPointGeo>(segmentOrigin, segmentEnd);

            double length = Calculations.GetPathLength(from, to, target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            // Reverse direction
            length = Calculations.GetPathLength(to, from, target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);
        }
예제 #22
0
        public void GetPathLengthPolylineThrowaExceptionIfPointDistanceGreaterThenEPS()
        {
            Polyline<IPointGeo> target = new Polyline<IPointGeo>();
            target.Nodes.Add(new PointGeo(10, 10));
            target.Nodes.Add(new PointGeo(10, 11));
            target.Nodes.Add(new PointGeo(11, 11));

            PointGeo from = new PointGeo(10, 11);
            PointGeo to = new PointGeo(11, 11.1);

            Assert.Throws<ArgumentException>(delegate {Calculations.GetPathLength(from, to, target);});
        }
예제 #23
0
        public void GetPathLengthPolylineReturnsCorrectLengthForPointaOnVariousegment_FromToSegmentsPath()
        {
            Polyline<IPointGeo> target = new Polyline<IPointGeo>();
            target.Nodes.Add(new PointGeo(10, 10));
            target.Nodes.Add(new PointGeo(10, 11));
            target.Nodes.Add(new PointGeo(11, 11));
            target.Nodes.Add(new PointGeo(11, 12));
            target.Nodes.Add(new PointGeo(12, 12));

            PointGeo from = new PointGeo(10, 10.4);
            PointGeo to = new PointGeo(11, 11.3);
            double exceptedLength = Calculations.GetDistance2D(from, new PointGeo(10, 11)) +
                                                            Calculations.GetDistance2D(new PointGeo(10, 11), new PointGeo(11, 11)) +
                                                            Calculations.GetDistance2D(new PointGeo(11, 11), to);

            double length = Calculations.GetPathLength(from, target.Segments[0], to, target.Segments[2], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            // Reverse direction
            length = Calculations.GetPathLength(to, target.Segments[2], from, target.Segments[0], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);
        }
예제 #24
0
        public void GetPathLengthPolylineReturnsCorrectLengthForPointaOnTheSameSegment()
        {
            Polyline<IPointGeo> target = new Polyline<IPointGeo>();
            target.Nodes.Add(new PointGeo(10, 10));
            target.Nodes.Add(new PointGeo(10, 11));
            target.Nodes.Add(new PointGeo(11, 11));
            target.Nodes.Add(new PointGeo(11, 12));

            PointGeo from = new PointGeo(10, 10.5);
            PointGeo to = new PointGeo(10, 10.6);
            double exceptedLength = Calculations.GetDistance2D(from, to);

            double length = Calculations.GetPathLength(from, to, target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            // Reverse direction
            length = Calculations.GetPathLength(to, from, target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);
        }
예제 #25
0
        public void GetPathLengthPolylineReturnsCorrectLengthForPointaOnSegmentEnds_FromToSegmentsPath()
        {
            Polyline<IPointGeo> target = new Polyline<IPointGeo>();
            target.Nodes.Add(new PointGeo(10, 10));
            target.Nodes.Add(new PointGeo(10, 11));
            target.Nodes.Add(new PointGeo(11, 11));
            target.Nodes.Add(new PointGeo(11, 12));
            target.Nodes.Add(new PointGeo(12, 12));

            PointGeo from = new PointGeo(10, 11);
            PointGeo to = new PointGeo(11, 12);
            double exceptedLength = Calculations.GetDistance2D(new PointGeo(10, 11), new PointGeo(11, 11)) +
                                                            Calculations.GetDistance2D(new PointGeo(11, 11), new PointGeo(11, 12));

            // Every endpoint is a part of two segments
            double length = Calculations.GetPathLength(from, target.Segments[0], to, target.Segments[2], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            length = Calculations.GetPathLength(from, target.Segments[0], to, target.Segments[3], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            length = Calculations.GetPathLength(from, target.Segments[1], to, target.Segments[2], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            length = Calculations.GetPathLength(from, target.Segments[1], to, target.Segments[3], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            // Reverse dirrection
            length = Calculations.GetPathLength(to, target.Segments[2], from, target.Segments[0], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            length = Calculations.GetPathLength(to, target.Segments[3], from, target.Segments[0], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            length = Calculations.GetPathLength(to, target.Segments[2], from, target.Segments[1], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);

            length = Calculations.GetPathLength(to, target.Segments[3], from, target.Segments[1], target);
            Assert.InRange(length, exceptedLength - Calculations.EpsLength, exceptedLength + Calculations.EpsLength);
        }
예제 #26
0
        public void GetLengthSegmentReturnsSegmentLength()
        {
            PointGeo origin = new PointGeo(10, 10);
            PointGeo end = new PointGeo(11, 11);

            Segment<IPointGeo> target = new Segment<IPointGeo>(origin, end);
            double length = Calculations.GetLength(target);

            Assert.InRange(length, length - Calculations.EpsLength, length + Calculations.EpsLength);
        }
예제 #27
0
        public void PolylineNodesGetsListOfNodes()
        {
            PointGeo p1 = new PointGeo(1, 2);
            PointGeo p2 = new PointGeo(3, 4);

            Polyline<PointGeo> target = new Polyline<PointGeo>();
            target.Nodes.Add(p1);
            target.Nodes.Add(p2);

            Assert.Equal(p1, target.Nodes[0]);
            Assert.Equal(p2, target.Nodes[1]);
        }
예제 #28
0
        public void PolylineSegmentsReturnsListOfSegments()
        {
            PointGeo pt1 = new PointGeo(1, 2);
            PointGeo pt2 = new PointGeo(3, 4);
            PointGeo pt3 = new PointGeo(5, 6);

            Polyline<IPointGeo> target = new Polyline<IPointGeo>();
            target.Nodes.Add(pt1);
            target.Nodes.Add(pt2);
            target.Nodes.Add(pt3);

            IList<Segment<IPointGeo>> segments = target.Segments;

            Assert.Equal(2, segments.Count);

            Assert.Equal(pt1, segments[0].StartPoint);
            Assert.Equal(pt2, segments[0].EndPoint);

            Assert.Equal(pt2, segments[1].StartPoint);
            Assert.Equal(pt3, segments[1].EndPoint);
        }
예제 #29
0
        public void PolylineSegmentsReturnsListOfSegmentsAfterPolylineChange()
        {
            PointGeo pt1 = new PointGeo(1, 2);
            PointGeo pt2 = new PointGeo(3, 4);
            PointGeo pt3 = new PointGeo(5, 6);

            Polyline<IPointGeo> target = new Polyline<IPointGeo>();
            target.Nodes.Add(pt1);
            target.Nodes.Add(pt2);

            IList<Segment<IPointGeo>> segments = target.Segments;

            target.Nodes.Add(pt3);
            segments = target.Segments;

            Assert.Equal(2, segments.Count);
        }
예제 #30
0
        public void CalculationsGetLengthReturnsLengthAsSumOfDistanceBetweenPoints()
        {
            Polyline<IPointGeo> line = new Polyline<IPointGeo>();
            PointGeo pt1 = new PointGeo(50, 16);
            PointGeo pt2 = new PointGeo(50.1, 16.1);
            PointGeo pt3 = new PointGeo(50.2, 16.3);
            line.Nodes.Add(pt1);
            line.Nodes.Add(pt2);
            line.Nodes.Add(pt3);

            double exceptedLength = Calculations.GetDistance2D(pt1, pt2) + Calculations.GetDistance2D(pt2, pt3);
            double error = Math.Abs(exceptedLength - Calculations.GetLength(line));

            Assert.True(error < 0.1);
        }