Example #1
0
        private static int PerformSimplification(float threshold, SIMPLIFY_METHOD method)
        {
            int size = 0;

            if (threshold < 0.0f)
            {
                threshold = 0.0f;
            }
            if (threshold > 1.0f)
            {
                threshold = 1.0f;
            }

            switch (method)
            {
            case SIMPLIFY_METHOD.SQUARE_DIST:
                size = CGAL_SquareDistCostSimplify(threshold);
                break;

            case SIMPLIFY_METHOD.SCALED_SQUARE_DIST:
                size = CGAL_ScaledSquareDistCostSimplify(threshold);
                break;
            }

            return(size);
        }
Example #2
0
        public static Polygon2f Simplify(Polygon2f polygon, float threshold, SIMPLIFY_METHOD method = SIMPLIFY_METHOD.SQUARE_DIST)
        {
            if (!polygon.IsSimple)
            {
                throw new ArgumentException("Polygon must be simple.");
            }

            if (polygon.HasHoles)
            {
                throw new NotImplementedException("Polygon with holes not implemented.");
            }

            if (polygon.VerticesCount < 3)
            {
                Polygon2f simplified = new Polygon2f(polygon.Positions);
                simplified.CalculatePolygon();
                return(simplified);
            }
            else
            {
                CGAL_LoadPoints(polygon.Positions, polygon.Positions.Length);

                int size = PerformSimplification(threshold, method);

                Polygon2f simplified = new Polygon2f(size);

                for (int i = 0; i < size; i++)
                {
                    simplified.Positions[i] = CGAL_GetSimplifiedVector2f(i);
                }

                simplified.CalculatePolygon();

                CGAL_Clear();

                return(simplified);
            }
        }