//--------------------------------------------------
// Title:		MyCoord
// Author:		Tony Kim 
// Date:		2006 Nov 10 
// Description: 
//		Allows drawing of multiple "graphs" in a 
//		window
//--------------------------------------------------
#pragma once

#include "MyCoord.h"

MyCoord::MyCoord()
{
	max_x = 0;
	min_x = 0;
	max_y = 0;
	min_y = 0;
	w_width = 0;
	w_height = 0;
	w_anchor_x = 0;
	w_anchor_y = 0;
}

MyCoord::MyCoord( int p_max_x, int p_min_x,
				  int p_max_y, int p_min_y,
				  int p_w_width, int p_w_height,
			      int p_anchor_x, int p_anchor_y,
				  int p_min_width, int p_min_height,
				  int p_min_anchor_x, int p_min_anchor_y)
{
	max_x = p_max_x;
	min_x = p_min_x;
	max_y = p_max_y;
	min_y = p_min_y;
	w_width = p_w_width;
	w_height = p_w_height;
	w_anchor_x = p_anchor_x;
	w_anchor_y = p_anchor_y;
	
	// Input parameters are the dimensions when maximized
	w_max.width = w_width;
	w_max.height = w_height;
	w_max.anchor_x = p_anchor_x;
	w_max.anchor_y = p_anchor_y;

	// Dimensions when minimized;
	w_min.width = p_min_width;
	w_min.height = p_min_height;
	if( p_min_anchor_x >= 0 )
		w_min.anchor_x = p_min_anchor_x;
	else
		w_min.anchor_x = p_anchor_x;
	if( p_min_anchor_y >= 0 )
		w_min.anchor_y = p_min_anchor_y;
	else
		w_min.anchor_y = p_anchor_y;
}

void MyCoord::Set( int p_max_x, int p_min_x,
				   int p_max_y, int p_min_y,
				   int p_w_width, int p_w_height,
			       int p_anchor_x, int p_anchor_y,
				   int p_min_width, int p_min_height,
			       int p_min_anchor_x, int p_min_anchor_y)
{
	max_x = p_max_x;
	min_x = p_min_x;
	max_y = p_max_y;
	min_y = p_min_y;
	w_width = p_w_width;
	w_height = p_w_height;
	w_anchor_x = p_anchor_x;
	w_anchor_y = p_anchor_y;
	
	// Input parameters are the dimensions when maximized
	w_max.width = w_width;
	w_max.height = w_height;
	w_max.anchor_x = p_anchor_x;
	w_max.anchor_y = p_anchor_y;

	// Dimensions when minimized;
	w_min.width = p_min_width;
	w_min.height = p_min_height;
	if( p_min_anchor_x >= 0 )
		w_min.anchor_x = p_min_anchor_x;
	else
		w_min.anchor_x = p_anchor_x;
	if( p_min_anchor_y >= 0 )
		w_min.anchor_y = p_min_anchor_y;
	else
		w_min.anchor_y = p_anchor_y;
}

int wx( double math_x, MyCoord frame )
{
	return (int)(frame.GetAnchX() + (double)frame.GetWidth() / (double)(frame.GetMaxX() - frame.GetMinX()) * (double)(math_x - frame.GetMinX()));
}

int wy( double math_y, MyCoord frame )
{
	return (int)(frame.GetAnchY() + (double)frame.GetHeight() / (double)(frame.GetMinY()-frame.GetMaxY()) * (double)(math_y - frame.GetMaxY()));
}

double math_x( int wx, MyCoord frame )
{
	return (double)(frame.GetMinX() + (double)(frame.GetMaxX()-frame.GetMinX())/(double)(frame.GetWidth())*(double)(wx - frame.GetAnchX()));
}

double math_y( int wy, MyCoord frame )
{
	return (double)(frame.GetMaxY() + (double)(frame.GetMinY() - frame.GetMaxY())/(double)(frame.GetHeight())*(double)(wy - frame.GetAnchY()));
}