Skip to content

Commit eb090a0

Browse files
authored
Merge pull request #1138 from compas-dev/lts-backports/sync-230423
LTS backports/sync 230423
2 parents 96b3d98 + c4fb71b commit eb090a0

File tree

9 files changed

+72
-31
lines changed

9 files changed

+72
-31
lines changed

.github/workflows/ironpython.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: "[RPC tests] Install CPython dependencies"
2424
run: |
2525
python -m pip install --upgrade pip
26-
pip install cython --install-option='--no-cython-compile'
26+
pip install cython --config-settings="--build-option=--no-cython-compile"
2727
- name: "[RPC tests] Install COMPAS on CPython"
2828
run: |
2929
pip install --no-cache-dir .

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ 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
20+
* Fixed support for `System.Decimal` data type on json serialization.
1921

2022
### Removed
2123

src/compas/data/encoders.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@
88

99
from compas.data.exceptions import DecoderError
1010

11+
IDictionary = None
12+
numpy_support = False
13+
dotnet_support = False
14+
1115
# We don't do this from `compas.IPY` to avoid circular imports
1216
if "ironpython" == platform.python_implementation().lower():
17+
dotnet_support = True
18+
1319
try:
20+
import System
1421
from System.Collections.Generic import IDictionary
1522
except: # noqa: E722
16-
IDictionary = None
17-
else:
18-
IDictionary = None
23+
pass
24+
25+
try:
26+
import numpy as np
27+
28+
numpy_support = True
29+
except ImportError:
30+
numpy_support = False
1931

2032

2133
def cls_from_dtype(dtype):
@@ -113,11 +125,7 @@ def default(self, o):
113125
if hasattr(o, "__next__"):
114126
return list(o)
115127

116-
try:
117-
import numpy as np
118-
except ImportError:
119-
pass
120-
else:
128+
if numpy_support:
121129
if isinstance(o, np.ndarray):
122130
return o.tolist()
123131
if isinstance(
@@ -144,6 +152,10 @@ def default(self, o):
144152
if isinstance(o, np.void):
145153
return None
146154

155+
if dotnet_support:
156+
if isinstance(o, System.Decimal):
157+
return float(o)
158+
147159
return super(DataEncoder, self).default(o)
148160

149161

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/data/test_json.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import compas
2-
3-
from compas.geometry import Point, Vector, Frame
4-
from compas.geometry import Box
5-
from compas.geometry import Transformation
6-
7-
from compas.datastructures import Network
82
from compas.datastructures import Mesh
3+
from compas.datastructures import Network
94
from compas.datastructures import VolMesh
5+
from compas.geometry import Box
6+
from compas.geometry import Frame
7+
from compas.geometry import Point
8+
from compas.geometry import Transformation
9+
from compas.geometry import Vector
1010

1111

1212
def test_json_native():
@@ -15,20 +15,6 @@ def test_json_native():
1515
assert after == [[], [], {}, "", 1, 1.0, True, None]
1616

1717

18-
if not compas.IPY:
19-
import numpy as np
20-
21-
def test_json_numpy():
22-
before = [
23-
np.array([1, 2, 3]),
24-
np.array([1.0, 2.0, 3.0]),
25-
np.float64(1.0),
26-
np.int32(1),
27-
]
28-
after = compas.json_loads(compas.json_dumps(before))
29-
assert after == [[1, 2, 3], [1.0, 2.0, 3.0], 1.0, 1]
30-
31-
3218
def test_json_primitive():
3319
before = Point(0, 0, 0)
3420
after = compas.json_loads(compas.json_dumps(before))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import compas
2+
3+
try:
4+
import System
5+
6+
def test_decimal():
7+
before = System.Decimal(100.0)
8+
9+
after = compas.json_loads(compas.json_dumps(before))
10+
assert after == 100.0
11+
12+
except ImportError:
13+
pass
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import compas
2+
3+
try:
4+
import numpy as np
5+
6+
def test_json_numpy():
7+
before = [
8+
np.array([1, 2, 3]),
9+
np.array([1.0, 2.0, 3.0]),
10+
np.float64(1.0),
11+
np.int32(1),
12+
]
13+
after = compas.json_loads(compas.json_dumps(before))
14+
assert after == [[1, 2, 3], [1.0, 2.0, 3.0], 1.0, 1]
15+
16+
except ImportError:
17+
pass

tests/compas/geometry/test_core.py

Lines changed: 11 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,16 @@ 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 = [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+
237+
assert area_polygon(polygon) >= 0
238+
# the same polygon with vertices list shifted by 3 positions :
239+
polygon_ = polygon[3:] + polygon[:3]
240+
assert area_polygon(polygon_) >= 0
241+
242+
233243
# ==============================================================================
234244
# normals
235245
# ==============================================================================\

0 commit comments

Comments
 (0)