2024-11-06 17:02:59 -07:00
|
|
|
#include "Rhombus.h"
|
2024-11-18 00:16:40 -07:00
|
|
|
|
2024-11-06 17:02:59 -07:00
|
|
|
#include "GeometryUtils.h"
|
|
|
|
#include "IsoscelesTriangle.h"
|
|
|
|
|
|
|
|
bool Rhombus::validate() {
|
2024-11-18 00:18:28 -07:00
|
|
|
double sideOne = calculate_distance(mVertices[0], mVertices[1]);
|
|
|
|
double sideTwo = calculate_distance(mVertices[1], mVertices[2]);
|
|
|
|
double sideThree = calculate_distance(mVertices[2], mVertices[3]);
|
|
|
|
double sideFour = calculate_distance(mVertices[3], mVertices[0]);
|
2024-11-06 17:02:59 -07:00
|
|
|
|
2024-11-18 00:18:28 -07:00
|
|
|
IsoscelesTriangle firstTriangle;
|
|
|
|
firstTriangle.setCoordinate(0, mVertices[0]);
|
|
|
|
firstTriangle.setCoordinate(1, mVertices[1]);
|
|
|
|
firstTriangle.setCoordinate(2, mVertices[2]);
|
2024-11-06 17:02:59 -07:00
|
|
|
|
2024-11-18 00:18:28 -07:00
|
|
|
IsoscelesTriangle secondTriangle;
|
|
|
|
secondTriangle.setCoordinate(0, mVertices[0]);
|
|
|
|
secondTriangle.setCoordinate(1, mVertices[2]);
|
|
|
|
secondTriangle.setCoordinate(2, mVertices[3]);
|
2024-11-06 17:02:59 -07:00
|
|
|
|
2024-11-18 00:18:28 -07:00
|
|
|
// A valid rhombus must (a) Have vertices (0, 1, 2) make a valid isosceles
|
|
|
|
// triangle, (b) Have vertices (0, 2, 3) make a valid isosceles triangle,
|
|
|
|
// and (c) Have all sides of equal length
|
|
|
|
return firstTriangle.validate() && secondTriangle.validate() &&
|
|
|
|
(double_eq(sideOne, sideTwo) && double_eq(sideTwo, sideThree) &&
|
|
|
|
double_eq(sideThree, sideFour));
|
2024-11-06 17:02:59 -07:00
|
|
|
}
|