mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
support php8019 and some cleanup (by @D-aHTuCT)
This commit is contained in:
parent
cf0f9df267
commit
b60f0877e1
376 changed files with 6528 additions and 13472 deletions
|
|
@ -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 . ")";
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue