Isis 3 Developer Reference
Distance.h
Go to the documentation of this file.
1 #ifndef Distance_h
2 #define Distance_h
3 
23 class QString;
24 
25 namespace Isis {
26  class Displacement;
27 
47  class Distance {
48  public:
54  enum Units {
73  };
74 
75  Distance();
76  Distance(double distance, Units distanceUnit);
77  Distance(double distanceInPixels, double pixelsPerMeter);
78  Distance(const Distance &distanceToCopy);
79  virtual ~Distance();
80 
81  double meters() const;
82  void setMeters(double distanceInMeters);
83 
84  double kilometers() const;
85  void setKilometers(double distanceInKilometers);
86 
87  double pixels(double pixelsPerMeter = 1.0) const;
88  void setPixels(double distanceInPixels, double pixelsPerMeter = 1.0);
89 
90  double solarRadii() const;
91  void setSolarRadii(double distanceInSolarRadii);
92 
93  QString toString() const;
94  bool isValid() const;
95 
96  bool operator >(const Distance &otherDistance) const;
97  bool operator <(const Distance &otherDistance) const;
98 
107  bool operator >=(const Distance &otherDistance) const {
108  return *this > otherDistance || *this == otherDistance;
109  }
110 
111 
120  bool operator <=(const Distance &otherDistance) const {
121  return *this < otherDistance || *this == otherDistance;
122  }
123 
124 
133  bool operator ==(const Distance &otherDistance) const {
134  return meters() == otherDistance.meters();
135  }
136 
137 
146  bool operator !=(const Distance &otherDistance) const {
147  return meters() != otherDistance.meters();
148  }
149 
150 
151  Distance &operator =(const Distance &distanceToCopy);
152  Distance operator +(const Distance &distanceToAdd) const;
153  Displacement operator -(const Distance &distanceToSub) const;
154  double operator /(const Distance &distanceToDiv) const;
155  Distance operator /(const double &valueToDiv) const;
156  Distance operator *(const double &valueToMult) const;
157  friend Distance operator *(double mult, Distance dist);
158  void operator +=(const Distance &distanceToAdd);
159  void operator -=(const Distance &distanceToSub);
160  void operator /=(const double &valueToDiv);
161  void operator *=(const double &valueToMult);
162 
163  protected:
164  virtual double distance(Units distanceUnit) const;
165  virtual void setDistance(const double &distance, Units distanceUnit);
166 
167  private:
172  double m_distanceInMeters;
173  };
174 }
175 
176 #endif
bool operator>=(const Distance &otherDistance) const
Compare two distances with the greater than or equal to operator.
Definition: Distance.h:107
double meters() const
Get the distance in meters.
Definition: Distance.cpp:97
void operator/=(const double &valueToDiv)
Divide this distance by a value and assign the result to ourself.
Definition: Distance.cpp:384
Distance operator+(const Distance &distanceToAdd) const
Add another distance to this distance (1km + 1m = 1005m)
Definition: Distance.cpp:266
bool operator<(const Distance &otherDistance) const
Compare two distances with the less than operator.
Definition: Distance.cpp:234
Units
This is a list of available units to access and store Distances in.
Definition: Distance.h:54
double solarRadii() const
Get the distance in solar radii (a unit of ~696,265km).
Definition: Distance.cpp:167
void operator+=(const Distance &distanceToAdd)
Add and assign the given distance to ourselves.
Definition: Distance.cpp:352
QString toString() const
Get a textual representation of this distance.
Definition: Distance.cpp:189
Displacement operator-(const Distance &distanceToSub) const
Subtract another distance from this distance (1km - 1m = 995m).
Definition: Distance.cpp:280
virtual double distance(Units distanceUnit) const
This is a helper method to access distances in a universal manner with uniform error checking...
Definition: Distance.cpp:417
void operator*=(const double &valueToMult)
Multiply this distance by a value and assign the result to ourself.
Definition: Distance.cpp:399
"Solar radius is a unit of distance used to express the size of stars in astronomy equal to the curre...
Definition: Distance.h:72
The distance is being specified in kilometers.
Definition: Distance.h:58
double pixels(double pixelsPerMeter=1.0) const
Get the distance in pixels using the given conversion ratio.
Definition: Distance.cpp:143
Distance()
This initializes the distance to an invalid state.
Definition: Distance.cpp:33
double kilometers() const
Get the distance in kilometers.
Definition: Distance.cpp:118
Distance measurement, usually in meters.
Definition: Distance.h:47
double operator/(const Distance &distanceToDiv) const
Divide another distance into this distance (5m / 1m = 5).
Definition: Distance.cpp:296
void setMeters(double distanceInMeters)
Set the distance in meters.
Definition: Distance.cpp:108
bool operator!=(const Distance &otherDistance) const
Compare two distances with the != operator.
Definition: Distance.h:146
void setPixels(double distanceInPixels, double pixelsPerMeter=1.0)
Set the distance in pixels.
Definition: Distance.cpp:157
Distance operator*(const double &valueToMult) const
Multiply this distance by a value (5m * 2 = 10m).
Definition: Distance.cpp:325
bool operator>(const Distance &otherDistance) const
Compare two distances with the greater than operator.
Definition: Distance.cpp:216
virtual ~Distance()
This will free the memory allocated by this instance of the Distance class.
Definition: Distance.cpp:85
void setKilometers(double distanceInKilometers)
Set the distance in kilometers.
Definition: Distance.cpp:130
bool operator==(const Distance &otherDistance) const
Compare two distances with the == operator.
Definition: Distance.h:133
bool operator<=(const Distance &otherDistance) const
Compare two distances with the less than or equal to operator.
Definition: Distance.h:120
bool isValid() const
Test if this distance has been initialized or not.
Definition: Distance.cpp:204
void operator-=(const Distance &distanceToSub)
Subtract and assign the given distance from ourself.
Definition: Distance.cpp:369
Displacement is a signed length, usually in meters.
Definition: Displacement.h:43
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void setSolarRadii(double distanceInSolarRadii)
Set the distance in solar radii.
Definition: Distance.cpp:179
The distance is being specified in meters.
Definition: Distance.h:56
virtual void setDistance(const double &distance, Units distanceUnit)
This is a helper method to set distances in a universal manner with uniform error checking...
Definition: Distance.cpp:464
The distance is being specified in pixels.
Definition: Distance.h:60
Distance & operator=(const Distance &distanceToCopy)
Assign this distance to the value of another distance.
Definition: Distance.cpp:251