STYLE: rebase edge on labelPair, additional methods in Pair

- use FixedList first/last in Pair first/second

- consistent first/second access for line
This commit is contained in:
Mark Olesen 2017-10-06 20:10:49 +02:00
parent 049617d037
commit f76552f7f9
17 changed files with 486 additions and 356 deletions

View File

@ -282,7 +282,7 @@ Foam::tmp<Foam::triSurfacePointScalarField> Foam::automatic::load()
forAll(surface_, fI) forAll(surface_, fI)
{ {
faces[fI] = surface_.triSurface::operator[](fI).triFaceFace(); faces[fI] = surface_.triSurface::operator[](fI);
} }
vtkSurfaceWriter().write vtkSurfaceWriter().write

View File

@ -721,7 +721,7 @@ int main(int argc, char *argv[])
isoFaces.setSize(iso.size()); isoFaces.setSize(iso.size());
forAll(isoFaces, i) forAll(isoFaces, i)
{ {
isoFaces[i] = iso[i].triFaceFace(); isoFaces[i] = iso[i];
} }
isoPoints = iso.points(); isoPoints = iso.points();
} }

View File

@ -150,7 +150,7 @@ void writeZoning
faceList faces(surf.size()); faceList faces(surf.size());
forAll(surf, i) forAll(surf, i)
{ {
faces[i] = surf[i].triFaceFace(); faces[i] = surf[i];
} }
vtkSurfaceWriter().write vtkSurfaceWriter().write

View File

@ -368,7 +368,7 @@ int main(int argc, char *argv[])
faces.setSize(surf.size()); faces.setSize(surf.size());
forAll(surf, fi) forAll(surf, fi)
{ {
faces[fi] = surf[fi].triFaceFace(); faces[fi] = surf[fi];
} }
} }

View File

