summaryrefslogtreecommitdiff
path: root/Client/Source/Math/Vector2.hpp
blob: 65f2c10c25cda17b019fe24c9a0203a980a8ecb4 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once 

#include "../Utilities/Assert.h"
#include "../Math/Functions.h"

template <typename T> 
class Vector2Template
{
public:
	Vector2Template(T x = 0, T y = 0)
	{
		this->x = x;
		this->y = y;
	}
	inline void Set(T x, T y)
	{
		this->x = x;
		this->y = y;
	}

	Vector2Template Clamp(T xmin, T xmax, T ymin, T ymax)
	{
		Vector2Template v;
		v.x = clamp(x, xmin, xmax);
		v.y = clamp(y, ymin, ymax);
		return v;
	}

	T operator[](int i)
	{
		if (i == 0) return x;
		else if (i == 1) return y;
		Assert(false);
	}

	bool operator == (const Vector2Template& v) const
	{
		return v.x == x && v.y == y;
	}

	bool operator != (const Vector2Template& v) const
	{
		return v.x != x || v.y != y;
	}

	Vector2Template<T> operator - (const Vector2Template& v) const
	{
		Vector2Template<T> res = Vector2Template<T>(x - v.x, y - v.y);
		return res;
	}


	float x, y;

	static Vector2Template<T> zero;
	static Vector2Template<T> one ;

};

using Vector2f = Vector2Template<float>;
using Vector2i = Vector2Template<int>;


template<typename T>
Vector2Template<T> Vector2Template<T>::zero = Vector2Template(0, 0);
template<typename T>
Vector2Template<T> Vector2Template<T>::one = Vector2Template(1, 1);