Skip to content

Polycurve

a curve that is comprised of multiple curves connected

segments class-attribute instance-attribute

segments: List[ICurve] = field(default_factory=list)

length property writable

length: float

area property writable

area: float

is_closed

is_closed(tolerance: float = 1e-06) -> bool

checks if the polycurve is closed (comparing start of first segment to end of last segment)

Source code in src/specklepy/objects/geometry/polycurve.py
def is_closed(self, tolerance: float = 1e-6) -> bool:
    """
    checks if the polycurve is closed
    (comparing start of first segment to end of last segment)
    """
    if len(self.segments) < 1:
        return False

    first_segment = self.segments[0]
    last_segment = self.segments[-1]

    if not (hasattr(first_segment, "start") and hasattr(last_segment, "end")):
        return False

    start_pt = first_segment.start
    end_pt = last_segment.end

    if not (isinstance(start_pt, Point) and isinstance(end_pt, Point)):
        return False

    return start_pt.distance_to(end_pt) <= tolerance

calculate_length

calculate_length() -> float

calculate total length of all segments

Source code in src/specklepy/objects/geometry/polycurve.py
def calculate_length(self) -> float:
    """
    calculate total length of all segments
    """
    total_length = 0.0
    for segment in self.segments:
        if hasattr(segment, "length"):
            total_length += segment.length
    return total_length

from_polyline classmethod

from_polyline(polyline: Polyline) -> Polycurve

constructs a new polycurve instance from an existing polyline curve

Source code in src/specklepy/objects/geometry/polycurve.py
@classmethod
def from_polyline(cls, polyline: Polyline) -> "Polycurve":
    """
    constructs a new polycurve instance from an existing polyline curve
    """
    polycurve = cls(units=polyline.units)
    points = polyline.get_points()
    for i in range(len(points) - 1):
        line = Line(start=points[i], end=points[i + 1], units=polyline.units)
        polycurve.segments.append(line)

    if polyline.is_closed():
        line = Line(start=points[-1], end=points[0], units=polyline.units)
        polycurve.segments.append(line)

    if hasattr(polyline, "_length"):
        polycurve.length = polyline.length
    if hasattr(polyline, "_area"):
        polycurve.area = polyline.area

    return polycurve