diff options
Diffstat (limited to 'labs/src/point.cpp')
-rw-r--r-- | labs/src/point.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/labs/src/point.cpp b/labs/src/point.cpp new file mode 100644 index 0000000..1619bb6 --- /dev/null +++ b/labs/src/point.cpp @@ -0,0 +1,54 @@ +#include "../include/point.hpp" + +Point::Point(double x, double y) { + set(x, y); +} + +void Point::set(double x, double y) { + set_x(x); + set_y(y); +} + +void Point::set_x(double x) { + this->x = x; + calc_distance(); +} + +void Point::set_y(double y) { + this->y = y; + calc_distance(); +} + +void Point::origin_symmetry() { + set(-x, -y); +} + +void Point::translate(Point p) { + set(x+p.x, y+p.y); +} + +double Point::get_x() { + return x; +} + +double Point::get_y() { + return y; +} + +double Point::get_distance() { + return distance; +} + +double Point::get_distance(Point p) { + return sqrt(pow(x-p.x, 2) + pow(y-p.y, 2)); +} + +std::string Point::str() { + std::stringstream ss; + ss << "(" << x << ", " << y << ")"; + return ss.str(); +} + +void Point::calc_distance() { + distance = sqrt(pow(x, 2) + pow(y, 2)); +} |