initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / meshShapes / edge / edgeI.H
blob236de73ac8bb38cd62617f5064187aa75c04b3d3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "IOstreams.H"
29 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
32 // return
33 //  -  0: different
34 //  - +1: identical
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])
39     {
40         return 1;
41     }
42     else if (a[0] == b[1] && a[1] == b[0])
43     {
44         return -1;
45     }
46     else
47     {
48         return 0;
49     }
53 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
55 inline Foam::edge::edge()
59 inline Foam::edge::edge(const label a, const label b)
61     start() = a;
62     end() = b;
66 inline Foam::edge::edge(const FixedList<label, 2>& a)
68     start() = a[0];
69     end() = a[1];
73 inline Foam::edge::edge(Istream& is)
75     FixedList<label, 2>(is)
79 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
81 inline Foam::label Foam::edge::start() const
83     return operator[](0);
86 inline Foam::label& Foam::edge::start()
88     return operator[](0);
92 inline Foam::label Foam::edge::end() const
94     return operator[](1);
97 inline Foam::label& Foam::edge::end()
99     return operator[](1);
103 inline Foam::label Foam::edge::otherVertex(const label a) const
105     if (a == start())
106     {
107         return end();
108     }
109     else if (a == end())
110     {
111         return start();
112     }
113     else
114     {
115         // The given vertex is not on the edge in the first place.
116         return -1;
117     }
121 inline Foam::label Foam::edge::commonVertex(const edge& a) const
123     if (start() == a.start() || start() == a.end())
124     {
125         return start();
126     }
127     else if (end() == a.start() || end() == a.end())
128     {
129         return end();
130     }
131     else
132     {
133         // No shared vertex.
134         return -1;
135     }
139 inline Foam::edge Foam::edge::reverseEdge() const
141     return edge(end(), start());
145 inline Foam::point Foam::edge::centre(const pointField& p) const
147     return 0.5*(p[start()] + p[end()]);
151 inline Foam::vector Foam::edge::vec(const pointField& p) const
153     return p[end()] - p[start()];
157 inline Foam::scalar Foam::edge::mag(const pointField& p) const
159     return ::Foam::mag(vec(p));
163 inline Foam::linePointRef Foam::edge::line(const pointField& p) const
165     return linePointRef(p[start()], p[end()]);
169 // * * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * //
171 inline bool Foam::operator==(const edge& a, const edge& b)
173     return edge::compare(a,b) != 0;
177 inline bool Foam::operator!=(const edge& a, const edge& b)
179     return edge::compare(a,b) == 0;
183 // ************************************************************************* //