diff --git a/Math/Geometry/ConvexHull/GrahamScan.php b/Math/Geometry/ConvexHull/GrahamScan.php index df65eedd1..fc4881080 100644 --- a/Math/Geometry/ConvexHull/GrahamScan.php +++ b/Math/Geometry/ConvexHull/GrahamScan.php @@ -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 $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 $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; diff --git a/Math/Geometry/ConvexHull/MonotoneChain.php b/Math/Geometry/ConvexHull/MonotoneChain.php index 9599031af..2cc2c4a1d 100755 --- a/Math/Geometry/ConvexHull/MonotoneChain.php +++ b/Math/Geometry/ConvexHull/MonotoneChain.php @@ -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; } diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index c26161fa5..844ce89e0 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -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();