-
Notifications
You must be signed in to change notification settings - Fork 0
/
vecteur.cpp
42 lines (31 loc) · 942 Bytes
/
vecteur.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
39
40
41
42
#include "vecteur.h"
#include <math.h>
vecteur::vecteur() {}
vecteur::vecteur(const vecteur &old) {
this->x = old.x;
this->y = old.y;
}
vecteur::vecteur(const double &x, const double &y) : x(x), y(y) {}
double vecteur::norme() {
return sqrt(pow(this->x, 2) + pow(this->y, 2));
}
void vecteur::normalize() {
// TODO : Implement func
}
vecteur& vecteur::operator+=(vecteur const& a) {
this->x += a.x;
this->y += a.y;
return *this;
}
vecteur operator+(vecteur const& a, vecteur const& b) {
vecteur copie(a); //On utilise le constructeur de copie
copie += b; //On appelle la méthode d'addition qui modifie l'objet `copie`
return copie; //Et on renvoie le résultat. Ni a ni b n'ont changé.
}
bool operator==(const vecteur& lhs, const vecteur& rhs) {
return lhs.x == rhs.x && lhs.y == rhs.y;
}
std::ostream& operator<<(std::ostream& os, const vecteur& c) {
os << "(" << c.x << ";" << c.y << ")";
return os;
}