mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-11 22:38:42 +00:00
phpstan fixes
This commit is contained in:
parent
921703a5b5
commit
0422411c89
|
|
@ -14,10 +14,10 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\Algorithm\Backpack;
|
namespace phpOMS\Algorithm\Knappsack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matching a value with a set of coins
|
* Backpack for the Knappsack problem
|
||||||
*
|
*
|
||||||
* @package phpOMS\Algorithm\Knappsack
|
* @package phpOMS\Algorithm\Knappsack
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
|
|
@ -26,38 +26,99 @@ namespace phpOMS\Algorithm\Backpack;
|
||||||
*/
|
*/
|
||||||
class Backpack
|
class Backpack
|
||||||
{
|
{
|
||||||
private $maxCost = 0.0;
|
/**
|
||||||
|
* Maximum amount of cost this backpack can hold
|
||||||
|
*
|
||||||
|
* @var float
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private float $maxCost = 0.0;
|
||||||
|
|
||||||
private $value = 0.0;
|
/**
|
||||||
|
* Current value
|
||||||
|
*
|
||||||
|
* @var float
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private float $value = 0.0;
|
||||||
|
|
||||||
private $cost = 0.0;
|
/**
|
||||||
|
* Current cost
|
||||||
|
*
|
||||||
|
* @var float
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private float $cost = 0.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Items inside the backpack
|
||||||
|
*
|
||||||
|
* @var Item[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private array $items = [];
|
private array $items = [];
|
||||||
|
|
||||||
public function __construct($maxCost)
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param float $maxCost Maximum amount of costs the backpack can hold
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function __construct(float $maxCost)
|
||||||
{
|
{
|
||||||
$this->maxCost = $maxCost;
|
$this->maxCost = $maxCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValue()
|
/**
|
||||||
|
* Get the value of the stored items
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getValue() : float
|
||||||
{
|
{
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCost()
|
/**
|
||||||
|
* Get the cost of the stored items
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getCost() : float
|
||||||
{
|
{
|
||||||
return $this->cost;
|
return $this->cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get items
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getItems() : array
|
public function getItems() : array
|
||||||
{
|
{
|
||||||
return $this->items;
|
return $this->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add item to backpack
|
||||||
|
*
|
||||||
|
* @param Item $item Item
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function addItem(Item $item) : void
|
public function addItem(Item $item) : void
|
||||||
{
|
{
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
$this->value += $item->getValue();
|
$this->value += $item->getValue();
|
||||||
$this->cost += $item->getCost();
|
$this->cost += $item->getCost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\Algorithm\PathFinding;
|
namespace phpOMS\Algorithm\PathFinding;
|
||||||
|
|
||||||
|
use phpOMS\Stdlib\Base\Heap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform path finding.
|
* Perform path finding.
|
||||||
*
|
*
|
||||||
|
|
@ -24,14 +26,19 @@ namespace phpOMS\Algorithm\PathFinding;
|
||||||
*/
|
*/
|
||||||
class JumpPointSearch implements PathFinderInterface
|
class JumpPointSearch implements PathFinderInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public static function findPath(
|
public static function findPath(
|
||||||
int $startX, int $startY,
|
int $startX, int $startY,
|
||||||
int $endX, int $endY,
|
int $endX, int $endY,
|
||||||
Grid $grid,
|
Grid $grid,
|
||||||
int $heuristic, int $movement
|
int $heuristic, int $movement
|
||||||
) : Path {
|
) : Path {
|
||||||
|
/** @var null|AStarNode $startNode */
|
||||||
$startNode = $grid->getNode($startX, $startY);
|
$startNode = $grid->getNode($startX, $startY);
|
||||||
$endNode = $grid->getNode($endX, $endY);
|
/** @var null|AStarNode $endNode */
|
||||||
|
$endNode = $grid->getNode($endX, $endY);
|
||||||
|
|
||||||
if ($startNode === null || $endNode === null) {
|
if ($startNode === null || $endNode === null) {
|
||||||
return new Path($grid);
|
return new Path($grid);
|
||||||
|
|
@ -41,8 +48,9 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
$startNode->setF(0.0);
|
$startNode->setF(0.0);
|
||||||
$startNode->setOpened(true);
|
$startNode->setOpened(true);
|
||||||
|
|
||||||
$openList = new Heap(function($node1, $node2) { return $node1->getF() - $node2->getF(); });
|
$openList = new Heap(function(AStarNode $node1, AStarNode $node2) { return $node1->getF() - $node2->getF(); });
|
||||||
$openList->push($startNode);
|
$openList->push($startNode);
|
||||||
|
|
||||||
$node = null;
|
$node = null;
|
||||||
|
|
||||||
while (!$openList->isEmpty()) {
|
while (!$openList->isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class Grid
|
||||||
|
|
||||||
public function getNode(int $x, int $y) : ?Node
|
public function getNode(int $x, int $y) : ?Node
|
||||||
{
|
{
|
||||||
if (!isset($this->nodes[$y]) || $this->nodes[$y][$x]) {
|
if (!isset($this->nodes[$y]) || !isset($this->nodes[$y][$x])) {
|
||||||
// todo: add null node to grid because we need to modify some properties later on and remember them!
|
// todo: add null node to grid because we need to modify some properties later on and remember them!
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -59,6 +59,15 @@ class Grid
|
||||||
return $this->nodes[$y][$x];
|
return $this->nodes[$y][$x];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isWalkable(int $x, int $y) : bool
|
||||||
|
{
|
||||||
|
if (!isset($this->nodes[$y]) || !isset($this->nodes[$y][$x]) || !$this->nodes[$y][$x]->isWalkable()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function getNeighbors(Node $node, int $movement) : array
|
public function getNeighbors(Node $node, int $movement) : array
|
||||||
{
|
{
|
||||||
$x = $node->getX();
|
$x = $node->getX();
|
||||||
|
|
@ -75,22 +84,22 @@ class Grid
|
||||||
$d3 = false;
|
$d3 = false;
|
||||||
|
|
||||||
// todo: check $x and $y because original implementation is flipped!!!
|
// todo: check $x and $y because original implementation is flipped!!!
|
||||||
if ($this->getNode($x, $y - 1)->isWalkable()) {
|
if ($this->isWalkable($x, $y - 1)) {
|
||||||
$neighbors[] = $this->getNode($x, $y - 1);
|
$neighbors[] = $this->getNode($x, $y - 1);
|
||||||
$s0 = true;
|
$s0 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getNode($x + 1, $y)->isWalkable()) {
|
if ($this->isWalkable($x + 1, $y)) {
|
||||||
$neighbors[] = $this->getNode($x + 1, $y);
|
$neighbors[] = $this->getNode($x + 1, $y);
|
||||||
$s1 = true;
|
$s1 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getNode($x, $y + 1)->isWalkable()) {
|
if ($this->isWalkable($x, $y + 1)) {
|
||||||
$neighbors[] = $this->getNode($x, $y + 1);
|
$neighbors[] = $this->getNode($x, $y + 1);
|
||||||
$s2 = true;
|
$s2 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getNode($x - 1, $y)->isWalkable()) {
|
if ($this->isWalkable($x - 1, $y)) {
|
||||||
$neighbors[] = $this->getNode($x - 1, $y);
|
$neighbors[] = $this->getNode($x - 1, $y);
|
||||||
$s3 = true;
|
$s3 = true;
|
||||||
}
|
}
|
||||||
|
|
@ -116,19 +125,19 @@ class Grid
|
||||||
$d3 = true;
|
$d3 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($d0 && $this->getNode($x - 1, $y - 1)->isWalkable()) {
|
if ($d0 && $this->isWalkable($x - 1, $y - 1)) {
|
||||||
$neighbors[] = $this->getNode($x - 1, $y - 1);
|
$neighbors[] = $this->getNode($x - 1, $y - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($d1 && $this->getNode($x + 1, $y - 1)->isWalkable()) {
|
if ($d1 && $this->isWalkable($x + 1, $y - 1)) {
|
||||||
$neighbors[] = $this->getNode($x + 1, $y - 1);
|
$neighbors[] = $this->getNode($x + 1, $y - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($d2 && $this->getNode($x + 1, $y + 1)->isWalkable()) {
|
if ($d2 && $this->isWalkable($x + 1, $y + 1)) {
|
||||||
$neighbors[] = $this->getNode($x + 1, $y + 1);
|
$neighbors[] = $this->getNode($x + 1, $y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($d3 && $this->getNode($x - 1, $y + 1)->isWalkable()) {
|
if ($d3 && $this->isWalkable($x - 1, $y + 1)) {
|
||||||
$neighbors[] = $this->getNode($x - 1, $y + 1);
|
$neighbors[] = $this->getNode($x - 1, $y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\Algorithm\PathFinding;
|
namespace phpOMS\Algorithm\PathFinding;
|
||||||
|
|
||||||
|
use phpOMS\Stdlib\Base\Heap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform path finding.
|
* Perform path finding.
|
||||||
*
|
*
|
||||||
|
|
@ -24,14 +26,19 @@ namespace phpOMS\Algorithm\PathFinding;
|
||||||
*/
|
*/
|
||||||
class JumpPointSearch implements PathFinderInterface
|
class JumpPointSearch implements PathFinderInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public static function findPath(
|
public static function findPath(
|
||||||
int $startX, int $startY,
|
int $startX, int $startY,
|
||||||
int $endX, int $endY,
|
int $endX, int $endY,
|
||||||
Grid $grid,
|
Grid $grid,
|
||||||
int $heuristic, int $movement
|
int $heuristic, int $movement
|
||||||
) : Path {
|
) : Path {
|
||||||
|
/** @var null|JumpPointNode $startNode */
|
||||||
$startNode = $grid->getNode($startX, $startY);
|
$startNode = $grid->getNode($startX, $startY);
|
||||||
$endNode = $grid->getNode($endX, $endY);
|
/** @var null|JumpPointNode $endNode */
|
||||||
|
$endNode = $grid->getNode($endX, $endY);
|
||||||
|
|
||||||
if ($startNode === null || $endNode === null) {
|
if ($startNode === null || $endNode === null) {
|
||||||
return new Path($grid);
|
return new Path($grid);
|
||||||
|
|
@ -66,7 +73,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function identifySuccessors(Node $node, Grid $grid, int $heuristic, int $movement, Node $endNode, Heap $openList) : Heap
|
public static function identifySuccessors(JumpPointNode $node, Grid $grid, int $heuristic, int $movement, JumpPointNode $endNode, Heap $openList) : Heap
|
||||||
{
|
{
|
||||||
$neighbors = self::findNeighbors($node, $movement, $grid);
|
$neighbors = self::findNeighbors($node, $movement, $grid);
|
||||||
$neighborsLength = \count($neighbors);
|
$neighborsLength = \count($neighbors);
|
||||||
|
|
@ -84,7 +91,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
|
|
||||||
if (!$jumpPoint->isOpened() || $ng < $jumpPoint->getG()) {
|
if (!$jumpPoint->isOpened() || $ng < $jumpPoint->getG()) {
|
||||||
$jumpPoint->setG($ng);
|
$jumpPoint->setG($ng);
|
||||||
$jumpPoint->setH($jumpPoint->getH() ?? Heuristic::metric($jumpPoint->getCoordinates(), $endNode->getCoordinates(), $metric));
|
$jumpPoint->setH($jumpPoint->getH() ?? Heuristic::metric($jumpPoint->getCoordinates(), $endNode->getCoordinates(), $heuristic));
|
||||||
$jumpPoint->setF($jumpPoint->getG() + $jumpPoint->getH());
|
$jumpPoint->setF($jumpPoint->getG() + $jumpPoint->getH());
|
||||||
$jumpPoint->setParent($node);
|
$jumpPoint->setParent($node);
|
||||||
|
|
||||||
|
|
@ -100,7 +107,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $openList;
|
return $openList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function findNeighbors(Node $node, int $movement, Grid $grid) : array
|
private static function findNeighbors(JumpPointNode $node, int $movement, Grid $grid) : array
|
||||||
{
|
{
|
||||||
if ($movement === MovementType::STRAIGHT) {
|
if ($movement === MovementType::STRAIGHT) {
|
||||||
return self::findNeighborsStraight($node, $grid);
|
return self::findNeighborsStraight($node, $grid);
|
||||||
|
|
@ -113,7 +120,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return self::findNeighborsDiagonalNoObstacle($node, $grid);
|
return self::findNeighborsDiagonalNoObstacle($node, $grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function findNeighborsStraight(Node $node, Grid $grid) : array
|
private static function findNeighborsStraight(JumpPointNode $node, Grid $grid) : array
|
||||||
{
|
{
|
||||||
if ($node->getParent() === null) {
|
if ($node->getParent() === null) {
|
||||||
return $grid->getNeighbors($node, MovementType::STRAIGHT);
|
return $grid->getNeighbors($node, MovementType::STRAIGHT);
|
||||||
|
|
@ -125,32 +132,34 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
$px = $node->getParent()->getX();
|
$px = $node->getParent()->getX();
|
||||||
$py = $node->getParent()->getY();
|
$py = $node->getParent()->getY();
|
||||||
|
|
||||||
|
/** @var int $dx */
|
||||||
$dx = ($x - $px) / \max(\abs($x - $px), 1);
|
$dx = ($x - $px) / \max(\abs($x - $px), 1);
|
||||||
|
/** @var int $dy */
|
||||||
$dy = ($y - $py) / \may(\abs($y - $py), 1);
|
$dy = ($y - $py) / \may(\abs($y - $py), 1);
|
||||||
|
|
||||||
$neighbors = [];
|
$neighbors = [];
|
||||||
if ($dx !== 0) {
|
if ($dx !== 0) {
|
||||||
if ($grid->getNode($x, $y - 1)->isWalkable()) {
|
if ($grid->isWalkable($x, $y - 1)) {
|
||||||
$neighbors[] = $grid->getNode($x, $y - 1);
|
$neighbors[] = $grid->getNode($x, $y - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x, $y + 1)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + 1)) {
|
||||||
$neighbors[] = $grid->getNode($x, $y + 1);
|
$neighbors[] = $grid->getNode($x, $y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x + $dx, $y)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y);
|
$neighbors[] = $grid->getNode($x + $dx, $y);
|
||||||
}
|
}
|
||||||
} elseif ($dy !== 0) {
|
} elseif ($dy !== 0) {
|
||||||
if ($grid->getNode($x - 1, $y)->isWalkable()) {
|
if ($grid->isWalkable($x - 1, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x - 1, $y);
|
$neighbors[] = $grid->getNode($x - 1, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x + 1, $y)->isWalkable()) {
|
if ($grid->isWalkable($x + 1, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + 1, $y);
|
$neighbors[] = $grid->getNode($x + 1, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x, $y + $dy);
|
$neighbors[] = $grid->getNode($x, $y + $dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +167,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $neighbors;
|
return $neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function findNeighborsDiagonal(Node $node, Grid $grid) : array
|
private static function findNeighborsDiagonal(JumpPointNode $node, Grid $grid) : array
|
||||||
{
|
{
|
||||||
if ($node->getParent() === null) {
|
if ($node->getParent() === null) {
|
||||||
return $grid->getNeighbors($node, MovementType::DIAGONAL);
|
return $grid->getNeighbors($node, MovementType::DIAGONAL);
|
||||||
|
|
@ -170,52 +179,54 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
$px = $node->getParent()->getX();
|
$px = $node->getParent()->getX();
|
||||||
$py = $node->getParent()->getY();
|
$py = $node->getParent()->getY();
|
||||||
|
|
||||||
|
/** @var int $dx */
|
||||||
$dx = ($x - $px) / \max(\abs($x - $px), 1);
|
$dx = ($x - $px) / \max(\abs($x - $px), 1);
|
||||||
|
/** @var int $dy */
|
||||||
$dy = ($y - $py) / \may(\abs($y - $py), 1);
|
$dy = ($y - $py) / \may(\abs($y - $py), 1);
|
||||||
|
|
||||||
$neighbors = [];
|
$neighbors = [];
|
||||||
if ($dx !== 0 && $dy !== 0) {
|
if ($dx !== 0 && $dy !== 0) {
|
||||||
if ($grid->getNode($x, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x, $y + $dy);
|
$neighbors[] = $grid->getNode($x, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x + $dx, $y)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y);
|
$neighbors[] = $grid->getNode($x + $dx, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x + $dx, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y + $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y + $dy);
|
$neighbors[] = $grid->getNode($x + $dx, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$grid->getNode($x - $dx, $y)->isWalkable()) {
|
if (!$grid->isWalkable($x - $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x - $dx, $y + $dy);
|
$neighbors[] = $grid->getNode($x - $dx, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$grid->getNode($x, $y - $dy)->isWalkable()) {
|
if (!$grid->isWalkable($x, $y - $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y - $dy);
|
$neighbors[] = $grid->getNode($x + $dx, $y - $dy);
|
||||||
}
|
}
|
||||||
} elseif ($dx === 0) {
|
} elseif ($dx === 0) {
|
||||||
if ($grid->getNode($x, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x, $y + $dy);
|
$neighbors[] = $grid->getNode($x, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$grid->getNode($x + 1, $y)->isWalkable()) {
|
if (!$grid->isWalkable($x + 1, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + 1, $y + $dy);
|
$neighbors[] = $grid->getNode($x + 1, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$grid->getNode($x - 1, $y)->isWalkable()) {
|
if (!$grid->isWalkable($x - 1, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x - 1, $y + $dy);
|
$neighbors[] = $grid->getNode($x - 1, $y + $dy);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($grid->getNode($x + $dx, $y)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y);
|
$neighbors[] = $grid->getNode($x + $dx, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$grid->getNode($x, $y + 1)->isWalkable()) {
|
if (!$grid->isWalkable($x, $y + 1)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y + 1);
|
$neighbors[] = $grid->getNode($x + $dx, $y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$grid->getNode($x, $y - 1)->isWalkable()) {
|
if (!$grid->isWalkable($x, $y - 1)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y - 1);
|
$neighbors[] = $grid->getNode($x + $dx, $y - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -223,7 +234,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $neighbors;
|
return $neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function findNeighborsDiagonalOneObstacle(Node $node, Grid $grid) : array
|
private static function findNeighborsDiagonalOneObstacle(JumpPointNode $node, Grid $grid) : array
|
||||||
{
|
{
|
||||||
if ($node->getParent() === null) {
|
if ($node->getParent() === null) {
|
||||||
return $grid->getNeighbors($node, MovementType::DIAGONAL_ONE_OBSTACLE);
|
return $grid->getNeighbors($node, MovementType::DIAGONAL_ONE_OBSTACLE);
|
||||||
|
|
@ -235,47 +246,49 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
$px = $node->getParent()->getX();
|
$px = $node->getParent()->getX();
|
||||||
$py = $node->getParent()->getY();
|
$py = $node->getParent()->getY();
|
||||||
|
|
||||||
|
/** @var int $dx */
|
||||||
$dx = ($x - $px) / \max(\abs($x - $px), 1);
|
$dx = ($x - $px) / \max(\abs($x - $px), 1);
|
||||||
|
/** @var int $dy */
|
||||||
$dy = ($y - $py) / \may(\abs($y - $py), 1);
|
$dy = ($y - $py) / \may(\abs($y - $py), 1);
|
||||||
|
|
||||||
$neighbors = [];
|
$neighbors = [];
|
||||||
if ($dx !== 0 && $dy !== 0) {
|
if ($dx !== 0 && $dy !== 0) {
|
||||||
if ($grid->getNode($x, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x, $y + $dy);
|
$neighbors[] = $grid->getNode($x, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x + $dx, $y)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y);
|
$neighbors[] = $grid->getNode($x + $dx, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x, $y + $dy) || $grid->getNode($x + $dx, $y)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + $dy) || $grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y + $dy);
|
$neighbors[] = $grid->getNode($x + $dx, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$grid->getNode($x - $dx, $y) && $grid->getNode($x, $y + $dy)->isWalkable()) {
|
if (!$grid->getNode($x - $dx, $y) && $grid->isWalkable($x, $y + $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x - $dx, $y + $dy);
|
$neighbors[] = $grid->getNode($x - $dx, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$grid->getNode($x, $y - $dy) && $grid->getNode($x + $dx, $y)->isWalkable()) {
|
if (!$grid->getNode($x, $y - $dy) && $grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y - $dy);
|
$neighbors[] = $grid->getNode($x + $dx, $y - $dy);
|
||||||
}
|
}
|
||||||
} elseif ($dx === 0) {
|
} elseif ($dx === 0) {
|
||||||
if ($grid->getNode($x, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x, $y + $dy);
|
$neighbors[] = $grid->getNode($x, $y + $dy);
|
||||||
if (!$grid->getNode($x + 1, $y)->isWalkable()) {
|
if (!$grid->isWalkable($x + 1, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + 1, $y + $dy);
|
$neighbors[] = $grid->getNode($x + 1, $y + $dy);
|
||||||
}
|
}
|
||||||
if (!$grid->getNode($x - 1, $y)->isWalkable()) {
|
if (!$grid->isWalkable($x - 1, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x - 1, $y + $dy);
|
$neighbors[] = $grid->getNode($x - 1, $y + $dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($grid->getNode($x + $dx, $y)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y);
|
$neighbors[] = $grid->getNode($x + $dx, $y);
|
||||||
if (!$grid->getNode($x, $y + 1)->isWalkable()) {
|
if (!$grid->isWalkable($x, $y + 1)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y + 1);
|
$neighbors[] = $grid->getNode($x + $dx, $y + 1);
|
||||||
}
|
}
|
||||||
if (!$grid->getNode($x, $y - 1)->isWalkable()) {
|
if (!$grid->isWalkable($x, $y - 1)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y - 1);
|
$neighbors[] = $grid->getNode($x + $dx, $y - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +297,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $neighbors;
|
return $neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function findNeighborsDiagonalNoObstacle(Node $node, Grid $grid) : array
|
private static function findNeighborsDiagonalNoObstacle(JumpPointNode $node, Grid $grid) : array
|
||||||
{
|
{
|
||||||
if ($node->getParent() === null) {
|
if ($node->getParent() === null) {
|
||||||
return $grid->getNeighbors($node, MovementType::DIAGONAL_NO_OBSTACLE);
|
return $grid->getNeighbors($node, MovementType::DIAGONAL_NO_OBSTACLE);
|
||||||
|
|
@ -296,26 +309,28 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
$px = $node->getParent()->getX();
|
$px = $node->getParent()->getX();
|
||||||
$py = $node->getParent()->getY();
|
$py = $node->getParent()->getY();
|
||||||
|
|
||||||
|
/** @var int $dx */
|
||||||
$dx = ($x - $px) / \max(\abs($x - $px), 1);
|
$dx = ($x - $px) / \max(\abs($x - $px), 1);
|
||||||
|
/** @var int $dy */
|
||||||
$dy = ($y - $py) / \may(\abs($y - $py), 1);
|
$dy = ($y - $py) / \may(\abs($y - $py), 1);
|
||||||
|
|
||||||
$neighbors = [];
|
$neighbors = [];
|
||||||
if ($dx !== 0 && $dy !== 0) {
|
if ($dx !== 0 && $dy !== 0) {
|
||||||
if ($grid->getNode($x, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + $dy)) {
|
||||||
$neighbors[] = $grid->getNode($x, $y + $dy);
|
$neighbors[] = $grid->getNode($x, $y + $dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x + $dx, $y)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y);
|
$neighbors[] = $grid->getNode($x + $dx, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x, $y + $dy) || $grid->getNode($x + $dx, $y)->isWalkable()) {
|
if ($grid->isWalkable($x, $y + $dy) || $grid->isWalkable($x + $dx, $y)) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y + $dy);
|
$neighbors[] = $grid->getNode($x + $dx, $y + $dy);
|
||||||
}
|
}
|
||||||
} elseif ($dx !== 0 && $dy === 0) {
|
} elseif ($dx !== 0 && $dy === 0) {
|
||||||
$isNextWalkable = $grid->getNode($x + $dx, $y)->isWalkable();
|
$isNextWalkable = $grid->isWalkable($x + $dx, $y);
|
||||||
$isTopWalkable = $grid->getNode($x, $y + 1)->isWalkable();
|
$isTopWalkable = $grid->isWalkable($x, $y + 1);
|
||||||
$isBottomWalkable = $grid->getNode($x, $y - 1)->isWalkable();
|
$isBottomWalkable = $grid->isWalkable($x, $y - 1);
|
||||||
|
|
||||||
if ($isNextWalkable) {
|
if ($isNextWalkable) {
|
||||||
$neighbors[] = $grid->getNode($x + $dx, $y);
|
$neighbors[] = $grid->getNode($x + $dx, $y);
|
||||||
|
|
@ -336,9 +351,9 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
$neighbors[] = $grid->getNode($x, $y - 1);
|
$neighbors[] = $grid->getNode($x, $y - 1);
|
||||||
}
|
}
|
||||||
} elseif ($dx === 0 && $dy !== 0) {
|
} elseif ($dx === 0 && $dy !== 0) {
|
||||||
$isNextWalkable = $grid->getNode($x, $y + $dy)->isWalkable();
|
$isNextWalkable = $grid->isWalkable($x, $y + $dy);
|
||||||
$isRightWalkable = $grid->getNode($x + 1, $y)->isWalkable();
|
$isRightWalkable = $grid->isWalkable($x + 1, $y);
|
||||||
$isLeftWalkable = $grid->getNode($x - 1, $y)->isWalkable();
|
$isLeftWalkable = $grid->isWalkable($x - 1, $y);
|
||||||
|
|
||||||
if ($isNextWalkable) {
|
if ($isNextWalkable) {
|
||||||
$neighbors[] = $grid->getNode($x, $y + $dy);
|
$neighbors[] = $grid->getNode($x, $y + $dy);
|
||||||
|
|
@ -363,7 +378,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $neighbors;
|
return $neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function jump(Node $node, Node $endNode, int $movement, Grid $grid) : ?Node
|
private static function jump(JumpPointNode $node, JumpPointNode $endNode, int $movement, Grid $grid) : ?JumpPointNode
|
||||||
{
|
{
|
||||||
if ($movement === MovementType::STRAIGHT) {
|
if ($movement === MovementType::STRAIGHT) {
|
||||||
return self::jumpStraight($node, $endNode, $grid);
|
return self::jumpStraight($node, $endNode, $grid);
|
||||||
|
|
@ -376,7 +391,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return self::jumpDiagonalNoObstacle($node, $endNode, $grid);
|
return self::jumpDiagonalNoObstacle($node, $endNode, $grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function jumpStraight(Node $node, Node $endNode, Grid $grid) : ?Node
|
private static function jumpStraight(JumpPointNode $node, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode
|
||||||
{
|
{
|
||||||
$x = $node->getX();
|
$x = $node->getX();
|
||||||
$y = $node->getY();
|
$y = $node->getY();
|
||||||
|
|
@ -396,14 +411,14 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dx !== 0) {
|
if ($dx !== 0) {
|
||||||
if (($grid->getNode($x, $y - 1)->isWalkable() && !$grid->getNode($x - $dx, $y - 1)->isWalkable())
|
if (($grid->isWalkable($x, $y - 1) && !$grid->isWalkable($x - $dx, $y - 1))
|
||||||
|| ($grid->getNode($x, $y + 1)->isWalkable() && !$grid->getNode($x - $dx, $y + 1)->isWalkable())
|
|| ($grid->isWalkable($x, $y + 1) && !$grid->isWalkable($x - $dx, $y + 1))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
} elseif ($dy !== 0) {
|
} elseif ($dy !== 0) {
|
||||||
if (($grid->getNode($x - 1, $y)->isWalkable() && !$grid->getNode($x - 1, $y - $dy)->isWalkable())
|
if (($grid->isWalkable($x - 1, $y) && !$grid->isWalkable($x - 1, $y - $dy))
|
||||||
|| ($grid->getNode($x + 1, $y)->isWalkable() && !$grid->getNode($x + 1, $y - $dy)->isWalkable())
|
|| ($grid->isWalkable($x + 1, $y) && !$grid->isWalkable($x + 1, $y - $dy))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
@ -420,7 +435,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return self::jumpStraight($grid->getNode($x + $dx, $y + $dy), $node, $grid);
|
return self::jumpStraight($grid->getNode($x + $dx, $y + $dy), $node, $grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function jumpDiagonal(Node $node, Node $endNode, Grid $grid) : ?Node
|
private static function jumpDiagonal(JumpPointNode $node, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode
|
||||||
{
|
{
|
||||||
$x = $node->getX();
|
$x = $node->getX();
|
||||||
$y = $node->getY();
|
$y = $node->getY();
|
||||||
|
|
@ -440,8 +455,8 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dx !== 0 && $dy !== 0) {
|
if ($dx !== 0 && $dy !== 0) {
|
||||||
if (($grid->getNode($x - $dx, $y + $dy)->isWalkable() && !$grid->getNode($x - $dx, $y)->isWalkable())
|
if (($grid->isWalkable($x - $dx, $y + $dy) && !$grid->isWalkable($x - $dx, $y))
|
||||||
|| ($grid->getNode($x + $dx, $y - $dy)->isWalkable() && !$grid->getNode($x, $y - $dy)->isWalkable())
|
|| ($grid->isWalkable($x + $dx, $y - $dy) && !$grid->isWalkable($x, $y - $dy))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
@ -452,14 +467,14 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
} elseif ($dx !== 0 && $dy === 0) {
|
} elseif ($dx !== 0 && $dy === 0) {
|
||||||
if (($grid->getNode($x + $dx, $y + 1)->isWalkable() && !$grid->getNode($x, $y + 1)->isWalkable())
|
if (($grid->isWalkable($x + $dx, $y + 1) && !$grid->isWalkable($x, $y + 1))
|
||||||
|| ($grid->getNode($x + $dx, $y - 1)->isWalkable() && !$grid->getNode($x, $y - 1)->isWalkable())
|
|| ($grid->isWalkable($x + $dx, $y - 1) && !$grid->isWalkable($x, $y - 1))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (($grid->getNode($x + 1, $y + $dy)->isWalkable() && !$grid->getNode($x + 1, $y)->isWalkable())
|
if (($grid->isWalkable($x + 1, $y + $dy) && !$grid->isWalkable($x + 1, $y))
|
||||||
|| ($grid->getNode($x - 1, $y + $dy)->isWalkable() && !$grid->getNode($x - 1, $y)->isWalkable())
|
|| ($grid->isWalkable($x - 1, $y + $dy) && !$grid->isWalkable($x - 1, $y))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
@ -468,7 +483,7 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return self::jumpDiagonal($grid->getNode($x + $dx, $y + $dy), $node, $grid);
|
return self::jumpDiagonal($grid->getNode($x + $dx, $y + $dy), $node, $grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function jumpDiagonalOneObstacle(Node $node, Node $endNode, Grid $grid) : ?Node
|
private static function jumpDiagonalOneObstacle(JumpPointNode $node, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode
|
||||||
{
|
{
|
||||||
$x = $node->getX();
|
$x = $node->getX();
|
||||||
$y = $node->getY();
|
$y = $node->getY();
|
||||||
|
|
@ -488,8 +503,8 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dx !== 0 && $dy !== 0) {
|
if ($dx !== 0 && $dy !== 0) {
|
||||||
if (($grid->getNode($x - $dx, $y + $dy)->isWalkable() && !$grid->getNode($x - $dx, $y)->isWalkable())
|
if (($grid->isWalkable($x - $dx, $y + $dy) && !$grid->isWalkable($x - $dx, $y))
|
||||||
|| ($grid->getNode($x + $dx, $y - $dy)->isWalkable() && !$grid->getNode($x, $y - $dy)->isWalkable())
|
|| ($grid->isWalkable($x + $dx, $y - $dy) && !$grid->isWalkable($x, $y - $dy))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
@ -500,27 +515,27 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
} elseif ($dx !== 0 && $dy === 0) {
|
} elseif ($dx !== 0 && $dy === 0) {
|
||||||
if (($grid->getNode($x + $dx, $y + 1)->isWalkable() && !$grid->getNode($x, $y + 1)->isWalkable())
|
if (($grid->isWalkable($x + $dx, $y + 1) && !$grid->isWalkable($x, $y + 1))
|
||||||
|| ($grid->getNode($x + $dx, $y - 1)->isWalkable() && !$grid->getNode($x, $y - 1)->isWalkable())
|
|| ($grid->isWalkable($x + $dx, $y - 1) && !$grid->isWalkable($x, $y - 1))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (($grid->getNode($x + 1, $y + $dy)->isWalkable() && !$grid->getNode($x + 1, $y)->isWalkable())
|
if (($grid->isWalkable($x + 1, $y + $dy) && !$grid->isWalkable($x + 1, $y))
|
||||||
|| ($grid->getNode($x - 1, $y + $dy)->isWalkable() && !$grid->getNode($x - 1, $y)->isWalkable())
|
|| ($grid->isWalkable($x - 1, $y + $dy) && !$grid->isWalkable($x - 1, $y))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x + $dx, $y)->isWalkable() || $grid->getNode($x, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y) || $grid->isWalkable($x, $y + $dy)) {
|
||||||
return self::jumpDiagonalOneObstacle($grid->getNode($x + $dx, $y + $dy), $node, $grid);
|
return self::jumpDiagonalOneObstacle($grid->getNode($x + $dx, $y + $dy), $node, $grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function jumpDiagonalNoObstacle(Node $node, Node $endNode, Grid $grid) : ?Node
|
private static function jumpDiagonalNoObstacle(JumpPointNode $node, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode
|
||||||
{
|
{
|
||||||
$x = $node->getX();
|
$x = $node->getX();
|
||||||
$y = $node->getY();
|
$y = $node->getY();
|
||||||
|
|
@ -546,20 +561,20 @@ class JumpPointSearch implements PathFinderInterface
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
} elseif ($dx !== 0 && $dy === 0) {
|
} elseif ($dx !== 0 && $dy === 0) {
|
||||||
if (($grid->getNode($x, $y - 1)->isWalkable() && !$grid->getNode($x - $dx, $y - 1)->isWalkable())
|
if (($grid->isWalkable($x, $y - 1) && !$grid->isWalkable($x - $dx, $y - 1))
|
||||||
|| ($grid->getNode($x, $y + 1)->isWalkable() && !$grid->getNode($x - $dx, $y + 1)->isWalkable())
|
|| ($grid->isWalkable($x, $y + 1) && !$grid->isWalkable($x - $dx, $y + 1))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
} elseif ($dx === 0 && $dy !== 0) {
|
} elseif ($dx === 0 && $dy !== 0) {
|
||||||
if (($grid->getNode($x - 1, $y)->isWalkable() && !$grid->getNode($x - 1, $y - $dy)->isWalkable())
|
if (($grid->isWalkable($x - 1, $y) && !$grid->isWalkable($x - 1, $y - $dy))
|
||||||
|| ($grid->getNode($x + 1, $y)->isWalkable() && !$grid->getNode($x + 1, $y - $dy)->isWalkable())
|
|| ($grid->isWalkable($x + 1, $y) && !$grid->isWalkable($x + 1, $y - $dy))
|
||||||
) {
|
) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($grid->getNode($x + $dx, $y)->isWalkable() || $grid->getNode($x, $y + $dy)->isWalkable()) {
|
if ($grid->isWalkable($x + $dx, $y) || $grid->isWalkable($x, $y + $dy)) {
|
||||||
return self::jumpDiagonalNoObstacle($grid->getNode($x + $dx, $y + $dy), $node, $grid);
|
return self::jumpDiagonalNoObstacle($grid->getNode($x + $dx, $y + $dy), $node, $grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,10 @@ class Path
|
||||||
}
|
}
|
||||||
|
|
||||||
$node = $this->grid->getNode($x0, $y0);
|
$node = $this->grid->getNode($x0, $y0);
|
||||||
|
|
||||||
|
if ($node === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $line;
|
return $line;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,21 @@ namespace phpOMS\Algorithm\PathFinding;
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
interface PathFinderInterface {
|
interface PathFinderInterface {
|
||||||
|
/**
|
||||||
|
* Find path from one point to another
|
||||||
|
*
|
||||||
|
* @param int $startX Start point X-Coordinate
|
||||||
|
* @param int $startY Start point Y-Coordinate
|
||||||
|
* @param int $endX End point X-Coordinate
|
||||||
|
* @param int $endY End point Y-Coordinate
|
||||||
|
* @param Grid $grid Grid with the walkable points
|
||||||
|
* @param int $heuristic Heuristic algorithm to use in order to calculate the distance for a good path
|
||||||
|
* @param int $movement Allowed movement (e.g. straight, diagonal, ...)
|
||||||
|
*
|
||||||
|
* @return Path
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public static function findPath(
|
public static function findPath(
|
||||||
int $startX, int $startY,
|
int $startX, int $startY,
|
||||||
int $endX, int $endY,
|
int $endX, int $endY,
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Business\Finance;
|
||||||
*/
|
*/
|
||||||
final class Depreciation
|
final class Depreciation
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Constructure
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate linear depretiation rate
|
* Calculate linear depretiation rate
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,15 @@ use phpOMS\Math\Statistic\Average;
|
||||||
*/
|
*/
|
||||||
final class FinanceFormulas
|
final class FinanceFormulas
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Constructure
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annual Percentage Yield
|
* Annual Percentage Yield
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,16 @@ namespace phpOMS\Business\Finance;
|
||||||
*/
|
*/
|
||||||
final class Loan
|
final class Loan
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Constructure
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Balloon Loan - Payments
|
* Balloon Loan - Payments
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,16 @@ namespace phpOMS\Business\Finance;
|
||||||
*/
|
*/
|
||||||
final class Lorenzkurve
|
final class Lorenzkurve
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Constructure
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate Gini coefficient
|
* Calculate Gini coefficient
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,16 @@ namespace phpOMS\Business\Finance;
|
||||||
*/
|
*/
|
||||||
final class StockBonds
|
final class StockBonds
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Constructure
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bond Equivalent Yield
|
* Bond Equivalent Yield
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ final class Metrics
|
||||||
* Constructure
|
* Constructure
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ final class Metrics
|
||||||
* Constructure
|
* Constructure
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ final class MarketShareEstimation
|
||||||
* Constructure
|
* Constructure
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,10 @@ abstract class SettingsAbstract implements OptionsInterface
|
||||||
/**
|
/**
|
||||||
* Database connection instance.
|
* Database connection instance.
|
||||||
*
|
*
|
||||||
* @var null|ConnectionAbstract
|
* @var ConnectionAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected ?ConnectionAbstract $connection = null;
|
protected ConnectionAbstract $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings table.
|
* Settings table.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\DataStorage\Database;
|
namespace phpOMS\DataStorage\Database;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\Query\QueryType;
|
use phpOMS\DataStorage\Database\Query\QueryType;
|
||||||
use phpOMS\DataStorage\DataStorageConnectionInterface;
|
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database query builder.
|
* Database query builder.
|
||||||
|
|
@ -30,18 +30,18 @@ abstract class BuilderAbstract
|
||||||
/**
|
/**
|
||||||
* Grammar.
|
* Grammar.
|
||||||
*
|
*
|
||||||
* @var null|GrammarAbstract
|
* @var GrammarAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected ?GrammarAbstract $grammar = null;
|
protected GrammarAbstract $grammar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database connection.
|
* Database connection.
|
||||||
*
|
*
|
||||||
* @var null|DataStorageConnectionInterface
|
* @var ConnectionAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected ?DataStorageConnectionInterface $connection = null;
|
protected ConnectionAbstract $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query type.
|
* Query type.
|
||||||
|
|
@ -70,11 +70,11 @@ abstract class BuilderAbstract
|
||||||
/**
|
/**
|
||||||
* Get connection
|
* Get connection
|
||||||
*
|
*
|
||||||
* @return DataStorageConnectionInterface
|
* @return ConnectionAbstract
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getConnection() : DataStorageConnectionInterface
|
public function getConnection() : ConnectionAbstract
|
||||||
{
|
{
|
||||||
return $this->connection;
|
return $this->connection;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,10 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
/**
|
/**
|
||||||
* Database connection.
|
* Database connection.
|
||||||
*
|
*
|
||||||
* @var null|ConnectionAbstract
|
* @var ConnectionAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static ?ConnectionAbstract $db = null;
|
protected static ConnectionAbstract $db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwriting extended values.
|
* Overwriting extended values.
|
||||||
|
|
@ -2003,9 +2003,6 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populate data.
|
|
||||||
*
|
|
||||||
* @param mixed $obj Object to add the relations to
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ use phpOMS\DataStorage\Database\Connection\ConnectionFactory;
|
||||||
use phpOMS\DataStorage\Database\Connection\NullConnection;
|
use phpOMS\DataStorage\Database\Connection\NullConnection;
|
||||||
use phpOMS\DataStorage\DataStorageConnectionInterface;
|
use phpOMS\DataStorage\DataStorageConnectionInterface;
|
||||||
use phpOMS\DataStorage\DataStoragePoolInterface;
|
use phpOMS\DataStorage\DataStoragePoolInterface;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database pool handler.
|
* Database pool handler.
|
||||||
|
|
@ -33,7 +34,7 @@ final class DatabasePool implements DataStoragePoolInterface
|
||||||
/**
|
/**
|
||||||
* Databases.
|
* Databases.
|
||||||
*
|
*
|
||||||
* @var DataStorageConnectionInterface[]
|
* @var ConnectionAbstract[]
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private array $pool = [];
|
private array $pool = [];
|
||||||
|
|
@ -73,11 +74,11 @@ final class DatabasePool implements DataStoragePoolInterface
|
||||||
*
|
*
|
||||||
* @param string $key Database key
|
* @param string $key Database key
|
||||||
*
|
*
|
||||||
* @return DataStorageConnectionInterface
|
* @return ConnectionAbstract
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function get(string $key = '') : DataStorageConnectionInterface
|
public function get(string $key = '') : ConnectionAbstract
|
||||||
{
|
{
|
||||||
if ((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) {
|
if ((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) {
|
||||||
return new NullConnection();
|
return new NullConnection();
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ abstract class GrammarAbstract
|
||||||
*
|
*
|
||||||
* @param array $elements Elements
|
* @param array $elements Elements
|
||||||
* @param string $prefix Prefix for table
|
* @param string $prefix Prefix for table
|
||||||
* @param string $column Is always column?
|
* @param bool $column Is column?
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -316,12 +316,12 @@ class Grammar extends GrammarAbstract
|
||||||
return $this->compileSystem($value->getColumn(), $prefix);
|
return $this->compileSystem($value->getColumn(), $prefix);
|
||||||
} elseif ($value instanceof Builder) {
|
} elseif ($value instanceof Builder) {
|
||||||
return '(' . \rtrim($value->toSql(), ';') . ')';
|
return '(' . \rtrim($value->toSql(), ';') . ')';
|
||||||
} elseif ($value instanceof \JsonSerializable) {
|
} elseif ($value instanceof \JsonSerializable) {
|
||||||
$encoded = \json_encode($value);
|
$encoded = \json_encode($value);
|
||||||
|
|
||||||
return $encoded ? $encoded : null;
|
return $encoded ? $encoded : 'NULL';
|
||||||
} elseif ($value instanceof \Serializable) {
|
} elseif ($value instanceof \Serializable) {
|
||||||
return $element->serialize();
|
return $value->serialize();
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException(\gettype($value));
|
throw new \InvalidArgumentException(\gettype($value));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,6 @@ class MicrosoftGrammar extends Grammar
|
||||||
|
|
||||||
$query->limit = $query->limit ?? 1;
|
$query->limit = $query->limit ?? 1;
|
||||||
|
|
||||||
return 'SELECT TOP ' . $query->limit . ' ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY IDX FETCH FIRST ' . $query->limit . ' ROWS ONLY';
|
return 'SELECT TOP ' . $query->limit . ' ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY IDX FETCH FIRST ' . ($query->limit ?? 1) . ' ROWS ONLY';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,6 @@ class MysqlGrammar extends Grammar
|
||||||
$expression = '*';
|
$expression = '*';
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY \rand() ' . $this->compileLimit($query, $query->limit);
|
return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY \rand() ' . $this->compileLimit($query, $query->limit ?? 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,6 @@ class OracleGrammar extends Grammar
|
||||||
|
|
||||||
$query->limit = $query->limit ?? 1;
|
$query->limit = $query->limit ?? 1;
|
||||||
|
|
||||||
return 'SELECT ' . $expression . ' FROM (SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY dbms_random.value) WHERE rownum >= 1 AND rownum <= ' . $query->limit;
|
return 'SELECT ' . $expression . ' FROM (SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY dbms_random.value) WHERE rownum >= 1 AND rownum <= ' . ($query->limit ?? 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,6 @@ class PostgresGrammar extends Grammar
|
||||||
$expression = '*';
|
$expression = '*';
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit);
|
return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit ?? 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,6 @@ class SQLiteGrammar extends Grammar
|
||||||
$expression = '*';
|
$expression = '*';
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit);
|
return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit ?? 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
DataStorage/Database/Schema/Field.php
Normal file
27
DataStorage/Database/Schema/Field.php
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package phpOMS\DataStorage\Database\Schema
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\DataStorage\Database\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database table
|
||||||
|
*
|
||||||
|
* @package phpOMS\DataStorage\Database\Schema
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class Field
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ class MysqlGrammar extends Grammar
|
||||||
* Compile from.
|
* Compile from.
|
||||||
*
|
*
|
||||||
* @param Builder $query Builder
|
* @param Builder $query Builder
|
||||||
* @param array $table Tables
|
* @param string $table Tables
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
|
|
|
||||||
27
DataStorage/Database/Schema/Table.php
Normal file
27
DataStorage/Database/Schema/Table.php
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.4
|
||||||
|
*
|
||||||
|
* @package phpOMS\DataStorage\Database\Schema
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\DataStorage\Database\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database table
|
||||||
|
*
|
||||||
|
* @package phpOMS\DataStorage\Database\Schema
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class Table
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,8 @@ namespace phpOMS\DataStorage\Database;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||||
use phpOMS\DataStorage\Database\Schema\Builder;
|
use phpOMS\DataStorage\Database\Schema\Builder;
|
||||||
|
use phpOMS\DataStorage\Database\Schema\Field;
|
||||||
|
use phpOMS\DataStorage\Database\Schema\Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database schema mapper.
|
* Database schema mapper.
|
||||||
|
|
@ -30,10 +32,10 @@ class SchemaMapper
|
||||||
/**
|
/**
|
||||||
* Database connection.
|
* Database connection.
|
||||||
*
|
*
|
||||||
* @var null|ConnectionAbstract
|
* @var ConnectionAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected ?ConnectionAbstract $db = null;
|
protected ConnectionAbstract $db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
@ -95,11 +97,11 @@ class SchemaMapper
|
||||||
public function getFields(string $table) : array
|
public function getFields(string $table) : array
|
||||||
{
|
{
|
||||||
$builder = new Builder($this->db);
|
$builder = new Builder($this->db);
|
||||||
$tNames = $builder->selectFields()->execute();
|
$tNames = $builder->selectFields($table)->execute();
|
||||||
|
|
||||||
$fields = [];
|
$fields = [];
|
||||||
foreach ($tNames as $name) {
|
foreach ($tNames as $name) {
|
||||||
$fields[] = $this->getField($name);
|
$fields[] = $this->getField($table, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,10 @@ final class ModuleManager
|
||||||
/**
|
/**
|
||||||
* Application instance.
|
* Application instance.
|
||||||
*
|
*
|
||||||
* @var null|ApplicationAbstract
|
* @var ApplicationAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private ?ApplicationAbstract $app = null;
|
private ApplicationAbstract $app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installed modules.
|
* Installed modules.
|
||||||
|
|
@ -249,7 +249,7 @@ final class ModuleManager
|
||||||
if (empty($this->all)) {
|
if (empty($this->all)) {
|
||||||
\chdir($this->modulePath);
|
\chdir($this->modulePath);
|
||||||
$files = \glob('*', \GLOB_ONLYDIR);
|
$files = \glob('*', \GLOB_ONLYDIR);
|
||||||
$c = \count($files);
|
$c = $files === false ? 0 : \count($files);
|
||||||
|
|
||||||
for ($i = 0; $i < $c; ++$i) {
|
for ($i = 0; $i < $c; ++$i) {
|
||||||
$path = $this->modulePath . '/' . $files[$i] . '/info.json';
|
$path = $this->modulePath . '/' . $files[$i] . '/info.json';
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,12 @@ class Heap
|
||||||
{
|
{
|
||||||
private \Closure $compare;
|
private \Closure $compare;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Heap elements
|
||||||
|
*
|
||||||
|
* @var array<int, mixed>
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private array $nodes = [];
|
private array $nodes = [];
|
||||||
|
|
||||||
public function __construct(\Closure $compare = null)
|
public function __construct(\Closure $compare = null)
|
||||||
|
|
@ -39,7 +45,7 @@ class Heap
|
||||||
|
|
||||||
while ($lo < $hi) {
|
while ($lo < $hi) {
|
||||||
$mid = (int) \floor(($lo + $hi) / 2);
|
$mid = (int) \floor(($lo + $hi) / 2);
|
||||||
if (($this->compare)($x, $this->node[$mid]) < 0) {
|
if (($this->compare)($x, $this->nodes[$mid]) < 0) {
|
||||||
$hi = $mid;
|
$hi = $mid;
|
||||||
} else {
|
} else {
|
||||||
$lo = $mid + 1;
|
$lo = $mid + 1;
|
||||||
|
|
@ -210,7 +216,7 @@ class Heap
|
||||||
$this->nodes = [];
|
$this->nodes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function empty() : bool
|
public function isEmpty() : bool
|
||||||
{
|
{
|
||||||
return empty($this->nodes);
|
return empty($this->nodes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user