#include <iostream.h>
#include "vector.h"
#include "planes.h"

int main()
{
    Coord low;			// Lower corner of ATC control region
    Coord high;			// Upper corner of ATC control region
    Coord pos;			// Current simulated position of plane
    Coord displayUpperRight(100,100);	// Simulated maximum window size
    Coord lowWindSize(0,0);	// Window's lower-left corner
    Coord transformed;		// Holds output from user's new function
    const float LIMIT = 0.1;	// Result within this distance is OK
    Plane* testPlane;	

	cout << "Please enter the lower X coordinate of your ATC region: ";
	cin >> low.x;
	cout << "Please enter the lower Y coordinate of your ATC region: ";
	cin >> low.y;
	cout << "Please enter the upper X coordinate of your ATC region: ";
	cin >> high.x;
	cout << "Please enter the upper Y coordinate of your ATC region: ";
	cin >> high.y;
	cout << endl;

	// First make sure that outOfRange works given the constants
	// supplied above.  If either of these tests fails, it means
	// that outOfRange isn't implemented properly or that the user
	// lied about their constants.

	testPlane = new Plane(1, low);
	if (testPlane->outOfRange())
	{
	    cout << "ERROR: A plane at " << low 
		 << " was considered out of range!" << endl;
	    exit(1);
	}
	delete testPlane;

	testPlane = new Plane(1, high);
	if (testPlane->outOfRange())
	{
	    cout << "ERROR: A plane at " << high
		 << " was considered out of range!" << endl;
	    exit(1);
	}
	delete testPlane;


	// Now we test the transformCoordinates function.
	// First make sure that the lower-left corner of their
	// ATC region maps to 0,0...

	testPlane = new Plane(1, low);
	transformed = testPlane->transformCoordinates(displayUpperRight);
	if (transformed.distance(lowWindSize) > LIMIT)
	{
	    cout << "New function returned wrong answer!" << endl;
	    cout << "Lower left corner of ATC region didn't map to "
	         << lowWindSize << endl;
	    cout << "Instead, it mapped to: " << transformed << endl;
	    exit(1);
	}
	delete testPlane;

	// Now see if the upper corner of their ATC region maps
	// to displayUpperRight...

	testPlane = new Plane(1, high);
	transformed = testPlane->transformCoordinates(displayUpperRight);
	if (transformed.distance(displayUpperRight) > LIMIT)
	{
	    cout << "New function returned wrong answer!" << endl;
	    cout << "Upper right corner of ATC region didn't map to "
		 << displayUpperRight << endl;
	    cout << "Instead, it mapped to: " << transformed << endl;
	    exit(1);
	}
	delete testPlane;

	// To be safe, see that a point in the middle of the ATC
	// region maps to the middle of the window...

	pos.x = (high.x-low.x)/2 + low.x;
	pos.y = (high.y-low.y)/2 + low.y;
	testPlane = new Plane(1, pos);

	transformed = testPlane->transformCoordinates(displayUpperRight);
	pos.x = displayUpperRight.x/2;
	pos.y = displayUpperRight.y/2;
	if (transformed.distance(pos) > LIMIT)
	{
	    cout << "New function returned wrong answer!" << endl;
	    cout << "Middle of ATC region didn't map to " << pos << endl;
	    cout << "Instead, it mapped to: " << transformed << endl;
	    exit(1);
	}

	cout << "\tYour transformCoordinates function works!" << endl;
	cout << "\tGet a coach over here to sign you off!" << endl << endl;

	return 0;
}

