Skip to content

Commit 183a12a

Browse files
baehrjogonzalocasas
authored andcommitted
fix in area_polygon
1 parent 96b3d98 commit 183a12a

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636
- Chen Kasirer <<[email protected]>> [@chenkasirer](https://github.com/chenkasirer)
3737
- Nickolas Maslarinos <<[email protected]>> [@nmaslarinos](https://github.com/nmaslarinos)
3838
- Katerina Toumpektsi <<[email protected]>> [@katarametin](https://github.com/katarametin)
39+
- Joelle Baehr-Bruyere <<[email protected]>> [@baehrjo](https://github.com/baehrjo)

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
* Fixed bug that caused a new-line at the end of the `compas.HERE` constant in IronPython for Mac.
1717
* Fixed Grasshopper `draw_polylines` method to return `PolylineCurve` instead of `Polyline` because the latter shows as only points.
1818
* Fixed uninstall post-process.
19+
* Fixed `area_polygon` that was, in some cases, returning a negative area
1920

2021
### Removed
2122

src/compas/geometry/_core/size.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def area_polygon(polygon):
6565
area += 0.5 * length_vector(n)
6666
else:
6767
area -= 0.5 * length_vector(n)
68-
return area
68+
return abs(area)
6969

7070

7171
def area_polygon_xy(polygon):

tests/compas/geometry/test_core.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from compas.geometry import Polyhedron
6-
from compas.geometry import Polygon
6+
from compas.geometry import Point, Polygon
77
from compas.geometry import Rotation
88
from compas.geometry import allclose
99
from compas.geometry import angle_vectors
@@ -230,6 +230,14 @@ def test_area_triangle(triangle, R):
230230
assert close(triangle.area, 0.5)
231231

232232

233+
def test_area_polygon():
234+
# create a test closed (here planar xy) non-convex polygon :
235+
polygon = Polygon([Point(-7, -15, 0), Point(-5, 9, 0), Point(13, 0, 0), Point(0, -2, 0), Point(0, -6, 0), Point(-4, -10, 0)])
236+
assert area_polygon(polygon) >= 0
237+
# the same polygon with vertices list shifted by 3 positions :
238+
polygon_ = Polygon([Point(0, -2, 0), Point(0, -6, 0), Point(-4, -10, 0), Point(-7, -15, 0), Point(-5, 9, 0), Point(13, 0, 0)])
239+
assert area_polygon(polygon_) >= 0
240+
233241
# ==============================================================================
234242
# normals
235243
# ==============================================================================\

0 commit comments

Comments
 (0)