compas-dev / compas

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

Polyline & Polygon length bug #1156

Open nmaslarinos opened 1 year ago

nmaslarinos commented 1 year ago

Describe the bug When modifying a Polyline's or Polygon's points attribute by adding or removings items from the list, the length attribute is not updated. This problem also occurs when using methods, such as shorten, which directly perform modifications to the list.

To Reproduce Steps to reproduce the behavior:

  1. Environment: VS Code
  2. Sample code:
    pl = Polyline([(0,0), (1,0)])
    print(pl.length)
    pl.points.append(Point(2,0))
    print(pl.length)
  3. The results are: 1.0 and 1.0

Expected behavior It would be normal that modifying the points would result in the recalculation of the polyline's length (and on this note, the lines as well)

Desktop (please complete the following information):

nmaslarinos commented 1 year ago

One idea for a fix would be to create append, extend, insert, del, and pop methods to complement the existing __get__ and __set__ methods. Also, turning the points into a read-only attribute would make the above bud impossible to reproduce, but it could break certain codes.