Beispiel #1
0
        /// <summary>
        /// Returns the convex hull from a collection of XLD contours.
        /// </summary>
        /// <param name="from">The collection of XLD contours to be processed.</param>
        /// <returns>An XLD contour that is the convex hull.</returns>
        /// <example> HXLDCont convexHullXld = MyXldContours.ConvexHull (); .</example>
        public static HXLDCont ConvexHull(this HXLDCont from)
        {
            HXLDCont tempContour = new HXLDCont(), convexHull = new HXLDCont();
            HTuple   cumulativeRows = new HTuple(), cumulativeColumns = new HTuple();

            try
            {
                if (@from != null && @from.IsValid())
                {
                    int count = @from.CountObj();
                    if (count > 1)
                    {
                        HTuple rows, columns;
                        for (int i = 1; i <= count; i++)
                        {
                            @from[i].GetContourXld(out rows, out columns);
                            cumulativeRows    = cumulativeRows.TupleConcat(rows);
                            cumulativeColumns = cumulativeColumns.TupleConcat(columns);
                        }

                        tempContour.GenContourPolygonXld(
                            cumulativeRows,
                            cumulativeColumns);
                        convexHull = tempContour.ShapeTransXld("convex");
                    }
                    else
                    {
                        convexHull = @from.ShapeTransXld("convex");
                    }
                }

                if (convexHull.IsInitialized())
                {
                    return(convexHull.CopyObj(1, -1));
                }
                else
                {
                    return(new HXLDCont());
                }
            }
            finally
            {
                tempContour.Dispose();
                convexHull.Dispose();
            }
        }