Improve the mosaic algorithm further #43

Merged
Roflin merged 4 commits from improve-mosaic into master 2023-12-21 16:34:27 +01:00
2 changed files with 27 additions and 3 deletions
Showing only changes of commit d2fa547257 - Show all commits

View File

@ -8,15 +8,18 @@
class AssetIterator extends Asset
{
private Database $db;
private $direction;
private $return_format;
private $res_assets;
private $res_meta;
private $res_thumbs;
private Database $db;
protected function __construct($res_assets, $res_meta, $res_thumbs, $return_format)
protected function __construct($res_assets, $res_meta, $res_thumbs, $return_format, $direction)
{
$this->db = Registry::get('db');
$this->direction = $direction;
$this->res_assets = $res_assets;
$this->res_meta = $res_meta;
$this->res_thumbs = $res_thumbs;
@ -174,7 +177,7 @@ class AssetIterator extends Asset
'_' => '_',
]);
$iterator = new self($res_assets, $res_meta, $res_thumbs, $return_format);
$iterator = new self($res_assets, $res_meta, $res_thumbs, $return_format, $params['direction']);
// Returning total count, too?
if ($return_count)
@ -190,4 +193,14 @@ class AssetIterator extends Asset
else
return $iterator;
}
public function isAscending()
{
return $this->direction === 'asc';
}
public function isDescending()
{
return $this->direction === 'desc';
}
}

View File

@ -8,6 +8,7 @@
class PhotoMosaic
{
private $descending;
private AssetIterator $iterator;
private $layouts;
private $processedImages = 0;
@ -19,6 +20,7 @@ class PhotoMosaic
{
$this->iterator = $iterator;
$this->layouts = $this->availableLayouts();
$this->descending = $iterator->isDescending();
}
public function __destruct()
@ -143,8 +145,17 @@ class PhotoMosaic
return -$priority_diff;
}
private function orderQueueByDate()
{
usort($this->queue, function($a, $b) {
$score = $a->getDateCaptured() <=> $b->getDateCaptured();
return $score * ($this->descending ? -1 : 1);
});
}
private function pushToQueue(Image $image)
{
$this->queue[] = $image;
$this->orderQueueByDate();
}
}