math

class Vec2

A 2D vector.

Public Functions

double getLength() const

Get the length of the vector.

Returns:

The length of the vector if no overflow happens, otherwise -1.0

bool normalize()

Normalize the vector in-place.

Fails if an overflow occurs or the vector is the zero vector

double distanceTo(const Vec2 &other) const

Get the distance to another vector.

Parameters:

other – The other vector.

Returns:

The distance to another vector if no overflow happens, otherwise -1.0

Vec2 operator+(const Vec2 &other) const

Adds two vectors.

Parameters:

other – the other vector

Returns:

a vector sum of the other two, or the zero vector on overflow

Vec2 operator-(const Vec2 &other) const

Subtracts two vectors.

Parameters:

other – the subtracted vector

Returns:

a vector difference of the other two, or the zero vector on overflow

Vec2 &operator+=(const Vec2 &other)

in-place addition of another vector to this

Parameters:

other – the other vector

Returns:

reference to *this

bool operator==(const Vec2 &other) const

Checks if two vectors are the same.

Parameters:

other – the vector to compare to

Returns:

true if the vectors are close to the same, false otherwise

bool operator!=(const Vec2 &other) const

Checks if two vectors are different.

Parameters:

other – the vector to compare to

Returns:

true if the vectors are not close to the same, false otherwise

Public Static Functions

static Vec2 ZERO()

Get a vector with all components set to 0.

Returns:

The zero vector.

Vec2 kn::math::clampVec(const Vec2 &vec, const Vec2 &min, const Vec2 &max)

Clamp a vector.

Parameters:
  • vec – The vector to clamp.

  • min – The minimum value.

  • max – The maximum value.

Returns:

The clamped vector.

Vec2 kn::math::lerpVec(const Vec2 &a, const Vec2 &b, double t)

Linearly interpolate a vector.

Parameters:
  • a – The first vector.

  • b – The second vector.

  • t – The time.

Returns:

The interpolated vector.