Isis 3 Programmer Reference
Displacement.h
1 #ifndef Displacement_h
2 #define Displacement_h
3 
9 /* SPDX-License-Identifier: CC0-1.0 */
10 
11 namespace Isis {
12  class Distance;
13 
31  class Displacement {
32  public:
38  enum Units {
44  Pixels
45  };
46 
47  Displacement();
48  Displacement(double displacement, Units distanceUnit);
49  Displacement(double displacementInPixels, double pixelsPerMeter);
50  Displacement(const Distance &distanceToCopy);
51 
56 
57  double meters() const;
58  void setMeters(double displacementInMeters);
59 
60  double kilometers() const;
61  void setKilometers(double displacementInKilometers);
62 
63  double pixels(double pixelsPerMeter = 1.0) const;
64  void setPixels(double distanceInPixels, double pixelsPerMeter = 1.0);
65 
66  bool isValid() const;
67 
77  bool operator >(const Displacement &otherDisplacement) const;
78  bool operator <(const Displacement &otherDisplacement) const;
79 
80 
89  bool operator >=(const Displacement &otherDisplacement) const {
90  return *this > otherDisplacement || *this == otherDisplacement;
91  }
92 
93 
102  bool operator <=(const Displacement &otherDisplacement) const {
103  return *this < otherDisplacement || *this == otherDisplacement;
104  }
105 
116  bool operator !=(const Displacement &otherDisplacement) const {
117  return !(*this == otherDisplacement);
118  }
119 
130  bool operator ==(const Displacement &otherDisplacement) const {
131  return m_displacementInMeters ==
132  otherDisplacement.m_displacementInMeters;
133  }
134 
135  Displacement operator +(const Displacement &displacementToAdd) const;
136  Displacement operator -(const Displacement &displacementToSub) const;
137  Displacement operator -(const Distance &distanceToSub) const;
138  double operator /(const Displacement &displacementToDiv) const;
139  Displacement operator /(const double &valueToDiv) const;
140  Displacement operator *(const double &valueToMult) const;
141  friend Displacement operator *(double mult, Displacement displacement);
142  void operator +=(const Displacement &displacementToAdd);
143  void operator -=(const Displacement &displacementToSub);
144  void operator -=(const Distance &distanceToSub);
145  void operator /=(const double &valueToDiv);
146  void operator *=(const double &valueToMult);
147 
148  protected:
149  double displacement(Units displacementUnit) const;
150  void setDisplacement(const double &displacement, Units displacementUnit);
151 
152  private:
158  };
159 }
160 
161 #endif
Isis::Displacement::operator==
bool operator==(const Displacement &otherDisplacement) const
Compare the lengths of 2 displacements with the == operator.
Definition: Displacement.h:130
Isis::Displacement::operator>=
bool operator>=(const Displacement &otherDisplacement) const
Compare the distances of 2 displacements with the >= operator.
Definition: Displacement.h:89
Isis::Displacement::m_displacementInMeters
double m_displacementInMeters
This is the displacement value that this class is encapsulating, always stored in meters.
Definition: Displacement.h:157
Isis::Displacement::Meters
@ Meters
The distance is being specified in meters.
Definition: Displacement.h:40
Isis::Displacement::operator/=
void operator/=(const double &valueToDiv)
Divide this displacement by a value and assign the result to ourself.
Definition: Displacement.cpp:329
Isis::Displacement::operator*
Displacement operator*(const double &valueToMult) const
Multiply this displacement by a value (5m * 2 = 10m).
Definition: Displacement.cpp:264
Isis::Displacement::~Displacement
~Displacement()
Free the memory allocated by this instance of the displacement class.
Definition: Displacement.h:55
Isis::Displacement::operator!=
bool operator!=(const Displacement &otherDisplacement) const
Compare the lengths of 2 displacements with the != operator.
Definition: Displacement.h:116
Isis::Displacement::Units
Units
This is a list of available units to access and store Distances in.
Definition: Displacement.h:38
Isis::Displacement::operator<
bool operator<(const Displacement &otherDisplacement) const
Compare two displacements with the less than operator.
Definition: Displacement.cpp:173
Isis::Displacement::setDisplacement
void setDisplacement(const double &displacement, Units displacementUnit)
This is a helper method to set displacements in a universal manner with uniform error checking.
Definition: Displacement.cpp:400
Isis::Displacement::setKilometers
void setKilometers(double displacementInKilometers)
Set the displacement in kilometers.
Definition: Displacement.cpp:105
Isis::Displacement::operator-
Displacement operator-(const Displacement &displacementToSub) const
Subtract another displacement from this displacement (1km - 5m = 995m).
Definition: Displacement.cpp:206
Isis::Displacement::Pixels
@ Pixels
The distance is being specified in pixels.
Definition: Displacement.h:44
Isis::Displacement::operator-=
void operator-=(const Displacement &displacementToSub)
Subtract the given displacement from ourself and assign.
Definition: Displacement.cpp:303
Isis::Distance
Distance measurement, usually in meters.
Definition: Distance.h:34
Isis::Displacement
Displacement is a signed length, usually in meters.
Definition: Displacement.h:31
Isis::Displacement::operator/
double operator/(const Displacement &displacementToDiv) const
Divide another displacement into this displacement (5m / 1m = 5).
Definition: Displacement.cpp:236
Isis::Displacement::meters
double meters() const
Get the displacement in meters.
Definition: Displacement.cpp:73
Isis::Displacement::setMeters
void setMeters(double displacementInMeters)
Set the displacement in meters.
Definition: Displacement.cpp:84
Isis::Displacement::operator+=
void operator+=(const Displacement &displacementToAdd)
Add and assign the given displacement to ourselves.
Definition: Displacement.cpp:290
Isis::Displacement::Displacement
Displacement()
This initializes the displacement to an invalid state.
Definition: Displacement.cpp:20
Isis::Displacement::pixels
double pixels(double pixelsPerMeter=1.0) const
Get the displacement in pixels using the given conversion ratio.
Definition: Displacement.cpp:117
Isis::Displacement::setPixels
void setPixels(double distanceInPixels, double pixelsPerMeter=1.0)
Set the displacement in pixels.
Definition: Displacement.cpp:130
Isis::Displacement::kilometers
double kilometers() const
Get the displacement in kilometers.
Definition: Displacement.cpp:94
Isis::Displacement::displacement
double displacement(Units displacementUnit) const
This is a helper method to access displacements in a universal manner with uniform error checking.
Definition: Displacement.cpp:358
Isis::Displacement::operator+
Displacement operator+(const Displacement &displacementToAdd) const
Add another displacement to this displacement (1km + 5m = 1005m)
Definition: Displacement.cpp:191
Isis::Displacement::isValid
bool isValid() const
Test if this displacement has been initialized or not.
Definition: Displacement.cpp:141
Isis::Displacement::operator<=
bool operator<=(const Displacement &otherDisplacement) const
Compare the lengths of 2 displacements with the <= operator.
Definition: Displacement.h:102
Isis::Displacement::operator*=
void operator*=(const double &valueToMult)
Multiply this displacement by a value and assign the result to ourself.
Definition: Displacement.cpp:342
Isis::Displacement::operator>
bool operator>(const Displacement &otherDisplacement) const
Get the displacement in meters.
Definition: Displacement.cpp:154
Isis::Displacement::Kilometers
@ Kilometers
The distance is being specified in kilometers.
Definition: Displacement.h:42
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16