cpp02/ex03/Point.cpp

28 lines
829 B
C++
Raw Normal View History

2025-05-15 10:55:59 +02:00
#include "Point.hpp"
#include <iostream>
Point::Point() : x(0), y(0) {}
Point::Point(float x, float y) : x(Fixed(x)), y(Fixed(y)) {}
Point::Point(Point const &other) : x(other.x), y(other.y) {}
Point &Point::operator=(const Point &other) {
(void)other;
std::cerr << "WARNING: called Point::operator=, which is a noop due to x and "
"y being const."
<< std::endl;
return *this;
};
Point::~Point() {}
2025-05-20 13:34:30 +02:00
Fixed Point::getX() const { return x; }
Fixed Point::getY() const { return y; }
2025-05-15 10:55:59 +02:00
Fixed Point::triangleArea(Point const &a, Point const &b, Point const &c) {
return (((a.x * (b.y - c.y)) + (b.x * (c.y - a.y)) + (c.x * (a.y - b.y))) / 2)
.abs();
}
std::ostream &operator<<(std::ostream &stream, const Point &p) {
2025-05-20 13:34:30 +02:00
stream << "(" << p.getX() << ", " << p.getY() << ")";
2025-05-15 10:55:59 +02:00
return stream;
}