Beispiel #1
0
        public static IEnumerable <IPath> Split(this IEnumerable <IPath> paths, IPath clipee, out IEnumerable <PointM3> iPoints, LineSplitResultType resultType = LineSplitResultType.All)
        {
            List <IPath> result = new List <IPath>();

            #region Determine Points

            List <PointM3> intersectionPoints = new List <PointM3>();

            var pathArray = paths.ToArray();
            for (int i = 0, to = pathArray.Length; i < to; i++)
            {
                intersectionPoints.AddRange(pathArray[i].Intersect(clipee, i));
            }

            #endregion

            #region Remove identic neighbours and order by M3 ( = stat on clipee)

            intersectionPoints = intersectionPoints.RemoveIdenticNeighbours <PointM3>().ToList();
            intersectionPoints.Sort(new PointM3Comparerer <double>());

            #endregion

            #region Split clipee

            double   stat       = 0D;
            int      counter    = 0;
            Polyline clipeeLine = new Polyline(clipee);

            foreach (var intersectPoint in intersectionPoints)
            {
                if (Math.Abs(stat - (double)intersectPoint.M3) > 1e-7)
                {
                    var clippedLine = Algorithm.PolylineSplit(clipeeLine, stat, (double)intersectPoint.M3);
                    if (clippedLine != null && clippedLine.PathCount == 1)
                    {
                        if (resultType == LineSplitResultType.All ||
                            (resultType == LineSplitResultType.Even && counter % 2 == 1) ||
                            (resultType == LineSplitResultType.Odd && counter % 2 == 0))
                        {
                            result.Add(clippedLine[0]);
                        }
                    }
                }

                counter++;
                stat = (double)intersectPoint.M3;
            }
            if (stat < clipeeLine.Length)
            {
                var clippedLine = Algorithm.PolylineSplit(clipeeLine, stat, clipeeLine.Length);
                if (clippedLine != null && clippedLine.PathCount == 1)
                {
                    if (resultType == LineSplitResultType.All ||
                        (resultType == LineSplitResultType.Even && counter % 2 == 1) ||
                        (resultType == LineSplitResultType.Odd && counter % 2 == 0))
                    {
                        result.Add(clippedLine[0]);
                    }
                }
            }

            #endregion

            iPoints = intersectionPoints;
            return(result);
        }
Beispiel #2
0
        public static IEnumerable <IPath> Split(this IEnumerable <IPath> paths, IPath clipee, LineSplitResultType resultType = LineSplitResultType.All)
        {
            IEnumerable <PointM3> dummy;

            return(paths.Split(clipee, out dummy, resultType));
        }