Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

feature: Add method `$microplateSet->positionFromLocation($location, … #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Add method `$microplateSet->positionFromLocation($location, $direction)`
- Add method `MicroplateSet::positionFromLocation`


- ## v6.3.0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- ## v6.3.0
## v6.3.0


### Added

Expand Down
16 changes: 15 additions & 1 deletion src/MicroplateSet/MicroplateSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(CoordinateSystem $coordinateSystem)
$this->coordinateSystem = $coordinateSystem;
}

/** @return list<string> */
/** @return array<int,string> */
Copy link
Member

Choose a reason for hiding this comment

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

list is a stronger guarantee, why weaken it?

abstract public function plateIDs(): array;

public function plateCount(): int
Expand Down Expand Up @@ -50,4 +50,18 @@ public function locationFromPosition(int $setPosition, FlowDirection $direction)
$this->plateIDs()[$plateIndex]
);
}

/**
* @param Location<TCoordinateSystem> $location
*/
Comment on lines +54 to +56
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* @param Location<TCoordinateSystem> $location
*/
/** @param Location<TCoordinateSystem> $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));
Comment on lines +62 to +63
Copy link
Member

Choose a reason for hiding this comment

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

This makes no sense to me, array_keys($this->plateIDs()) will be something like [0, 1, ..] - then you index into this with another plateID? Maybe you need array_search?


return $positionOnSet;
}
}
2 changes: 2 additions & 0 deletions tests/Unit/MicroplateSet/MicroplateSetABCDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<array{position: int, coordinatesString: string, plateID: string}> */
Expand Down