Skip to content

Commit 8253ab4

Browse files
committed
fix: get_absolute_location includes anchor even if parent is None
1 parent 961e00d commit 8253ab4

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
129129
- fix get_child_location for resources rotated by 180 degrees (https://github.com/PyLabRobot/pylabrobot/pull/269)
130130
- volume tracking on channel 1-n (https://github.com/PyLabRobot/pylabrobot/pull/273)
131131
- correct trash location on Vantage (https://github.com/PyLabRobot/pylabrobot/pull/285)
132+
- `Resource.get_absolute_location` includes anchor even if parent is None
132133

133134
### Removed
134135

pylabrobot/resources/resource.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,24 @@ def get_absolute_location(self, x: str = "l", y: str = "f", z: str = "b") -> Coo
212212
"""
213213

214214
assert self.location is not None, f"Resource {self.name} has no location."
215+
216+
rotated_anchor = Coordinate(
217+
*matrix_vector_multiply_3x3(
218+
self.get_absolute_rotation().get_rotation_matrix(),
219+
self.get_anchor(x=x, y=y, z=z).vector(),
220+
)
221+
)
222+
215223
if self.parent is None:
216-
return self.location
217-
parent_pos = self.parent.get_absolute_location()
224+
return self.location + rotated_anchor
218225

226+
parent_pos = self.parent.get_absolute_location()
219227
rotated_location = Coordinate(
220228
*matrix_vector_multiply_3x3(
221229
self.parent.get_absolute_rotation().get_rotation_matrix(),
222230
self.location.vector(),
223231
)
224232
)
225-
rotated_anchor = Coordinate(
226-
*matrix_vector_multiply_3x3(
227-
self.get_absolute_rotation().get_rotation_matrix(),
228-
self.get_anchor(x=x, y=y, z=z).vector(),
229-
)
230-
)
231233
return parent_pos + rotated_location + rotated_anchor
232234

233235
def _get_rotated_corners(self) -> List[Coordinate]:

pylabrobot/resources/resource_tests.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Tests for Resource"""
2-
31
import math
42
import unittest
53
import unittest.mock
@@ -138,6 +136,13 @@ def test_get_absolute_location_with_anchor(self):
138136
Coordinate(20, 15, 20),
139137
)
140138

139+
single = Resource("single", size_x=5, size_y=5, size_z=5)
140+
single.location = Coordinate.zero()
141+
self.assertEqual(
142+
single.get_absolute_location(x="right", y="front", z="top"),
143+
Coordinate(5, 0, 5),
144+
)
145+
141146
def test_unassign_child(self):
142147
deck = Deck()
143148
parent = Resource("parent", size_x=10, size_y=10, size_z=10)

0 commit comments

Comments
 (0)