예제 #1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/
        public static Polyline ClipPolylines(Polyline subject, Polyline clip)
        {
            Polyline clippedPolyline = new Polyline();
            var      clippedPoints   = GetIntersectedPolygon(subject.ControlPoints, clip.ControlPoints);

            if (clippedPoints.Count > 0)
            {
                clippedPoints.Add(clippedPoints[0]);
            }
            clippedPolyline = Create.Polyline(clippedPoints);
            return(clippedPolyline);
        }
예제 #2
0
파일: Extend.cs 프로젝트: BHoM/BHoM_Engine
        public static Polyline Extend(this Polyline curve, double start = 0.0, double end = 0.0, bool tangentExtensions = false, double tolerance = Tolerance.Distance)
        {
            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);
            }

            Polyline    result = new Polyline();
            List <Line> lines  = curve.SubParts();

            if (start < 0 && -start > lines[0].ILength())
            {
                double startCut = -lines[0].ILength();

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

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

                if (lines.Count > 1)
                {
                    lines[0] = lines[0].Extend(start - startCut, 0, false, tolerance);
                }
                else
                {
                    lines[0] = lines[0].Extend(start - startCut, end, tangentExtensions, tolerance);
                    result   = Create.Polyline(lines);
                    return(result);
                }
            }
            else
            {
                lines[0] = lines[0].Extend(start, 0, tangentExtensions, tolerance);
            }

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

            result = Create.Polyline(lines);
            return(result);
        }