<?php
$matrix = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16],
// [17, 18, 19, 20]
];
$r = 1;
matrixRotation($matrix, $r);
function matrixRotation($matrix, $r) {
$m = new Matrix($matrix);
$m->rotate();
// print_r($m->get());
}
class Matrix
{
private $mx;
private $m;
private $n;
private $a; // i [a,b]
private $b;
private $c; // j [c,d]
private $d;
public function get() {
return $this->mx;
}
public function __construct($mx) {
try {
$this->set($mx);
} catch(\Exception $e) {
echo $e->getMessage();
// exit(1);
}
}
private function set(array $mx) {
$this->m = count($mx);
$this->n = count($mx[0]);
$this->a = 0;
$this->b = $this->m-1;
$this->c = 0;
$this->d = $this->n-1;
$this->mx = $mx;
}
public function rotate($r = 1) {
$k = 0;
while(1) {
$this->a += $k;
$this->b -= $k;
$this->c += $k;
$this->d -= $k;
var_dump($this->a, $this->b,$this->c,$this->d);
break;
if (
$this->a === $this->b ||
$this->c === $this->d
) {
break;
}
$mult = 2*($this->m-2*$k)+2*($this->n-2*$k)-4;
$rm = $r % $mult;
while($rm--) {
print_r('rotateSquare'.PHP_EOL);
// $this->rotateSquare();
}
++$k;
}
}
private function rotateSquare() {
$t = []; //transite
for($i=0; $i<$this->m; ++$i) {
for($j=0; $j<$this->n; ++$j) {
$t[$i][$j] = [0,0];
}
}
$j=$this->c;
for($i=$this->a; $i<$this->b; ++$i) {
$t[$i][$j] = [-1,0];
}
$i=$this->b;
for($j=$this->c; $j<$this->d; ++$j) {
$t[$i][$j] = [0,1];
}
$j=$this->d;
for($i=$this->b; $i>$this->a; --$i) {
$t[$i][$j] = [1,0];
}
$i=$this->a;
for($j=$this->d; $j<$this->c; --$j) {
$t[$i][$j] = [0,-1];
}
prtint_r($t);
// $temp = [];
// for($i=0; $i<$this->m; ++$i) {
// for($j=0; $j<$this->n; ++$j) {
// $iOffset = $t[$i][$j][0];
// $jOffset = $t[$i][$j][1];
// $temp[$i+$iOffset][$j+$jOffset] = $this->mx[$i][$j];
// }
// }
// $this->mx = $this->ksort($temp);
// return $this;
}
private function ksort($temp) {
foreach($temp as &$ar){
ksort($ar);
}
ksort($temp);
return $temp;
}
}
- Output for git.master, git.master_jit, rfc.property-hooks
- int(0)
int(3)
int(0)
int(3)
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:
54.24 ms | 401 KiB | 8 Q