@ -28,7 +28,7 @@ Description
An edge is a list of two point labels. The functionality it provides An edge is a list of two point labels. The functionality it provides
supports the discretisation on a 2-D flat mesh. supports the discretisation on a 2-D flat mesh.
The edge is implemented as a FixedList of labels. The edge is implemented as a Pair/FixedList of labels.
As well as geometrically relevant methods, it also provides methods As well as geometrically relevant methods, it also provides methods
similar to HashSet for additional convenience. similar to HashSet for additional convenience.
Valid point labels are always non-negative (since they correspond to Valid point labels are always non-negative (since they correspond to
@ -37,6 +37,7 @@ Description
can be filled with a HashSet-like functionality. can be filled with a HashSet-like functionality.
SourceFiles SourceFiles
edge.C
edgeI.H edgeI.H
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -44,10 +45,9 @@ SourceFiles
#ifndef edge_H #ifndef edge_H
#define edge_H #define edge_H
#include "FixedList.H"
#include "labelPair.H" #include "labelPair.H"
#include "pointField.H"
#include "linePointRef.H" #include "linePointRef.H"
#include "pointField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -60,7 +60,7 @@ namespace Foam
class edge class edge
: :
public FixedList<label, 2> public labelPair
{ {
// Private Member Functions // Private Member Functions
@ -93,19 +93,19 @@ public:
//- Construct null with invalid point labels (-1) //- Construct null with invalid point labels (-1)
inline edge(); inline edge();
//- Construct from components //- Construct from two point labels
inline edge(const label from, const label to); inline edge(const label from, const label to);
//- Construct, optionally sorted with start less-than end //- Construct from pair of labels
inline edge(const label from, const label to, const bool doSort);
//- Construct from two labels
inline edge(const labelPair& pair); inline edge(const labelPair& pair);
//- Construct from FixedList //- Construct from list
inline edge(const FixedList<label, 2>& lst); inline edge(const FixedList<label, 2>& lst);
//- Construct, optionally sorted with start less-than end //- Construct from two point labels, sorted with first less-than second
inline edge(const label from, const label to, const bool doSort);
//- Construct from list, sorted with first less-than second
inline edge(const FixedList<label, 2>& lst, const bool doSort); inline edge(const FixedList<label, 2>& lst, const bool doSort);
//- Construct from Istream //- Construct from Istream
@ -116,16 +116,26 @@ public:
// Access // Access
//- Return start vertex label //- Return first vertex label
using labelPair::first;
//- Return last (second) vertex label
using labelPair::last;
//- Return second (last) vertex label
using labelPair::second;
//- Return start (first) vertex label
inline label start() const; inline label start() const;
//- Return start vertex label //- Return start (first) vertex label
inline label& start(); inline label& start();
//- Return end vertex label //- Return end (last/second) vertex label
inline label end() const; inline label end() const;
//- Return end vertex label //- Return end (last/second) vertex label
inline label& end(); inline label& end();
//- Return reverse edge as copy. //- Return reverse edge as copy.
@ -143,10 +153,6 @@ public:
// No special handling of negative point labels. // No special handling of negative point labels.
inline label maxVertex() const; inline label maxVertex() const;
//- True if start() is less-than end()
// No special handling of negative point labels.
inline bool sorted() const;
//- Return true if point label is found in edge. //- Return true if point label is found in edge.
// Always false for a negative label. // Always false for a negative label.
inline bool found(const label pointLabel) const; inline bool found(const label pointLabel) const;
@ -175,14 +181,6 @@ public:
// Return the effective size after collapsing. // Return the effective size after collapsing.
inline label collapse(); inline label collapse();
//- Flip the edge in-place.
// No special handling of negative point labels.
inline void flip();
//- Sort so that start() is less-than end()
// No special handling of negative point labels.
inline void sort();
// Hash-like functions // Hash-like functions
@ -211,8 +209,8 @@ public:
// Returns true on success. Negative labels never insert. // Returns true on success. Negative labels never insert.
// Return the number of slots filled. // Return the number of slots filled.
// Similar to a HashTable::insert(). // Similar to a HashTable::insert().
template<unsigned AnySize> template<unsigned Size>
inline label insert(const FixedList<label, AnySize>& lst); inline label insert(const FixedList<label, Size>& lst);
//- Fill open slots with the indices if they did not previously exist. //- Fill open slots with the indices if they did not previously exist.
// Returns true on success. Negative labels never insert. // Returns true on success. Negative labels never insert.
@ -231,8 +229,8 @@ public:
//- Remove existing indices from the edge and set locations to '-1'. //- Remove existing indices from the edge and set locations to '-1'.
// Returns the number of changes. // Returns the number of changes.
template<unsigned AnySize> template<unsigned Size>
inline label erase(const FixedList<label, AnySize>& lst); inline label erase(const FixedList<label, Size>& lst);
//- Remove existing indices from the edge and set locations to '-1'. //- Remove existing indices from the edge and set locations to '-1'.
// Returns the number of changes. // Returns the number of changes.
@ -265,7 +263,7 @@ public:
// Comparison // Comparison
//- Compare edges //- Compare edges
// Returns: // \return
// - 0: different // - 0: different
// - +1: identical values and order used // - +1: identical values and order used
// - -1: identical values, but in different order // - -1: identical values, but in different order
@ -274,7 +272,14 @@ public:
}; };
// Global Operators // * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
//- Return reverse of an edge
inline edge reverse(const edge& e)
{
return edge(e.second(), e.first());
}
//- Compare edges for equal content, ignoring orientation //- Compare edges for equal content, ignoring orientation
inline bool operator==(const edge& a, const edge& b); inline bool operator==(const edge& a, const edge& b);
@ -290,15 +295,15 @@ inline unsigned Hash<edge>::operator()(const edge& e, unsigned seed) const
{ {
unsigned val = seed; unsigned val = seed;
if (e[0] < e[1]) if (e.first() < e.second())
{ {
val = Hash<label>()(e[0], val); val = Hash<label>()(e.first(), val);
val = Hash<label>()(e[1], val); val = Hash<label>()(e.second(), val);
} }
else else
{ {
val = Hash<label>()(e[1], val); val = Hash<label>()(e.second(), val);
val = Hash<label>()(e[0], val); val = Hash<label>()(e.first(), val);
} }
return val; return val;
@ -313,7 +318,7 @@ inline unsigned Hash<edge>::operator()(const edge& e) const
return Hash<edge>()(e, 0); return Hash<edge>()(e, 0);
} }
// Edges are a pair of labels - thus contiguous
template<> template<>
inline bool contiguous<edge>() {return true;} inline bool contiguous<edge>() {return true;}

View File

@ -24,24 +24,12 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "IOstreams.H" #include "IOstreams.H"
#include "Swap.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
inline int Foam::edge::compare(const edge& a, const edge& b) inline int Foam::edge::compare(const edge& a, const edge& b)
{ {
if (a[0] == b[0] && a[1] == b[1]) return labelPair::compare(a, b);
{
return 1;
}
else if (a[0] == b[1] && a[1] == b[0])
{
return -1;
}
else
{
return 0;
}
} }
@ -56,7 +44,7 @@ inline Foam::label Foam::edge::insertMultiple
{ {
// Available slots. // Available slots.
// Don't use count() since it has special treatment for duplicates // Don't use count() since it has special treatment for duplicates
const int maxChange = (start() < 0 ? 1 : 0) + (end() < 0 ? 1 : 0); const int maxChange = (first() < 0 ? 1 : 0) + (second() < 0 ? 1 : 0);
int changed = 0; int changed = 0;
if (maxChange) if (maxChange)
@ -86,7 +74,7 @@ inline Foam::label Foam::edge::eraseMultiple
{ {
// Occupied slots. // Occupied slots.
// Don't use count() since it has special treatment for duplicates // Don't use count() since it has special treatment for duplicates
const int maxChange = (start() >= 0 ? 1 : 0) + (end() >= 0 ? 1 : 0); const int maxChange = (first() >= 0 ? 1 : 0) + (second() >= 0 ? 1 : 0);
int changed = 0; int changed = 0;
if (maxChange) if (maxChange)
@ -109,64 +97,43 @@ inline Foam::label Foam::edge::eraseMultiple
inline Foam::edge::edge() inline Foam::edge::edge()
: :
FixedList<label, 2>(-1) labelPair(-1, -1)
{} {}
inline Foam::edge::edge(const label from, const label to) inline Foam::edge::edge(const label from, const label to)
{ :
start() = from; labelPair(from, to)
end() = to; {}
}
inline Foam::edge::edge(const label from, const label to, const bool doSort)
{
if (doSort && from > to)
{
start() = to;
end() = from;
}
else
{
start() = from;
end() = to;
}
}
inline Foam::edge::edge(const labelPair& pair) inline Foam::edge::edge(const labelPair& pair)
{ :
start() = pair.first(); labelPair(pair.first(), pair.second())
end() = pair.second(); {}
}
inline Foam::edge::edge(const FixedList<label, 2>& lst) inline Foam::edge::edge(const FixedList<label, 2>& lst)
{ :
start() = lst[0]; labelPair(lst.first(), lst.last())
end() = lst[1]; {}
}
inline Foam::edge::edge(const label from, const label to, const bool doSort)
:
labelPair(from, to, doSort)
{}
inline Foam::edge::edge(const FixedList<label, 2>& lst, const bool doSort) inline Foam::edge::edge(const FixedList<label, 2>& lst, const bool doSort)
{ :
if (doSort && lst[0] > lst[1]) labelPair(lst, doSort)
{ {}
start() = lst[1];
end() = lst[0];
}
else
{
start() = lst[0];
end() = lst[1];
}
}
inline Foam::edge::edge(Istream& is) inline Foam::edge::edge(Istream& is)
: :
FixedList<label, 2>(is) labelPair(is)
{} {}
@ -174,42 +141,47 @@ inline Foam::edge::edge(Istream& is)
inline Foam::label Foam::edge::start() const inline Foam::label Foam::edge::start() const
{ {
return operator[](0); return first();
} }
inline Foam::label& Foam::edge::start() inline Foam::label& Foam::edge::start()
{ {
return operator[](0); return first();
} }
inline Foam::label Foam::edge::end() const inline Foam::label Foam::edge::end() const
{ {
return operator[](1); return second();
} }
inline Foam::label& Foam::edge::end() inline Foam::label& Foam::edge::end()
{ {
return operator[](1); return second();
} }
inline Foam::label Foam::edge::minVertex() const inline Foam::label Foam::edge::minVertex() const
{ {
return (start() < end() ? start() : end()); return (first() < second() ? first() : second());
} }
inline Foam::label Foam::edge::maxVertex() const inline Foam::label Foam::edge::maxVertex() const
{ {
return (start() > end() ? start() : end()); return (first() > second() ? first() : second());
} }
inline bool Foam::edge::found(const label pointLabel) const inline bool Foam::edge::found(const label pointLabel) const
{ {
// -1: always false // -1: always false
return (pointLabel >= 0 && (pointLabel == start() || pointLabel == end())); return
(
pointLabel >= 0
&& (pointLabel == first() || pointLabel == second())
);
} }
@ -218,11 +190,11 @@ inline Foam::label Foam::edge::which(const label pointLabel) const
// -1: always false // -1: always false
if (pointLabel >= 0) if (pointLabel >= 0)
{ {
if (pointLabel == start()) if (pointLabel == first())
{ {
return 0; return 0;
} }
if (pointLabel == end()) if (pointLabel == second())
{ {
return 1; return 1;
} }
@ -233,43 +205,39 @@ inline Foam::label Foam::edge::which(const label pointLabel) const
inline bool Foam::edge::connects(const edge& other) const inline bool Foam::edge::connects(const edge& other) const
{ {
return (other.found(start()) || other.found(end())); return (other.found(first()) || other.found(second()));
} }
inline Foam::label Foam::edge::commonVertex(const edge& other) const inline Foam::label Foam::edge::commonVertex(const edge& other) const
{ {
if (other.found(start())) if (other.found(first()))
{ {
return start(); return first();
} }
else if (other.found(end())) if (other.found(second()))
{ {
return end(); return second();
}
else
{
// No shared vertex.
return -1;
} }
// No shared vertex.
return -1;
} }
inline Foam::label Foam::edge::otherVertex(const label index) const inline Foam::label Foam::edge::otherVertex(const label index) const
{ {
if (index == start()) if (index == first())
{ {
return end(); return second();
} }
else if (index == end()) if (index == second())
{ {
return start(); return first();
}
else
{
// The given vertex is not on the edge in the first place.
return -1;
} }
// The given vertex is not on the edge in the first place.
return -1;
} }
@ -280,12 +248,12 @@ inline Foam::label Foam::edge::collapse()
// catch any '-1' (eg, if called multiple times) // catch any '-1' (eg, if called multiple times)
label n = 2; label n = 2;
if (start() == end() || end() < 0) if (first() == second() || second() < 0)
{ {
end() = -1; second() = -1;
--n; --n;
} }
if (start() < 0) if (first() < 0)
{ {
--n; --n;
} }
@ -294,48 +262,27 @@ inline Foam::label Foam::edge::collapse()
} }
inline bool Foam::edge::sorted() const
{
return (start() < end());
}
inline void Foam::edge::sort()
{
if (start() > end())
{
flip();
}
}
inline void Foam::edge::flip()
{
Swap(operator[](0), operator[](1));
}
inline Foam::edge Foam::edge::reverseEdge() const inline Foam::edge Foam::edge::reverseEdge() const
{ {
return edge(end(), start()); return edge(second(), first());
} }
inline void Foam::edge::clear() inline void Foam::edge::clear()
{ {
start() = -1; first() = -1;
end() = -1; second() = -1;
} }
inline Foam::label Foam::edge::count() const inline Foam::label Foam::edge::count() const
{ {
label n = 2; label n = 2;
if (start() == end() || end() < 0) if (first() == second() || second() < 0)
{ {
--n; --n;
} }
if (start() < 0) if (first() < 0)
{ {
--n; --n;
} }
@ -346,7 +293,7 @@ inline Foam::label Foam::edge::count() const
inline bool Foam::edge::empty() const inline bool Foam::edge::empty() const
{ {
return (start() < 0 && end() < 0); return (first() < 0 && second() < 0);
} }
@ -358,21 +305,21 @@ inline bool Foam::edge::insert(const label index)
return false; return false;
} }
if (start() < 0) if (first() < 0)
{ {
// Store at [0], if not duplicate of [1] // Store at first, if not duplicate of second
if (index != end()) if (index != second())
{ {
start() = index; first() = index;
return true; return true;
} }
} }
else if (end() < 0) else if (second() < 0)
{ {
// Store at [1], if not duplicate of [0] // Store at second, if not duplicate of first
if (index != start()) if (index != first())
{ {
end() = index; second() = index;
return true; return true;
} }
} }
@ -387,8 +334,8 @@ inline Foam::label Foam::edge::insert(const UList<label>& lst)
} }
template<unsigned AnySize> template<unsigned Size>
inline Foam::label Foam::edge::insert(const FixedList<label, AnySize>& lst) inline Foam::label Foam::edge::insert(const FixedList<label, Size>& lst)
{ {
return insertMultiple(lst.begin(), lst.end()); return insertMultiple(lst.begin(), lst.end());
} }
@ -409,16 +356,16 @@ inline Foam::label Foam::edge::erase(const label index)
} }
label n = 0; label n = 0;
if (index == start()) if (index == first())
{ {
start() = -1; first() = -1;
++n; ++n;
} }
// Automatically handle duplicates, which should not have been there anyhow // Automatically handle duplicates, which should not have been there anyhow
if (index == end()) if (index == second())
{ {
end() = -1; second() = -1;
++n; ++n;
} }
@ -432,8 +379,8 @@ inline Foam::label Foam::edge::erase(const UList<label>& lst)
} }
template<unsigned AnySize> template<unsigned Size>
inline Foam::label Foam::edge::erase(const FixedList<label, AnySize>& lst) inline Foam::label Foam::edge::erase(const FixedList<label, Size>& lst)
{ {
return eraseMultiple(lst.begin(), lst.end()); return eraseMultiple(lst.begin(), lst.end());
} }
@ -450,7 +397,7 @@ inline Foam::label Foam::edge::erase(std::initializer_list<label> lst)
inline Foam::point Foam::edge::centre(const UList<point>& pts) const inline Foam::point Foam::edge::centre(const UList<point>& pts) const
{ {
#ifdef FULLDEBUG #ifdef FULLDEBUG
if (start() < 0 || end() < 0) if (first() < 0 || second() < 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "negative point index on edge " << *this << "negative point index on edge " << *this
@ -458,14 +405,14 @@ inline Foam::point Foam::edge::centre(const UList<point>& pts) const
} }
#endif #endif
return 0.5*(pts[start()] + pts[end()]); return 0.5*(pts[first()] + pts[second()]);
} }
inline Foam::vector Foam::edge::vec(const UList<point>& pts) const inline Foam::vector Foam::edge::vec(const UList<point>& pts) const
{ {
#ifdef FULLDEBUG #ifdef FULLDEBUG
if (start() < 0 || end() < 0) if (first() < 0 || second() < 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "negative point index on edge " << *this << "negative point index on edge " << *this
@ -473,14 +420,14 @@ inline Foam::vector Foam::edge::vec(const UList<point>& pts) const
} }
#endif #endif
return pts[end()] - pts[start()]; return pts[second()] - pts[first()];
} }
inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const
{ {
#ifdef FULLDEBUG #ifdef FULLDEBUG
if (start() < 0 || end() < 0) if (first() < 0 || second() < 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "negative point index on edge " << *this << "negative point index on edge " << *this
@ -488,7 +435,7 @@ inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const
} }
#endif #endif
Foam::vector v = pts[end()] - pts[start()]; Foam::vector v = pts[second()] - pts[first()];
v /= ::Foam::mag(v) + VSMALL; v /= ::Foam::mag(v) + VSMALL;
return v; return v;
@ -504,7 +451,7 @@ inline Foam::scalar Foam::edge::mag(const UList<point>& pts) const
inline Foam::linePointRef Foam::edge::line(const UList<point>& pts) const inline Foam::linePointRef Foam::edge::line(const UList<point>& pts) const
{ {
#ifdef FULLDEBUG #ifdef FULLDEBUG
if (start() < 0 || end() < 0) if (first() < 0 || second() < 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "negative point index on edge " << *this << "negative point index on edge " << *this
@ -512,7 +459,7 @@ inline Foam::linePointRef Foam::edge::line(const UList<point>& pts) const
} }
#endif #endif
return linePointRef(pts[start()], pts[end()]); return linePointRef(pts[first()], pts[second()]);
} }

