Skip to content

Commit

Permalink
fix: get_absolute_location includes anchor even if parent is None
Browse files Browse the repository at this point in the history
  • Loading branch information
rickwierenga committed Nov 13, 2024
1 parent a8c24d5 commit bb82c22
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- fix get_child_location for resources rotated by 180 degrees (https://github.com/PyLabRobot/pylabrobot/pull/269)
- volume tracking on channel 1-n (https://github.com/PyLabRobot/pylabrobot/pull/273)
- correct trash location on Vantage (https://github.com/PyLabRobot/pylabrobot/pull/285)
- `Resource.get_absolute_location` includes anchor even if parent is None

### Removed

Expand Down
18 changes: 10 additions & 8 deletions pylabrobot/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,24 @@ def get_absolute_location(self, x: str = "l", y: str = "f", z: str = "b") -> Coo
"""

assert self.location is not None, f"Resource {self.name} has no location."

rotated_anchor = Coordinate(
*matrix_vector_multiply_3x3(
self.get_absolute_rotation().get_rotation_matrix(),
self.get_anchor(x=x, y=y, z=z).vector(),
)
)

if self.parent is None:
return self.location
parent_pos = self.parent.get_absolute_location()
return self.location + rotated_anchor

parent_pos = self.parent.get_absolute_location()
rotated_location = Coordinate(
*matrix_vector_multiply_3x3(
self.parent.get_absolute_rotation().get_rotation_matrix(),
self.location.vector(),
)
)
rotated_anchor = Coordinate(
*matrix_vector_multiply_3x3(
self.get_absolute_rotation().get_rotation_matrix(),
self.get_anchor(x=x, y=y, z=z).vector(),
)
)
return parent_pos + rotated_location + rotated_anchor

def _get_rotated_corners(self) -> List[Coordinate]:
Expand Down
9 changes: 7 additions & 2 deletions pylabrobot/resources/resource_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Tests for Resource"""

import math
import unittest
import unittest.mock
Expand Down Expand Up @@ -138,6 +136,13 @@ def test_get_absolute_location_with_anchor(self):
Coordinate(20, 15, 20),
)

single = Resource("single", size_x=5, size_y=5, size_z=5)
single.location = Coordinate.zero()
self.assertEqual(
single.get_absolute_location(x="right", y="front", z="top"),
Coordinate(5, 0, 5),
)

def test_unassign_child(self):
deck = Deck()
parent = Resource("parent", size_x=10, size_y=10, size_z=10)
Expand Down

0 comments on commit bb82c22

Please sign in to comment.