Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef GNASH_POINT2DH
00025 #define GNASH_POINT2DH
00026
00027 #include <ostream>
00028 #include <cmath>
00029 #include <boost/cstdint.hpp>
00030
00031 namespace gnash {
00032 namespace geometry {
00033
00035
00038 class Point2d
00039 {
00040 public:
00041
00043 boost::int32_t x;
00044
00046 boost::int32_t y;
00047
00049 Point2d()
00050 :
00051 x(0), y(0)
00052 {
00053 }
00054
00056 Point2d(boost::int32_t cx, boost::int32_t cy)
00057 :
00058 x(cx), y(cy)
00059 {
00060 }
00061
00063
00068 Point2d(const Point2d& p0, const Point2d& p1, float t)
00069 :
00070 x( p0.x + (boost::int32_t)((p1.x - p0.x) * t)),
00071 y( p0.y + (boost::int32_t)((p1.y - p0.y) * t))
00072 {
00073 }
00074
00076
00079 Point2d& setTo(const boost::int32_t cx, const boost::int32_t cy)
00080 {
00081 x = cx;
00082 y = cy;
00083 return *this;
00084 }
00085
00087
00094 Point2d& setTo(const Point2d& p0, const Point2d& p1, float t)
00095 {
00096 x = p0.x + (boost::int32_t)((p1.x - p0.x) * t);
00097 y = p0.y + (boost::int32_t)((p1.y - p0.y) * t);
00098 return *this;
00099 }
00100
00102 static
00103 boost::int64_t squareDistance(const Point2d& p0, const Point2d& p1)
00104 {
00105 boost::int64_t hside = p1.x - p0.x;
00106 boost::int64_t vside = p1.y - p0.y;
00107
00108 return hside*hside + vside*vside;
00109 }
00110
00112 boost::int64_t squareDistance(const Point2d& p) const
00113 {
00114 return squareDistance(*this, p);
00115 }
00116
00118 boost::int32_t distance(const Point2d& p) const
00119 {
00120 return (boost::int32_t)( std::sqrt( static_cast<double>(squareDistance(p)) ) );
00121 }
00122
00123 bool operator== (const Point2d& p) const
00124 {
00125 return (x == p.x) && (y == p.y);
00126 }
00127
00128 bool operator!=(const Point2d& p) const
00129 {
00130 return ! (*this == p);
00131 }
00132 };
00133
00135 inline std::ostream&
00136 operator<< (std::ostream& os, const Point2d& p)
00137 {
00138 return os << "Point2d(" << p.x << "," << p.y << ")";
00139 }
00140
00141 }
00142
00143 typedef geometry::Point2d point;
00144
00145 }
00146
00147 #endif // GNASH_POINT2DH
00148
00149
00150
00151
00152