aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Vector2.h
blob: 0e419366fdd68bb218bf912d7c2c0ae9319933e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

namespace crepe {

//! 2D vector
template <class T>
struct Vector2 {
	//! X component of the vector
	T x = 0;
	//! Y component of the vector
	T y = 0;

	//! Subtracts another vector from this vector and returns the result.
	Vector2 operator-(const Vector2 & other) const;

	//! Adds another vector to this vector and returns the result.
	Vector2 operator+(const Vector2 & other) const;

	//! Multiplies this vector by a scalar and returns the result.
	Vector2 operator*(double scalar) const;

	//! Multiplies this vector by another vector element-wise and updates this vector.
	Vector2 & operator*=(const Vector2 & other);

	//! Adds another vector to this vector and updates this vector.
	Vector2 & operator+=(const Vector2 & other);

	//! Adds a scalar value to both components of this vector and updates this vector.
	Vector2 & operator+=(double other);

	//! Returns the negation of this vector.
	Vector2 operator-() const;

	//! Checks if this vector is equal to another vector.
	bool operator==(const Vector2 & other) const;

	//! Checks if this vector is not equal to another vector.
	bool operator!=(const Vector2 & other) const;
};

} // namespace crepe

#include "Vector2.hpp"