support php8019 and some cleanup (by @D-aHTuCT)

This commit is contained in:
kotyara 2022-07-26 16:06:34 +05:00
parent cf0f9df267
commit b60f0877e1
376 changed files with 6528 additions and 13472 deletions

View file

@ -1,87 +1,42 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class Matrix implements ArrayAccess{
private $matrix = array();
private $matrix = [];
private $rows = 0;
private $columns = 0;
public function offsetExists($offset){
return isset($this->matrix[(int) $offset]);
}
public function offsetGet($offset){
return $this->matrix[(int) $offset];
}
public function offsetSet($offset, $value){
$this->matrix[(int) $offset] = $value;
}
public function offsetUnset($offset){
unset($this->matrix[(int) $offset]);
}
public function __construct($rows, $columns, array $set = array()){
public function __construct($rows, $columns, array $set = []){
$this->rows = max(1, (int) $rows);
$this->columns = max(1, (int) $columns);
$this->set($set);
}
public function set(array $m){
for($r = 0; $r < $this->rows; ++$r){
$this->matrix[$r] = array();
$this->matrix[$r] = [];
for($c = 0; $c < $this->columns; ++$c){
$this->matrix[$r][$c] = isset($m[$r][$c]) ? $m[$r][$c] : 0;
}
}
}
public function getRows(){
return ($this->rows);
public function offsetExists($offset){
return isset($this->matrix[(int) $offset]);
}
public function getColumns(){
return ($this->columns);
public function offsetGet($offset){
return $this->matrix[(int) $offset];
}
public function setElement($row, $column, $value){
if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
return false;
}
$this->matrix[(int) $row][(int) $column] = $value;
return true;
public function offsetSet($offset, $value){
$this->matrix[(int) $offset] = $value;
}
public function getElement($row, $column){
if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
return false;
}
return $this->matrix[(int) $row][(int) $column];
public function offsetUnset($offset){
unset($this->matrix[(int) $offset]);
}
public function isSquare(){
return $this->rows === $this->columns;
}
public function add(Matrix $matrix){
if($this->rows !== $matrix->getRows() or $this->columns !== $matrix->getColumns()){
return false;
@ -94,7 +49,30 @@ class Matrix implements ArrayAccess{
}
return $result;
}
public function getRows(){
return ($this->rows);
}
public function getColumns(){
return ($this->columns);
}
public function setElement($row, $column, $value){
if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
return false;
}
$this->matrix[(int) $row][(int) $column] = $value;
return true;
}
public function getElement($row, $column){
if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
return false;
}
return $this->matrix[(int) $row][(int) $column];
}
public function substract(Matrix $matrix){
if($this->rows !== $matrix->getRows() or $this->columns !== $matrix->getColumns()){
return false;
@ -107,7 +85,7 @@ class Matrix implements ArrayAccess{
}
return $result;
}
public function multiplyScalar($number){
$result = clone $this;
for($r = 0; $r < $this->rows; ++$r){
@ -117,8 +95,7 @@ class Matrix implements ArrayAccess{
}
return $result;
}
public function divideScalar($number){
$result = clone $this;
for($r = 0; $r < $this->rows; ++$r){
@ -128,7 +105,7 @@ class Matrix implements ArrayAccess{
}
return $result;
}
public function transpose(){
$result = new Matrix($this->columns, $this->rows);
for($r = 0; $r < $this->rows; ++$r){
@ -138,8 +115,7 @@ class Matrix implements ArrayAccess{
}
return $result;
}
//Naive Matrix product, O(n^3)
public function product(Matrix $matrix){
if($this->columns !== $matrix->getRows()){
return false;
@ -157,9 +133,9 @@ class Matrix implements ArrayAccess{
}
return $result;
}
//Computation of the determinant of 2x2 and 3x3 matrices
//Naive Matrix product, O(n^3)
public function determinant(){
if($this->isSquare() !== true){
return false;
@ -174,14 +150,20 @@ class Matrix implements ArrayAccess{
}
return false;
}
//Computation of the determinant of 2x2 and 3x3 matrices
public function isSquare(){
return $this->rows === $this->columns;
}
public function __toString(){
$s = "";
for($r = 0; $r < $this->rows; ++$r){
$s .= implode(",", $this->matrix[$r]).";";
$s .= implode(",", $this->matrix[$r]) . ";";
}
return "Matrix({$this->rows}x{$this->columns};".substr($s, 0, -1).")";
return "Matrix({$this->rows}x{$this->columns};" . substr($s, 0, -1) . ")";
}
}

View file

@ -1,25 +1,7 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class Vector2{
public $x, $y;
public function __construct($x = 0, $y = 0){
@ -43,6 +25,14 @@ class Vector2{
return (int) $this->y;
}
public function subtract($x = 0, $y = 0){
if(($x instanceof Vector2) === true){
return $this->add(-$x->x, -$x->y);
}else{
return $this->add(-$x, -$y);
}
}
public function add($x = 0, $y = 0){
if(($x instanceof Vector2) === true){
return $this->add($x->x, $x->y);
@ -53,14 +43,6 @@ class Vector2{
}
}
public function subtract($x = 0, $y = 0){
if(($x instanceof Vector2) === true){
return $this->add(-$x->x, -$x->y);
}else{
return $this->add(-$x, -$y);
}
}
public function ceil(){
return new Vector2((int) ($this->x + 1), (int) ($this->y + 1));
}
@ -76,14 +58,10 @@ class Vector2{
public function abs(){
return new Vector2(abs($this->x), abs($this->y));
}
public function multiply($number){
return new Vector2($this->x * $number, $this->y * $number);
}
public function divide($number){
return new Vector2($this->x / $number, $this->y / $number);
}
public function distance($x = 0, $y = 0){
if(($x instanceof Vector2) === true){
@ -100,15 +78,7 @@ class Vector2{
return pow($this->x - $x, 2) + pow($this->y - $y, 2);
}
}
public function length(){
return sqrt($this->lengthSquared());
}
public function lengthSquared(){
return $this->x * $this->x + $this->y * $this->y;
}
public function normalize(){
$len = $this->length();
if($len != 0){
@ -116,13 +86,24 @@ class Vector2{
}
return new Vector2(0, 0);
}
public function length(){
return sqrt($this->lengthSquared());
}
public function lengthSquared(){
return $this->x * $this->x + $this->y * $this->y;
}
public function divide($number){
return new Vector2($this->x / $number, $this->y / $number);
}
public function dot(Vector2 $v){
return $this->x * $v->x + $this->y * $v->y;
}
public function __toString(){
return "Vector2(x=".$this->x.",y=".$this->y.")";
return "Vector2(x=" . $this->x . ",y=" . $this->y . ")";
}
}

View file

@ -1,25 +1,7 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class Vector3{
public $x, $y, $z;
public function __construct($x = 0, $y = 0, $z = 0){
@ -28,18 +10,6 @@ class Vector3{
$this->z = $z;
}
public function getX(){
return $this->x;
}
public function getY(){
return $this->y;
}
public function getZ(){
return $this->z;
}
public function getFloorX(){
return (int) $this->x;
}
@ -56,14 +26,26 @@ class Vector3{
return $this->getX();
}
public function getX(){
return $this->x;
}
public function getUp(){
return $this->getY();
}
public function getY(){
return $this->y;
}
public function getForward(){
return $this->getZ();
}
public function getZ(){
return $this->z;
}
public function getSouth(){
return $this->getX();
}
@ -72,6 +54,14 @@ class Vector3{
return $this->getZ();
}
public function subtract($x = 0, $y = 0, $z = 0){
if(($x instanceof Vector3) === true){
return $this->add(-$x->x, -$x->y, -$x->z);
}else{
return $this->add(-$x, -$y, -$z);
}
}
public function add($x = 0, $y = 0, $z = 0){
if(($x instanceof Vector3) === true){
return $this->add($x->x, $x->y, $x->z);
@ -80,21 +70,9 @@ class Vector3{
}
}
public function subtract($x = 0, $y = 0, $z = 0){
if(($x instanceof Vector3) === true){
return $this->add(-$x->x, -$x->y, -$x->z);
}else{
return $this->add(-$x, -$y, -$z);
}
}
public function multiply($number){
return new Vector3($this->x * $number, $this->y * $number, $this->z * $number);
}
public function divide($number){
return new Vector3($this->x / $number, $this->y / $number, $this->z / $number);
}
public function ceil(){
return new Vector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
@ -111,7 +89,7 @@ class Vector3{
public function abs(){
return new Vector3(abs($this->x), abs($this->y), abs($this->z));
}
public function getSide($side, $step = 1){
switch((int) $side){
case 0:
@ -125,7 +103,7 @@ class Vector3{
case 4:
return new Vector3($this->x - $step, $this->y, $this->z);
case 5:
return new Vector3($this->x + $step, $this->y, $this->z);
return new Vector3($this->x + $step, $this->y, $this->z);
default:
return $this;
}
@ -146,23 +124,15 @@ class Vector3{
return pow($this->x - $x, 2) + pow($this->y - $y, 2) + pow($this->z - $z, 2);
}
}
public function maxPlainDistance($x = 0, $z = 0){
if(($x instanceof Vector3) === true){
return $this->maxPlainDistance($x->x, $x->z);
}else{
return max(abs($this->x - $x), abs($this->z - $z));
}
}
}
public function length(){
return sqrt($this->lengthSquared());
}
public function lengthSquared(){
return $this->x * $this->x + $this->y * $this->y + $this->z * $this->z;
}
public function normalize(){
$len = $this->length();
if($len != 0){
@ -170,11 +140,23 @@ class Vector3{
}
return new Vector3(0, 0, 0);
}
public function length(){
return sqrt($this->lengthSquared());
}
public function lengthSquared(){
return $this->x * $this->x + $this->y * $this->y + $this->z * $this->z;
}
public function divide($number){
return new Vector3($this->x / $number, $this->y / $number, $this->z / $number);
}
public function dot(Vector3 $v){
return $this->x * $v->x + $this->y * $v->y + $this->z * $v->z;
}
public function cross(Vector3 $v){
return new Vector3(
$this->y * $v->z - $this->z * $v->y,
@ -184,7 +166,6 @@ class Vector3{
}
public function __toString(){
return "Vector3(x=".$this->x.",y=".$this->y.",z=".$this->z.")";
return "Vector3(x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
}
}

View file

@ -1,28 +1,8 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class VectorMath{
public static function getDirection2D($azimuth){
return new Vector2(cos($azimuth), sin($azimuth));
}
}