A5/GeometryUtils.cpp

33 lines
864 B
C++
Raw Normal View History

2024-11-06 17:02:59 -07:00
#include "GeometryUtils.h"
2024-11-18 00:16:40 -07:00
#include <cmath>
const double EPSILON = 1e-7;
2024-11-06 17:02:59 -07:00
bool double_eq(double first, double second) {
if (std::abs(first - second) <= EPSILON) {
return true;
} else {
return false;
}
2024-11-06 17:02:59 -07:00
}
double calculate_distance(Coordinate& firstPoint, Coordinate& secondPoint) {
return std::sqrt(std::pow(secondPoint.x - firstPoint.x, 2) +
std::pow(secondPoint.y - firstPoint.y, 2));
2024-11-06 17:02:59 -07:00
}
bool lengths_make_triangle(double sideOne, double sideTwo, double sideThree) {
// Not a triangle if one of the side lengths is 0
if (sideOne <= 0 || sideTwo <= 0 || sideThree <= 0) {
return false;
}
2024-11-06 17:02:59 -07:00
// Not a triangle if the sum of any two side lengths >= the third length
if (sideOne + sideTwo <= sideThree || sideTwo + sideThree <= sideOne ||
sideThree + sideOne <= sideTwo) {
return false;
}
2024-11-06 17:02:59 -07:00
return true;
2024-11-06 17:02:59 -07:00
}