Dualie
Loading...
Searching...
No Matches
Vector2.hpp
1//
2// Created by caleb on 6/16/24.
3//
4
5#ifndef DUALIE_VECTOR2_HPP
6#define DUALIE_VECTOR2_HPP
7
8#include <string>
9
10namespace dl{
11
16 template<class T> class Vector2 {
17
18 public:
19
20 T x;
21 T y;
22
23 Vector2() {
24 x = 0;
25 y = 0;
26 }
27
28 Vector2(T x, T y) {
29 this->x = x;
30 this->y = y;
31 }
32
33 dl::Vector2<T> operator+(dl::Vector2<T> vector) const {
34
35 return dl::Vector2<T>(this->x + vector.x, this->y + vector.y);
36 }
37 dl::Vector2<T> operator-(dl::Vector2<T> vector) const {
38 return dl::Vector2<T>(this->x - vector.x, this->y - vector.y);
39 }
40 dl::Vector2<T> operator*(dl::Vector2<T> vector) const {
41 return dl::Vector2<T>(this->x * vector.x, this->y * vector.y);
42 }
43 dl::Vector2<T> operator/(dl::Vector2<T> vector) const {
44 return dl::Vector2<T>(this->x / vector.x, this->y / vector.y);
45 }
46 bool operator==(dl::Vector2<T> vector) const {
47 return (this->x == vector.x) && (this->y == vector.y);
48 }
49 bool operator!=(dl::Vector2<T> vector) const {
50 return (this->x != vector.x) || (this->y != vector.y);
51 }
52
57 std::string toString() const {
58 return "(" + std::to_string((int)x) + ", " + std::to_string((int)y) + ")";
59 }
60
61 };
62
63
64
65 using Vector2f = dl::Vector2<float>;
66 using Vector2i = dl::Vector2<int>;
67}
68
69
70
71#endif //DUALIE_VECTOR2_HPP
Used to contain a set of two numbers.
Definition Vector2.hpp:16
std::string toString() const
Converts the vector to a floored string for printing purposes.
Definition Vector2.hpp:57