/////////////////////////////////////////////////////////////////////////
// 
// vertex.cpp 
// Jesse Doane
// April, 2000

#include "vertex.h"

///////////////////////////////////////////////////////////////////////////////

Vertex::Vertex( void ){}

///////////////////////////////////////////////////////////////////////////////

Vertex::Vertex( Vertex* v ){

this->x = v->x;
this->y = v->y;
}
///////////////////////////////////////////////////////////////////////////////
//
// check bounds, see if point has exceeded the edge of the world
//

int Vertex::CheckBounds( void ){

	if( x > 630 ){
		
		return HIT_RIGHT;
	}
	if( x < 10 ){
		
		return HIT_LEFT;
	}
	if( y > 470 ){
		
		return HIT_TOP;
	}
	if( y < 10 ){
		
		return HIT_BOTTOM;
	}
return -1;
}
///////////////////////////////////////////////////////////////////////////////
//
// rotate the vertex by angle theta around p
//
void Vertex::Rotate( Vertex* p, double theta ){

double new_x, new_y;

if( !memcmp( p, this, sizeof( Vertex ) ) ) return;

this->Sub( p );

new_x = this->x * cos( theta ) - this->y * sin( theta );
new_y = this->x * sin( theta ) + this->y * cos( theta );

this->x = new_x;
this->y = new_y;

this->Add( p );
}
/////////////////////////////////////////////////////////////////////////
//
//  Dot product of this vertex ( vector ) with p

double Vertex::Dot( Vertex* p ){

return (this->x * p->x) + (this->y * p->y);
}
/////////////////////////////////////////////////////////////////////////
//
// magnitude of vector

double Vertex::Norm( void ){

return sqrt( this->Dot( this ) );
}
////////////////////////////////////////////////////////////////////////
// 
// subtract some other vertex from this

void Vertex::Sub( Vertex* the_other ){ 

this->x -= the_other->x;
this->y -= the_other->y;
}
/////////////////////////////////////////////////////////////////////////
//
// add etc.

void Vertex::Add( Vertex* the_other ){ 

this->x += the_other->x;
this->y += the_other->y; 
}
