From 6674d44fd0c2185022a1ad80c4949ed96a7e44d4 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Thu, 11 Apr 2024 23:50:57 +0200 Subject: [PATCH] junk --- src/main.cpp | 7 +++++++ src/point.cpp | 9 +++++++++ src/point.hpp | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5b0b1d3..9e8bc6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,13 @@ int main(int argc, char *argv[]) { Point p = Point(10, 5); std::cout << p << std::endl; p.move(5, 5); + + if (p.distance(Point(0, 0)) == p.distanceOrigin()) { + std::cout << "Distance is the same" << std::endl; + } else { + std::cout << "Distance is not the same" << std::endl; + } + std::cout << p << std::endl; std::cout << "Hello, World!" << std::endl; return 0; diff --git a/src/point.cpp b/src/point.cpp index a31c805..8d35173 100644 --- a/src/point.cpp +++ b/src/point.cpp @@ -1,4 +1,5 @@ #include "point.hpp" +#include Point::Point(int x, int y) { this->x = x; @@ -23,6 +24,14 @@ void Point::set(int x, int y) { this->y = y; } +float Point::distance(Point p) { + return sqrt(pow(this->x - p.x, 2) + pow(this->y - p.y, 2)); +} + +float Point::distanceOrigin() { + return sqrt(pow(this->x, 2) + pow(this->y, 2)); +} + std::ostream &operator<<(std::ostream &os, const Point &obj) { os << "Point: (" << obj.x << ", " << obj.y << ")"; return os; diff --git a/src/point.hpp b/src/point.hpp index f43c85b..967f519 100644 --- a/src/point.hpp +++ b/src/point.hpp @@ -1,6 +1,6 @@ #include -class Point { +class __attribute__((__packed__)) Point { private: int x, y; @@ -12,6 +12,8 @@ class Point { void setX(int x); void setY(int y); void move(int dx, int dy); + float distance(Point p); + float distanceOrigin(); friend std::ostream &operator<<(std::ostream &os, const Point &obj); };