Exemple #1
0
        /***************************************************/

        private static PolyCurve ExtendTangent(this PolyCurve curve, double start = 0.0, double end = 0.0, double tolerance = Tolerance.Distance)
        {
            if (-start > curve.Length() || -end > curve.Length()) //ExtendTangent allows to trim the curve but only to the limit of it's length.
            {
                Reflection.Compute.RecordError("Extension value too small");

                return(null);
            }

            if (start < 0 && end < 0)
            {
                return(curve.Extend(start, end, false, tolerance));
            }

            if (start < 0 && !(end < 0))
            {
                curve = curve.Extend(start, 0, false, tolerance);
                return(curve.ExtendTangent(0, end, tolerance));
            }

            if (!(start < 0) && end < 0)
            {
                curve = curve.Extend(0, end, false, tolerance);
                return(curve.ExtendTangent(start, 0, tolerance));
            }

            List <ICurve> curves = curve.SubParts();

            if (curves.Count == 1)
            {
                return new PolyCurve {
                           Curves = curves[0].IExtend(start, end, true, tolerance).ISubParts().ToList()
                }
            }
            ;
            else
            {
                curves[0] = curves[0].IExtend(start, 0, true, tolerance);

                curves[curves.Count - 1] = curves[curves.Count - 1].IExtend(0, end, true, tolerance);
                return(new PolyCurve {
                    Curves = curves
                });
            }
        }
Exemple #2
0
        public static PolyCurve Extend(this PolyCurve curve, double start = 0.0, double end = 0.0, bool tangentExtensions = false, double tolerance = Tolerance.Distance)
        {
            if (tangentExtensions)
            {
                return(curve.ExtendTangent(start, end, tolerance));
            }

            if (curve.IsClosed(tolerance))
            {
                Reflection.Compute.RecordNote("Cannot Trim or Extend closed curves.");
                return(curve);
            }

            if (start + end + curve.Length() < tolerance)
            {
                Reflection.Compute.RecordError("Negative extend values are smaller than curve length.");
                return(null);
            }

            List <ICurve> curves = curve.SubParts();

            if (start < 0 && -start > curves[0].ILength())
            {
                double startCut = -curves[0].ILength();
                while (startCut > start && curves.Count > 1)
                {
                    curves.RemoveAt(0);
                    startCut -= curves[0].ILength();
                }

                startCut += curves[0].ILength();

                if (curves.Count > 1)
                {
                    curves[0] = curves[0].IExtend(start - startCut, 0, tangentExtensions, tolerance);
                }
                else
                {
                    curves[0] = curves[0].IExtend(start - startCut, end, tangentExtensions, tolerance);
                    return(new PolyCurve {
                        Curves = curves
                    });
                }
            }
            else
            {
                curves[0] = curves[0].IExtend(start, 0, tangentExtensions, tolerance);
            }

            if (end < 0 && -end > curves[curves.Count - 1].ILength())
            {
                double endCut = -curves[curves.Count - 1].ILength();
                while (endCut > end)
                {
                    curves.RemoveAt(curves.Count - 1);
                    endCut -= curves[curves.Count - 1].ILength();
                }
                endCut += curves[curves.Count - 1].ILength();
                curves[curves.Count - 1] = curves[curves.Count - 1].IExtend(0, end - endCut, tangentExtensions, tolerance);
            }
            else
            {
                curves[curves.Count - 1] = curves[curves.Count - 1].IExtend(0, end, tangentExtensions, tolerance);
            }

            return(new PolyCurve {
                Curves = curves
            });
        }