33 lines
No EOL
864 B
C++
33 lines
No EOL
864 B
C++
#include "GeometryUtils.h"
|
|
|
|
#include <cmath>
|
|
|
|
const double EPSILON = 1e-7;
|
|
|
|
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 <= 0 || sideTwo <= 0 || sideThree <= 0) {
|
|
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;
|
|
} |