/*
  4th july: on linkedin, Keyvan Hadjari asked how to simulate OO in C.
  simpletestVector2.c: simple test program for Vector2 class
*/


#include <stdio.h>
#include <stdlib.h>

#include "vector2.h"


int main( void )
{
	Vector2 a  = new_Vector2( 10, 0 );
	Vector2 b  = new_Vector2( 0, 10 );

	// d = a->magnitude() using OM0 (object-method-call) helper
	double d = OM0(a,magnitude);

	printf( "magnitude of " );
	OM0(a,print);
	printf( " is %g\n", d );

	// d = a->distance_to(a),
	//     using OM1 (object-method-1param-call) helper
	d = OM1(a,distance_to,a);

	printf( "distance from " );
	OM0(a,print);                       // a->print()
	printf( " to itself is %g\n", d );

	// d = a->distance_to(b), using OM1 helper
	d     = OM1(a,distance_to,b);

	printf( "distance from " );
	OM0(a,print);                       // a->print()
	printf( " to " );
	OM0(b,print);                       // b->print()
	printf( " is %g\n", d );

	printf( "normalizing a: " );
	OM0(a,print);
	OM0(a,normalize);
	d = OM0(a,magnitude);
	printf( " gives " );
	OM0(a,print);
	printf( " with magnitude %g\n", d );

	printf( "scaling a: " );
	OM0(a,print);
	printf( " by 5 " );
	OM1(a,scale,5);
	printf( " gives " );
	OM0(a,print);
	d = OM0(a,magnitude);
	printf( " with magnitude %g\n", d );

	printf( "adding b: " );
	OM0(b,print);
	printf( " to a: " );
	OM0(a,print);
	OM1(a,add,b);
	printf( " gives " );
	OM0(a,print);
	d = OM0(a,magnitude);
	printf( " with magnitude %g\n", d );

	printf( "a isa %s, b isa %s\n", a->isa, b->isa );

	OM0( b, dispose );
	OM0( a, dispose );
	exit(0);
	return 0;
}
