| @@ 8-60 (lines=53) @@ | ||
| 5 | use CL\Matrix\Element; |
|
| 6 | use CL\Matrix\Matrix; |
|
| 7 | ||
| 8 | class Column extends AbstractVector |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @param Matrix $matrix |
|
| 12 | * @param int $matrixOffset |
|
| 13 | */ |
|
| 14 | public function setMatrix(Matrix $matrix, $matrixOffset) |
|
| 15 | { |
|
| 16 | $this->matrix = $matrix; |
|
| 17 | ||
| 18 | foreach ($this->getElements() as $offset => $element) { |
|
| 19 | if (!$this->matrix->hasRow($offset)) { |
|
| 20 | $this->matrix->setRow($offset, new Row([])); |
|
| 21 | } |
|
| 22 | ||
| 23 | $this->matrix->getRow($offset)->addElement($element); |
|
| 24 | } |
|
| 25 | ||
| 26 | $this->matrixOffset = $matrixOffset; |
|
| 27 | } |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @param Element $element |
|
| 31 | */ |
|
| 32 | public function addElement(Element $element) |
|
| 33 | { |
|
| 34 | array_push($this->elements, $element); |
|
| 35 | ||
| 36 | $keys = array_keys($this->elements); |
|
| 37 | $offset = end($keys); |
|
| 38 | ||
| 39 | if ($this->matrix) { |
|
| 40 | if ($this->matrix->hasRow($offset)) { |
|
| 41 | $this->matrix->getRow($offset)->addElement($element); |
|
| 42 | } |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param int $offset |
|
| 48 | * @param Element $element |
|
| 49 | */ |
|
| 50 | public function setElement($offset, Element $element) |
|
| 51 | { |
|
| 52 | $this->elements[$offset] = $element; |
|
| 53 | ||
| 54 | if ($this->matrix) { |
|
| 55 | if ($this->matrix->hasRow($offset)) { |
|
| 56 | $this->matrix->getRow($offset)->setElement($this->matrixOffset, $element); |
|
| 57 | } |
|
| 58 | } |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||
| @@ 8-60 (lines=53) @@ | ||
| 5 | use CL\Matrix\Element; |
|
| 6 | use CL\Matrix\Matrix; |
|
| 7 | ||
| 8 | class Row extends AbstractVector |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @param Matrix $matrix |
|
| 12 | * @param int $matrixOffset |
|
| 13 | */ |
|
| 14 | public function setMatrix(Matrix $matrix, $matrixOffset) |
|
| 15 | { |
|
| 16 | $this->matrix = $matrix; |
|
| 17 | ||
| 18 | foreach ($this->getElements() as $offset => $element) { |
|
| 19 | if (!$this->matrix->hasColumn($offset)) { |
|
| 20 | $this->matrix->setColumn($offset, new Column([])); |
|
| 21 | } |
|
| 22 | ||
| 23 | $this->matrix->getColumn($offset)->addElement($element); |
|
| 24 | } |
|
| 25 | ||
| 26 | $this->matrixOffset = $matrixOffset; |
|
| 27 | } |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @param Element $element |
|
| 31 | */ |
|
| 32 | public function addElement(Element $element) |
|
| 33 | { |
|
| 34 | array_push($this->elements, $element); |
|
| 35 | ||
| 36 | $keys = array_keys($this->elements); |
|
| 37 | $offset = end($keys); |
|
| 38 | ||
| 39 | if ($this->matrix) { |
|
| 40 | if ($this->matrix->hasColumn($offset)) { |
|
| 41 | $this->matrix->getColumn($offset)->addElement($element); |
|
| 42 | } |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param int $offset |
|
| 48 | * @param Element $element |
|
| 49 | */ |
|
| 50 | public function setElement($offset, Element $element) |
|
| 51 | { |
|
| 52 | $this->elements[$offset] = $element; |
|
| 53 | ||
| 54 | if ($this->matrix) { |
|
| 55 | if ($this->matrix->hasColumn($offset)) { |
|
| 56 | $this->matrix->getColumn($offset)->setElement($this->matrixOffset, $element); |
|
| 57 | } |
|
| 58 | } |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||