View File

@ -773,14 +773,14 @@ int Foam::face::edgeDirection(const edge& e) const
{ {
forAll(*this, i) forAll(*this, i)
{ {
if (operator[](i) == e.start()) if (operator[](i) == e.first())
{ {
if (operator[](rcIndex(i)) == e.end()) if (operator[](rcIndex(i)) == e.second())
{ {
// Reverse direction // Reverse direction
return -1; return -1;
} }
else if (operator[](fcIndex(i)) == e.end()) else if (operator[](fcIndex(i)) == e.second())
{ {
// Forward direction // Forward direction
return 1; return 1;
@ -789,14 +789,14 @@ int Foam::face::edgeDirection(const edge& e) const
// No match // No match
return 0; return 0;
} }
else if (operator[](i) == e.end()) else if (operator[](i) == e.second())
{ {
if (operator[](rcIndex(i)) == e.start()) if (operator[](rcIndex(i)) == e.first())
{ {
// Forward direction // Forward direction
return 1; return 1;
} }
else if (operator[](fcIndex(i)) == e.start()) else if (operator[](fcIndex(i)) == e.first())
{ {
// Reverse direction // Reverse direction
return -1; return -1;

View File

@ -50,6 +50,7 @@ SourceFiles
#include "faceListFwd.H" #include "faceListFwd.H"
#include "intersection.H" #include "intersection.H"
#include "pointHit.H" #include "pointHit.H"
#include "FixedList.H"
#include "ListListOps.H" #include "ListListOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -106,15 +107,15 @@ class face
//- Enumeration listing the modes for split() //- Enumeration listing the modes for split()
enum splitMode enum splitMode
{ {
COUNTTRIANGLE, // count if split into triangles COUNTTRIANGLE, //!< count if split into triangles
COUNTQUAD, // count if split into triangles&quads COUNTQUAD, //!< count if split into triangles and quads
SPLITTRIANGLE, // split into triangles SPLITTRIANGLE, //!< split into triangles
SPLITQUAD // split into triangles&quads SPLITQUAD //!< split into triangles and quads
}; };
//- Split face into triangles or triangles&quads. //- Split face into triangles or triangles and quads.
// Stores results quadFaces[quadI], triFaces[triI] // Stores results quadFaces[quadI], triFaces[triI]
// Returns number of new faces created // \return number of new faces created
label split label split
( (
const splitMode mode, const splitMode mode,
@ -152,12 +153,19 @@ public:
//- Construct from list of labels //- Construct from list of labels
explicit inline face(const labelUList& lst); explicit inline face(const labelUList& lst);
//- Construct from list of labels
template<unsigned Size>
explicit inline face(const FixedList<label, Size>& lst);
//- Construct from an initializer list of labels //- Construct from an initializer list of labels
explicit inline face(std::initializer_list<label> lst); explicit inline face(std::initializer_list<label> lst);
//- Construct by transferring the parameter contents //- Transfer (move) construct
explicit inline face(const Xfer<labelList>& lst); explicit inline face(const Xfer<labelList>& lst);
//- Move construct
explicit inline face(labelList&& lst);
//- Copy construct from triFace //- Copy construct from triFace
face(const triFace& f); face(const triFace& f);
@ -311,8 +319,8 @@ public:
//- Return n-th face edge //- Return n-th face edge
inline edge faceEdge(const label n) const; inline edge faceEdge(const label n) const;
//- Return the edge direction on the face //- The edge direction on the face
// Returns: // \return
// - 0: edge not found on the face // - 0: edge not found on the face
// - +1: forward (counter-clockwise) on the face // - +1: forward (counter-clockwise) on the face
// - -1: reverse (clockwise) on the face // - -1: reverse (clockwise) on the face
@ -373,9 +381,10 @@ public:
) const; ) const;
//- Compare faces //- Compare faces
// 0: different // \return
// +1: identical // - 0: different
// -1: same face, but different orientation // - +1: identical
// - -1: same face, but different orientation
static int compare(const face& a, const face& b); static int compare(const face& a, const face& b);
//- Return true if the faces have the same vertices //- Return true if the faces have the same vertices

View File

@ -57,6 +57,13 @@ inline Foam::face::face(const labelUList& lst)
{} {}
template<unsigned Size>
inline Foam::face::face(const FixedList<label, Size>& lst)
:
labelList(lst)
{}
inline Foam::face::face(std::initializer_list<label> lst) inline Foam::face::face(std::initializer_list<label> lst)
: :
labelList(lst) labelList(lst)
@ -69,6 +76,12 @@ inline Foam::face::face(const Xfer<labelList>& lst)
{} {}
inline Foam::face::face(labelList&& lst)
:
labelList(std::move(lst))
{}
inline Foam::face::face(Istream& is) inline Foam::face::face(Istream& is)
{ {
is >> *this; is >> *this;
@ -87,9 +100,10 @@ inline Foam::pointField Foam::face::points
// For each point in list, set it to the point in 'pnts' addressed // For each point in list, set it to the point in 'pnts' addressed
// by 'labs' // by 'labs'
forAll(p, i) label i = 0;
for (const label pointi : *this)
{ {
p[i] = meshPoints[operator[](i)]; p[i++] = meshPoints[pointi];
} }
// Return list // Return list

View File

@ -86,7 +86,7 @@ public:
const label c const label c
); );
//- Construct from a list of 3 labels. //- Copy construct from a list of 3 labels.
explicit inline triFace(const labelUList& lst); explicit inline triFace(const labelUList& lst);
//- Construct from an initializer list of 3 labels //- Construct from an initializer list of 3 labels
@ -223,14 +223,14 @@ public:
inline edge faceEdge(const label n) const; inline edge faceEdge(const label n) const;
//- Return the edge direction on the face //- Return the edge direction on the face
// Returns: // \return
// - +1: forward (counter-clockwise) on the face // - +1: forward (counter-clockwise) on the face
// - -1: reverse (clockwise) on the face // - -1: reverse (clockwise) on the face
// - 0: edge not found on the face // - 0: edge not found on the face
inline int edgeDirection(const edge& e) const; inline int edgeDirection(const edge& e) const;
//- Compare triFaces //- Compare triFaces
// Returns: // \return:
// - 0: different // - 0: different
// - +1: identical // - +1: identical
// - -1: same face, but different orientation // - -1: same face, but different orientation

View File

@ -147,13 +147,7 @@ inline Foam::pointField Foam::triFace::points(const UList<point>& points) const
inline Foam::face Foam::triFace::triFaceFace() const inline Foam::face Foam::triFace::triFaceFace() const
{ {
Foam::face f(3); return Foam::face(*this);
f[0] = operator[](0);
f[1] = operator[](1);
f[2] = operator[](2);
return f;
} }
@ -342,14 +336,14 @@ inline Foam::edgeList Foam::triFace::edges() const
{ {
edgeList e(3); edgeList e(3);
e[0].start() = operator[](0); e[0].first() = operator[](0);
e[0].end() = operator[](1); e[0].second() = operator[](1);
e[1].start() = operator[](1); e[1].first() = operator[](1);
e[1].end() = operator[](2); e[1].second() = operator[](2);
e[2].start() = operator[](2); e[2].first() = operator[](2);
e[2].end() = operator[](0); e[2].second() = operator[](0);
return e; return e;
} }
@ -369,18 +363,18 @@ inline int Foam::triFace::edgeDirection(const edge& e) const
{ {
if if
( (
(operator[](0) == e.start() && operator[](1) == e.end()) (operator[](0) == e.first() && operator[](1) == e.second())
|| (operator[](1) == e.start() && operator[](2) == e.end()) || (operator[](1) == e.first() && operator[](2) == e.second())
|| (operator[](2) == e.start() && operator[](0) == e.end()) || (operator[](2) == e.first() && operator[](0) == e.second())
) )
{ {
return 1; return 1;
} }
else if else if
( (
(operator[](0) == e.end() && operator[](1) == e.start()) (operator[](0) == e.second() && operator[](1) == e.first())
|| (operator[](1) == e.end() && operator[](2) == e.start()) || (operator[](1) == e.second() && operator[](2) == e.first())
|| (operator[](2) == e.end() && operator[](0) == e.start()) || (operator[](2) == e.second() && operator[](0) == e.first())
) )
{ {
return -1; return -1;

View File

@ -57,10 +57,10 @@ class Ostream;
template<class Point, class PointRef> class line; template<class Point, class PointRef> class line;
template<class Point, class PointRef> template<class Point, class PointRef>
inline Istream& operator>>(Istream&, line<Point, PointRef>&); inline Istream& operator>>(Istream& is, line<Point, PointRef>& l);
template<class Point, class PointRef> template<class Point, class PointRef>
inline Ostream& operator<<(Ostream&, const line<Point, PointRef>&); inline Ostream& operator<<(Ostream& os, const line<Point, PointRef>& l);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -72,7 +72,11 @@ class line
{ {
// Private data // Private data
PointRef a_, b_; //- First point
PointRef a_;
//- Second point
PointRef b_;
public: public:
@ -86,7 +90,7 @@ public:
// The indices could be from edge etc. // The indices could be from edge etc.
inline line inline line
( (
const UList<Point>&, const UList<Point>& points,
const FixedList<label, 2>& indices const FixedList<label, 2>& indices
); );
@ -96,56 +100,62 @@ public:
// Member functions // Member functions
// Access // Access
//- Return first point //- Return first point
inline PointRef start() const; inline PointRef first() const;
//- Return second point //- Return second point
inline PointRef end() const; inline PointRef second() const;
//- Return first point
inline PointRef start() const;
//- Return second point
inline PointRef end() const;
// Properties // Properties
//- Return centre (centroid) //- Return centre (centroid)
inline Point centre() const; inline Point centre() const;
//- Return scalar magnitude //- Return scalar magnitude
inline scalar mag() const; inline scalar mag() const;
//- Return start-to-end vector //- Return start-to-end vector
inline Point vec() const; inline Point vec() const;
//- Return the unit vector (start-to-end) //- Return the unit vector (start-to-end)
inline Point unitVec() const; inline Point unitVec() const;
//- Return nearest distance to line from a given point //- Return nearest distance to line from a given point
// If the nearest point is on the line, return a hit // If the nearest point is on the line, return a hit
PointHit<Point> nearestDist(const Point& p) const; PointHit<Point> nearestDist(const Point& p) const;
//- Return nearest distance from line to line. Returns distance //- Return nearest distance from line to line. Returns distance
// and sets both points (one on *this, one on the provided // and sets both points (one on *this, one on the provided
// linePointRef. // linePointRef.
scalar nearestDist scalar nearestDist
( (
const line<Point, const Point&>& edge, const line<Point, const Point&>& edge,
Point& thisPoint, Point& thisPoint,
Point& edgePoint Point& edgePoint
) const; ) const;
// Ostream operator // Ostream operator
friend Istream& operator>> <Point, PointRef> friend Istream& operator>> <Point, PointRef>
( (
Istream&, Istream& is,
line& line& l
); );
friend Ostream& operator<< <Point, PointRef> friend Ostream& operator<< <Point, PointRef>
( (
Ostream&, Ostream& os,
const line& const line& l
); );
}; };

View File

@ -57,15 +57,29 @@ inline Foam::line<Point, PointRef>::line(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Point, class PointRef> template<class Point, class PointRef>
inline PointRef Foam::line<Point, PointRef>::start() const inline PointRef Foam::line<Point, PointRef>::first() const
{ {
return a_; return a_;
} }
template<class Point, class PointRef>
inline PointRef Foam::line<Point, PointRef>::second() const
{
return b_;
}
template<class Point, class PointRef>
inline PointRef Foam::line<Point, PointRef>::start() const
{
return first();
}
template<class Point, class PointRef> template<class Point, class PointRef>
inline PointRef Foam::line<Point, PointRef>::end() const inline PointRef Foam::line<Point, PointRef>::end() const
{ {
return b_; return second();
} }
@ -110,21 +124,21 @@ Foam::PointHit<Point> Foam::line<Point, PointRef>::nearestDist
Point w(p - a_); Point w(p - a_);
scalar c1 = v & w; const scalar c1 = v & w;
if (c1 <= 0) if (c1 <= 0)
{ {
return PointHit<Point>(false, a_, Foam::mag(p - a_), true); return PointHit<Point>(false, a_, Foam::mag(p - a_), true);
} }
scalar c2 = v & v; const scalar c2 = v & v;
if (c2 <= c1) if (c2 <= c1)
{ {
return PointHit<Point>(false, b_, Foam::mag(p - b_), true); return PointHit<Point>(false, b_, Foam::mag(p - b_), true);
} }
scalar b = c1/c2; const scalar b = c1/c2;
Point pb(a_ + b*v); Point pb(a_ + b*v);

View File

@ -28,6 +28,9 @@ Description
An ordered pair of two objects of type \<T\> with first() and second() An ordered pair of two objects of type \<T\> with first() and second()
elements. elements.
SourceFiles
PairI.H
See also See also
Foam::Tuple2 for storing two objects of dissimilar types. Foam::Tuple2 for storing two objects of dissimilar types.
@ -48,10 +51,10 @@ namespace Foam
Class Pair Declaration Class Pair Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type> template<class T>
class Pair class Pair
: :
public FixedList<Type, 2> public FixedList<T, 2>
{ {
public: public:
@ -59,131 +62,96 @@ public:
// Constructors // Constructors
//- Null constructor //- Null constructor
inline Pair() inline Pair();
{}
//- Construct from components //- Construct from components
inline Pair(const Type& f, const Type& s) inline Pair(const T& f, const T& s);
{
first() = f;
second() = s;
}
//- Construct from FixedList //- Construct from FixedList
inline Pair(const FixedList<Type, 2>& lst) inline Pair(const FixedList<T, 2>& lst);
:
FixedList<Type, 2>(lst) //- Construct, optionally sorted with first less-than second
{} inline Pair(const T& f, const T& s, const bool doSort);
//- Construct, optionally sorted with first less-than second
inline Pair(const FixedList<T, 2>& lst, const bool doSort);
//- Construct from Istream //- Construct from Istream
inline Pair(Istream& is) inline Pair(Istream& is);
:
FixedList<Type, 2>(is)
{}
// Member Functions // Member Functions
//- Return first // Access
inline const Type& first() const
{
return this->operator[](0);
}
//- Return first //- Return first element
inline Type& first() using FixedList<T, 2>::first;
{
return this->operator[](0);
}
//- Return second //- Return last element
inline const Type& second() const using FixedList<T, 2>::last;
{
return this->operator[](1);
}
//- Return second //- Return second element, which is also the last element
inline Type& second() inline const T& second() const;
{
return this->operator[](1);
}
//- Return other //- Return second element, which is also the last element
inline const Type& other(const Type& a) const inline T& second();
{
if (first() == second()) //- Return other element
{ inline const T& other(const T& a) const;
FatalErrorInFunction
<< "Call to other only valid for Pair with differing"
<< " elements:" << *this << abort(FatalError); // Queries
}
else if (first() == a) //- True if first() is less-than second()
{ inline bool sorted() const;
return second();
}
else // Editing
{
if (second() != a) //- Flip the Pair in-place.
{ inline void flip();
FatalErrorInFunction
<< "Pair " << *this //- Sort so that first() is less-than second()
<< " does not contain " << a << abort(FatalError); inline void sort();
}
return first();
}
}
// Comparison // Comparison
//- Compare Pairs //- Compare Pairs
// Returns: // \return
// - 0: different // - 0: different
// - +1: identical values and order used // - +1: identical values and order used
// - -1: identical values, but in reversed order // - -1: identical values, but in reversed order
static inline int compare(const Pair<Type>& a, const Pair<Type>& b) static inline int compare(const Pair<T>& a, const Pair<T>& b);
{
if (a[0] == b[0] && a[1] == b[1])
{
return 1;
}
else if (a[0] == b[1] && a[1] == b[0])
{
return -1;
}
else
{
return 0;
}
}
}; };
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
template<class Type> //- Return reverse of a Pair
Pair<Type> reverse(const Pair<Type>& p) template<class T>
Pair<T> reverse(const Pair<T>& p)
{ {
return Pair<Type>(p.second(), p.first()); return Pair<T>(p.second(), p.first());
} }
template<class Type> template<class T>
bool operator==(const Pair<Type>& a, const Pair<Type>& b) bool operator==(const Pair<T>& a, const Pair<T>& b)
{ {
return (a.first() == b.first() && a.second() == b.second()); return (a.first() == b.first() && a.second() == b.second());
} }
template<class Type> template<class T>
bool operator!=(const Pair<Type>& a, const Pair<Type>& b) bool operator!=(const Pair<T>& a, const Pair<T>& b)
{ {
return !(a == b); return !(a == b);
} }
template<class Type> template<class T>
bool operator<(const Pair<Type>& a, const Pair<Type>& b) bool operator<(const Pair<T>& a, const Pair<T>& b)
{ {
return return
( (
@ -197,22 +165,22 @@ bool operator<(const Pair<Type>& a, const Pair<Type>& b)
} }
template<class Type> template<class T>
bool operator<=(const Pair<Type>& a, const Pair<Type>& b) bool operator<=(const Pair<T>& a, const Pair<T>& b)
{ {
return !(b < a); return !(b < a);
} }
template<class Type> template<class T>
bool operator>(const Pair<Type>& a, const Pair<Type>& b) bool operator>(const Pair<T>& a, const Pair<T>& b)
{ {
return (b < a); return (b < a);
} }
template<class Type> template<class T>
bool operator>=(const Pair<Type>& a, const Pair<Type>& b) bool operator>=(const Pair<T>& a, const Pair<T>& b)
{ {
return !(a < b); return !(a < b);
} }
@ -224,6 +192,10 @@ bool operator>=(const Pair<Type>& a, const Pair<Type>& b)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "PairI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,165 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "Swap.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class T>
inline int Foam::Pair<T>::compare(const Pair<T>& a, const Pair<T>& b)
{
if (a.first() == b.first() && a.second() == b.second())
{
return 1;
}
if (a.first() == b.second() && a.second() == b.first())
{
return -1;
}
return 0;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline Foam::Pair<T>::Pair()
{}
template<class T>
inline Foam::Pair<T>::Pair(const T& f, const T& s)
{
first() = f;
second() = s;
}
template<class T>
inline Foam::Pair<T>::Pair(const FixedList<T, 2>& lst)
:
FixedList<T, 2>(lst)
{}
template<class T>
inline Foam::Pair<T>::Pair(const T& f, const T& s, const bool doSort)
{
if (doSort && f < s)
{
first() = s;
second() = f;
}
else
{
first() = f;
second() = s;
}
}
template<class T>
inline Foam::Pair<T>::Pair(const FixedList<T, 2>& lst, const bool doSort)
:
Pair<T>(lst.first(), lst.last(), doSort)
{}
template<class T>
inline Foam::Pair<T>::Pair(Istream& is)
:
FixedList<T, 2>(is)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline const T& Foam::Pair<T>::second() const
{
return last();
}
template<class T>
inline T& Foam::Pair<T>::second()
{
return last();
}
template<class T>
inline const T& Foam::Pair<T>::other(const T& a) const
{
if (first() == second())
{
FatalErrorInFunction
<< "Call to other only valid for Pair with differing"
<< " elements:" << *this << abort(FatalError);
}
else if (a == first())
{
return second();
}
else
{
if (a != second())
{
FatalErrorInFunction
<< "Pair " << *this
<< " does not contain " << a << abort(FatalError);
}
return first();
}
}
template<class T>
inline bool Foam::Pair<T>::sorted() const
{
return (first() < second());
}
template<class T>
inline void Foam::Pair<T>::flip()
{
Foam::Swap(first(), second());
}
template<class T>
inline void Foam::Pair<T>::sort()
{
if (second() < first())
{
flip();
}
}
// ************************************************************************* //

View File

@ -144,7 +144,7 @@ public:
}; };
//- Return reverse of a tuple2 //- Return reverse of a Tuple2
template<class Type1, class Type2> template<class Type1, class Type2>
inline Tuple2<Type2, Type1> reverse(const Tuple2<Type1, Type2>& t) inline Tuple2<Type2, Type1> reverse(const Tuple2<Type1, Type2>& t)
{ {

View File

@ -937,7 +937,7 @@ void Foam::triSurface::triFaceFaces(List<face>& plainFaces) const
forAll(*this, facei) forAll(*this, facei)
{ {
plainFaces[facei] = operator[](facei).triFaceFace(); plainFaces[facei] = this->operator[](facei);
} }
} }