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]); }
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)); }
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); }
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); }
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)); }
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); }
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)); }
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); }
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)); }
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); }); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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; }
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); }
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);}); }
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); }
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); }
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); }
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); }
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]); }
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); }
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); }
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); }