GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Vector2 Class Reference

Public Member Functions

 __construct ($x=0, $y=0)
 
 getX ()
 
 getY ()
 
 getFloorX ()
 
 getFloorY ()
 
 add ($x, $y=0)
 
 subtract ($x, $y=0)
 
 ceil ()
 
 floor ()
 
 round ()
 
 abs ()
 
 multiply ($number)
 
 divide ($number)
 
 distance ($x, $y=0)
 
 distanceSquared ($x, $y=0)
 
 length ()
 
 lengthSquared ()
 
 normalize ()
 
 dot (Vector2 $v)
 
 __toString ()
 

Static Public Member Functions

static createRandomDirection (Random $random)
 

Data Fields

 $x
 
 $y
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $x = 0,
  $y = 0 
)

Vector2 constructor.

Parameters
int$x
int$y
36  {
37  $this->x = $x;
38  $this->y = $y;
39  }

Member Function Documentation

◆ __toString()

__toString ( )
Returns
string
209  {
210  return "Vector2(x=" . $this->x . ",y=" . $this->y . ")";
211  }

◆ abs()

abs ( )
Returns
Vector2
121  {
122  return new Vector2(abs($this->x), abs($this->y));
123  }

◆ add()

add (   $x,
  $y = 0 
)
Parameters
$x
int$y
Returns
Vector2
75  {
76  if($x instanceof Vector2){
77  return $this->add($x->x, $x->y);
78  }else{
79  return new Vector2($this->x + $x, $this->y + $y);
80  }
81  }

◆ ceil()

ceil ( )
Returns
Vector2
100  {
101  return new Vector2((int) ($this->x + 1), (int) ($this->y + 1));
102  }

◆ createRandomDirection()

static createRandomDirection ( Random  $random)
static
Parameters
Random$random
Returns
Vector2
218  {
219  return VectorMath::getDirection2D($random->nextFloat() * 2 * pi());
220  }

◆ distance()

distance (   $x,
  $y = 0 
)
Parameters
$x
int$y
Returns
float
149  {
150  if($x instanceof Vector2){
151  return sqrt($this->distanceSquared($x->x, $x->y));
152  }else{
153  return sqrt($this->distanceSquared($x, $y));
154  }
155  }

◆ distanceSquared()

distanceSquared (   $x,
  $y = 0 
)
Parameters
$x
int$y
Returns
number
163  {
164  if($x instanceof Vector2){
165  return $this->distanceSquared($x->x, $x->y);
166  }else{
167  return pow($this->x - $x, 2) + pow($this->y - $y, 2);
168  }
169  }

◆ divide()

divide (   $number)
Parameters
$number
Returns
Vector2
139  {
140  return new Vector2($this->x / $number, $this->y / $number);
141  }

◆ dot()

dot ( Vector2  $v)
Parameters
Vector2$v
Returns
int
202  {
203  return $this->x * $v->x + $this->y * $v->y;
204  }

◆ floor()

floor ( )
Returns
Vector2
107  {
108  return new Vector2((int) $this->x, (int) $this->y);
109  }

◆ getFloorX()

getFloorX ( )
Returns
int
58  {
59  return (int) $this->x;
60  }

◆ getFloorY()

getFloorY ( )
Returns
int
65  {
66  return (int) $this->y;
67  }

◆ getX()

getX ( )
Returns
int
44  {
45  return $this->x;
46  }

◆ getY()

getY ( )
Returns
int
51  {
52  return $this->y;
53  }

◆ length()

length ( )
Returns
float
174  {
175  return sqrt($this->lengthSquared());
176  }

◆ lengthSquared()

lengthSquared ( )
Returns
int
181  {
182  return $this->x * $this->x + $this->y * $this->y;
183  }

◆ multiply()

multiply (   $number)
Parameters
$number
Returns
Vector2
130  {
131  return new Vector2($this->x * $number, $this->y * $number);
132  }

◆ normalize()

normalize ( )
Returns
Vector2
188  {
189  $len = $this->lengthSquared();
190  if($len != 0){
191  return $this->divide(sqrt($len));
192  }
193 
194  return new Vector2(0, 0);
195  }

◆ round()

round ( )
Returns
Vector2
114  {
115  return new Vector2(round($this->x), round($this->y));
116  }

◆ subtract()

subtract (   $x,
  $y = 0 
)
Parameters
$x
int$y
Returns
Vector2
89  {
90  if($x instanceof Vector2){
91  return $this->add(-$x->x, -$x->y);
92  }else{
93  return $this->add(-$x, -$y);
94  }
95  }

Field Documentation

◆ $x

$x

◆ $y

$y

The documentation for this class was generated from the following file: