-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.cpp
38 lines (38 loc) · 950 Bytes
/
helper.cpp
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
#include "helper.h"
using namespace std;
Vec::Vec(){
x=0;
y=0;
}
Vec::Vec(double a, double b){
x=a;
y=b;
}
double Vec::distance(Vec v){
return (sqrt(pow((this->x-v.x),2)+pow((this->y-v.y),2)));
}
bool operator== (const Vec &v1, const Vec&v2){
return(v1.x == v2.x && v1.y == v2.y);
}
Vec operator+ (const Vec &v1, const Vec&v2){
return(Vec(v1.x+v2.x,v1.y+v2.y));
}
Vec operator* (const double &k, const Vec&v2){
return(Vec(v2.x*k,k*v2.y));
}
reg::reg(){
this->center = Vec(0,0);
this->size = 2048;
}
reg::reg(Vec c, double s){
this->center=c;
this->size=s;
}
bool reg::region_are_same(reg r1){
return (r1.center==this->center);
}
bool reg::contains_vec(Vec p){
bool x_true = (this->center.x-(this->size)/2.0) < p.x && (this->center.x+(this->size)/2.0) > p.x ;
bool y_true = (this->center.y-(this->size)/2.0) < p.y && (this->center.y+(this->size)/2.0) > p.y ;
return x_true && y_true;
}