34 lines
951 B
C++
34 lines
951 B
C++
|
#include <cmath>
|
||
|
|
||
|
#include "GeometryUtils.h"
|
||
|
|
||
|
const double EPSILON = std::numeric_limits<double>::epsilon();
|
||
|
|
||
|
bool double_eq(double first, double second) {
|
||
|
if (std::abs(first - second) <= EPSILON) {
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
double calculate_distance(Coordinate& firstPoint, Coordinate& secondPoint) {
|
||
|
return std::sqrt(
|
||
|
std::pow(secondPoint.x - firstPoint.x, 2)
|
||
|
+ std::pow(secondPoint.y - firstPoint.y, 2)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
bool lengths_make_triangle(double sideOne, double sideTwo, double sideThree) {
|
||
|
// Not a triangle if one of the side lengths is 0
|
||
|
if (sideOne <= EPSILON || sideTwo <= EPSILON || sideThree <= EPSILON) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// 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;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|