Vec2
A two-dimensional vector with x and y components.
Category: Utility
Base class: _BlipValue
Properties
maxComponent : float (Read-Only)
Maximum component of the vector.
minComponent : float (Read-Only)
The minimum component of the vector.
x : float
The x component of the vector.
UserName: X
y : float
The y component of the vector.
UserName: Y
Constructors
__init__(self)
__init__(self, other: Vec2)
Copy constructor for Vec2
__init__(self, v: Int2)
__init__(self, v: Vec)
__init__(self, _x: float, _y: float)
Methods
_initParams(self) -> Any
A serialisable tuple of the Int2 parameters
abs(self) -> Vec2
The absolute value of the vector.
Returns A new vector containing the component-wise absolute value of this vector.
angle(self) -> float
The angle of the vector, measured counter-clockwise from the positive x-axis.
Returns The angle of the vector in normalised coordinates.
aspect(self) -> float
The aspect ratio of the vector, defined as the ratio of the x component to the y component.
Returns The aspect ratio of the vector.
dot(self, v: Vec2) -> float
The dot product of two vectors.
Parameters:
- v: The other vector to calculate the dot product with.
Returns The dot product of this vector and the other vector.
length(self) -> float
The length of the vector in 2D space.
Returns The length of the vector.
normalise(self) -> Vec2
Normalises the vector to have a length of 1.
Returns The normalised vector.
restrict(self, min: Vec2, max: Vec2) -> Vec2
Restricts the vector to be within a minimum and maximum range.
Parameters:
- min: A vector of minimum values for each component.
- max: A vector of maximum values for each component.
Returns A new vector with components restricted to the minimum and maximum range.
rotate(self, a: float) -> Vec2
Rotates the vector by a degrees anticlockwise.
Parameters:
- a: The angle of rotation in degrees.
Returns A new vector rotated by the specified angle.
roundClosest(self, f: float) -> Vec2
Rounds the components of this vector to the nearest integer multiple of a given factor.
Rounds to the nearest multiple of f using the round half toward zero rule
eg. 0 <= x <= 0.5 will round to 0, 0.5 < x <= 1 will round to 1
Parameters:
- f: The factor to round to.
Returns A new vector with rounded components.
roundDown(self, f: float) -> Vec2
Rounds the components of this vector down to the nearest integer multiple of a given factor.
Parameters:
- f: The factor to round down to.
Returns A new vector with rounded components.
vmax(self, v: Vec2) -> Vec2
Component-wise maximum of two vectors.
Parameters:
- v: The other vector to compare with.
Returns A new vector containing the component-wise maximum of this and the other vector.
vmin(self, v: Vec2) -> Vec2
Component-wise minimum of two vectors.
Parameters:
- v: The other vector to compare with.
Returns A new vector containing the component-wise minimum of this and the other vector.
Special Methods
__add__(self, v: Vec2) -> Vec2
Adds two vectors.
Parameters:
- v: The Vec2 object to add to this one.
Returns The component-wise sum of this and the input vector.
__div__(self, s) -> Any
Divides the vector by a scalar value.
Parameters:
- s: The scalar value to divide the vector by.
Returns A new vector that is the result of dividing the components of this vector by the given scalar value.
__eq__(self, v: Vec2) -> bool
Tests for equality between two vectors.
Parameters:
- v: The vector to compare with.
Returns True if both components of the vectors are equal, false otherwise.
__getitem__(self, key) -> Any
Get an item from the Vec2 by index.
Parameters:
- key: The index of the desired item. Must be 0 or 1
Returns The x element if the index is 0, the y element if the index is 1
__len__(self) -> Any
The length of the Vec2
Returns Always returns 2
__mul__(self, s) -> Any
Multiplies the vector by a scalar value.
Parameters:
- s: The scalar value to multiply with.
Returns A new vector that is the result of multiplying the components of this vector by the given scalar value.
__ne__(self, v: Vec2) -> bool
Tests for inequality between two vectors.
Parameters:
- v: The other vector to compare with.
Returns True if either of the components of the vectors are not equal, false otherwise.
__neg__(self) -> Any
The negative of the Vec2
Returns The Vec2 with its x and y components negated
__rdiv__(self, other) -> Any
Divide another vector by this vector
Parameters:
- other: The vector which is divided by this
Returns The element-wise division other/self
__repr__(self) -> Any
String representation of the Vec2
__rmul__(self, s) -> Any
Multiplies the vector by a scalar value.
Parameters:
- s: The scalar value to multiply with.
Returns A new vector that is the result of multiplying the components of this vector by the given scalar value.
__str__(self) -> Any
String representation of the Vec2
__sub__(self, v: Vec2) -> Vec2
Subtracts another vector from this vector.
Parameters:
- v: The Vec2 object to subtract from this vector.
Returns The resulting vector after component-wise subtraction.