Пример #1
0
        /// <summary>
        /// This is called by the "ConvexHull" class.
        /// </summary>
        /// <typeparam name="TVertex"></typeparam>
        /// <typeparam name="TFace"></typeparam>
        /// <param name="data"></param>
        /// <param name="config">If null, default ConvexHullComputationConfig.GetDefault() is used.</param>
        /// <returns></returns>
        internal static ConvexHull <TVertex, TFace> GetConvexHull <TVertex, TFace>(IList <TVertex> data, ConvexHullComputationConfig config)
            where TFace : ConvexFace <TVertex, TFace>, new()
            where TVertex : IVertex
        {
            config = config ?? new ConvexHullComputationConfig();

            var vertices = new IVertex[data.Count];

            for (int i = 0; i < data.Count; i++)
            {
                vertices[i] = data[i];
            }
            ConvexHullInternal ch = new ConvexHullInternal(vertices, false, config);

            ch.FindConvexHull();

            var hull = new TVertex[ch.ConvexHull.Count];

            for (int i = 0; i < hull.Length; i++)
            {
                hull[i] = (TVertex)ch.Vertices[ch.ConvexHull[i]];
            }

            return(new ConvexHull <TVertex, TFace> {
                Points = hull, Faces = ch.GetConvexFaces <TVertex, TFace>()
            });
        }
Пример #2
0
        internal static ConvexHull <TVertex, TFace> GetConvexHull <TVertex, TFace>(IList <TVertex> data, ConvexHullComputationConfig config) where TVertex : IVertex where TFace : ConvexFace <TVertex, TFace>, new()
        {
            config ??= new ConvexHullComputationConfig();
            IVertex[] vertices = new IVertex[data.Count];
            for (int i = 0; i < data.Count; i++)
            {
                vertices[i] = data[i];
            }
            ConvexHullInternal internal2 = new ConvexHullInternal(vertices, false, config);

            internal2.FindConvexHull();
            return(new ConvexHull <TVertex, TFace> {
                Points = internal2.GetHullVertices <TVertex>(data),
                Faces = internal2.GetConvexFaces <TVertex, TFace>()
            });
        }
Пример #3
0
        /// <summary>
        /// Computes the Delaunay triangulation.
        /// </summary>
        /// <typeparam name="TVertex"></typeparam>
        /// <typeparam name="TCell"></typeparam>
        /// <param name="data"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        internal static TCell[] GetDelaunayTriangulation <TVertex, TCell>(IList <TVertex> data, TriangulationComputationConfig config)
            where TCell : TriangulationCell <TVertex, TCell>, new()
            where TVertex : IVertex
        {
            config = config ?? new TriangulationComputationConfig();

            var vertices = new IVertex[data.Count];

            for (int i = 0; i < data.Count; i++)
            {
                vertices[i] = data[i];
            }
            ConvexHullInternal ch = new ConvexHullInternal(vertices, true, config);

            ch.FindConvexHull();
            ch.PostProcessTriangulation(config);

            return(ch.GetConvexFaces <TVertex, TCell>());
        }