moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / misc / goniometry.cc
blob07f9ae5012c3fede22e729a1d2410d8408c83e61
1 /**
2 This file is part of Kig, a KDE program for Interactive Geometry...
3 Copyright (C) 2004 Dominique Devriese <devriese@kde.org>
4 Copyright (C) 2004 Pino Toscano <toscano.pino@tiscali.it>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA
20 **/
23 #include "goniometry.h"
25 #include <qstringlist.h>
27 #include <kdebug.h>
28 #include <klocale.h>
30 #include <cmath>
32 Goniometry::Goniometry()
34 mvalue = 0.0;
35 msys = Rad;
38 Goniometry::Goniometry( double value, Goniometry::System system )
40 mvalue = value;
41 msys = system;
44 Goniometry::~Goniometry()
48 void Goniometry::setValue( double value )
50 mvalue = value;
53 const double Goniometry::value() const
55 return mvalue;
58 void Goniometry::setSystem( Goniometry::System system )
60 msys = system;
63 void Goniometry::convertTo( Goniometry::System system )
65 mvalue = convert( mvalue, msys, system );
66 msys = system;
69 const Goniometry::System Goniometry::system() const
71 return msys;
74 double Goniometry::getValue( Goniometry::System system )
76 return convert( mvalue, msys, system );
79 Goniometry& Goniometry::operator=( const Goniometry& g )
81 mvalue = g.value();
82 msys = g.system();
83 return *this;
86 double Goniometry::convert( const double angle, const Goniometry::System from, const Goniometry::System to )
88 switch( from )
90 case Deg:
92 if ( to == Rad )
93 return angle * M_PI / 180;
94 if ( to == Grad )
95 return angle * 10 / 9;
96 break;
98 case Rad:
100 if ( to == Deg )
101 return angle * 180 / M_PI;
102 if ( to == Grad )
103 return angle * 200 / M_PI;
104 break;
106 case Grad:
108 if ( to == Deg )
109 return angle * 9 / 10;
110 if ( to == Rad )
111 return angle * M_PI / 200;
112 break;
115 return angle;
118 QStringList Goniometry::systemList()
120 QStringList sl;
121 sl << i18n( "Translators: Degrees", "Deg" );
122 sl << i18n( "Translators: Radians", "Rad" );
123 sl << i18n( "Translators: Gradians", "Grad" );
124 return sl;
127 Goniometry::System Goniometry::intToSystem( const int index )
129 if( index == 0 )
130 return Deg;
131 else if( index == 1 )
132 return Rad;
133 else if( index == 2 )
134 return Grad;
135 kdDebug() << "No goniometric system with index " << index << endl;
136 return Rad;