00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "error.H"
00034
00035 #include "point2D.H"
00036 #include "IOstreams.H"
00037
00038
00039
00040 namespace Foam
00041 {
00042
00043
00044
00045
00046 inline point2D::point2D()
00047 :
00048 X(0.0),
00049 Y(0.0)
00050 {}
00051
00052
00053
00054 inline point2D::point2D(const scalar XX, const scalar YY)
00055 :
00056 X(XX),
00057 Y(YY)
00058 {}
00059
00060
00061
00062 inline point2D::point2D(const point& p)
00063 :
00064 X(p.x()),
00065 Y(p.y())
00066 {}
00067
00068
00069
00070 inline point2D::point2D(Istream& is)
00071 {
00072
00073 is.readBegin("point2D");
00074
00075 is >> X >> Y;
00076
00077
00078 is.readEnd("point2D");
00079
00080
00081 is.check("point2D::point2D(Istream& is)");
00082 }
00083
00084
00085
00086
00087 inline point2D::~point2D()
00088 {}
00089
00090
00091
00092
00093 inline scalar point2D::x() const
00094 {
00095 return X;
00096 }
00097
00098
00099 inline scalar point2D::y() const
00100 {
00101 return Y;
00102 }
00103
00104
00105
00106
00107 inline void point2D::operator=(const point2D& a)
00108 {
00109 X = a.X;
00110 Y = a.Y;
00111 }
00112
00113 inline void point2D::operator*=(const scalar& val)
00114 {
00115 X *= val;
00116 Y *= val;
00117 }
00118
00119
00120
00121
00122 inline point2D operator+(const point2D& p1, const point2D& p2)
00123 {
00124 return point2D(p1.X + p2.X, p1.Y + p2.Y);
00125 }
00126
00127
00128 inline point2D operator-(const point2D& p1, const point2D& p2)
00129 {
00130 return point2D(p1.X - p2.X , p1.Y - p2.Y);
00131 }
00132
00133
00134 inline point2D operator*(const scalar& s, const point2D& p)
00135 {
00136 return point2D(s*p.X, s*p.Y);
00137 }
00138
00139
00140 inline bool operator==(const point2D& p1, const point2D& p2)
00141 {
00142 return (p1.X == p2.X && p1.Y == p2.Y);
00143 }
00144
00145
00146 inline bool operator!=(const point2D& p1, const point2D& p2)
00147 {
00148 return !(p1 == p2);
00149 }
00150
00151
00152 inline scalar distance(const point2D& p1, const point2D& p2)
00153 {
00154 return sqrt(sqr(p1.X-p2.X) + sqr(p1.Y-p2.Y));
00155 }
00156
00157
00158
00159
00160 inline Ostream& operator<<(Ostream& os, const point2D& p)
00161 {
00162 os << token::BEGIN_LIST
00163 << p.X
00164 << token::SPACE
00165 << p.Y
00166 << token::END_LIST;
00167
00168
00169 os.check("Ostream& operator<<(Ostream&, const point2D&)");
00170
00171 return os;
00172 }
00173
00174
00175
00176
00177 }
00178
00179