Skip to content

Commit 29b48ef

Browse files
committed
Includes closed shape coordinates
1 parent a24cec2 commit 29b48ef

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/planar2/polygon.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,19 @@ def is_simple_known(self):
351351
"""
352352
return self._simple is not _unknown
353353

354+
@property
355+
def verts(self):
356+
"""Coordinates of the polygon vertices."""
357+
vert_coords = list(map(list, zip(*self.values_mut)))
358+
return vert_coords
359+
360+
@property
361+
def verts_closed(self):
362+
"""Coordinates of the polygon vertices with the first vertex added to the last."""
363+
ext = self.values_mut + [self.values_mut[0]]
364+
verts_ext = list(map(list, zip(*ext)))
365+
return verts_ext
366+
354367
def _segments_intersect(self, a, b, c, d):
355368
"""Return True if the line segment a->b intersects with
356369
line segment c->d

lib/planar2/vector.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
import math
34-
import planar2
34+
import planar2 as planar
3535
from planar2.util import cached_property, assert_unorderable, cos_sin_deg
3636

3737

@@ -80,6 +80,16 @@ def y(self):
8080
"""The vertical coordinate."""
8181
return self[1]
8282

83+
@property
84+
def xy(self):
85+
"""Coordinate values"""
86+
return tuple(self)
87+
88+
@property
89+
def xy_mut(self):
90+
"""Mutable version of coordinate values."""
91+
return list(self)
92+
8393
@cached_property
8494
def length(self):
8595
"""The length or scalar magnitude of the vector."""
@@ -479,6 +489,20 @@ class Seq2(object):
479489
def __init__(self, vectors):
480490
self._vectors = [Vec2(*v) for v in vectors]
481491

492+
@property
493+
def nvecs(self):
494+
"""The number of constituent points."""
495+
return len(self._vectors)
496+
497+
@property
498+
def values(self):
499+
"""Coordinates of all consituent points."""
500+
return tuple(self._vectors[i].xy for i in range(self.nvecs))
501+
502+
@property
503+
def values_mut(self):
504+
return list(self._vectors[i].xy_mut for i in range(self.nvecs))
505+
482506
@classmethod
483507
def from_points(cls, points):
484508
"""Create a new 2D sequence from an iterable of points"""

0 commit comments

Comments
 (0)