ENH: added edge::valid() method

- simple check for unique and non-negative point labels
This commit is contained in:
Mark Olesen
2018-09-13 09:48:01 +02:00
parent 0e8704defe
commit 0d5283a6bc
2 changed files with 16 additions and 7 deletions

View File

@ -134,6 +134,9 @@ public:
// No special handling of negative point labels. // No special handling of negative point labels.
inline label maxVertex() const; inline label maxVertex() const;
//- Return true if the vertices are unique and non-negative.
inline bool valid() 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;
@ -146,19 +149,19 @@ public:
// Negative point labels never connect. // Negative point labels never connect.
inline bool connects(const edge& other) const; inline bool connects(const edge& other) const;
//- Return vertex common with otherEdge or -1 on failure //- Return vertex common with other edge or -1 on failure
// Negative point labels are never considered common between edges. // Negative point labels are never considered common between edges.
inline label commonVertex(const edge& other) const; inline label commonVertex(const edge& other) const;
//- Given one vertex index, return the other one. //- Given the point label for one vertex, return the other one.
// No special treatment for negative point labels. // No special treatment for negative point labels.
inline label otherVertex(const label index) const; inline label otherVertex(const label pointLabel) const;
// Editing // Editing
//- 'Collapse' edge by marking duplicate point labels as '-1', //- 'Collapse' edge by marking duplicate point labels as '-1',
// the lower vertex is retained. //- the lower vertex is retained.
// Return the effective size after collapsing. // Return the effective size after collapsing.
inline label collapse(); inline label collapse();

View File

@ -114,6 +114,12 @@ inline Foam::label Foam::edge::maxVertex() const
} }
inline bool Foam::edge::valid() const
{
return (first() != second() && first() >= 0 && second() >= 0);
}
inline bool Foam::edge::found(const label pointLabel) const inline bool Foam::edge::found(const label pointLabel) const
{ {
// -1: always false // -1: always false
@ -166,13 +172,13 @@ inline Foam::label Foam::edge::commonVertex(const edge& other) const
} }
inline Foam::label Foam::edge::otherVertex(const label index) const inline Foam::label Foam::edge::otherVertex(const label pointLabel) const
{ {
if (index == first()) if (pointLabel == first())
{ {
return second(); return second();
} }
if (index == second()) if (pointLabel == second())
{ {
return first(); return first();
} }