Blame ETL/test/angle.cpp

darco b3016b
/*! ========================================================================
darco b3016b
** Extended Template and Library Test Suite
darco b3016b
** Angle Class Test
dooglus 36d01e
** $Id$
darco b3016b
**
darco b3016b
** Copyright (c) 2002 Robert B. Quattlebaum Jr.
dooglus 756c0d
** Copyright (c) 2008 Chris Moore
darco b3016b
**
darco b3016b
** This package is free software; you can redistribute it and/or
darco b3016b
** modify it under the terms of the GNU General Public License as
darco b3016b
** published by the Free Software Foundation; either version 2 of
darco b3016b
** the License, or (at your option) any later version.
darco b3016b
**
darco b3016b
** This package is distributed in the hope that it will be useful,
darco b3016b
** but WITHOUT ANY WARRANTY; without even the implied warranty of
darco b3016b
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
darco b3016b
** General Public License for more details.
darco b3016b
**
darco b3016b
** === N O T E S ===========================================================
darco b3016b
**
darco b3016b
** ========================================================================= */
darco b3016b
darco b3016b
/* === H E A D E R S ======================================================= */
darco b3016b
darco b3016b
#include <stdio.h></stdio.h>
darco b3016b
#include <etl angle=""></etl>
darco b3016b
#include <etl clock=""></etl>
darco b3016b
#include <etl bezier=""></etl>
darco b3016b
#include <etl hermite=""></etl>
darco b3016b
darco b3016b
/* === M A C R O S ========================================================= */
darco b3016b
darco b3016b
using namespace std;
darco b3016b
using namespace etl;
darco b3016b
darco b3016b
/* === C L A S S E S ======================================================= */
darco b3016b
darco b3016b
template <class angle=""></class>
darco b3016b
void angle_cos_speed_test(void)
darco b3016b
{
darco b3016b
	Angle a,b,c,d;
darco b3016b
	float tmp,tmp2;
dooglus cee594
darco b3016b
	for(tmp=-1.0;tmp<1.0;tmp+=0.000002)
darco b3016b
	{
darco b3016b
		a=(typename Angle::cos)(tmp);
darco b3016b
		b=(typename Angle::cos)(tmp);
darco b3016b
		c=(typename Angle::cos)(tmp);
darco b3016b
		d=(typename Angle::cos)(tmp);
darco b3016b
		tmp2=((typename Angle::cos)(a)).get();
darco b3016b
		tmp2=((typename Angle::cos)(b)).get();
darco b3016b
		tmp2=((typename Angle::cos)(c)).get();
dooglus cee594
		tmp2=((typename Angle::cos)(d)).get();
darco b3016b
	}
fce3e7
	if (tmp2 == 0) return; // disable unused warning
darco b3016b
}
darco b3016b
template <class angle=""></class>
darco b3016b
void angle_sin_speed_test(void)
darco b3016b
{
darco b3016b
	Angle a,b,c,d;
darco b3016b
	float tmp,tmp2;
dooglus cee594
darco b3016b
	for(tmp=-1.0;tmp<1.0;tmp+=0.000002)
darco b3016b
	{
darco b3016b
		a=(typename Angle::sin)(tmp);
darco b3016b
		b=(typename Angle::sin)(tmp);
darco b3016b
		c=(typename Angle::sin)(tmp);
darco b3016b
		d=(typename Angle::sin)(tmp);
darco b3016b
		tmp2=((typename Angle::sin)(a)).get();
darco b3016b
		tmp2=((typename Angle::sin)(b)).get();
darco b3016b
		tmp2=((typename Angle::sin)(c)).get();
dooglus cee594
		tmp2=((typename Angle::sin)(d)).get();
darco b3016b
	}
fce3e7
	if (tmp2 == 0) return; // disable unused warning
darco b3016b
}
darco b3016b
template <class angle=""></class>
darco b3016b
void angle_tan_speed_test(void)
darco b3016b
{
darco b3016b
	Angle a,b,c,d;
darco b3016b
	float tmp,tmp2;
dooglus cee594
darco b3016b
	for(tmp=-1.0;tmp<1.0;tmp+=0.000002)
darco b3016b
	{
darco b3016b
		a=(typename Angle::tan)(tmp);
darco b3016b
		b=(typename Angle::tan)(tmp);
darco b3016b
		c=(typename Angle::tan)(tmp);
darco b3016b
		d=(typename Angle::tan)(tmp);
darco b3016b
		tmp2=((typename Angle::tan)(a)).get();
darco b3016b
		tmp2=((typename Angle::tan)(b)).get();
darco b3016b
		tmp2=((typename Angle::tan)(c)).get();
dooglus cee594
		tmp2=((typename Angle::tan)(d)).get();
darco b3016b
	}
fce3e7
	if (tmp2 == 0) return; // disable unused warning
darco b3016b
}
darco b3016b
template <class angle,="" class="" mytan=""></class>
darco b3016b
void angle_atan2_speed_test(void)
darco b3016b
{
darco b3016b
	Angle a,b,c;
darco b3016b
	float x,y;
dooglus cee594
darco b3016b
	for(y=-10.0;y<10.0;y+=0.05)
darco b3016b
		for(x=-10.0;x<10.0;x+=0.05)
darco b3016b
		{
darco b3016b
			a=mytan(y,x);
darco b3016b
			a=mytan(x,y);
darco b3016b
			b=mytan(y,x);
darco b3016b
			b=mytan(x,y);
darco b3016b
			c=mytan(y,x);
darco b3016b
			c=mytan(x,y);
darco b3016b
			a=mytan(y,x);
darco b3016b
			a=mytan(x,y);
darco b3016b
			b=mytan(y,x);
darco b3016b
			b=mytan(x,y);
darco b3016b
			c=mytan(y,x);
darco b3016b
			c=mytan(x,y);
darco b3016b
		}
darco b3016b
}
darco b3016b
darco b3016b
int angle_test()
darco b3016b
{
darco b3016b
	int ret=0;
darco b3016b
	float dist;
dooglus cee594
darco b3016b
	dist=angle::deg(angle::deg(330).dist(angle::deg(30))).get();
darco b3016b
	printf("angle: angular difference between 330deg and 30deg is %0.1fdeg\n",dist);
dooglus 0c1ee1
	if(floor(dist+0.5)!=300)
darco b3016b
	{
dooglus 0c1ee1
		printf("angle: error: should be 300deg!\n");
darco b3016b
		ret++;
dooglus cee594
	}
darco b3016b
darco b3016b
	dist=angle::deg(angle::deg(30).dist(angle::deg(330))).get();
darco b3016b
	printf("angle: angular difference between 30deg and 330deg is %0.1fdeg\n",dist);
dooglus 0c1ee1
	if(floor(dist+0.5)!=-300)
darco b3016b
	{
dooglus 0c1ee1
		printf("angle: error: should be -300deg!\n");
darco b3016b
		ret++;
dooglus cee594
	}
darco b3016b
darco b3016b
	dist=angle::deg(angle::deg(30).dist(angle::deg(-30))).get();
darco b3016b
	printf("angle: angular difference between 30deg and -30deg is %0.1fdeg\n",dist);
darco b3016b
	if(floor(dist+0.5)!=60)
darco b3016b
	{
darco b3016b
		printf("angle: error: should be 60deg!\n");
darco b3016b
		ret++;
dooglus cee594
	}
darco b3016b
darco b3016b
	dist=angle::deg(angle::deg(-30).dist(angle::deg(30))).get();
darco b3016b
	printf("angle: angular difference between -30deg and 30deg is %0.1fdeg\n",dist);
darco b3016b
	if(floor(dist+0.5)!=-60)
darco b3016b
	{
darco b3016b
		printf("angle: error: should be -60deg!\n");
darco b3016b
		ret++;
dooglus cee594
	}
darco b3016b
darco b3016b
	dist=angle::deg(angle::deg(20).dist(angle::deg(195))).get();
darco b3016b
	printf("angle: angular difference between 20deg and 195deg is %0.1fdeg\n",dist);
darco b3016b
	if(floor(dist+0.5)!=-175)
darco b3016b
	{
darco b3016b
		printf("angle: error: should be -175deg!\n");
darco b3016b
		ret++;
dooglus cee594
	}
darco b3016b
darco b3016b
	dist=angle::deg(angle::deg(20).dist(angle::deg(205))).get();
darco b3016b
	printf("angle: angular difference between 20deg and 205deg is %0.1fdeg\n",dist);
dooglus 0c1ee1
	if(floor(dist+0.5)!=-185)
darco b3016b
	{
dooglus 0c1ee1
		printf("angle: error: should be -185deg!\n");
darco b3016b
		ret++;
dooglus cee594
	}
darco b3016b
darco b3016b
	int i;
darco b3016b
darco b3016b
	for(i=-1000;i<1000;i++)
darco b3016b
	{
darco b3016b
		dist=angle::deg(angle::deg(20+i+360).dist(angle::deg(205+i-360))).get();
dooglus 0c1ee1
		if(floor(dist+0.5)!=535)
darco b3016b
		{
darco b3016b
			printf("angle: error: Badness at %d!\n",i);
darco b3016b
			ret++;
dooglus cee594
		}
dooglus cee594
darco b3016b
	}
darco b3016b
darco b3016b
	for(i=-1000;i<1000;i++)
darco b3016b
	{
darco b3016b
		dist=angle::deg(angle::deg(20+i-360).dist(angle::deg(195+i+360))).get();
dooglus 0c1ee1
		if(floor(dist+0.5)!=-895)
darco b3016b
		{
darco b3016b
			printf("angle: error: Badness at %d!\n",i);
darco b3016b
			ret++;
dooglus cee594
		}
dooglus cee594
darco b3016b
	}
darco b3016b
darco b3016b
darco b3016b
darco b3016b
	{
darco b3016b
		float f;
darco b3016b
		angle a(angle::deg(-2005));
darco b3016b
		angle b(angle::deg(200));
darco b3016b
darco b3016b
		affine_combo<angle> combo;</angle>
dooglus cee594
darco b3016b
		hermite<angle> hermie(a,b,b.dist(a),b.dist(a));</angle>
dooglus cee594
darco b3016b
		for(f=0;f<1.001;f+=0.1)
darco b3016b
		{
darco b3016b
			printf("@%f--affine_combo: %f hermie: %f\n",angle::deg(f).get(),angle::deg(combo(a,b,f)).get(),angle::deg(hermie(f)).get());
darco b3016b
		}
dooglus cee594
darco b3016b
	}
darco b3016b
darco b3016b
	return ret;
darco b3016b
}
darco b3016b
darco b3016b
/* === E N T R Y P O I N T ================================================= */
darco b3016b
darco b3016b
int main()
darco b3016b
{
darco b3016b
	int error=0;
dooglus cee594
darco b3016b
	error+=angle_test();
dooglus cee594
darco b3016b
	return error;
darco b3016b
}