#include<iostream>
#include<cmath>
#include "quadrilateral.h"
#include "trapezoid.h"
#include "parallelogram.h"
#include "rectangle.h"
#include "square.h"
using namespace std;

bool Equals(double xVal, double yVal)
{
	const double epsilon = 10e-10;
	if(abs(xVal - yVal) <= epsilon * abs(xVal))
	{
		return true;
	}
	return false;
}

int main()
{
	double a1, a2, b1, b2, c1, c2, dx, dy, p1, p2, q1, q2, r1, r2, t1, t2;
	Point a, b, c, d, p, q, r, t;
	Quadrilateral quad;
	Trapezoid trap;
	Parallelogram par;
	Rectangle rect;
	Square sq;
	int number;
	//Point a(-4,-1), b(4,-1), c(4,7), d(-4,7);
	double s1 = b.Slope(a), s2 = c.Slope(b), s3 = d.Slope(c), s4 = a.Slope(d);
	double d1 = a.Distance(b), d2 = b.Distance(c), d3 = c.Distance(b);
	double d4 =	d.Distance(a);
	
	/*cout << "Test for Point" << endl;
	cout << "------------------" << endl;
	cout << "Enter the coordinates for point p: ";
	cin >> p1 >> p2;
	p.SetAll(p1,p2);
	cout << "Enter the coordinates for point q: ";
	cin >> q1 >> q2;
	q.SetAll(q1,q2);
	cout << "Enter the coordinates for point r: ";
	cin >> r1 >> r2;
	r.SetAll(r1,r2);
	cout << "Enter the coordinates for point t: ";
	cin >> t1 >> t2;
	t.SetAll(t1,t2);
	cout << "Point p: " << "(" << p.GetX() << "," << p.GetY() << ")" << endl;
	cout << "Point q: " << "(" << q.GetX() << "," << q.GetY() << ")" << endl;
	cout << "Point r: " << "(" << r.GetX() << "," << r.GetY() << ")" << endl;
	cout << "Point t: " << "(" << t.GetX() << "," << t.GetY() << ")" << endl;
	cout << "Slope: " << q.Slope(p) << endl;
	cout << "Distance: " << p.Distance(q) << endl;
	cout << endl;
	if(q.Slope(p) == t.Slope(r))
	{
		cout << "Two lines are parallel lines" << endl;
	}
	else if((((q.Slope(p)) * -(r.Slope(q))) == -1)
	|| (((q.Slope(p)) == UNDEFINED && (r.Slope(q)) == 0)
	|| ((r.Slope(q)) == UNDEFINED && (q.Slope(p)) == 0)))
	{
		cout << "Two lines are perpendicular" << endl;
	}
	cout << endl;*/
 	cout << "Test for different shapes" << endl;
	cout << "---------------------------" << endl;
	cout << "Enter the coordinates for the first point: ";
	cin >> a1 >> a2;
	cout << "Enter the coordinates for the second point: ";
	cin >> b1 >> b2;
	cout << "Enter the coordinates for the third point: ";
	cin >> c1 >> c2;
	cout << "Enter the coordinates for the fourth point: ";
	cin >> dx >> dy;
	quad.SetAll(a, b, c, d);
	trap.SetAll(a, b, c, d);
	par.SetAll(a, b, c, d);
	rect.SetAll(a, b, c, d);
	sq.SetAll(a, b, c, d);
	cout << "Enter 0 for quadrilateral, 1 for trapezoid," << endl;
	cout << "2 for paralleogram, 3 for rectangle, or 4 for square: ";
	cin >> number;
	if(number == 0)
	{
		quad.Print();
		cout << "Perimeter of quadrilateral: " << quad.Perimeter() << endl;
		cout << "Area of quadrilateral: " << quad.Area() << endl;
	}
	else if(number == 1)
	{
		trap.Print();
		if(Equals(s1,s3))
		{
			cout << "Perimeter of trapezoid: " << trap.Perimeter() << endl;
			cout << "Area of trapezoid: " << trap.Area() << endl;
		}
		else
		{
			cout << "The lines are not parallel." << endl;
		}
	}
	else if(number == 2)
	{
		par.Print();
		if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d3) && Equals(d2,d4))
		{
			cout << "Perimeter of parallelogram: " << par.Perimeter() << endl;
			cout << "Area of parallelogram: " << par.Area() << endl;
		}
		else
		{
			cout << "The lines are not parallel or the sides" << endl;
			cout << "are not the same length." << endl;
		} 
	}
	else if(number == 3)
	{
		rect.Print();
		if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d3) && Equals(d2,d4) 
		&& (((s1 * -s2) == -1) || ((s1 == UNDEFINED && s2 == 0) 
		|| (s2 == UNDEFINED && s1 == 0))) && (((s2 * -s3) == -1) 
		|| ((s2 == UNDEFINED && s3 == 0)  || (s3 == UNDEFINED && s2 == 0)))
		&& (((s3 * -s4) == -1) || ((s3 == UNDEFINED && s4 == 0)
		|| (s4 == UNDEFINED && s3 == 0))) && (((s4 * -s1) == -1) 
		|| ((s4 == UNDEFINED && s1 == 0) || (s1 == UNDEFINED && s4 == 0))))
		{
			cout << "Perimeter of rectangle: " << rect.Perimeter() << endl;
			cout << "Area of rectangle: " << rect.Area() << endl;
		}
		else
		{
			cout << "The lines are not parallel or the" << endl;
			cout << "sides are not the same length to the opposites." << endl;
		} 
	}
	else if(number == 4)
	{
		sq.Print();
		if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d2) && Equals(d1,d3) 
		&& Equals(d1,d4) && Equals(d2,d3) && Equals(d2,d4) && Equals(d3,d4)
		&& (((s1 * -s2) == -1) || ((s1 == UNDEFINED && s2 == 0) 
		|| (s2 == UNDEFINED && s1 == 0))) && (((s2 * -s3) == -1) 
		|| ((s2 == UNDEFINED && s3 == 0)  || (s3 == UNDEFINED && s2 == 0)))
		&& (((s3 * -s4) == -1) || ((s3 == UNDEFINED && s4 == 0)
		|| (s4 == UNDEFINED && s3 == 0))) && (((s4 * -s1) == -1) 
		|| ((s4 == UNDEFINED && s1 == 0) || (s1 == UNDEFINED && s4 == 0))))
		{
			cout << "Perimeter of square: " << sq.Perimeter() << endl;
			cout << "Area of square: " << sq.Area() << endl;
		}
		else
		{
			cout << "The lines are not parallel or the sides" << endl;
			cout << "are not the same length to each other." << endl;
		} 
	}
	else
	{
		cout << "There was an error for input." << endl;
	}
	return 0;
}


