26 lines
No EOL
1.1 KiB
C++
26 lines
No EOL
1.1 KiB
C++
#include "Rhombus.h"
|
|
#include "GeometryUtils.h"
|
|
#include "IsoscelesTriangle.h"
|
|
|
|
bool Rhombus::validate() {
|
|
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]);
|
|
|
|
IsoscelesTriangle firstTriangle;
|
|
firstTriangle.setCoordinate(0, mVertices[0]);
|
|
firstTriangle.setCoordinate(1, mVertices[1]);
|
|
firstTriangle.setCoordinate(2, mVertices[2]);
|
|
|
|
IsoscelesTriangle secondTriangle;
|
|
secondTriangle.setCoordinate(0, mVertices[0]);
|
|
secondTriangle.setCoordinate(1, mVertices[2]);
|
|
secondTriangle.setCoordinate(2, mVertices[3]);
|
|
|
|
// 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));
|
|
} |