-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector2.h
43 lines (31 loc) · 881 Bytes
/
Vector2.h
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
#pragma once
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#define MAXN 1000000
class Vector2
{
public:
Vector2() : x(0.f), y(0.f) { }
Vector2(float x, float y) : x(x), y(y) { }
void Scramble();
Vector2& operator=(const Vector2 &vec) { x = vec.x; y = vec.y; return *this; }
public:
float x, y;
};
inline Vector2 operator-(const Vector2 &lhs, const Vector2 &rhs) { return Vector2(lhs.x-rhs.x, lhs.y-rhs.y); }
inline Vector2 operator+(const Vector2 &lhs, const Vector2 &rhs) { return Vector2(lhs.x + rhs.x, lhs.y + rhs.y); }
inline Vector2 operator*(const Vector2 &v, float s)
{
return Vector2(v.x*s, v.y*s);
}
inline Vector2 operator*(float s, const Vector2 &v)
{
return Vector2(v.x*s, v.y*s);
}
inline void Vector2::Scramble()
{
x = rand() % (MAXN + 1) / (float)(MAXN + 1);
y = rand() % (MAXN + 1) / (float)(MAXN + 1);
}