mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 01:38:41 +00:00
test fixes
This commit is contained in:
parent
5ba31111bc
commit
6e461461e0
|
|
@ -45,16 +45,14 @@ final class GrahamScan
|
|||
*/
|
||||
public static function createConvexHull(array $points) : array
|
||||
{
|
||||
$count = \count($points);
|
||||
|
||||
if ($count < 3) {
|
||||
return [];
|
||||
if (($n = \count($points)) < 3) {
|
||||
return $points;
|
||||
}
|
||||
|
||||
$min = 1;
|
||||
$points = \array_merge([null], $points);
|
||||
|
||||
for ($i = 2; $i < $count; ++$i) {
|
||||
for ($i = 2; $i < $n; ++$i) {
|
||||
if ($points[$i]['y'] < $points[$min]['y']
|
||||
|| ($points[$i]['y'] === $points[$min]['y'] && $points[$i]['x'] < $points[$min]['x'])
|
||||
) {
|
||||
|
|
@ -69,7 +67,7 @@ final class GrahamScan
|
|||
$c = $points[1];
|
||||
|
||||
/** @var array<int, array{x:int|float, y:int|float}> $subpoints */
|
||||
$subpoints = \array_slice($points, 2, $count);
|
||||
$subpoints = \array_slice($points, 2, $n);
|
||||
\usort($subpoints, function (array $a, array $b) use ($c) : int {
|
||||
// @todo: Might be wrong order of comparison
|
||||
return \atan2($a['y'] - $c['y'], $a['x'] - $c['x']) <=> \atan2($b['y'] - $c['y'], $b['x'] - $c['x']);
|
||||
|
|
@ -77,14 +75,14 @@ final class GrahamScan
|
|||
|
||||
/** @var array<int, array{x:int|float, y:int|float}> $points */
|
||||
$points = \array_merge([$points[0], $points[1]], $subpoints);
|
||||
$points[0] = $points[$count];
|
||||
$points[0] = $points[$n];
|
||||
|
||||
$size = 1;
|
||||
for ($i = 2; $i <= $count; ++$i) {
|
||||
for ($i = 2; $i <= $n; ++$i) {
|
||||
while (self::ccw($points[$size - 1], $points[$size], $points[$i]) <= 0) {
|
||||
if ($size > 1) {
|
||||
--$size;
|
||||
} elseif ($i === $count) {
|
||||
} elseif ($i === $n) {
|
||||
break;
|
||||
} else {
|
||||
++$i;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ final class MonotoneChain
|
|||
*/
|
||||
public static function createConvexHull(array $points) : array
|
||||
{
|
||||
if (($n = \count($points)) < 2) {
|
||||
if (($n = \count($points)) < 3) {
|
||||
return $points;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -772,14 +772,14 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
}
|
||||
}
|
||||
|
||||
return self::fromArray($sum);
|
||||
return Vector::fromArray($sum);
|
||||
} elseif ($axis === 1) {
|
||||
$sum = [];
|
||||
foreach ($this->matrix as $idx => $row) {
|
||||
$sum[$idx] = \array_sum($row);
|
||||
}
|
||||
|
||||
return self::fromArray($sum);
|
||||
return Vector::fromArray($sum);
|
||||
}
|
||||
|
||||
return new self();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user