mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
Possible fix for #391
This commit is contained in:
parent
204a4ce831
commit
02721c09a4
5 changed files with 89 additions and 9 deletions
|
|
@ -110,6 +110,26 @@ 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){
|
||||
return $this->divide($len);
|
||||
}
|
||||
return new Vector2(0, 0);
|
||||
}
|
||||
|
||||
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.")";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue