@@ -19,7 +19,7 @@ class Polygon2(object):
19
19
index to the larger index will walk clockwise around the polygon.
20
20
21
21
.. note::
22
-
22
+
23
23
Polygons should be used as if they were completely immutable to
24
24
ensure correctness. All attributes of Polygon2 can be reconstructed
25
25
from the points array, and thus cannot be changed on their own and
@@ -205,9 +205,9 @@ def from_regular(cls, sides, length, start_rads = None, start_degs = None, cente
205
205
206
206
Finally, each vertex is found using ``<radius * cos(angle), radius * sin(angle)>``
207
207
208
- If the center is not specified, the bounding box of the polygon is calculated while the vertices
209
- are being found, and the center of the bounding box is set to the center of the circle. This
210
- is never greater than (circumradius, circumradius).
208
+ If the center is not specified, the minimum of the bounding box of the
209
+ polygon is calculated while the vertices are being found, and the inverse
210
+ of that value is offset to the rest of the points in the polygon.
211
211
212
212
:param sides: the number of sides in the polygon
213
213
:type sides: :class:`numbers.Number`
@@ -251,8 +251,6 @@ def from_regular(cls, sides, length, start_rads = None, start_degs = None, cente
251
251
pts = []
252
252
_minx = 0
253
253
_miny = 0
254
- _maxx = 0
255
- _maxy = 0
256
254
for i in range (sides ):
257
255
x = center .x + math .cos (angle ) * radius
258
256
y = center .y + math .sin (angle ) * radius
@@ -262,13 +260,11 @@ def from_regular(cls, sides, length, start_rads = None, start_degs = None, cente
262
260
if _recenter :
263
261
_minx = min (_minx , x )
264
262
_miny = min (_miny , y )
265
- _maxx = max (_maxx , x )
266
- _maxy = max (_maxy , y )
267
263
268
264
if _recenter :
269
- _newcenter = vector2 .Vector2 (( _maxx - _minx ) / 2 , ( _maxy - _miny ) / 2 )
265
+ _offset = vector2 .Vector2 (- _minx , - _miny )
270
266
for i in range (sides ):
271
- pts [i ] += _newcenter
267
+ pts [i ] += _offset
272
268
273
269
return cls (pts , suppress_errors = True )
274
270
@@ -407,8 +403,8 @@ def contains_point(polygon, offset, point):
407
403
:type offset: :class:`pygorithm.geometry.vector2.Vector2` or None
408
404
:param point: the point to check
409
405
:type point: :class:`pygorithm.geometry.vector2.Vector2`
410
- :returns: ( on edge, contained)
411
- :rtype: ( bool, bool)
406
+ :returns: on edge, contained
407
+ :rtype: bool, bool
412
408
"""
413
409
414
410
_previous = polygon .points [0 ]
@@ -520,7 +516,7 @@ def _create_link(pts):
520
516
:type pts: list of :class:`pygorithm.geometry.vector2.Vector2`
521
517
"""
522
518
523
- param0 = "+" .join (('%28{}%2C+{}%29' .format (v .x , v .y )) for v in pts )
519
+ param0 = "+" .join (('%28{}%2C+{}%29' .format (round ( v .x , 3 ), round ( v .y , 3 ) )) for v in pts )
524
520
xmin = pts [0 ].x
525
521
xmax = xmin
526
522
ymin = pts [1 ].y
0 commit comments