aboutsummaryrefslogtreecommitdiff
path: root/include/fml/vec2.h
blob: d02e855bb83a71ad1177f061f7824ba5bddd5401 (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
#ifndef VEC2_H
#define VEC2_H
#include <iostream>

#include "fml.h"

namespace fml {
    class vec2 {
    public:
        scalar v[2];
    public:
        vec2();
        vec2(scalar x);
        vec2(scalar x, scalar y);
        scalar &operator[](int index);
        scalar operator[](int index) const;
        vec2 operator*(scalar scale) const;
        vec2 operator/(scalar scale) const;
        vec2 operator+(const vec2 &other) const;
        vec2 operator-(const vec2 &other) const;
        vec2 operator-() const;
        const vec2 &operator*=(scalar scale);
        const vec2 &operator/=(scalar scale);
        const vec2 &operator+=(const vec2 &other);
        const vec2 &operator-=(const vec2 &other);
        scalar magnitude() const;
        scalar magnitudeSquared() const;
        vec2 normalize() const;
        vec2 rotateby(scalar angle);
        scalar dot(const vec2 &other) const;
    };

    vec2 operator*(scalar scale, const vec2 &v);

    std::ostream &operator<<(std::ostream &output, const vec2 &v);
    std::istream &operator>>(std::istream &input, vec3 &v);
}

#endif