Skip to content

Commit b56c063

Browse files
committed
Add axis aligned line repr and str
* pygorithm/geometry/axisall.py - add __str__ and __repr__ * pygorithm/geometry/polygon2.py - document _create_links
1 parent 7547b18 commit b56c063

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

pygorithm/geometry/axisall.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,55 @@ def contains_point(line, point):
171171
elif point < line.min or point > line.max:
172172
return False, False
173173
else:
174-
return False, True
174+
return False, True
175+
176+
def __repr__(self):
177+
"""
178+
Create an unambiguous representation of this axis aligned
179+
line.
180+
181+
Example:
182+
183+
.. code-block:: python
184+
185+
from pygorithm.geometry import axisall
186+
187+
aal = axisall.AxisAlignedLine(None, 3, 5)
188+
189+
# prints AxisAlignedLine(axis=None, min=3, max=5)
190+
print(repr(aal))
191+
192+
:returns: un-ambiguous representation of this line
193+
:rtype: string
194+
"""
195+
196+
return "AxisAlignedLine(axis={}, min={}, max={})".format(repr(self.axis), self.min, self.max)
197+
198+
def __str__(self):
199+
"""
200+
Create a human-readable representation of this axis aligned line.
201+
202+
Example:
203+
204+
.. code-block:: python
205+
206+
from pygorithm.geometry import axisall
207+
208+
aal = axisall.AxisAlignedLine(None, 0.7071234, 0.7071234)
209+
210+
# prints axisall(along None from 0.707 to 0.707)
211+
print(aal)
212+
213+
:returns: human-readable representation of this line
214+
:rtype: string
215+
"""
216+
217+
pretty_min = round(self.min * 1000) / 1000
218+
if pretty_min == math.floor(pretty_min):
219+
pretty_min = math.floor(pretty_min)
220+
221+
pretty_max = round(self.max * 1000) / 1000
222+
if pretty_max == math.floor(pretty_max):
223+
pretty_max = math.floor(pretty_max)
224+
225+
return "axisall(along {} from {} to {})".format(str(axis), pretty_min, pretty_max)

pygorithm/geometry/polygon2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,17 @@ def find_intersection(poly1, poly2, offset1, offset2, find_mtv = True):
509509

510510
@staticmethod
511511
def _create_link(pts):
512+
"""
513+
Create a webmath link to display the polygon.
514+
515+
This isn't a perfect drawing since it doesn't show connections (so order is
516+
invisible). Avoid programatically connecting to the website. This is mostly
517+
used because it's very difficult to visualize polygons from lists of points.
518+
519+
:param pts: a set of points (order, number, etc. are irrelevant)
520+
:type pts: list of :class:`pygorithm.geometry.vector2.Vector2`
521+
"""
522+
512523
param0 = "+".join(('%28{}%2C+{}%29'.format(v.x, v.y)) for v in pts)
513524
xmin = pts[0].x
514525
xmax = xmin

0 commit comments

Comments
 (0)