25 lines
738 B
C++
25 lines
738 B
C++
|
|
#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() {}
|
||
|
|
|
||
|
|
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) {
|
||
|
|
stream << "(" << p.x << ", " << p.y << ")";
|
||
|
|
return stream;
|
||
|
|
}
|