Vec2

Represent a mathematical 2-dimensional vector.

struct Vec2 (
T
) {}

Members

Functions

abs
Vec2!T abs()

Remove negative components.

angle
T angle()

Returns the vector actual angle.

approach
Vec2!T approach(Vec2!T target, Vec2!T step)

Linear interpolation to approach a target

ceil
Vec2!T ceil()

Round up the values.

clamp
Vec2!T clamp(Vec2!T min, Vec2!T max)

Bounds the vector between those two.

clamp
Vec2!T clamp(Vec4!T clip)

Bounds the vector between those boundaries.

contain
Vec2!T contain(Vec2!T v)

While conserving the x/y ratio, returns the smallest vector possible that can contain the other vector. (like a size) \ Does not modify this vector.

cross
T cross(Vec2!T v)

Cross product of the 2 vectors.

distance
T distance(Vec2!T v)

The distance between this point and the other one.

distanceSquared
T distanceSquared(Vec2!T v)

The distance between this point and the other one squared. Not square rooted, so no crash and more efficient.

dot
T dot(Vec2!T v)

Dot product of the 2 vectors.

fit
Vec2!T fit(Vec2!T v)

While conserving the x/y ratio, returns the largest vector possible that fits inside the other vector. (like a size) \ Does not modify this vector.

floor
Vec2!T floor()

Truncate the values.

isBetween
bool isBetween(Vec2!T min, Vec2!T max)

Is this vector between those boundaries ?

length
T length()

The total length of this vector.

lengthSquared
T lengthSquared()

The squared length of this vector. Can be null, and more efficiant than length.

lerp
Vec2!T lerp(Vec2!T end, float t)

Returns an interpolated vector from this vector to the end vector by a factor. \ Does not modify this vector.

max
Vec2!T max(Vec2!T v)

The larger vector possible between the two.

min
Vec2!T min(Vec2!T v)

The smaller vector possible between the two.

normal
Vec2!T normal()

The normal axis of this vector.

normalize
void normalize()

Transform this vector in a unit vector.

normalized
Vec2!T normalized()

Returns a unit vector from this one without modifying this one.

opBinary
Vec2!T opBinary(Vec2!T v)

Binary operations

opBinary
Vec2!T opBinary(T s)

Binary operations

opBinaryRight
Vec2!T opBinaryRight(T s)

Binary operations

opCast
Vec2!U opCast()

Conversion

opCmp
int opCmp(Vec2!T v)

Equality operations

opEquals
bool opEquals(Vec2!T v)

Equality operations

opOpAssign
Vec2!T opOpAssign(Vec2!T v)

Assignment

opOpAssign
Vec2!T opOpAssign(T s)

Assignment

opUnary
Vec2!T opUnary()

Unary operations

reflect
Vec2!T reflect(Vec2!T v)

Reflect this vector inside another one that represents the area change.

refract
Vec2!T refract(Vec2!T v, float eta)

Refracts this vector onto another one that represents the area change.

rotate
Vec2!T rotate(T angle)

Add an angle to this vector.

rotated
Vec2!T rotated(T angle)

Returns a vector with an added angle without modifying this one.

round
Vec2!T round()

Round the values to the nearest integer.

set
void set(T x_, T y_)

Changes {x, y}

sum
T sum()

Adds x and y.

toHash
size_t toHash()

Hash value.

Manifest constants

down
enum down;

{0, -1} vector.

down
enum down;

{0, -1} vector.

half
enum half;

{0.5, 0.5} vector. Its length is not 0.5 !

left
enum left;

{-1, 0} vector.

left
enum left;

{-1, 0} vector.

one
enum one;

{1, 1} vector. Its length is not one !

one
enum one;

{1, 1} vector. Its length is not one !

one
enum one;

{1, 1} vector. Its length is not one !

right
enum right;

{1, 0} vector.

right
enum right;

{1, 0} vector.

up
enum up;

{0, 1} vector.

up
enum up;

{0, 1} vector.

zero
enum zero;

Null vector.

zero
enum zero;

Null vector.

zero
enum zero;

Null vector.

Static functions

angled
Vec2!T angled(T angle)

Returns a unit vector with an angle.

Variables

x
T x;

x-axis coordinate.

y
T y;

y-axis coordinate.

Meta