FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

edgeI.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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/IOstreams.H>
00027 
00028 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
00029 
00030 
00031 // return
00032 //  -  0: different
00033 //  - +1: identical
00034 //  - -1: same edge, but different orientation
00035 inline int Foam::edge::compare(const edge& a, const edge& b)
00036 {
00037     if (a[0] == b[0] && a[1] == b[1])
00038     {
00039         return 1;
00040     }
00041     else if (a[0] == b[1] && a[1] == b[0])
00042     {
00043         return -1;
00044     }
00045     else
00046     {
00047         return 0;
00048     }
00049 }
00050 
00051 
00052 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00053 
00054 inline Foam::edge::edge()
00055 {}
00056 
00057 
00058 inline Foam::edge::edge(const label a, const label b)
00059 {
00060     start() = a;
00061     end() = b;
00062 }
00063 
00064 
00065 inline Foam::edge::edge(const FixedList<label, 2>& a)
00066 {
00067     start() = a[0];
00068     end() = a[1];
00069 }
00070 
00071 
00072 inline Foam::edge::edge(Istream& is)
00073 :
00074     FixedList<label, 2>(is)
00075 {}
00076 
00077 
00078 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00079 
00080 inline Foam::label Foam::edge::start() const
00081 {
00082     return operator[](0);
00083 }
00084 
00085 inline Foam::label& Foam::edge::start()
00086 {
00087     return operator[](0);
00088 }
00089 
00090 
00091 inline Foam::label Foam::edge::end() const
00092 {
00093     return operator[](1);
00094 }
00095 
00096 inline Foam::label& Foam::edge::end()
00097 {
00098     return operator[](1);
00099 }
00100 
00101 
00102 inline Foam::label Foam::edge::otherVertex(const label a) const
00103 {
00104     if (a == start())
00105     {
00106         return end();
00107     }
00108     else if (a == end())
00109     {
00110         return start();
00111     }
00112     else
00113     {
00114         // The given vertex is not on the edge in the first place.
00115         return -1;
00116     }
00117 }
00118 
00119 
00120 inline Foam::label Foam::edge::commonVertex(const edge& a) const
00121 {
00122     if (start() == a.start() || start() == a.end())
00123     {
00124         return start();
00125     }
00126     else if (end() == a.start() || end() == a.end())
00127     {
00128         return end();
00129     }
00130     else
00131     {
00132         // No shared vertex.
00133         return -1;
00134     }
00135 }
00136 
00137 
00138 inline Foam::edge Foam::edge::reverseEdge() const
00139 {
00140     return edge(end(), start());
00141 }
00142 
00143 
00144 inline Foam::point Foam::edge::centre(const pointField& p) const
00145 {
00146     return 0.5*(p[start()] + p[end()]);
00147 }
00148 
00149 
00150 inline Foam::vector Foam::edge::vec(const pointField& p) const
00151 {
00152     return p[end()] - p[start()];
00153 }
00154 
00155 
00156 inline Foam::scalar Foam::edge::mag(const pointField& p) const
00157 {
00158     return ::Foam::mag(vec(p));
00159 }
00160 
00161 
00162 inline Foam::linePointRef Foam::edge::line(const pointField& p) const
00163 {
00164     return linePointRef(p[start()], p[end()]);
00165 }
00166 
00167 
00168 // * * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * //
00169 
00170 inline bool Foam::operator==(const edge& a, const edge& b)
00171 {
00172     return edge::compare(a,b) != 0;
00173 }
00174 
00175 
00176 inline bool Foam::operator!=(const edge& a, const edge& b)
00177 {
00178     return edge::compare(a,b) == 0;
00179 }
00180 
00181 
00182 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines