public void CanCreateMesh() { var label = "Plane"; var color = new[] { 0.2f, 0.4f, 0.6f, 1f }; var vertices = new[] { new[] { 0f, 0f, 0f }, new[] { 1f, 0f, 0f }, new[] { 1f, 1f, 0f }, new[] { 0f, 1f, 0f } }; var indices = new[] { new[] { 0, 1, 2 }, new[] { 0, 2, 3 } }; var factory = new GeometryFactory(); factory.BeginMesh(label); factory.SetColor(color[0], color[1], color[2], color[3]); foreach (var vertex in vertices) { factory.AddVertex(vertex[0], vertex[1], vertex[2]); } foreach (var triangle in indices) { factory.AddTriangle(triangle[0], triangle[1], triangle[2]); } var mesh = factory.CompleteMesh(); Assert.Equal(label, mesh.Label); Assert.True(AreEqual(color, mesh.Color)); var allVerticesAreEqual = mesh.Vertices.Zip(vertices, (vector, array) => AreEqual(array, vector)).All(b => b); Assert.True(allVerticesAreEqual); var allIndicesAreEqual = mesh.TriangleIndices.Zip(indices, (list, array) => AreEqual(array, list)).All(b => b); Assert.True(allIndicesAreEqual); }
/// <summary> /// Tests execution for multiple graphs. /// </summary> /// <param name="metadataPreservation">Indicates whether the metadata should be preserved.</param> private void TestExecuteForGraphs(Boolean metadataPreservation) { // empty graph IGeometryGraph sourceGraph = new GeometryFactory(ProjectedCoordinateReferenceSystems.HD72_EOV).CreateGraph(); IDictionary <OperationParameter, Object> parameters = new Dictionary <OperationParameter, Object>(); parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, ProjectedCoordinateReferenceSystems.WGS84_WorldMercator); parameters.Add(CommonOperationParameters.MetadataPreservation, metadataPreservation); GraphReferenceTransformation transformation = new GraphReferenceTransformation(sourceGraph, parameters); transformation.Execute(); IGeometryGraph resultGraph = transformation.Result as IGeometryGraph; Assert.AreEqual(0, resultGraph.VertexCount); Assert.AreEqual(0, resultGraph.EdgeCount); Assert.AreEqual(sourceGraph.Metadata, resultGraph.Metadata); // graph with points and edges Coordinate[] coordinates = new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 20), new Coordinate(30, 30) }; sourceGraph = new GeometryFactory(ProjectedCoordinateReferenceSystems.HD72_EOV).CreateGraph(); IGraphVertex[] vertices = coordinates.Select(coordinate => sourceGraph.AddVertex(coordinate)).ToArray(); sourceGraph.AddEdge(vertices[0], vertices[1]); sourceGraph.AddEdge(vertices[1], vertices[2]); transformation = new GraphReferenceTransformation(sourceGraph, parameters); transformation.Execute(); resultGraph = transformation.Result as IGeometryGraph; Assert.AreEqual(3, resultGraph.VertexCount); Assert.AreEqual(2, resultGraph.EdgeCount); Assert.AreEqual(1, resultGraph.OutEdges(resultGraph.Vertices[0]).Count); Assert.AreEqual(resultGraph.Vertices[1], resultGraph.OutEdges(resultGraph.Vertices[0]).First().Target); Assert.AreEqual(1, resultGraph.OutEdges(resultGraph.Vertices[1]).Count); Assert.AreEqual(resultGraph.Vertices[2], resultGraph.OutEdges(resultGraph.Vertices[1]).First().Target); for (Int32 vertexIndex = 0; vertexIndex < resultGraph.VertexCount; vertexIndex++) { GeoCoordinate sourceGeoCoordinate = ProjectedCoordinateReferenceSystems.HD72_EOV.Projection.Reverse(coordinates[vertexIndex]); GeoCoordinate expectedGeoCoordinate = GeographicTransformations.HD72_WGS84_V1.Forward(sourceGeoCoordinate); Coordinate expectedCoordinate = ProjectedCoordinateReferenceSystems.WGS84_WorldMercator.Projection.Forward(expectedGeoCoordinate); Assert.AreEqual(expectedCoordinate, resultGraph.Vertices[vertexIndex].Coordinate); } // not supported geometry Mock <IGeometry> geometryMock = new Mock <IGeometry>(MockBehavior.Loose); geometryMock.Setup(geometry => geometry.Factory).Returns(() => new GeometryFactory(ProjectedCoordinateReferenceSystems.HD72_EOV)); geometryMock.Setup(geometry => geometry.ReferenceSystem).Returns(() => ProjectedCoordinateReferenceSystems.HD72_EOV); transformation = new GraphReferenceTransformation(geometryMock.Object, parameters); Assert.Throws <InvalidOperationException>(() => transformation.Execute()); }