Skip to content

Commit 21bbd2a

Browse files
authored
Merge pull request #1407 from compas-dev/sphere_edges
fixed Sphere._vertices used before populated
2 parents fb5bc8e + 1a3d641 commit 21bbd2a

File tree

9 files changed

+72
-4
lines changed

9 files changed

+72
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
* Fixed bug in `VolMesh.delete_cell`.
15+
* Fixed `NoneType` error when calling `compas.geometry.Sphere.edges`.
16+
1517

1618
### Removed
1719

src/compas/geometry/shapes/capsule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def compute_faces(self): # type: () -> list[list[int]]
297297
if v % 2 == 1:
298298
v += 1
299299

300-
vertices = self._vertices
300+
vertices = self.vertices
301301

302302
faces = []
303303

src/compas/geometry/shapes/cone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def compute_faces(self): # type: () -> list[list[int]]
267267
list[list[int]]
268268
269269
"""
270-
vertices = self._vertices
270+
vertices = self.vertices
271271

272272
faces = []
273273
first = 0

src/compas/geometry/shapes/cylinder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def compute_faces(self): # type: () -> list[list[int]]
267267
"""
268268
u = self.resolution_u
269269

270-
vertices = self._vertices
270+
vertices = self.vertices
271271

272272
faces = []
273273
# side faces

src/compas/geometry/shapes/sphere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def compute_faces(self): # type: () -> list[list[int]]
218218
u = self.resolution_u
219219
v = self.resolution_v
220220

221-
vertices = self._vertices
221+
vertices = self.vertices
222222

223223
faces = []
224224

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from compas.geometry import Capsule
4+
5+
6+
@pytest.fixture
7+
def capsule():
8+
return Capsule(123.0, 13.0)
9+
10+
11+
def test_capsule_discretization(capsule):
12+
# just checking these don't break. Could not quickly find a formula that worked to test the actual values
13+
# as function of the resolution
14+
assert capsule.edges
15+
assert capsule.faces
16+
assert capsule.vertices

tests/compas/geometry/test_cone.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from compas.geometry import Cone
4+
5+
6+
@pytest.fixture
7+
def cone():
8+
return Cone(432.0, 123.0)
9+
10+
11+
def test_cone_discretization(cone):
12+
# just checking these don't break. Could not quickly find a formula that worked to test the actual values
13+
# as function of the resolution
14+
assert cone.edges
15+
assert cone.faces
16+
assert cone.vertices
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
from compas.geometry import Cylinder
3+
4+
5+
@pytest.fixture
6+
def cylinder():
7+
return Cylinder(radius=0.3, height=1.6)
8+
9+
10+
def test_cylinder_discretization(cylinder):
11+
# just checking these don't break. Could not quickly find a formula that worked to test the actual values
12+
# as function of the resolution
13+
assert cylinder.edges
14+
assert cylinder.faces
15+
assert cylinder.vertices
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from compas.geometry import Frame
4+
from compas.geometry import Sphere
5+
6+
7+
@pytest.fixture
8+
def sphere():
9+
return Sphere(450.0, Frame.worldXY())
10+
11+
12+
def test_sphere_discretization(sphere):
13+
expected_face_count = sphere.resolution_v * sphere.resolution_u
14+
expected_vertex_count = (sphere.resolution_v - 1) * sphere.resolution_u + 2
15+
expected_edge_count = expected_face_count * 2 - sphere.resolution_u
16+
17+
assert len(sphere.edges) == expected_edge_count
18+
assert len(sphere.faces) == expected_face_count
19+
assert len(sphere.vertices) == expected_vertex_count

0 commit comments

Comments
 (0)