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

namespace Internal
{
    struct Vector2
    {
        Vector2(float x = 0, float y = 0)
        {
            this->x = x;
            this->y = y;
        }
        inline void Set(float x, float y)
        {
            this->x = x;
            this->y = y;
        }

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

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

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

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

        float x, y;

        static Vector2 zero;
        static Vector2 one;
    };
}