summaryrefslogtreecommitdiff
path: root/Runtime/Math/Vector2.h
blob: 7c519b842e034fecbe353e21512184ae51cb8d4a (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
#pragma once
#include "MathHelper.h"
#include "Runtime/Utilities/Assert.h"

namespace Internal
{
    template<typename T>
    struct Vector2T
    {
        Vector2T(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;
        }

		Vector2T Clamp(T xmin, T xmax, T ymin, T ymax)
		{
			Vector2T 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 Vector2T& v) const
        {
            return v.x == x && v.y == y;
        }

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

        T x, y;

        static Vector2T<T> zero;
        static Vector2T<T> one;
    };

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