mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
PHP8: use match function
This commit is contained in:
parent
1275a4558c
commit
f74e6e0638
41 changed files with 300 additions and 574 deletions
|
|
@ -140,16 +140,13 @@ class Matrix implements ArrayAccess{
|
|||
if($this->isSquare() !== true){
|
||||
return false;
|
||||
}
|
||||
switch($this->rows){
|
||||
case 1:
|
||||
return 0;
|
||||
case 2:
|
||||
return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0];
|
||||
case 3:
|
||||
return $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return match ($this->rows) {
|
||||
1 => 0,
|
||||
2 => $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0],
|
||||
3 => $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1],
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//Computation of the determinant of 2x2 and 3x3 matrices
|
||||
|
|
|
|||
|
|
@ -104,22 +104,15 @@ class Vector3{
|
|||
}
|
||||
|
||||
public function getSide($side, $step = 1){
|
||||
switch((int) $side){
|
||||
case 0:
|
||||
return new Vector3($this->x, $this->y - $step, $this->z);
|
||||
case 1:
|
||||
return new Vector3($this->x, $this->y + $step, $this->z);
|
||||
case 2:
|
||||
return new Vector3($this->x, $this->y, $this->z - $step);
|
||||
case 3:
|
||||
return new Vector3($this->x, $this->y, $this->z + $step);
|
||||
case 4:
|
||||
return new Vector3($this->x - $step, $this->y, $this->z);
|
||||
case 5:
|
||||
return new Vector3($this->x + $step, $this->y, $this->z);
|
||||
default:
|
||||
return $this;
|
||||
}
|
||||
return match ((int)$side) {
|
||||
0 => new Vector3($this->x, $this->y - $step, $this->z),
|
||||
1 => new Vector3($this->x, $this->y + $step, $this->z),
|
||||
2 => new Vector3($this->x, $this->y, $this->z - $step),
|
||||
3 => new Vector3($this->x, $this->y, $this->z + $step),
|
||||
4 => new Vector3($this->x - $step, $this->y, $this->z),
|
||||
5 => new Vector3($this->x + $step, $this->y, $this->z),
|
||||
default => $this,
|
||||
};
|
||||
}
|
||||
|
||||
public function distance($x = 0, $y = 0, $z = 0){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue