Hot Door CORE  0.7.0
Adobe® Illustrator® Plug-in Library
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
hdi::core::Angle Class Reference

Describes an angle, and allows for easy conversion between various units. More...

#include <hdicoreAngle.h>

Public Types

enum  Units { Radians = 1, Degrees = 2, Gradians = 3, Turns = 4 }
 Units supported for angle calculations.
 

Public Member Functions

 Angle ()
 Default Angle constructor; sets the angle to 0.0 radians. More...
 
 Angle (const double value_, const Units units_=Radians)
 Angle constructor; sets the angle to the provided value. More...
 
 Angle (const Angle &angle_)
 Angle copy constructor. More...
 
virtual ~Angle ()
 Angle destructor. More...
 
virtual bool equalWithinTol (const Angle &compare_, const Angle &tol_) const
 Checks for two angles being within a given tolerance of one another. More...
 
virtual bool operator== (const Angle &rhs_) const
 Compares two angles for equality. More...
 
virtual bool operator!= (const Angle &rhs_) const
 Compares two angles for inequality. More...
 
virtual bool operator< (const Angle &rhs_) const
 Checks if the target angle's value is less than the provided angle's. More...
 
virtual bool operator<= (const Angle &rhs_) const
 Checks if the target angle's value is less than or equal to the provided angle's. More...
 
virtual bool operator> (const Angle &rhs_) const
 Checks if the target angle's value is greater than the provided angle's. More...
 
virtual bool operator>= (const Angle &rhs_) const
 Checks if the target angle's value is greater than or equal to the provided angle's. More...
 
virtual Angle operator- () const
 Flips the sign of the target angle. More...
 
virtual Angle operator+ (const Angle &rhs_) const
 Allows two Angle objects to be added together with the + operator. More...
 
virtual Angle operator- (const Angle &rhs_) const
 Allows one Angle object to be substracted from another with the - operator. More...
 
virtual Angle operator* (const Angle &rhs_) const
 Allows two Angle objects to be multipled together with the * operator. More...
 
virtual Angle operator/ (const Angle &rhs_) const
 Allows one Angle object to be divided by another with the / operator. More...
 
virtual Angleoperator= (const Angle &rhs_)
 Allows one Angle object to be assigned from another. More...
 
virtual Angleoperator+= (const Angle &rhs_)
 Allows two Angle objects to be added together with the + operator, assigning the lefthand object. More...
 
virtual Angleoperator-= (const Angle &rhs_)
 Allows one Angle object to be substracted from another with the - operator, assigning the lefthand object. More...
 
virtual Angleoperator*= (const Angle &rhs_)
 Allows two Angle objects to be multipled together with the * operator, assigning the lefthand object. More...
 
virtual Angleoperator/= (const Angle &rhs_)
 Allows one Angle object to be divided by another with the / operator, assigning the lefthand object. More...
 
virtual Angle operator* (const double rhs_) const
 Allows an Angle object to be multipled by a constant. More...
 
virtual Angle operator/ (const double rhs_) const
 Allows an Angle object to be divided by a constant. More...
 
virtual Angleoperator*= (const double rhs_)
 Allows an Angle object to be multipled by a constant, assigning the lefthand object. More...
 
virtual Angleoperator/= (const double rhs_)
 Allows an Angle object to be divided by a constant, assigning the lefthand object. More...
 
virtual double asRadians () const
 Gets the value of the target object in radians. More...
 
virtual double asDegrees () const
 Gets the value of the target object in degrees. More...
 
virtual double asGradians () const
 Gets the value of the target object in gradians. More...
 
virtual double asTurns () const
 Gets the value of the target object in turns. More...
 
virtual double valueInUnits (const Units units_=Radians) const
 Gets the value of the target object in the given units. More...
 
virtual void setValueInUnits (const double value_, const Units units_=Radians)
 Sets the value of the target object in the given units. More...
 
virtual Angle range0To2Pi () const
 Changes the range of the angle value to be in [0,2pi]. More...
 
virtual Angle rangeNegPiToPi () const
 Changes the range of the angle value to be in [-pi,pi]. More...
 
virtual Angle nearest45 () const
 Constrains an angle to the nearest 45-degree (pi/4) interval. More...
 
virtual Angle constrain0ToPi () const
 Constrains the target Angle object's value to the range [0,pi]. More...
 
virtual Angle constrainPiOver2To3PiOver2 () const
 Constrains the target Angle object's value to the range [pi/2,3pi/2]. More...
 
virtual Angle constrainPiTo2Pi () const
 Constrains the target Angle object's value to the range [pi,2pi]. More...
 
virtual Angle constrainNegPiOver2ToPiOver2 () const
 Constrains the target Angle object's value to the range [-pi/2,pi/2]. More...
 
virtual Angle bisect (const Angle &angle2_) const
 Gets the bisection of the target Angle with a provided Angle on their most acute "side". More...
 
virtual Angle delta (const Angle &angle2_) const
 Gets the delta between the target Angle and a provided Angle object. More...
 
virtual bool firstQuadrant () const
 Tests if the target Angle lies in the first quadrant, were it from point (0,0) More...
 
virtual bool secondQuadrant () const
 Tests if the target Angle lies in the second quadrant, were it from point (0,0) More...
 
virtual bool thirdQuadrant () const
 Tests if the target Angle lies in the third quadrant, were it from point (0,0) More...
 
virtual bool fourthQuadrant () const
 Tests if the target Angle lies in the fourth quadrant, were it from point (0,0) More...
 
virtual int16_t quadrantNumber () const
 Gets the quadrant number for the target Angle, were it from point (0,0) More...
 
virtual double sin (const double tol_=10000.0 *maxDoublePrecision) const
 "Safely" computes the sine of an angle More...
 
virtual double cos (const double tol_=10000.0 *maxDoublePrecision) const
 "Safely" computes the cosine of an angle More...
 
virtual double tan (const double tol_=10000.0 *maxDoublePrecision) const
 "Safely" computes the tangent of an angle More...
 

Static Public Member Functions

static Angle asin (const double val_, const double tol_=10000.0 *maxDoublePrecision)
 "Safely" computes the angle for a given sine value More...
 
static Angle acos (const double val_, const double tol_=10000.0 *maxDoublePrecision)
 "Safely" computes the angle for a given cosine value More...
 
static Angle atan (const double val_, const double tol_=10000.0 *maxDoublePrecision)
 "Safely" computes the angle for a given tangent value More...
 
static Angle Zero ()
 Convenience method to construct an Angle object for zero radians, degrees, etc. More...
 
static Angle Pi ()
 Convenience method to construct an Angle object for pi radians. More...
 
static Angle TwoPi ()
 Convenience method to construct an Angle object for 2*pi radians. More...
 

Friends

geo::Angle * __accessImpl (const Angle &)
 
Angle __accessCtor (const geo::Angle &)
 

Detailed Description

Describes an angle, and allows for easy conversion between various units.

Constructor & Destructor Documentation

hdi::core::Angle::Angle ( )

Default Angle constructor; sets the angle to 0.0 radians.

Author
GW
Date
08/2013
hdi::core::Angle::Angle ( const double  value_,
const Units  units_ = Radians 
)

Angle constructor; sets the angle to the provided value.

Author
GW
Date
08/2013
Parameters
value_Value for the new Angle object
units_Units for the value_ object
hdi::core::Angle::Angle ( const Angle angle_)

Angle copy constructor.

Author
GW
Date
08/2013
Parameters
angle_Existing Angle object, whose values will be copied
virtual hdi::core::Angle::~Angle ( )
virtual

Angle destructor.

Author
GW
Date
08/2013

Member Function Documentation

static Angle hdi::core::Angle::acos ( const double  val_,
const double  tol_ = 10000.0 *maxDoublePrecision 
)
static

"Safely" computes the angle for a given cosine value

