Ejemplo n.º 1
0
        public static Curve CutCurve(Curve curve, double fromDistance, double toDistance)
        {
            var prevCurve = curve.RemoveOverlappingPoints2D();

            var accLen = 0d;
            var modifiedCurve = new Curve();
            var startFound = false;

            for (var i = 0; i < prevCurve.Points.Count - 1; i++)
            {
                var len = PointStrategies.EuclidianDistance(prevCurve.Points[i], prevCurve.Points[i + 1]);

                if (startFound == false && accLen + len >= fromDistance)
                {
                    GetNewStartCoordinates(prevCurve, fromDistance, i, accLen, modifiedCurve);
                    startFound = true;

                    if (accLen + len >= toDistance)
                    {
                        GetNewEndCoordinates(prevCurve, toDistance, i, accLen, modifiedCurve);
                        return modifiedCurve;
                    }

                    if (!MathHelper.DoublesAreEqual(accLen + len, fromDistance))
                    {
                        modifiedCurve.Points.Add(prevCurve.Points[i + 1]);
                    }
                }
                else if (accLen + len >= toDistance)
                {
                    if (!MathHelper.DoublesAreEqual(accLen + len, toDistance))
                    {
                        modifiedCurve.Points.Add(prevCurve.Points[i]);
                    }
                    GetNewEndCoordinates(prevCurve, toDistance, i, accLen, modifiedCurve);
                    return modifiedCurve;
                }
                else if (startFound)
                {
                    modifiedCurve.Points.Add(prevCurve.Points[i]);
                }

                accLen += len;
            }

            modifiedCurve.Points.Add(prevCurve.Points.Last());
            return modifiedCurve;
        }