Jamoma API  0.6.0.a19
Angle.cpp
1 // Angle.cpp
2 /***************************************************/
3 /*! \class Angle
4  \brief Angle class
5
6  This class implements an angle, which is given values
7  in degrees but converts and stores them as radians.
8
9  by Tristan Matthews and Nils Peters, 2007-2008.
10  */
11 /***************************************************/
12
13 #include "Angle.h"
14 #include "ext.h"
15 #include "TTBase.h"
16
17 const double Angle::PI_X_180 = kTTPi / 180.0;
18 extern bool globWarningFlag;
19
20 // default constructor
21 Angle::Angle() : min_(-kTTPi), max_(kTTPi), max2_(kTTTwoPi), coord_(0.0)
22 {}
23
24 // constraints check maybe not ideal
25 Angle::Angle(double nCoord, double min, double max, double max2) : min_(-kTTPi), max_(kTTPi), max2_(kTTTwoPi), coord_(0.0)
26 {
27  nCoord *= PI_X_180;
28  min *= PI_X_180;
29  max *= PI_X_180;
30
31  if (min < max && max <= max2)
32  {
33  min_ = min;
34  max_ = max;
35  max2_ = max2;
36  }
37  else
38  post("Invalid bounds for angle");
39
40  if (nCoord >= min_ && nCoord <= max_)
41  coord_ = nCoord;
42  else if (nCoord >= max_ && nCoord <= max2_ && max_ != max2_)
43  coord_ = nCoord - kTTTwoPi; // offset phase
44  else if (globWarningFlag)
45  post("Invalid angle, default to %f", coord_);
46 }
47
48 void Angle::operator ()(double nCoord) // set function
49 {
50  nCoord = nCoord * PI_X_180;
51
52  if (nCoord >= min_ && nCoord <= max_)
53  coord_ = nCoord;
54  else if (nCoord >= max_ && nCoord <= max2_ && max_ != max2_)
55  coord_ = nCoord - max2_;
56  else if (globWarningFlag)
57  post("Invalid angle %f, must be >= %f and <= %f", nCoord, min_, max_);
58 }
59
60 // get function
61 double Angle::operator ()() const
62 {
63  return coord_;
64 }
65
66 // vim:sw=4:et:cindent:
Angle()
Default class constructor.
Definition: Angle.cpp:21
static const double PI_X_180
Constant to convert degrees to radians.
Definition: Angle.h:36
TTFOUNDATION_EXPORT const TTFloat64 kTTTwoPi
Pre-calculated value of pi * 2.
Definition: TTBase.cpp:24
double operator()() const
Get angle.
Definition: Angle.cpp:61
Jamoma's lowest-level base class and related infrastructure.
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23