Skip to content

Commit 3201ffc

Browse files
committed
fix randomness in orientation function
1 parent eea47e0 commit 3201ffc

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
* Fixed `native_edge` property of `RhinoBrepEdge`.
2020
* Expose the parameters `radius` and `nmax` from `compas.topology._face_adjacency` to `compas.topology.face_adjacency` and further propagate them to `unify_cycles` and `Mesh.unify_cycles`.
21-
* Modify `face_adjacency` to avoid using `compas.topology._face_adjacency` by default when there are more than 100 faces, unless one of the parameters `radius`, `nmax` is passed
21+
* Modify `face_adjacency` to avoid using `compas.topology._face_adjacency` by default when there are more than 100 faces, unless one of the parameters `radius`, `nmax` is passed.
22+
* Changed `unify_cycles` to use the first face in the list as root if no root is provided.
2223

2324
### Removed
2425

src/compas/topology/orientation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ def unify_cycles(vertices, faces, root=None, nmax=None, max_distance=None):
193193
Exception
194194
If no all faces are included in the unnification process.
195195
196+
Notes
197+
-----
198+
The cycles of the faces will be aligned with the cycle direction of the root face.
199+
If no root face is specified, the first face in the list will be used.
200+
196201
"""
197202

198203
def unify(node, nbr):
@@ -210,7 +215,8 @@ def unify(node, nbr):
210215
return
211216

212217
if root is None:
213-
root = random.choice(list(range(len(faces))))
218+
# root = random.choice(list(range(len(faces))))
219+
root = 0
214220

215221
adj = face_adjacency(vertices, faces, nmax=nmax, max_distance=max_distance) # this is the only place where the vertex coordinates are used
216222

tests/compas/topology/test_unify_cycles.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
def test_unify_cycles():
1515
if compas.IPY:
1616
return
17+
1718
test_data = compas.json_load(os.path.join(HERE, "..", "fixtures", "topology", "vertices_faces.json"))
1819
vertices = test_data["vertices"]
1920
faces = test_data["faces"]
@@ -25,12 +26,15 @@ def test_unify_cycles():
2526
# no parameters
2627
unify_cycles(vertices, faces)
2728
assert TOL.is_close(volume, volume_polyhedron((vertices, faces)))
29+
2830
# only max_nbrs
2931
unify_cycles(vertices, faces, nmax=max_nbrs)
3032
assert TOL.is_close(volume, volume_polyhedron((vertices, faces)))
33+
3134
# only max_distance
3235
unify_cycles(vertices, faces, max_distance=max_edge_length)
3336
assert TOL.is_close(volume, volume_polyhedron((vertices, faces)))
37+
3438
# both parameters
3539
unify_cycles(vertices, faces, nmax=max_nbrs, max_distance=max_edge_length)
3640
assert TOL.is_close(volume, volume_polyhedron((vertices, faces)))

0 commit comments

Comments
 (0)