Isis 3 Programmer Reference
Distance.h
1 #ifndef Distance_h
2 #define Distance_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 class QString;
11 
12 namespace Isis {
13  class Displacement;
14 
34  class Distance {
35  public:
41  enum Units {
60  };
61 
62  Distance();
63  Distance(double distance, Units distanceUnit);
64  Distance(double distanceInPixels, double pixelsPerMeter);
65  Distance(const Distance &distanceToCopy);
66  virtual ~Distance();
67 
68  double meters() const;
69  void setMeters(double distanceInMeters);
70 
71  double kilometers() const;
72  void setKilometers(double distanceInKilometers);
73 
74  double pixels(double pixelsPerMeter = 1.0) const;
75  void setPixels(double distanceInPixels, double pixelsPerMeter = 1.0);
76 
77  double solarRadii() const;
78  void setSolarRadii(double distanceInSolarRadii);
79 
80  QString toString() const;
81  bool isValid() const;
82 
83  bool operator >(const Distance &otherDistance) const;
84  bool operator <(const Distance &otherDistance) const;
85 
94  bool operator >=(const Distance &otherDistance) const {
95  return *this > otherDistance || *this == otherDistance;
96  }
97 
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 meters() == otherDistance.meters();
122  }
123 
124 
133  bool operator !=(const Distance &otherDistance) const {
134  return meters() != otherDistance.meters();
135  }
136 
137 
138  Distance &operator =(const Distance &distanceToCopy);
139  Distance operator +(const Distance &distanceToAdd) const;
140  Displacement operator -(const Distance &distanceToSub) const;
141  double operator /(const Distance &distanceToDiv) const;
142  Distance operator /(const double &valueToDiv) const;
143  Distance operator *(const double &valueToMult) const;
144  friend Distance operator *(double mult, Distance dist);
145  void operator +=(const Distance &distanceToAdd);
146  void operator -=(const Distance &distanceToSub);
147  void operator /=(const double &valueToDiv);
148  void operator *=(const double &valueToMult);
149 
150  protected:
151  virtual double distance(Units distanceUnit) const;
152  virtual void setDistance(const double &distance, Units distanceUnit);
153 
154  private:
160  };
161 }
162 
163 #endif
Isis::Distance::kilometers
double kilometers() const
Get the distance in kilometers.
Definition: Distance.cpp:106
Isis::Distance::setPixels
void setPixels(double distanceInPixels, double pixelsPerMeter=1.0)
Set the distance in pixels.
Definition: Distance.cpp:145
Isis::Distance::operator>
bool operator>(const Distance &otherDistance) const
Compare two distances with the greater than operator.
Definition: Distance.cpp:204
Isis::Distance::Pixels
@ Pixels
The distance is being specified in pixels.
Definition: Distance.h:47
Isis::Distance::operator<
bool operator<(const Distance &otherDistance) const
Compare two distances with the less than operator.
Definition: Distance.cpp:222
Isis::Distance::operator=
Distance & operator=(const Distance &distanceToCopy)
Assign this distance to the value of another distance.
Definition: Distance.cpp:239
Isis::Distance::operator>=
bool operator>=(const Distance &otherDistance) const
Compare two distances with the greater than or equal to operator.
Definition: Distance.h:94
Isis::Distance::setKilometers
void setKilometers(double distanceInKilometers)
Set the distance in kilometers.
Definition: Distance.cpp:118
Isis::Distance::solarRadii
double solarRadii() const
Get the distance in solar radii (a unit of ~696,265km).
Definition: Distance.cpp:155
Isis::Distance::Units
Units
This is a list of available units to access and store Distances in.
Definition: Distance.h:41
Isis::Distance::SolarRadii
@ SolarRadii
"Solar radius is a unit of distance used to express the size of stars in astronomy equal to the curre...
Definition: Distance.h:59
Isis::Distance::setMeters
void setMeters(double distanceInMeters)
Set the distance in meters.
Definition: Distance.cpp:96
Isis::Distance
Distance measurement, usually in meters.
Definition: Distance.h:34
Isis::Distance::Kilometers
@ Kilometers
The distance is being specified in kilometers.
Definition: Distance.h:45
Isis::Displacement
Displacement is a signed length, usually in meters.
Definition: Displacement.h:31
Isis::Distance::operator!=
bool operator!=(const Distance &otherDistance) const
Compare two distances with the != operator.
Definition: Distance.h:133
Isis::Distance::setSolarRadii
void setSolarRadii(double distanceInSolarRadii)
Set the distance in solar radii.
Definition: Distance.cpp:167
Isis::Distance::Meters
@ Meters
The distance is being specified in meters.
Definition: Distance.h:43
Isis::Distance::~Distance
virtual ~Distance()
This will free the memory allocated by this instance of the Distance class.
Definition: Distance.cpp:73
Isis::Distance::toString
QString toString() const
Get a textual representation of this distance.
Definition: Distance.cpp:177
Isis::Distance::operator<=
bool operator<=(const Distance &otherDistance) const
Compare two distances with the less than or equal to operator.
Definition: Distance.h:107
Isis::Distance::isValid
bool isValid() const
Test if this distance has been initialized or not.
Definition: Distance.cpp:192
Isis::Distance::operator-
Displacement operator-(const Distance &distanceToSub) const
Subtract another distance from this distance (1km - 1m = 995m).
Definition: Distance.cpp:268
Isis::Distance::distance
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:405
Isis::Distance::Distance
Distance()
This initializes the distance to an invalid state.
Definition: Distance.cpp:21
Isis::Distance::operator/=
void operator/=(const double &valueToDiv)
Divide this distance by a value and assign the result to ourself.
Definition: Distance.cpp:372
Isis::Distance::setDistance
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:452
Isis::Distance::operator+=
void operator+=(const Distance &distanceToAdd)
Add and assign the given distance to ourselves.
Definition: Distance.cpp:340
Isis::Distance::operator*=
void operator*=(const double &valueToMult)
Multiply this distance by a value and assign the result to ourself.
Definition: Distance.cpp:387
Isis::Distance::operator-=
void operator-=(const Distance &distanceToSub)
Subtract and assign the given distance from ourself.
Definition: Distance.cpp:357
Isis::Distance::meters
double meters() const
Get the distance in meters.
Definition: Distance.cpp:85
Isis::Distance::operator+
Distance operator+(const Distance &distanceToAdd) const
Add another distance to this distance (1km + 1m = 1005m)
Definition: Distance.cpp:254
Isis::Distance::m_distanceInMeters
double m_distanceInMeters
This is the distance value that this class is encapsulating, always stored in meters.
Definition: Distance.h:159
Isis::Distance::operator*
Distance operator*(const double &valueToMult) const
Multiply this distance by a value (5m * 2 = 10m).
Definition: Distance.cpp:313
Isis::Distance::pixels
double pixels(double pixelsPerMeter=1.0) const
Get the distance in pixels using the given conversion ratio.
Definition: Distance.cpp:131
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::Distance::operator/
double operator/(const Distance &distanceToDiv) const
Divide another distance into this distance (5m / 1m = 5).
Definition: Distance.cpp:284
Isis::Distance::operator==
bool operator==(const Distance &otherDistance) const
Compare two distances with the == operator.
Definition: Distance.h:120