ENH: add 'containsAny' and extra 'contains' methods to boundBox

This commit is contained in:
Mark Olesen
2010-11-29 13:44:59 +01:00
parent a8e9b1457b
commit 24a96a21ca
3 changed files with 174 additions and 0 deletions

View File

@ -163,6 +163,90 @@ Foam::tmp<Foam::pointField> Foam::boundBox::corners() const
}
bool Foam::boundBox::contains(const UList<point>& points) const
{
if (points.empty())
{
return true;
}
forAll(points, i)
{
if (!contains(points[i]))
{
return false;
}
}
return true;
}
bool Foam::boundBox::contains
(
const UList<point>& points,
const labelUList& indices
) const
{
if (points.empty() || indices.empty())
{
return true;
}
forAll(indices, i)
{
if (!contains(points[indices[i]]))
{
return false;
}
}
return true;
}
bool Foam::boundBox::containsAny(const UList<point>& points) const
{
if (points.empty())
{
return true;
}
forAll(points, i)
{
if (contains(points[i]))
{
return true;
}
}
return false;
}
bool Foam::boundBox::containsAny
(
const UList<point>& points,
const labelUList& indices
) const
{
if (points.empty() || indices.empty())
{
return true;
}
forAll(indices, i)
{
if (contains(points[indices[i]]))
{
return true;
}
}
return false;
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)

View File

@ -174,6 +174,43 @@ public:
//- Contains point? (inside only)
inline bool containsInside(const point&) const;
//- Contains all of the points? (inside or on edge)
bool contains(const UList<point>&) const;
//- Contains all of the points? (inside or on edge)
bool contains
(
const UList<point>&,
const labelUList& indices
) const;
//- Contains all of the points? (inside or on edge)
template<unsigned Size>
bool contains
(
const UList<point>&,
const FixedList<label, Size>& indices
) const;
//- Contains any of the points? (inside or on edge)
bool containsAny(const UList<point>&) const;
//- Contains any of the points? (inside or on edge)
bool containsAny
(
const UList<point>&,
const labelUList& indices
) const;
//- Contains any of the points? (inside or on edge)
template<unsigned Size>
bool containsAny
(
const UList<point>&,
const FixedList<label, Size>& indices
) const;
// Friend Operators

View File

@ -73,4 +73,57 @@ Foam::boundBox::boundBox
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<unsigned Size>
bool Foam::boundBox::contains
(
const UList<point>& points,
const FixedList<label, Size>& indices
) const
{
// a FixedList is never empty
if (points.empty())
{
return false;
}
forAll(indices, i)
{
if (!contains(points[indices[i]]))
{
return false;
}
}
return true;
}
template<unsigned Size>
bool Foam::boundBox::containsAny
(
const UList<point>& points,
const FixedList<label, Size>& indices
) const
{
// a FixedList is never empty
if (points.empty())
{
return false;
}
forAll(indices, i)
{
if (contains(points[indices[i]]))
{
return true;
}
}
return false;
}
// ************************************************************************* //