Rewrite mosaic algorithm using declarative paradigm #42

Merged
Roflin merged 8 commits from new-mosaic into master 2023-12-03 12:37:41 +01:00
Showing only changes of commit 8e0e642d34 - Show all commits

View File

@ -8,10 +8,9 @@
class PhotoMosaic
{
private $queue = [];
const NUM_DAYS_CUTOFF = 7;
private AssetIterator $iterator;
private $queue = [];
public function __construct(AssetIterator $iterator)
{
@ -23,21 +22,9 @@ class PhotoMosaic
$this->iterator->clean();
}
public static function getRecentPhotos()
private static function daysApart(Image $a, Image $b)
{
return new self(AssetIterator::getByOptions([
'tag' => 'photo',
'order' => 'date_captured',
'direction' => 'desc',
'limit' => 15, // worst case: 3 rows * (portrait + 4 thumbs)
]));
}
private static function matchTypeMask(Image $image, $type_mask)
{
return ($type_mask & Image::TYPE_PANORAMA) && $image->isPanorama() ||
($type_mask & Image::TYPE_LANDSCAPE) && $image->isLandscape() ||
($type_mask & Image::TYPE_PORTRAIT) && $image->isPortrait();
return $a->getDateCaptured()->diff($b->getDateCaptured())->days;
}
private function fetchImage($desired_type = Image::TYPE_PORTRAIT | Image::TYPE_LANDSCAPE | Image::TYPE_PANORAMA, Image $refDateImage = null)
@ -66,25 +53,14 @@ class PhotoMosaic
return false;
}
private function pushToQueue(Image $image)
public static function getRecentPhotos()
{
$this->queue[] = $image;
}
private static function orderPhotos(Image $a, Image $b)
{
// Show images of highest priority first.
$priority_diff = $a->getPriority() - $b->getPriority();
if ($priority_diff !== 0)
return -$priority_diff;
// In other cases, we'll just show the newest first.
return $a->getDateCaptured() <=> $b->getDateCaptured();
}
private static function daysApart(Image $a, Image $b)
{
return $a->getDateCaptured()->diff($b->getDateCaptured())->days;
return new self(AssetIterator::getByOptions([
'tag' => 'photo',
'order' => 'date_captured',
'direction' => 'desc',
'limit' => 15, // worst case: 3 rows * (portrait + 4 thumbs)
]));
}
public function getRow()
@ -171,4 +147,27 @@ class PhotoMosaic
else
return [$photos, 'landscapes'];
}
private static function matchTypeMask(Image $image, $type_mask)
{
return ($type_mask & Image::TYPE_PANORAMA) && $image->isPanorama() ||
($type_mask & Image::TYPE_LANDSCAPE) && $image->isLandscape() ||
($type_mask & Image::TYPE_PORTRAIT) && $image->isPortrait();
}
private static function orderPhotos(Image $a, Image $b)
{
// Show images of highest priority first.
$priority_diff = $a->getPriority() - $b->getPriority();
if ($priority_diff !== 0)
return -$priority_diff;
// In other cases, we'll just show the newest first.
return $a->getDateCaptured() <=> $b->getDateCaptured();
}
private function pushToQueue(Image $image)
{
$this->queue[] = $image;
}
}