Skip to content

Commit d114251

Browse files
authored
Merge pull request #1530 from compas-dev/faster-transformation-to-rhino
Speed up Rhino transformation conversions
2 parents 5fc43fe + a98741e commit d114251

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
* `compas_rhino.uninstall` will try to remove compas packages from all possible install locations.
2525
* Changed `angle_vectors_projected` to raise `ValueError` when an input vector is parallel to projection normal.
2626
* Changed `angle_vectors` to raise `ValueError` when one of the input vectors is a zero-length vector instead of returning 0.
27+
* Changed `transformation_to_rhino` and `transformation_matrix_to_rhino` to assign the matrix components directly to the fields of `Rhino.Geometry.Transform` instead of looping over its indexer. About 11x faster per conversion, noticable when used inside an animation loop.
2728

2829
### Removed
2930

‎src/compas_rhino/conversions/transformations.py‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ def transformation_to_rhino(transformation):
1818
:rhino:`Rhino.Geometry.Transform`
1919
2020
"""
21-
transform = Rhino.Geometry.Transform(1.0)
22-
for i in range(0, 4):
23-
for j in range(0, 4):
24-
transform[i, j] = transformation[i, j]
25-
return transform
21+
return transformation_matrix_to_rhino(transformation.matrix)
2622

2723

2824
def transformation_matrix_to_rhino(matrix):
@@ -38,8 +34,10 @@ def transformation_matrix_to_rhino(matrix):
3834
:rhino:`Rhino.Geometry.Transform`
3935
4036
"""
41-
transform = Rhino.Geometry.Transform(1.0)
42-
for i in range(0, 4):
43-
for j in range(0, 4):
44-
transform[i, j] = matrix[i][j]
37+
row_0, row_1, row_2, row_3 = matrix
38+
transform = Rhino.Geometry.Transform.Identity
39+
transform.M00, transform.M01, transform.M02, transform.M03 = row_0
40+
transform.M10, transform.M11, transform.M12, transform.M13 = row_1
41+
transform.M20, transform.M21, transform.M22, transform.M23 = row_2
42+
transform.M30, transform.M31, transform.M32, transform.M33 = row_3
4543
return transform

0 commit comments

Comments
 (0)