-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec2.cpp
More file actions
98 lines (77 loc) · 1.24 KB
/
Copy pathvec2.cpp
File metadata and controls
98 lines (77 loc) · 1.24 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "vec2.hpp"
#include <cmath>
#include <cassert>
#include <iostream>
vec2::vec2()
:x(0.0f),y(0.0f)
{}
vec2::vec2(float x_param,float y_param)
:x(x_param),y(y_param)
{}
vec2& vec2::operator+=(const vec2& v)
{
x+=v.x;
y+=v.y;
return *this;
}
vec2& vec2::operator-=(const vec2& v)
{
x-=v.x;
y-=v.y;
return *this;
}
vec2& vec2::operator*=(float s)
{
x*=s; y*=s;
return *this;
}
vec2& vec2::operator/=(float s)
{
assert(fabs(s)>10e-6);
x/=s; y/=s;
return *this;
}
void print_screen(const vec2& v)
{
std::cout<<v.x<<" "<<v.y<<std::endl;
}
float norm(const vec2& v)
{
return std::sqrt(v.x*v.x+v.y*v.y);
}
float dot(const vec2& v0,const vec2& v1)
{
return v0.x*v1.x+v0.y*v1.y;
}
vec2 normalize(vec2& v)
{
vec2 temp=v;
temp/=norm(v);
return temp;
}
vec2 operator+(const vec2& v0,const vec2& v1)
{
vec2 temp=v0;
temp+=v1;
return temp;
}
vec2 operator-(const vec2& v0,const vec2& v1)
{
vec2 temp=v0;
temp-=v1;
return temp;
}
vec2 operator*(const vec2& v0,float s)
{
vec2 temp=v0;
temp*=s;
return temp;
}
vec2 operator*(float s,const vec2& v0)
{
return v0*s;
}
vec2 operator/(const vec2& v0,float s)
{
vec2 temp=v0;temp/=s;return temp;
}