1 //******************************************************************* 2 // 3 // License: See top level LICENSE.txt file. 4 // 5 // Author: David Burken 6 // 7 // Description: 8 // 9 // Contains class declaration for ossimDpt. 10 // Used to represent an double point containing an x and y data member. 11 // 12 //******************************************************************* 13 // $Id: ossimDpt.h 19793 2011-06-30 13:26:56Z gpotts $ 14 #ifndef ossimDpt_HEADER 15 #define ossimDpt_HEADER 16 17 #include <iosfwd> 18 #include <string> 19 #include <ossim/base/ossimConstants.h> 20 #include <ossim/base/ossimCommon.h> 21 #include <ossim/base/ossimString.h> 22 23 // Forward class declarations. 24 class ossimIpt; 25 class ossimFpt; 26 class ossimDpt3d; 27 class ossimGpt; 28 29 class OSSIMDLLEXPORT ossimDpt 30 { 31 public: 32 ossimDpt()33 ossimDpt() : x(0), y(0) {} 34 ossimDpt(double anX,double aY)35 ossimDpt(double anX, double aY) : x(anX), y(aY) {} 36 37 // trust the default generated copy-constructor 38 // ossimDpt(const ossimDpt& pt) = default; 39 40 ossimDpt(const ossimFpt& pt); 41 42 ossimDpt(const ossimIpt& pt); 43 44 ossimDpt(const ossimDpt3d &pt); 45 46 ossimDpt(const ossimGpt &pt); // assigns lat, lon only 47 48 // trust the default generated copy-constructor 49 // const ossimDpt& operator=(const ossimDpt&) = default; 50 51 const ossimDpt& operator=(const ossimFpt&); 52 53 const ossimDpt& operator=(const ossimIpt&); 54 55 const ossimDpt& operator=(const ossimDpt3d&); 56 57 const ossimDpt& operator=(const ossimGpt&); // assigns lat, lon only 58 59 bool operator==(const ossimDpt& pt) const 60 { return ( ossim::almostEqual(x, pt.x) && ossim::almostEqual(y, pt.y) ); } 61 62 bool operator!=(const ossimDpt& pt) const 63 { return !(*this == pt ); } 64 makeNan()65 void makeNan(){x = ossim::nan(); y=ossim::nan();} 66 hasNans()67 bool hasNans()const 68 { 69 return (ossim::isnan(x) || ossim::isnan(y)); 70 } 71 isNan()72 bool isNan()const 73 { 74 return (ossim::isnan(x) && ossim::isnan(y)); 75 } 76 77 /*! 78 * METHOD: length() 79 * Returns the RSS of the components. 80 */ length()81 double length() const { return sqrt(x*x + y*y); } 82 83 //*** 84 // OPERATORS: +, -, +=, -= 85 // Point add/subtract with other point: 86 //*** 87 ossimDpt operator+(const ossimDpt& p) const 88 { return ossimDpt(x+p.x, y+p.y); } 89 ossimDpt operator-(const ossimDpt& p) const 90 { return ossimDpt(x-p.x, y-p.y); } 91 const ossimDpt& operator+=(const ossimDpt& p) 92 { x += p.x; y += p.y; return *this; } 93 const ossimDpt& operator-=(const ossimDpt& p) 94 { x -= p.x; y -= p.y; return *this; } 95 96 //*** 97 // OPERATORS: *, / 98 // Scale point components by scalar: 99 //*** 100 ossimDpt operator*(const double& d) const 101 { return ossimDpt(d*x, d*y); } 102 ossimDpt operator/(const double& d) const 103 { return ossimDpt(x/d, y/d); } 104 const ossimDpt& operator*=(const double& d) 105 { x*=d; y*=d; return *this; } 106 107 /** Dot product */ 108 ossim_float64 operator*(const ossimDpt& pt)const 109 { return (x*pt.x+y*pt.y); } 110 111 std::ostream& print(std::ostream& os, ossim_uint32 precision=15) const; 112 113 friend OSSIMDLLEXPORT std::ostream& operator<<(std::ostream& os, 114 const ossimDpt& pt); 115 116 /** 117 * @param precision Output floating point precision. 118 * 119 * @return ossimString representing point. 120 * 121 * Output format: ( 30.00000000000000, -90.00000000000000 ) 122 * --------x-------- ---------y-------- 123 */ 124 ossimString toString(ossim_uint32 precision=15) const; 125 126 /** 127 * Initializes this point from string. This method opens an std::istream to 128 * s and then calls operator>>. 129 * 130 * Expected format: ( 30.00000000000000, -90.00000000000000 ) 131 * --------x-------- ---------y-------- 132 * 133 * @param s String to initialize from. 134 * 135 * @see operator>> 136 */ 137 void toPoint(const std::string& s); 138 139 /** 140 * Method to input the formatted string of the "operator<<". 141 * 142 * Expected format: ( 30.00000000000000, -90.00000000000000 ) 143 * --------x-------- ---------y-------- 144 * 145 * This method starts by doing a "makeNan" on pt. So if anything goes 146 * wrong with the stream or parsing pt could be all or partially nan. 147 * 148 * @param is Input stream std::istream to formatted text. 149 * @param pt osimDpt to be initialized from stream. 150 * @return std::istream pass in. 151 */ 152 friend OSSIMDLLEXPORT std::istream& operator>>(std::istream& is, 153 ossimDpt& pt); 154 bool isEqualTo(const ossimDpt& rhs, ossimCompareType compareType=OSSIM_COMPARE_FULL)const; 155 156 /** 157 * Returns the average of x and y 158 */ mean()159 double mean() const { return (x + y) / 2.0; } 160 161 //*** 162 // Public data members: 163 //*** 164 union {double x; double samp; double u; double lon;}; 165 union {double y; double line; double v; double lat;}; 166 167 }; 168 169 170 #endif /* #ifndef ossimDpt_HEADER */ 171