public static IRegion2D Simplify(IRegion2D region, double maxDiscretizationAngle = 5)
        {
            PolyLine2DDiscretizator discretizator = new PolyLine2DDiscretizator
            {
                NumberOfTiles = 1,
                LengthOfTile  = double.MaxValue,
                Angle         = maxDiscretizationAngle
            };
            var polyline        = region.Outline;
            var containsCircArc = polyline.Segments.FirstOrDefault(s => s is CircularArcSegment2D) != null;
            var polygon         = CreatePolygon(polyline, discretizator, true);
            var solution        = Clipper.SimplifyPolygon(polygon);

            if (solution.Count == 1)
            {
                var newRegion = new Region2D(CreatePolyline(solution[0], containsCircArc, maxDiscretizationAngle + 1));

                foreach (var opening in region.Openings)
                {
                    containsCircArc = opening.Segments.FirstOrDefault(s => s is CircularArcSegment2D) != null;
                    polygon         = CreatePolygon(opening, discretizator, true);
                    solution        = Clipper.SimplifyPolygon(polygon);
                    if (solution.Count == 1)
                    {
                        newRegion.Openings.Add(CreatePolyline(solution[0], containsCircArc, maxDiscretizationAngle + 1));
                    }
                    else
                    {
                        throw new System.NotImplementedException();
                    }
                }

                return(newRegion);
            }

            throw new System.NotImplementedException();
        }
        /// <summary>
        /// Ofset regionu.
        /// </summary>
        /// <param name="region"></param>
        /// <param name="delta"></param>
        /// <param name="joinType"></param>
        /// <param name="endType">Pokud bude etClosed, tak dela ofset vcetne otvoru, kladne delta je ven, zaporne dovnitr.
        /// Pokud nebude etClosed, tak dela ofset outline dovnitr i ven.</param>
        /// <param name="mitterLimit"></param>
        /// <returns></returns>
        public IRegion2D BuildOffset(IRegion2D region, double delta, JoinType joinType, EndType endType, double mitterLimit)
        {
            var polygons = CreatePolygons(region).ToList();
            var co       = new ClipperOffset(mitterLimit);

            co.AddPaths(polygons, joinType, endType);
            var solution = new List <List <IntPoint> >();

            co.Execute(ref solution, delta * ClipperScale);
            if (solution.Count > 0)
            {
                var outline  = CreatePolyline(solution[0], containsCircArc, MaxDiscretizationAngle + 1);
                var openings = new List <IPolyLine2D>(solution.Count - 1);
                for (var i = 1; i < solution.Count; ++i)
                {
                    openings.Add(CreatePolyline(solution[i], containsCircArc, MaxDiscretizationAngle + 1));
                }

                var result = new Region2D(outline, openings);
                return(result);
            }

            return(null);
        }