-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloat2.h
34 lines (25 loc) · 883 Bytes
/
float2.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
#ifndef FLOAT2_H
#define FLOAT2_H
#include <math.h>
class float2
{
public:
float x, y;
float2():x(0),y(0) {}
float2(float _x, float _y):x(_x),y(_y) {}
float2 operator*(float f) { return float2(x*f, y*f); }
float2 operator/(float f) { return float2(x/f, y/f); }
float2 &operator+=(float2 f) { x+=f.x; y+=f.y; return *this; }
float2 operator-(float2 f) { return float2(x - f.x, y - f.y); }
float2 operator+(float2 f) { return float2(x + f.x, y + f.y); }
bool operator>(float2 f) { if(x > f.x || y > f.y) return true; return false;; }
float2(float f);
float2 normalized();
void clampLen(float f);
float len() { return sqrt(x*x+y*y); }
void zero() { x=y=0.f; }
bool isZero() { return x==0.f && y==0.f; }
protected:
private:
};
#endif // FLOAT2_H