Package gameobjects :: Module vector2 :: Class Vector2
[hide private]
[frames] | no frames]

Class Vector2

source code


Instance Methods [hide private]
 
__init__(self, x=0.0, y=0.0)
Initialise a vector
source code
 
_get_length(self) source code
 
_set_length(self, length) source code
 
copy(self)
Returns a copy of this object.
source code
 
get_x(self) source code
 
set_x(self, x) source code
 
get_y(self) source code
 
set_y(self, y) source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
repr(x)
source code
 
__iter__(self) source code
 
__len__(self) source code
 
__getitem__(self, index)
Gets a component as though the vector were a list.
source code
 
__setitem__(self, index, value)
Sets a component as though the vector were a list.
source code
 
__eq__(self, rhs) source code
 
__ne__(self, rhs) source code
 
__hash__(self)
hash(x)
source code
 
__add__(self, rhs) source code
 
__iadd__(self, rhs) source code
 
__radd__(self, lhs) source code
 
__sub__(self, rhs) source code
 
__rsub__(self, lhs) source code
 
_isub__(self, rhs) source code
 
__mul__(self, rhs)
Return the result of multiplying this vector with a scalar or a vector-list object.
source code
 
__imul__(self, rhs)
Multiplys this vector with a scalar or a vector-list object.
source code
 
__rmul__(self, lhs) source code
 
__div__(self, rhs)
Return the result of dividing this vector by a scalar or a vector-list object.
source code
 
__idiv__(self, rhs)
Divides this vector with a scalar or a vector-list object.
source code
 
__rdiv__(self, lhs) source code
 
__neg__(self)
Return the negation of this vector.
source code
 
__pos__(self) source code
 
__nonzero__(self) source code
 
__call__(self, keys)
Used to swizzle a vector.
source code
Tuple
as_tuple(self)
Converts this vector to a tuple.
source code
 
get_length(self)
Returns the length of this vector.
source code
 
get_magnitude(self)
Returns the length of this vector.
source code
 
normalise(self)
Normalises this vector.
source code
 
normalize(self)
Normalises this vector.
source code
 
get_normalised(self) source code
 
get_normalized(self) source code
 
get_distance_to(self, p)
Returns the distance to a point.
source code

Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Methods [hide private]
 
from_floats(cls, x, y) source code
 
from_iter(cls, iterable)
Creates a Vector2 object from an iterable.
source code
 
from_points(cls, p1, p2)
Creates a Vector2 object between two points.
source code
 
_from_float_sequence(cls, sequence) source code
Class Variables [hide private]
  _gameobjects_vector = 2
Properties [hide private]
  length
Length of the vector
  x
x component.
  y
y component.
  u
u component (alias for x).
  v
v component (alias for y).
  _v

Inherited from object: __class__

Method Details [hide private]

__init__(self, x=0.0, y=0.0)
(Constructor)

source code 
Initialise a vector
Parameters:
  • x (number) - The x value (defaults to 0.), or a container of 2 values
  • y - The y value (defaults to 0.)
Overrides: object.__init__

from_iter(cls, iterable)
Class Method

source code 
Creates a Vector2 object from an iterable.
Parameters:
  • iterable - An iterable of at least 2 numeric values

from_points(cls, p1, p2)
Class Method

source code 
Creates a Vector2 object between two points.
Parameters:
  • p1 - First point
  • p2 - Second point

__str__(self)
(Informal representation operator)

source code 
str(x)
Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: object.__repr__
(inherited documentation)

__hash__(self)
(Hashing function)

source code 
hash(x)
Overrides: object.__hash__
(inherited documentation)

__call__(self, keys)
(Call operator)

source code 
Used to swizzle a vector.
Parameters:
  • keys (string) - A string containing a list of component names >>> vec = Vector(1, 2) >>> vec('yx') (1, 2)

as_tuple(self)

source code 
Converts this vector to a tuple.
Returns: Tuple
Tuple containing the vector components

get_distance_to(self, p)

source code 
Returns the distance to a point.
Returns:
distance

Property Details [hide private]

length

Length of the vector
Get Method:
gameobjects.vector2.Vector2._get_length(self)
Set Method:
gameobjects.vector2.Vector2._set_length(self, length)

x

x component.
Get Method:
gameobjects.vector2.Vector2.get_x(self)
Set Method:
gameobjects.vector2.Vector2.set_x(self, x)

y

y component.
Get Method:
gameobjects.vector2.Vector2.get_y(self)
Set Method:
gameobjects.vector2.Vector2.set_y(self, y)

u

u component (alias for x).
Get Method:
gameobjects.vector2.Vector2.get_x(self)
Set Method:
gameobjects.vector2.Vector2.set_y(self, y)

v

v component (alias for y).
Get Method:
gameobjects.vector2.Vector2.get_y(self)
Set Method:
gameobjects.vector2.Vector2.set_y(self, y)