2022-07-05 15:55:47 +02:00
|
|
|
<?php
|
|
|
|
|
2024-02-02 15:16:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-07-05 15:55:47 +02:00
|
|
|
namespace DNW\Skills\Numerics;
|
2016-05-24 14:10:39 +02:00
|
|
|
|
2025-04-15 08:14:08 +00:00
|
|
|
final class SquareMatrix extends Matrix
|
2016-05-24 14:10:39 +02:00
|
|
|
{
|
2023-08-02 13:19:35 +00:00
|
|
|
public function __construct(float|int ...$allValues)
|
2016-05-24 14:10:39 +02:00
|
|
|
{
|
2024-02-15 09:08:01 +00:00
|
|
|
$size = (int)sqrt(count($allValues));
|
2016-05-24 14:10:39 +02:00
|
|
|
|
2022-07-05 15:55:47 +02:00
|
|
|
$matrixData = [];
|
2016-05-24 14:10:39 +02:00
|
|
|
$allValuesIndex = 0;
|
|
|
|
|
2024-02-21 13:48:37 +00:00
|
|
|
for ($currentRow = 0; $currentRow < $size; ++$currentRow) {
|
|
|
|
for ($currentColumn = 0; $currentColumn < $size; ++$currentColumn) {
|
2016-05-24 14:10:39 +02:00
|
|
|
$matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-15 09:08:01 +00:00
|
|
|
parent::__construct($size, $size, $matrixData);
|
2016-05-24 14:10:39 +02:00
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|