Rewrite mosaic algorithm using declarative paradigm #42
@ -10,11 +10,13 @@ class PhotoMosaic
|
|||||||
{
|
{
|
||||||
const NUM_DAYS_CUTOFF = 7;
|
const NUM_DAYS_CUTOFF = 7;
|
||||||
private AssetIterator $iterator;
|
private AssetIterator $iterator;
|
||||||
|
private $layouts;
|
||||||
private $queue = [];
|
private $queue = [];
|
||||||
|
|
||||||
public function __construct(AssetIterator $iterator)
|
public function __construct(AssetIterator $iterator)
|
||||||
{
|
{
|
||||||
$this->iterator = $iterator;
|
$this->iterator = $iterator;
|
||||||
|
$this->layouts = $this->availableLayouts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
@ -22,6 +24,28 @@ class PhotoMosaic
|
|||||||
$this->iterator->clean();
|
$this->iterator->clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function availableLayouts()
|
||||||
|
{
|
||||||
|
static $layouts = [
|
||||||
|
// Single panorama
|
||||||
|
'panorama' => [Image::TYPE_PANORAMA],
|
||||||
|
|
||||||
|
// Big-small juxtapositions
|
||||||
|
'portrait' => [Image::TYPE_PORTRAIT, Image::TYPE_LANDSCAPE, Image::TYPE_LANDSCAPE],
|
||||||
|
'landscape' => [Image::TYPE_LANDSCAPE, Image::TYPE_LANDSCAPE, Image::TYPE_LANDSCAPE],
|
||||||
|
|
||||||
|
// Single row of three
|
||||||
|
'landscapes' => [Image::TYPE_LANDSCAPE, Image::TYPE_LANDSCAPE, Image::TYPE_LANDSCAPE],
|
||||||
|
'portraits' => [Image::TYPE_PORTRAIT, Image::TYPE_PORTRAIT, Image::TYPE_PORTRAIT],
|
||||||
|
|
||||||
|
// Fallback layouts
|
||||||
|
'duo' => [Image::TYPE_LANDSCAPE, Image::TYPE_LANDSCAPE],
|
||||||
|
'single' => [Image::TYPE_LANDSCAPE | Image::TYPE_PORTRAIT],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $layouts;
|
||||||
|
}
|
||||||
|
|
||||||
private static function daysApart(Image $a, Image $b)
|
private static function daysApart(Image $a, Image $b)
|
||||||
{
|
{
|
||||||
return $a->getDateCaptured()->diff($b->getDateCaptured())->days;
|
return $a->getDateCaptured()->diff($b->getDateCaptured())->days;
|
||||||
|
Loading…
Reference in New Issue
Block a user