예제 #1
0
파일: Matrix2d.php 프로젝트: jfdion/matrix
 public function isValid(Matrix $matrix)
 {
     $rowsSize = array_map(function ($row) {
         return count($row);
     }, $matrix->toArray());
     return count($rowsSize) > 0 && count(array_keys($rowsSize, $rowsSize[0])) == count($rowsSize);
 }
예제 #2
0
 protected function traverseRow(Matrix $matrix, $rotatedMatrix, $rowIndex)
 {
     for ($columnIndex = 0, $width = $matrix->getWidth(); $columnIndex < $width; $columnIndex++) {
         if (!isset($rotatedMatrix[$rowIndex]) || !isset($rotatedMatrix[$columnIndex])) {
             $rotatedMatrix[$columnIndex] = [];
         }
         $rotatedMatrix[$columnIndex] = $this->addValueToRow($rotatedMatrix[$columnIndex], $this->getMatrixValue($matrix, $rowIndex, $columnIndex));
     }
     return $rotatedMatrix;
 }
예제 #3
0
 protected function getMatrixValue(Matrix $matrix, $rowIndex, $columnIndex)
 {
     return $matrix->getValue($rowIndex, $columnIndex);
 }