Commit f76552f7 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: rebase edge on labelPair, additional methods in Pair

- use FixedList first/last in Pair first/second

- consistent first/second access for line
parent 049617d0
......@@ -282,7 +282,7 @@ Foam::tmp<Foam::triSurfacePointScalarField> Foam::automatic::load()
forAll(surface_, fI)
{
faces[fI] = surface_.triSurface::operator[](fI).triFaceFace();
faces[fI] = surface_.triSurface::operator[](fI);
}
vtkSurfaceWriter().write
......
......@@ -721,7 +721,7 @@ int main(int argc, char *argv[])
isoFaces.setSize(iso.size());
forAll(isoFaces, i)
{
isoFaces[i] = iso[i].triFaceFace();
isoFaces[i] = iso[i];
}
isoPoints = iso.points();
}
......
......@@ -150,7 +150,7 @@ void writeZoning
faceList faces(surf.size());
forAll(surf, i)
{
faces[i] = surf[i].triFaceFace();
faces[i] = surf[i];
}
vtkSurfaceWriter().write
......
......@@ -368,7 +368,7 @@ int main(int argc, char *argv[])
faces.setSize(surf.size());
forAll(surf, fi)
{
faces[fi] = surf[fi].triFaceFace();
faces[fi] = surf[fi];
}
}
......
......@@ -28,7 +28,7 @@ Description
An edge is a list of two point labels. The functionality it provides
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
similar to HashSet for additional convenience.
Valid point labels are always non-negative (since they correspond to
......@@ -37,6 +37,7 @@ Description
can be filled with a HashSet-like functionality.
SourceFiles
edge.C
edgeI.H
\*---------------------------------------------------------------------------*/
......@@ -44,10 +45,9 @@ SourceFiles
#ifndef edge_H
#define edge_H
#include "FixedList.H"
#include "labelPair.H"
#include "pointField.H"
#include "linePointRef.H"
#include "pointField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -60,7 +60,7 @@ namespace Foam
class edge
:
public FixedList<label, 2>
public labelPair
{
// Private Member Functions
......@@ -93,19 +93,19 @@ public:
//- Construct null with invalid point labels (-1)
inline edge();
//- Construct from components
//- Construct from two point labels
inline edge(const label from, const label to);
//- Construct, optionally sorted with start less-than end
inline edge(const label from, const label to, const bool doSort);
//- Construct from two labels
//- Construct from pair of labels
inline edge(const labelPair& pair);
//- Construct from FixedList
//- Construct from list
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);
//- Construct from Istream
......@@ -116,16 +116,26 @@ public:
// 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;
//- Return start vertex label
//- Return start (first) vertex label
inline label& start();
//- Return end vertex label
//- Return end (last/second) vertex label
inline label end() const;
//- Return end vertex label
//- Return end (last/second) vertex label
inline label& end();
//- Return reverse edge as copy.
......@@ -143,10 +153,6 @@ public:
// No special handling of negative point labels.
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.
// Always false for a negative label.
inline bool found(const label pointLabel) const;
......@@ -175,14 +181,6 @@ public:
// Return the effective size after collapsing.
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
......@@ -211,8 +209,8 @@ public:
// Returns true on success. Negative labels never insert.
// Return the number of slots filled.
// Similar to a HashTable::insert().
template<unsigned AnySize>
inline label insert(const FixedList<label, AnySize>& lst);
template<unsigned Size>
inline label insert(const FixedList<label, Size>& lst);
//- Fill open slots with the indices if they did not previously exist.
// Returns true on success. Negative labels never insert.
......@@ -231,8 +229,8 @@ public:
//- Remove existing indices from the edge and set locations to '-1'.
// Returns the number of changes.
template<unsigned AnySize>
inline label erase(const FixedList<label, AnySize>& lst);
template<unsigned Size>
inline label erase(const FixedList<label, Size>& lst);
//- Remove existing indices from the edge and set locations to '-1'.
// Returns the number of changes.
......@@ -265,7 +263,7 @@ public:
// Comparison
//- Compare edges
// Returns:
// \return
// - 0: different
// - +1: identical values and order used
// - -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
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;
if (e[0] < e[1])
if (e.first() < e.second())
{
val = Hash<label>()(e[0], val);
val = Hash<label>()(e[1], val);
val = Hash<label>()(e.first(), val);
val = Hash<label>()(e.second(), val);
}
else
{
val = Hash<label>()(e[1], val);
val = Hash<label>()(e[0], val);
val = Hash<label>()(e.second(), val);
val = Hash<label>()(e.first(), val);
}
return val;
......@@ -313,7 +318,7 @@ inline unsigned Hash<edge>::operator()(const edge& e) const
return Hash<edge>()(e, 0);
}
// Edges are a pair of labels - thus contiguous
template<>
inline bool contiguous<edge>() {return true;}
......
......@@ -24,24 +24,12 @@ License
\*---------------------------------------------------------------------------*/
#include "IOstreams.H"
#include "Swap.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
inline int Foam::edge::compare(const edge& a, const edge& 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;
}
return labelPair::compare(a, b);
}
......@@ -56,7 +44,7 @@ inline Foam::label Foam::edge::insertMultiple
{
// Available slots.
// 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;
if (maxChange)
......@@ -86,7 +74,7 @@ inline Foam::label Foam::edge::eraseMultiple
{
// Occupied slots.
// 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;
if (maxChange)
......@@ -109,64 +97,43 @@ inline Foam::label Foam::edge::eraseMultiple
inline Foam::edge::edge()
:
FixedList<label, 2>(-1)
labelPair(-1, -1)
{}
inline Foam::edge::edge(const label from, const label to)
{
start() = from;
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;
}
}
:
labelPair(from, to)
{}
inline Foam::edge::edge(const labelPair& pair)
{
start() = pair.first();
end() = pair.second();
}
:
labelPair(pair.first(), pair.second())
{}
inline Foam::edge::edge(const FixedList<label, 2>& lst)
{
start() = lst[0];
end() = lst[1];
}
:
labelPair(lst.first(), lst.last())
{}
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)
{
if (doSort && lst[0] > lst[1])
{
start() = lst[1];
end() = lst[0];
}
else
{
start() = lst[0];
end() = lst[1];
}
}
:
labelPair(lst, doSort)
{}
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
{
return operator[](0);
return first();
}
inline Foam::label& Foam::edge::start()
{
return operator[](0);
return first();
}
inline Foam::label Foam::edge::end() const
{
return operator[](1);
return second();
}
inline Foam::label& Foam::edge::end()
{
return operator[](1);
return second();
}
inline Foam::label Foam::edge::minVertex() const
{
return (start() < end() ? start() : end());
return (first() < second() ? first() : second());
}
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
{
// -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
if (pointLabel >= 0)
{
if (pointLabel == start())
if (pointLabel == first())
{
return 0;
}
if (pointLabel == end())
if (pointLabel == second())
{
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
{
return (other.found(start()) || other.found(end()));
return (other.found(first()) || other.found(second()));
}
inline Foam::label Foam::edge::commonVertex(const edge& other) const
{
if (other.found(start()))
{
return start();
}
else if (other.found(end()))
if (other.found(first()))
{
return end();
return first();
}
else
if (other.found(second()))
{
// No shared vertex.
return -1;
return second();
}
// No shared vertex.
return -1;
}
inline Foam::label Foam::edge::otherVertex(const label index) const
{
if (index == start())
{
return end();
}
else if (index == end())
if (index == first())
{
return start();
return second();
}
else
if (index == second())
{
// The given vertex is not on the edge in the first place.
return -1;
return first();
}
// 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)
label n = 2;
if (start() == end() || end() < 0)
if (first() == second() || second() < 0)
{
end() = -1;
second() = -1;
--n;
}
if (start() < 0)
if (first() < 0)
{
--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
{
return edge(end(), start());
return edge(second(), first());
}
inline void Foam::edge::clear()
{
start() = -1;
end() = -1;
first() = -1;
second() = -1;
}
inline Foam::label Foam::edge::count() const
{
label n = 2;
if (start() == end() || end() < 0)
if (first() == second() || second() < 0)
{
--n;
}
if (start() < 0)
if (first() < 0)
{
--n;
}
......@@ -346,7 +293,7 @@ inline Foam::label Foam::edge::count() 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;
}
if (start() < 0)
if (first() < 0)
{
// Store at [0], if not duplicate of [1]
if (index != end())
// Store at first, if not duplicate of second
if (index != second())
{
start() = index;
first() = index;
return true;
}
}
else if (end() < 0)
else if (second() < 0)
{
// Store at [1], if not duplicate of [0]
if (index != start())
// Store at second, if not duplicate of first
if (index != first())
{
end() = index;
second() = index;
return true;
}
}
......@@ -387,8 +334,8 @@ inline Foam::label Foam::edge::insert(const UList<label>& lst)
}
template<unsigned AnySize>
inline Foam::label Foam::edge::insert(const FixedList<label, AnySize>& lst)
template<unsigned Size>
inline Foam::label Foam::edge::insert(const FixedList<label, Size>& lst)
{