34 lines
587 B
C++
34 lines
587 B
C++
![]() |
#include "Vertex.h"
|
||
|
#include <math.h>
|
||
|
|
||
|
double Vertex::distanceSq(const Vertex &v) const {
|
||
|
return (x - v.x)*(x - v.x) + (y - v.y)*(y - v.y);
|
||
|
}
|
||
|
|
||
|
double Vertex::distance(const Vertex &v) const {
|
||
|
return sqrt(distanceSq(v));
|
||
|
}
|
||
|
|
||
|
|
||
|
Vertex Vertex::operator+(const Vertex &v) const {
|
||
|
return Vertex(x + v.x, y + v.y);
|
||
|
}
|
||
|
|
||
|
Vertex Vertex::operator-(const Vertex &v) const {
|
||
|
return Vertex(x - v.x, y - v.y);
|
||
|
}
|
||
|
|
||
|
Vertex& Vertex::operator+=(const Vertex &v) {
|
||
|
x += v.x;
|
||
|
y += v.y;
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
Vertex& Vertex::operator-=(const Vertex &v) {
|
||
|
x -= v.x;
|
||
|
y -= v.y;
|
||
|
|
||
|
return *this;
|
||
|
}
|