OpenFOAM logo
Open Source CFD Toolkit

point2DI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     point2D
00027 
00028 Description
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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00044 
00045 // Construct as null
00046 inline point2D::point2D()
00047 :
00048     X(0.0),
00049     Y(0.0)
00050 {}
00051 
00052 
00053 // Construct from components
00054 inline point2D::point2D(const scalar XX, const scalar YY)
00055 :
00056     X(XX),
00057     Y(YY)
00058 {}
00059 
00060 
00061 // Construct from point (uses only x and y components)
00062 inline point2D::point2D(const point& p)
00063 :
00064     X(p.x()),
00065     Y(p.y())
00066 {}
00067 
00068 
00069 // Construct from Istream
00070 inline point2D::point2D(Istream& is)
00071 {
00072     //- Read beginning of point2D
00073     is.readBegin("point2D");
00074 
00075     is >> X >> Y;
00076 
00077     //- Read end of point2D
00078     is.readEnd("point2D");
00079 
00080     //- Check state of Istream
00081     is.check("point2D::point2D(Istream& is)");
00082 }
00083 
00084 
00085 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00086 
00087 inline point2D::~point2D()
00088 {}
00089 
00090 
00091 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
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     //- Check state of IOstream
00169     os.check("Ostream& operator<<(Ostream&, const point2D&)");
00170 
00171     return os;
00172 }
00173 
00174 
00175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00176 
00177 } // End namespace Foam
00178 
00179 // ************************************************************************* //
For further information go to www.openfoam.org