Author
GW
Date
08/2013
Parameters
val_Cosine value, whose corresponding angle is required
tol_Tolerance around zero, whereupon the returned value will be rounded to 0.0
Returns
Arc cosine of val_ argument, modified to 0.0 exactly if original value is within tol_
Note
Due to floating-point precision limitations, it can be pretty bad if a cosine value is slightly off from zero. For example, an "erroneously" negative value can cause program errors due to having a negative sign (instead of positive). If a value is very close to zero, it is simply converted to exactly 0.0.
virtual double hdi::core::Angle::asDegrees ( ) const
virtual

Gets the value of the target object in degrees.

Author
GW
Date
08/2013
Returns
The value of the target Angle object in degrees
virtual double hdi::core::Angle::asGradians ( ) const
virtual

Gets the value of the target object in gradians.

Author
GW
Date
08/2013
Returns
The value of the target Angle object in gradians
static Angle hdi::core::Angle::asin ( const double  val_,
const double  tol_ = 10000.0 *maxDoublePrecision 
)
static

"Safely" computes the angle for a given sine value

Author
GW
Date
08/2013
Parameters
val_Sine value, whose corresponding angle is required
tol_Tolerance around zero, whereupon the returned value will be rounded to 0.0
Returns
Arc sine of val_ argument, modified to 0.0 exactly if original value is within tol_
Note
Due to floating-point precision limitations, it can be pretty bad if a sine value is slightly off from zero. For example, an "erroneously" negative value can cause program errors due to having a negative sign (instead of positive). If a value is very close to zero, it is simply converted to exactly 0.0.
virtual double hdi::core::Angle::asRadians ( ) const
virtual

Gets the value of the target object in radians.

Author
GW
Date
08/2013
Returns
The value of the target Angle object in radians
virtual double hdi::core::Angle::asTurns ( ) const
virtual

Gets the value of the target object in turns.

Author
GW
Date
08/2013
Returns
The value of the target Angle object in turns
static Angle hdi::core::Angle::atan ( const double  val_,
const double  tol_ = 10000.0 *maxDoublePrecision 
)
static

"Safely" computes the angle for a given tangent value

Author
GW
Date
08/2013
Parameters
val_Tangent value, whose corresponding angle is required
tol_Tolerance around zero, whereupon the returned value will be rounded to 0.0
Returns
Arc tangent of val_ argument, modified to 0.0 exactly if original value is within tol_
Note
Due to floating-point precision limitations, it can be pretty bad if a tangent value is slightly off from zero. For example, an "erroneously" negative value can cause program errors due to having a negative sign (instead of positive). If a value is very close to zero, it is simply converted to exactly 0.0.
virtual Angle hdi::core::Angle::bisect ( const Angle angle2_) const
virtual

Gets the bisection of the target Angle with a provided Angle on their most acute "side".

Author
GW
Date
08/2013
Parameters
angle2_Second angle
Returns
An Angle object forming the acute bisection of the target and the provided Angle
virtual Angle hdi::core::Angle::constrain0ToPi ( ) const
virtual

Constrains the target Angle object's value to the range [0,pi].

Author
GW
Date
08/2013
Returns
A copy of the target Angle object, but with its value constrained to [0,pi]
Note
This method essentially takes any angle in the range (pi,2pi) and "flips" it across the polar coordinate system to point in the opposite direction; i.e. 3pi/2 becomes pi/2.
virtual Angle hdi::core::Angle::constrainNegPiOver2ToPiOver2 ( ) const
virtual

Constrains the target Angle object's value to the range [-pi/2,pi/2].

Author
GW
Date
08/2013
Returns
A copy of the target Angle object, but with its value constrained to [-pi/2,pi/2]
Note
This method essentially takes any angle in the range (pi/2,3pi/2) and "flips" it across the polar coordinate system to point in the opposite direction; i.e. pi becomes 0.
virtual Angle hdi::core::Angle::constrainPiOver2To3PiOver2 ( ) const
virtual

Constrains the target Angle object's value to the range [pi/2,3pi/2].

