|
11 | 11 | from compas.geometry import Box
|
12 | 12 | from compas.geometry import Frame
|
13 | 13 | from compas.geometry import Translation
|
| 14 | + from compas.geometry import Transformation |
14 | 15 | from compas.scene import Group
|
15 | 16 |
|
16 | 17 | @pytest.fixture(autouse=True)
|
@@ -104,6 +105,42 @@ def test_sceneobject_transform():
|
104 | 105 | assert sceneobj3.frame == Frame([30.0, 20.0, 10.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0])
|
105 | 106 | assert sceneobj3.frame.to_transformation() == Translation.from_vector([30.0, 20.0, 10.0])
|
106 | 107 |
|
| 108 | + def test_sceneobject_frame_and_worldtransformation_setters(): |
| 109 | + """Test that frame and worldtransformation setters work correctly.""" |
| 110 | + scene = Scene() |
| 111 | + |
| 112 | + # Test on root object |
| 113 | + root_obj = scene.add(Box()) |
| 114 | + test_frame = Frame([10.0, 20.0, 30.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]) |
| 115 | + root_obj.frame = test_frame |
| 116 | + assert root_obj.frame == test_frame |
| 117 | + assert root_obj.worldtransformation == Transformation.from_frame(test_frame) |
| 118 | + |
| 119 | + # Test worldtransformation setter on root object |
| 120 | + test_transform = Translation.from_vector([5.0, 10.0, 15.0]) |
| 121 | + root_obj.worldtransformation = test_transform |
| 122 | + assert root_obj.worldtransformation == test_transform |
| 123 | + assert root_obj.transformation == test_transform |
| 124 | + |
| 125 | + # Test with parent-child relationship |
| 126 | + parent_obj = scene.add(Box()) |
| 127 | + child_obj = scene.add(Box(), parent=parent_obj) |
| 128 | + parent_obj.transformation = Translation.from_vector([10.0, 0.0, 0.0]) |
| 129 | + |
| 130 | + # Test frame setter with parent |
| 131 | + child_frame = Frame([30.0, 20.0, 10.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]) |
| 132 | + child_obj.frame = child_frame |
| 133 | + assert child_obj.frame == child_frame |
| 134 | + expected_local = parent_obj.worldtransformation.inverse() * Transformation.from_frame(child_frame) |
| 135 | + assert child_obj.transformation == expected_local |
| 136 | + |
| 137 | + # Test worldtransformation setter with parent |
| 138 | + child_world_transform = Translation.from_vector([50.0, 30.0, 20.0]) |
| 139 | + child_obj.worldtransformation = child_world_transform |
| 140 | + assert child_obj.worldtransformation == child_world_transform |
| 141 | + expected_local = parent_obj.worldtransformation.inverse() * child_world_transform |
| 142 | + assert child_obj.transformation == expected_local |
| 143 | + |
107 | 144 | def test_scene_clear():
|
108 | 145 | scene = Scene()
|
109 | 146 | sceneobj1 = scene.add(Box())
|
|
0 commit comments