/****************************************************************************** * * The MIT License (MIT) * * MIConvexHull, Copyright (c) 2015 David Sehnal, Matthew Campbell * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * *****************************************************************************/ using System.Collections.Generic; using System.Linq; namespace NWH.DWP2.MiConvexHull { /// /// Simple interface to unify different types of triangulations in the future. /// /// The type of the t vertex. /// The type of the t cell. public interface ITriangulation where TCell : TriangulationCell, new() where TVertex : IVertex { /// /// Triangulation simplexes. For 2D - triangles, 3D - tetrahedrons, etc ... /// /// The cells. IEnumerable Cells { get; } } /// /// Factory class for creating triangulations. /// public static class Triangulation { /// /// Creates the Delaunay triangulation of the input data. /// /// The type of the t vertex. /// The data. /// If null, default TriangulationComputationConfig is used. /// ITriangulation<TVertex, DefaultTriangulationCell<TVertex>>. public static ITriangulation> CreateDelaunay( IList data) where TVertex : IVertex { return DelaunayTriangulation>.Create(data); } /// /// Creates the Delaunay triangulation of the input data. /// /// The data. /// If null, default TriangulationComputationConfig is used. /// ITriangulation<DefaultVertex, DefaultTriangulationCell<DefaultVertex>>. public static ITriangulation> CreateDelaunay( IList data) { List points = data.Select(p => new DefaultVertex {Position = p,}).ToList(); return DelaunayTriangulation>.Create(points); } /// /// Creates the Delaunay triangulation of the input data. /// /// /// /// /// If null, default TriangulationComputationConfig is used. /// public static ITriangulation CreateDelaunay(IList data) where TVertex : IVertex where TFace : TriangulationCell, new() { return DelaunayTriangulation.Create(data); } /// /// Create the voronoi mesh. /// /// /// /// /// /// If null, default TriangulationComputationConfig is used. /// public static VoronoiMesh CreateVoronoi(IList data) where TCell : TriangulationCell, new() where TVertex : IVertex where TEdge : VoronoiEdge, new() { return VoronoiMesh.Create(data); } /// /// Create the voronoi mesh. /// /// /// /// If null, default TriangulationComputationConfig is used. /// public static VoronoiMesh , VoronoiEdge>> CreateVoronoi(IList data) where TVertex : IVertex { return VoronoiMesh , VoronoiEdge> >.Create(data); } /// /// Create the voronoi mesh. /// /// /// If null, default TriangulationComputationConfig is used. /// public static VoronoiMesh , VoronoiEdge>> CreateVoronoi(IList data) { List points = data.Select(p => new DefaultVertex {Position = p.ToArray(),}).ToList(); return VoronoiMesh , VoronoiEdge>>.Create(points); } /// /// Create the voronoi mesh. /// /// /// /// /// If null, default TriangulationComputationConfig is used. /// public static VoronoiMesh> CreateVoronoi( IList data) where TVertex : IVertex where TCell : TriangulationCell, new() { return VoronoiMesh>.Create(data); } } }