Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added the magic method `__str__` to `compas.geoemetry.Transformation`.

### Changed

* Fixed bug where mimic joints were considered configurable.
Expand Down
7 changes: 7 additions & 0 deletions src/compas/geometry/transformations/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def __eq__(self, other, tol=1e-05):
def __repr__(self):
return "Transformation({})".format(self.matrix)

def __str__(self):
s = "[[%s],\n" % ",".join([("%.4f" % n).rjust(10) for n in self.matrix[0]])
s += " [%s],\n" % ",".join([("%.4f" % n).rjust(10) for n in self.matrix[1]])
s += " [%s],\n" % ",".join([("%.4f" % n).rjust(10) for n in self.matrix[2]])
s += " [%s]]\n" % ",".join([("%.4f" % n).rjust(10) for n in self.matrix[3]])
return s

def __len__(self):
return len(self.matrix)

Expand Down
24 changes: 22 additions & 2 deletions tests/compas/geometry/test_transformations/test_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,30 @@ def test_list():
assert T.list == [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]


def concatenate():
def test_concatenated():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test was being skipped because it lacked the test_ prefix....

trans1 = [1, 2, 3]
angle1 = [-2.142, 1.141, -0.142]
T1 = Translation.from_vector(trans1)
R1 = Rotation.from_euler_angles(angle1)
M1 = T1.concatenate(R1)
M1 = T1.concatenated(R1)
assert allclose(M1, T1 * R1)


def test___repr__():
trans = [1, 2, 3]
axes = [-2.142, 1.141, -0.142]
angle = 0.7854
R = Rotation.from_axis_and_angle(axes, angle, point=trans)
assert R == eval(repr(R))


def test___str__():
s = '[[ 0.9345, -0.0798, 0.3469, -0.8157],\n' + \
' [ -0.1624, 0.7716, 0.6150, -1.2258],\n' + \
' [ -0.3168, -0.6311, 0.7081, 2.4546],\n' + \
' [ 0.0000, 0.0000, 0.0000, 1.0000]]\n'
trans = [1, 2, 3]
axes = [-2.142, 1.141, -0.142]
angle = 0.7854
R = Rotation.from_axis_and_angle(axes, angle, point=trans)
assert s == str(R)