compas-dev / compas

Core packages of the COMPAS framework.
https://compas.dev/compas/
MIT License
307 stars 104 forks source link

`offset_polygon()` returns `TypeError` when the parameter `polygon` is provided a `Polygon` instance #1215

Open ChiaChing-Yen opened 9 months ago

ChiaChing-Yen commented 9 months ago

Describe the bug The compas.geometry.offset_polygon() returns TypeError when the parameter polygon is provided a Polygon instance

To Reproduce Running this script with Python 3.11

from compas.geometry import Polygon
from compas.geometry import offset_polygon

pts = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]
polygon = Polygon(pts)

offset_polygon(pts, 0.1) # this works
offset_polygon(polygon, 0.1) # this is not working

returns

Traceback (most recent call last):
  File "/PATH/TO/SCRIPTS/offset.py", line 7, in <module>
    offset_polygon(polygon, 0.1)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ENV_NAME/lib/python3.11/site-packages/compas/geometry/offset/offset.py", line 147, in offset_polygon
    polygon = polygon + polygon[:1]
              ~~~~~~~~^~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'Polygon' and 'list'

Expected behavior As the doc implies, the polygon parameter should accept sequence[point] | [Polygon]

Desktop (please complete the following information):

ChiaChing-Yen commented 9 months ago

Also, the docs said that it returns a list where the first and last coordinates are identical. This is not the case when I run the script, and it returns 4 pts instead.

IMO this is a better behavior as it is consistent with the input.