Skip to content

Commit

Permalink
fix(togeometry): Enable to_polygon2d to accept more data types
Browse files Browse the repository at this point in the history
This way, I don't always have to convert a polycurve to a polyline.
  • Loading branch information
chriswmackey authored and Chris Mackey committed Jan 17, 2024
1 parent b601564 commit 7c9167c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ladybug_rhino/togeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import ladybug_rhino.planarize as _planar
from .fromgeometry import from_face3ds_to_joined_brep
from .config import tolerance
from .config import tolerance, angle_tolerance


"""____________2D GEOMETRY TRANSLATORS____________"""
Expand Down Expand Up @@ -64,16 +64,24 @@ def to_polyline2d(polyline):
A LineSegment2D will be returned if the input polyline has only two points.
"""
pts = [to_point2d(polyline.Point(i)) for i in range(polyline.PointCount)]
try:
pts = [to_point2d(polyline.Point(i)) for i in range(polyline.PointCount)]
except AttributeError: # likely a poly curve that can be be a polyline
polyline = polyline.ToPolyline(tolerance, angle_tolerance, 0, 1e6)
pts = [to_point2d(polyline.Point(i)) for i in range(polyline.PointCount)]
return Polyline2D(pts) if len(pts) != 2 else LineSegment2D.from_end_points(*pts)


def to_polygon2d(polygon):
"""Ladybug Polygon2D from Rhino closed PolyLineCurve."""
try:
pts = [to_point2d(polygon.Point(i)) for i in range(polygon.PointCount)]
except AttributeError: # likely a poly curve that can be be a polyline
polygon = polygon.ToPolyline(tolerance, angle_tolerance, 0, 1e6)
pts = [to_point2d(polygon.Point(i)) for i in range(polygon.PointCount)]
assert polygon.IsClosed, \
'Rhino PolyLineCurve must be closed to make a Ladybug Polygon2D.'
return Polygon2D(
[to_point2d(polygon.Point(i)) for i in range(polygon.PointCount - 1)])
return Polygon2D(pts)


def to_mesh2d(mesh, color_by_face=True):
Expand Down

0 comments on commit 7c9167c

Please sign in to comment.