Skip to content

Commit

Permalink
Merge pull request #1360 from compas-dev/fix-transformations
Browse files Browse the repository at this point in the history
Fix transformations
  • Loading branch information
tomvanmele authored Jun 22, 2024
2 parents b7111f2 + 4ba6b5e commit 7b4c795
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Changed `compas_ghpython/utilities/drawing.py` to remove `System` dependency.
* Fixed bug in `compas.geometry.ic_numpy`, which was caused by returning only the last transformation of the iteration process.
* Changed `compas.geometry.Geometry.scaled` to use `compas.geometry.Geometry.scale` on a copy.
* Changed `compas.geometry.Geometry.translated` to use `compas.geometry.Geometry.translate` on a copy.
* Changed `compas.geometry.Geometry.rotated` to use `compas.geometry.Geometry.rotate` on a copy.
* Changed `VolMesh._plane` back to point to a cell for every triplet of vertices.
* Fixed `VolMesh.add_halfface`, `VolMesh.add_cell`, `VolMesh.vertex_halffaces`, `VolMesh.vertex_cells`, `VolMesh.edge_halffaces`, `VolMesh.halfface_cell`, `VolMesh.halfface_opposite_cell`, `VolMesh.halfface_opposite_halfface`, `VolMesh.cell_neighbors`.
* Changed ordering of `Volmesh.edges()` to be deterministic.
Expand Down
10 changes: 0 additions & 10 deletions src/compas/data/conftest.py

This file was deleted.

15 changes: 8 additions & 7 deletions src/compas/geometry/_core/_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,13 +1496,6 @@ def decompose_matrix(M):
for j in range(4):
Mt[i][j] /= Mt[3][3]

translation = [M[0][3], M[1][3], M[2][3]]

# scale, shear, angles
scale = [0.0, 0.0, 0.0]
shear = [0.0, 0.0, 0.0]
angles = [0.0, 0.0, 0.0]

# copy Mt[:3, :3] into row
row = [
[0, 0, 0],
Expand All @@ -1513,6 +1506,14 @@ def decompose_matrix(M):
for j in range(3):
row[i][j] = Mt[i][j]

# translation
translation = [M[0][3], M[1][3], M[2][3]]

# scale, shear, angles
scale = [0.0, 0.0, 0.0]
shear = [0.0, 0.0, 0.0]
angles = [0.0, 0.0, 0.0]

scale[0] = norm_vector(row[0])
for i in range(3):
row[0][i] /= scale[0] # type: ignore
Expand Down
27 changes: 9 additions & 18 deletions src/compas/geometry/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,9 @@ def scaled(self, x, y=None, z=None): # type: (...) -> G
transformed
"""
from compas.geometry import Scale

if y is None:
y = x

if z is None:
z = x

return self.transformed(Scale.from_factors([x, y, z]))
geometry = self.copy() # type: Geometry
geometry.scale(x=x, y=y, z=z)
return geometry # type: ignore

def translate(self, vector):
"""Translate the geometry.
Expand Down Expand Up @@ -224,9 +218,9 @@ def translated(self, vector): # type: (...) -> G
transformed
"""
from compas.geometry import Translation

return self.transformed(Translation.from_vector(vector))
geometry = self.copy() # type: Geometry
geometry.translate(vector)
return geometry # type: ignore

def rotate(self, angle, axis=None, point=None):
"""Rotate the geometry.
Expand Down Expand Up @@ -288,9 +282,6 @@ def rotated(self, angle, axis=None, point=None): # type: (...) -> G
transformed
"""
from compas.geometry import Rotation

if axis is None:
axis = [0.0, 0.0, 1.0]

return self.transformed(Rotation.from_axis_and_angle(axis, angle, point))
geometry = self.copy() # type: Geometry
geometry.rotate(angle=angle, axis=axis, point=point)
return geometry # type: ignore

0 comments on commit 7b4c795

Please sign in to comment.