From 730be56492f9ea936c425939ee085d146ccd5e89 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Fri, 22 Sep 2023 13:56:15 +0200 Subject: [PATCH] feature: Add method `$microplateSet->positionFromLocation($location, $direction)` --- CHANGELOG.md | 8 +++++++- src/MicroplateSet/MicroplateSet.php | 16 +++++++++++++++- .../Unit/MicroplateSet/MicroplateSetABCDTest.php | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bcef50..4c0b6c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -## v6.3.0 +## v6.4.0 + +### Added + +- Add method `$microplateSet->positionFromLocation($location, $direction)` + +- ## v6.3.0 ### Added diff --git a/src/MicroplateSet/MicroplateSet.php b/src/MicroplateSet/MicroplateSet.php index 2fd52cd..5cbd00a 100644 --- a/src/MicroplateSet/MicroplateSet.php +++ b/src/MicroplateSet/MicroplateSet.php @@ -20,7 +20,7 @@ public function __construct(CoordinateSystem $coordinateSystem) $this->coordinateSystem = $coordinateSystem; } - /** @return list */ + /** @return array */ abstract public function plateIDs(): array; public function plateCount(): int @@ -50,4 +50,18 @@ public function locationFromPosition(int $setPosition, FlowDirection $direction) $this->plateIDs()[$plateIndex] ); } + + /** + * @param Location $location + */ + public function positionFromLocation(Location $location, FlowDirection $direction): int + { + $positionOnPlate = $location->coordinates + ->position($direction); + + $positionOnSet = $positionOnPlate * array_keys($this->plateIDs())[$location->plateID]; + assert(is_int($positionOnSet)); + + return $positionOnSet; + } } diff --git a/tests/Unit/MicroplateSet/MicroplateSetABCDTest.php b/tests/Unit/MicroplateSet/MicroplateSetABCDTest.php index cdfcbe0..bd2ab09 100644 --- a/tests/Unit/MicroplateSet/MicroplateSetABCDTest.php +++ b/tests/Unit/MicroplateSet/MicroplateSetABCDTest.php @@ -99,6 +99,8 @@ public function testSetLocationFromSetPositionFor96Wells(int $position, string $ $location = $microplateSet->locationFromPosition($position, FlowDirection::COLUMN()); self::assertSame($coordinatesString, $location->coordinates->toString()); self::assertSame($plateID, $location->plateID); + + self::assertSame($position, $microplateSet->positionFromLocation($location, FlowDirection::COLUMN())); } /** @return iterable */