FreeFOAM The Cross-Platform CFD Toolkit
edgeI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <OpenFOAM/IOstreams.H>
27 
28 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
29 
30 
31 // return
32 // - 0: different
33 // - +1: identical
34 // - -1: same edge, but different orientation
35 inline int Foam::edge::compare(const edge& a, const edge& b)
36 {
37  if (a[0] == b[0] && a[1] == b[1])
38  {
39  return 1;
40  }
41  else if (a[0] == b[1] && a[1] == b[0])
42  {
43  return -1;
44  }
45  else
46  {
47  return 0;
48  }
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 {}
56 
57 
58 inline Foam::edge::edge(const label a, const label b)
59 {
60  start() = a;
61  end() = b;
62 }
63 
64 
66 {
67  start() = a[0];
68  end() = a[1];
69 }
70 
71 
73 :
74  FixedList<label, 2>(is)
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
80 inline Foam::label Foam::edge::start() const
81 {
82  return operator[](0);
83 }
84 
85 inline Foam::label& Foam::edge::start()
86 {
87  return operator[](0);
88 }
89 
90 
91 inline Foam::label Foam::edge::end() const
92 {
93  return operator[](1);
94 }
95 
96 inline Foam::label& Foam::edge::end()
97 {
98  return operator[](1);
99 }
100 
101 
102 inline Foam::label Foam::edge::otherVertex(const label a) const
103 {
104  if (a == start())
105  {
106  return end();
107  }
108  else if (a == end())
109  {
110  return start();
111  }
112  else
113  {
114  // The given vertex is not on the edge in the first place.
115  return -1;
116  }
117 }
118 
119 
120 inline Foam::label Foam::edge::commonVertex(const edge& a) const
121 {
122  if (start() == a.start() || start() == a.end())
123  {
124  return start();
125  }
126  else if (end() == a.start() || end() == a.end())
127  {
128  return end();
129  }
130  else
131  {
132  // No shared vertex.
133  return -1;
134  }
135 }
136 
137 
139 {
140  return edge(end(), start());
141 }
142 
143 
145 {
146  return 0.5*(p[start()] + p[end()]);
147 }
148 
149 
151 {
152  return p[end()] - p[start()];
153 }
154 
155 
156 inline Foam::scalar Foam::edge::mag(const pointField& p) const
157 {
158  return ::Foam::mag(vec(p));
159 }
160 
161 
163 {
164  return linePointRef(p[start()], p[end()]);
165 }
166 
167 
168 // * * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * //
169 
170 inline bool Foam::operator==(const edge& a, const edge& b)
171 {
172  return edge::compare(a,b) != 0;
173 }
174 
175 
176 inline bool Foam::operator!=(const edge& a, const edge& b)
177 {
178  return edge::compare(a,b) == 0;
179 }
180 
181 
182 // ************************ vim: set sw=4 sts=4 et: ************************ //