Author
GW
Date
08/2013
Returns
A copy of the target Angle object, but with its value constrained to [pi/2,3pi/2]
Note
This method essentially takes any angle in the range (-pi/2,pi/2) and "flips" it across the polar coordinate system to point in the opposite direction; i.e. 0 becomes pi.
virtual Angle hdi::core::Angle::constrainPiTo2Pi ( ) const
virtual

Constrains the target Angle object's value to the range [pi,2pi].

Author
GW
Date
08/2013
Returns
A copy of the target Angle object, but with its value constrained to [pi,2pi]
Note
This method essentially takes any angle in the range (0,pi) and "flips" it across the polar coordinate system to point in the opposite direction; i.e. pi/2 becomes 3pi/2.
virtual double hdi::core::Angle::cos ( const double  tol_ = 10000.0 *maxDoublePrecision) const
virtual

"Safely" computes the cosine of an angle

Author
GW
Date
08/2013
Parameters
tol_Tolerance around zero, whereupon the returned value will be rounded to 0.0
Returns
Cosine of angle_ argument, modified to 0.0 exactly if original value is within tolerance
Note
Due to floating-point precision limitations, it can be pretty bad if a cosine value is slightly off from zero. For example, an "erroneously" negative value can cause program errors due to having a negative sign (instead of positive). If a value is very close to zero, it is simply converted to exactly 0.0.
virtual Angle hdi::core::Angle::delta ( const Angle angle2_) const
virtual

Gets the delta between the target Angle and a provided Angle object.

Author
GW
Date
08/2013
Parameters
angle2_Second angle
Returns
An Angle object representing the delta between the target and the provided Angle
Note
This method always returns the smallest of the two possible deltas; if you want the larger, subtract the returned Angle from 2*pi
virtual bool hdi::core::Angle::equalWithinTol ( const Angle compare_,
const Angle tol_ 
) const
virtual

Checks for two angles being within a given tolerance of one another.

Author
GW
Date
08/2013
Parameters
compare_Angle to compare against the target object
tol_Allowable tolerance between the two objects, for them to be considered "equal"
Returns
true if the angles are "equal" within the given tolerance
virtual bool hdi::core::Angle::firstQuadrant ( ) const
virtual

Tests if the target Angle lies in the first quadrant, were it from point (0,0)

Author
GW
Date
08/2013
Returns
true if the Angle is in quadrant one, false otherwise
virtual bool hdi::core::Angle::fourthQuadrant ( ) const
virtual

Tests if the target Angle lies in the fourth quadrant, were it from point (0,0)

Author
GW
Date
08/2013
Returns
true if the Angle is in quadrant four, false otherwise
virtual Angle hdi::core::Angle::nearest45 ( ) const
virtual

Constrains an angle to the nearest 45-degree (pi/4) interval.

Author
GW
Date
08/2013
Returns
The nearest 45-degree interval for the target Angle object
virtual bool hdi::core::Angle::operator!= ( const Angle rhs_) const
virtual

Compares two angles for inequality.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the != operator; the angle to compare against
Returns
true if the angles' values are unequal to each other, or false otherwise
virtual Angle hdi::core::Angle::operator* ( const Angle rhs_) const
virtual

Allows two Angle objects to be multipled together with the * operator.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the * operator; the angle to multiply by the target
Returns
A copy of the target angle, but with the value of rhs_ multiplied by it
virtual Angle hdi::core::Angle::operator* ( const double  rhs_) const
virtual

Allows an Angle object to be multipled by a constant.

Author
GW
Date
10/2013
Parameters
rhs_Righthand side of the * operator; the constant to multiply against the target
Returns
A copy of the target angle, but with its value multiplied by the constant
virtual Angle& hdi::core::Angle::operator*= ( const Angle rhs_)
virtual

Allows two Angle objects to be multipled together with the * operator, assigning the lefthand object.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the * operator; the angle to multiply by the target
Returns
The target Angle object, but with the value of rhs_ multiplied by it
virtual Angle& hdi::core::Angle::operator*= ( const double  rhs_)
virtual

Allows an Angle object to be multipled by a constant, assigning the lefthand object.

