Skip to content

Commit 8ac78b7

Browse files
committed
Fix geometry example
Add missing functions for the geometry example * docs/Geometry.rst - use from_regular rather than weird constructor * pygorithm/geometry/polygon2.py - Add form-regular and alternate tuple version for init
1 parent cfa57a6 commit 8ac78b7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

docs/Geometry.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Quick Start Guide
1414
from pygorithm.geometry import vector2
1515
1616
# create a regular polygon
17-
poly1 = polygon2.Polygon2(regular=True, sides=5, length=5)
17+
poly1 = polygon2.Polygon2.from_regular(5, 5)
1818
1919
# create a polygon from tuple (x, y) - note that the polygon must be concave
2020
poly2 = polygon2.Polygon2(points=[ (0, 0), (1, 0), (1, 1), (0, 1) ])

pygorithm/geometry/polygon2.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def __init__(self, points, suppress_errors = False):
6262
suppressed.
6363
6464
:param points: the ordered set of points on this polygon
65-
:type points: list of :class:`pygorithm.geometry.vector2.Vector2`
65+
:type points: list of :class:`pygorithm.geometry.vector2.Vector2` or \
66+
list of (:class:`numbers.Number`, :class:`numbers.Number`)
6667
6768
:param suppress_errors: True to not do somewhat expensive sanity checks
6869
:type suppress_errors: bool
@@ -74,6 +75,20 @@ def __init__(self, points, suppress_errors = False):
7475
"""
7576
pass
7677

78+
@classmethod
79+
def from_regular(cls, sides, length):
80+
"""
81+
Create a new regular polygon.
82+
83+
:param sides: the number of sides in the polygon
84+
:type sides: :class:`numbers.Number`
85+
:param length: the length of each sides
86+
:type length: :class:`numbers.Number`
87+
88+
:raises ValueError: if ``sides < 3`` or ``length <= 0``
89+
"""
90+
pass
91+
7792
@property
7893
def area(self):
7994
"""

0 commit comments

Comments
 (0)