extract functions from loops and remove unused code

This commit is contained in:
Arkadiusz Kondas 2016-08-02 13:23:58 +02:00
parent 637fd613b8
commit f186aa9c0b
2 changed files with 6 additions and 5 deletions

View File

@ -61,7 +61,7 @@ class Space extends SplObjectStorage
*/ */
public function addPoint(array $coordinates, $data = null) public function addPoint(array $coordinates, $data = null)
{ {
return $this->attach($this->newPoint($coordinates), $data); $this->attach($this->newPoint($coordinates), $data);
} }
/** /**
@ -74,7 +74,7 @@ class Space extends SplObjectStorage
throw new InvalidArgumentException('can only attach points to spaces'); throw new InvalidArgumentException('can only attach points to spaces');
} }
return parent::attach($point, $data); parent::attach($point, $data);
} }
/** /**
@ -230,8 +230,8 @@ class Space extends SplObjectStorage
protected function initializeKMPPClusters(int $clustersNumber) protected function initializeKMPPClusters(int $clustersNumber)
{ {
$clusters = []; $clusters = [];
$position = rand(1, count($this)); $this->rewind();
for ($i = 1, $this->rewind(); $i < $position && $this->valid(); $i++, $this->next());
$clusters[] = new Cluster($this, $this->current()->getCoordinates()); $clusters[] = new Cluster($this, $this->current()->getCoordinates());
$distances = new SplObjectStorage(); $distances = new SplObjectStorage();

View File

@ -193,7 +193,8 @@ class Matrix
$product = []; $product = [];
$multiplier = $matrix->toArray(); $multiplier = $matrix->toArray();
for ($i = 0; $i < $this->rows; ++$i) { for ($i = 0; $i < $this->rows; ++$i) {
for ($j = 0; $j < $matrix->getColumns(); ++$j) { $columns = $matrix->getColumns();
for ($j = 0; $j < $columns; ++$j) {
$product[$i][$j] = 0; $product[$i][$j] = 0;
for ($k = 0; $k < $this->columns; ++$k) { for ($k = 0; $k < $this->columns; ++$k) {
$product[$i][$j] += $this->matrix[$i][$k] * $multiplier[$k][$j]; $product[$i][$j] += $this->matrix[$i][$k] * $multiplier[$k][$j];