1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "IOstreams.H"
29 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
35 // - -1: same edge, but different orientation
36 inline int Foam::edge::compare(const edge& a, const edge& b)
38 if (a[0] == b[0] && a[1] == b[1])
42 else if (a[0] == b[1] && a[1] == b[0])
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 inline Foam::edge::edge()
59 inline Foam::edge::edge(const label a, const label b)
66 inline Foam::edge::edge(const FixedList<label, 2>& a)
73 inline Foam::edge::edge(Istream& is)
75 FixedList<label, 2>(is)
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 inline Foam::label Foam::edge::start() const
86 inline Foam::label& Foam::edge::start()
92 inline Foam::label Foam::edge::end() const
97 inline Foam::label& Foam::edge::end()
103 inline Foam::label Foam::edge::otherVertex(const label a) const
115 // The given vertex is not on the edge in the first place.
121 inline Foam::label Foam::edge::commonVertex(const edge& a) const
123 if (start() == a.start() || start() == a.end())
127 else if (end() == a.start() || end() == a.end())
139 inline void Foam::edge::flip()
141 Swap(operator[](0), operator[](1));
145 inline Foam::edge Foam::edge::reverseEdge() const
147 return edge(end(), start());
151 inline Foam::point Foam::edge::centre(const pointField& p) const
153 return 0.5*(p[start()] + p[end()]);
157 inline Foam::vector Foam::edge::vec(const pointField& p) const
159 return p[end()] - p[start()];
163 inline Foam::scalar Foam::edge::mag(const pointField& p) const
165 return ::Foam::mag(vec(p));
169 inline Foam::linePointRef Foam::edge::line(const pointField& p) const
171 return linePointRef(p[start()], p[end()]);
175 // * * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * //
177 inline bool Foam::operator==(const edge& a, const edge& b)
179 return edge::compare(a,b) != 0;
183 inline bool Foam::operator!=(const edge& a, const edge& b)
185 return edge::compare(a,b) == 0;
189 // ************************************************************************* //