Author
GW
Date
10/2013
Parameters
rhs_Righthand side of the * operator; the constant to multiply against the target
Returns
The target Angle object, but with its value multiplied by the constant
virtual Angle hdi::core::Angle::operator+ ( const Angle rhs_) const
virtual

Allows two Angle objects to be added together with the + operator.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the + operator; the angle to add to the target
Returns
A copy of the target angle, but with the value of rhs_ added to it
virtual Angle& hdi::core::Angle::operator+= ( const Angle rhs_)
virtual

Allows two Angle objects to be added together with the + operator, assigning the lefthand object.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the + operator; the angle to add to the target
Returns
The target Angle object, but with the value of rhs_ added to it
virtual Angle hdi::core::Angle::operator- ( ) const
virtual

Flips the sign of the target angle.

Author
GW
Date
08/2013
Returns
A copy of the target Angle object, but with the sign of its value flipped
virtual Angle hdi::core::Angle::operator- ( const Angle rhs_) const
virtual

Allows one Angle object to be substracted from another with the - operator.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the - operator; the angle to subtract from the target
Returns
A copy of the target angle, but with the value of rhs_ subtracted from it
virtual Angle& hdi::core::Angle::operator-= ( const Angle rhs_)
virtual

Allows one Angle object to be substracted from another with the - operator, assigning the lefthand object.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the - operator; the angle to subtract from the target
Returns
The target Angle object, but with the value of rhs_ subtracted from it
virtual Angle hdi::core::Angle::operator/ ( const Angle rhs_) const
virtual

Allows one Angle object to be divided by another with the / operator.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the / operator; the angle to divide into the target
Returns
A copy of the target angle, but with the value of rhs_ divided into it
virtual Angle hdi::core::Angle::operator/ ( const double  rhs_) const
virtual

Allows an Angle object to be divided by a constant.

Author
GW
Date
10/2013
Parameters
rhs_Righthand side of the / operator; the constant to divide into the target
Returns
A copy of the target angle, but with its value updated by dividing the constant into it
virtual Angle& hdi::core::Angle::operator/= ( const Angle rhs_)
virtual

Allows one Angle object to be divided by another with the / operator, assigning the lefthand object.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the / operator; the angle to divide into the target
Returns
The target Angle object, but with the value of rhs_ divided into it
virtual Angle& hdi::core::Angle::operator/= ( const double  rhs_)
virtual

Allows an Angle object to be divided by a constant, assigning the lefthand object.

Author
GW
Date
10/2013
Parameters
rhs_Righthand side of the / operator; the constant to divide into the target
Returns
The target Angle object, but with its value updated by dividing the constant into it
virtual bool hdi::core::Angle::operator< ( const Angle rhs_) const
virtual

Checks if the target angle's value is less than the provided angle's.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the < operator; the angle to compare against
Returns
true if the target angle's value is less than the value for rhs_, once their ranges are restricted to [0,2pi]
virtual bool hdi::core::Angle::operator<= ( const Angle rhs_) const
virtual

Checks if the target angle's value is less than or equal to the provided angle's.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the <= operator; the angle to compare against
Returns
true if the target angle's value is less than or equal to the value for rhs_, once their ranges are restricted to [0,2pi]
virtual Angle& hdi::core::Angle::operator= ( const Angle rhs_)
virtual

Allows one Angle object to be assigned from another.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the = operator; the object to copy a value from
Returns
The target Angle object, but with its value updated to match that of the rhs_ argument
virtual bool hdi::core::Angle::operator== ( const Angle rhs_) const
virtual

Compares two angles for equality.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the == operator; the angle to compare against
Returns
true if both angles' values are binary equal to each other, or false otherwise
virtual bool hdi::core::Angle::operator> ( const Angle rhs_) const
virtual

Checks if the target angle's value is greater than the provided angle's.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the > operator; the angle to compare against
Returns
true if the target angle's value is greater than the value for rhs_, once their ranges are restricted to [0,2pi]
virtual bool hdi::core::Angle::operator>= ( const Angle rhs_) const
virtual

Checks if the target angle's value is greater than or equal to the provided angle's.

Author
GW
Date
08/2013
Parameters
rhs_Righthand side of the >= operator; the angle to compare against
Returns
true if the target angle's value is greater than or equal to the value for rhs_, once their ranges are restricted to [0,2pi]
static Angle hdi::core::Angle::Pi ( )
static

Convenience method to construct an Angle object for pi radians.

Author
GW
Date
08/2013
Returns
An Angle object for pi radians
virtual int16_t hdi::core::Angle::quadrantNumber ( ) const
virtual

Gets the quadrant number for the target Angle, were it from point (0,0)

Author
GW
Date
08/2013
Returns
The quadrant number for the angle, or 0 for error (which should never happen...)
virtual Angle hdi::core::Angle::range0To2Pi ( ) const
virtual

Changes the range of the angle value to be in [0,2pi].

Author
GW
Date
08/2013
Returns
An equivalent angle to the target, but forced within range [0,2pi]
virtual Angle hdi::core::Angle::rangeNegPiToPi ( ) const
virtual

Changes the range of the angle value to be in [-pi,pi].

Author
GW
Date
08/2013
Returns
An equivalent angle to the target, but forced within range [-pi,pi]
virtual bool hdi::core::Angle::secondQuadrant ( ) const
virtual

Tests if the target Angle lies in the second quadrant, were it from point (0,0)

Author
GW
Date
08/2013
Returns
true if the Angle is in quadrant two, false otherwise
virtual void hdi::core::Angle::setValueInUnits ( const double  value_,
const Units  units_ = Radians 
)
virtual

Sets the value of the target object in the given units.

Author
GW
Date
08/2013
Parameters
value_Value, in "units_" units, to set
units_Units for the value_ argument
virtual double hdi::core::Angle::sin ( const double  tol_ = 10000.0 *maxDoublePrecision) const
virtual

"Safely" computes the sine of an angle

Author
GW
Date
08/2013
Parameters
tol_Tolerance around zero, whereupon the returned value will be rounded to 0.0
Returns
Sine of the target angle, modified to 0.0 exactly if original value is within tolerance
Note
Due to floating-point precision limitations, it can be pretty bad if a sine value is slightly off from zero. For example, an "erroneously" negative value can cause program errors due to having a negative sign (instead of positive). If a value is very close to zero, it is simply converted to exactly 0.0.
virtual double hdi::core::Angle::tan ( const double  tol_ = 10000.0 *maxDoublePrecision) const
virtual

"Safely" computes the tangent of an angle

Author
GW
Date
08/2013
Parameters
tol_Tolerance around zero, whereupon the returned value will be rounded to 0.0
Returns
Tangent of angle_ argument, modified to 0.0 exactly if original value is within tolerance
Note
Due to floating-point precision limitations, it can be pretty bad if a tangent value is slightly off from zero. For example, an "erroneously" negative value can cause program errors due to having a negative sign (instead of positive). If a value is very close to zero, it is simply converted to exactly 0.0.
virtual bool hdi::core::Angle::thirdQuadrant ( ) const
virtual

Tests if the target Angle lies in the third quadrant, were it from point (0,0)

Author
GW
Date
08/2013
Returns
true if the Angle is in quadrant three, false otherwise
static Angle hdi::core::Angle::TwoPi ( )
static

Convenience method to construct an Angle object for 2*pi radians.

Author
GW
Date
08/2013
Returns
An Angle object for 2*pi radians
virtual double hdi::core::Angle::valueInUnits ( const Units  units_ = Radians) const
virtual

Gets the value of the target object in the given units.

Author
GW
Date
08/2013
Parameters
units_Desired units for the return value
Returns
The value of the target Angle object in the provided units
static Angle hdi::core::Angle::Zero ( )
static

Convenience method to construct an Angle object for zero radians, degrees, etc.

Author
GW
Date
08/2013
Returns
An Angle object for 0.0 radians, degrees, etc.