ENH: boundBox: Move overlaps function from treeBoundBox.
Update indexedOctree::overlaps to use boundBox::overlaps.
This commit is contained in:
parent
4be7afde0a
commit
26a9fbb6e1
@ -47,36 +47,9 @@ bool Foam::indexedOctree<Type>::overlaps
|
||||
const point& sample
|
||||
)
|
||||
{
|
||||
// Find out where sample is in relation to bb.
|
||||
// Find nearest point on bb.
|
||||
scalar distSqr = 0;
|
||||
boundBox bb(p0, p1);
|
||||
|
||||
for (direction dir = 0; dir < vector::nComponents; dir++)
|
||||
{
|
||||
scalar d0 = p0[dir] - sample[dir];
|
||||
scalar d1 = p1[dir] - sample[dir];
|
||||
|
||||
if ((d0 > 0) != (d1 > 0))
|
||||
{
|
||||
// sample inside both extrema. This component does not add any
|
||||
// distance.
|
||||
}
|
||||
else if (mag(d0) < mag(d1))
|
||||
{
|
||||
distSqr += d0*d0;
|
||||
}
|
||||
else
|
||||
{
|
||||
distSqr += d1*d1;
|
||||
}
|
||||
|
||||
if (distSqr > nearestDistSqr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return bb.overlaps(sample, nearestDistSqr);
|
||||
}
|
||||
|
||||
|
||||
|
@ -66,6 +66,7 @@ void Foam::boundBox::calculate(const UList<point>& points, const bool doReduce)
|
||||
min_ = points[0];
|
||||
max_ = points[0];
|
||||
|
||||
|
||||
for (label i = 1; i < points.size(); i++)
|
||||
{
|
||||
min_ = ::Foam::min(min_, points[i]);
|
||||
@ -299,6 +300,24 @@ bool Foam::boundBox::containsAny
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::boundBox::distanceFromBoxSqr(const point& pt) const
|
||||
{
|
||||
if (contains(pt))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Clip the point to the range of the bounding box
|
||||
const scalar surfPtx = Foam::max(Foam::min(pt.x(), max_.x()), min_.x());
|
||||
const scalar surfPty = Foam::max(Foam::min(pt.y(), max_.y()), min_.y());
|
||||
const scalar surfPtz = Foam::max(Foam::min(pt.z(), max_.z()), min_.z());
|
||||
|
||||
const point surfacePt(surfPtx, surfPty, surfPtz);
|
||||
|
||||
return magSqr(pt - surfacePt);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
|
||||
|
@ -176,6 +176,9 @@ public:
|
||||
//- Overlaps/touches boundingBox?
|
||||
inline bool overlaps(const boundBox&) const;
|
||||
|
||||
//- Overlaps boundingSphere (centre + sqr(radius))?
|
||||
inline bool overlaps(const point&, const scalar radiusSqr) const;
|
||||
|
||||
//- Contains point? (inside or on edge)
|
||||
inline bool contains(const point&) const;
|
||||
|
||||
@ -222,6 +225,10 @@ public:
|
||||
const FixedList<label, Size>& indices
|
||||
) const;
|
||||
|
||||
//- Distance of a point from the box.
|
||||
// Return 0 if inside.
|
||||
scalar distanceFromBoxSqr(const point&) const;
|
||||
|
||||
|
||||
// Friend Operators
|
||||
|
||||
|
@ -128,6 +128,45 @@ inline bool Foam::boundBox::overlaps(const boundBox& bb) const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::boundBox::overlaps
|
||||
(
|
||||
const point& centre,
|
||||
const scalar radiusSqr
|
||||
) const
|
||||
{
|
||||
// Find out where centre is in relation to bb.
|
||||
// Find nearest point on bb.
|
||||
scalar distSqr = 0;
|
||||
|
||||
for (direction dir = 0; dir < vector::nComponents; dir++)
|
||||
{
|
||||
scalar d0 = min_[dir] - centre[dir];
|
||||
scalar d1 = max_[dir] - centre[dir];
|
||||
|
||||
if ((d0 > 0) != (d1 > 0))
|
||||
{
|
||||
// centre inside both extrema. This component does not add any
|
||||
// distance.
|
||||
}
|
||||
else if (Foam::mag(d0) < Foam::mag(d1))
|
||||
{
|
||||
distSqr += d0*d0;
|
||||
}
|
||||
else
|
||||
{
|
||||
distSqr += d1*d1;
|
||||
}
|
||||
|
||||
if (distSqr > radiusSqr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::boundBox::contains(const point& pt) const
|
||||
{
|
||||
return
|
||||
|
@ -238,45 +238,6 @@ Foam::treeBoundBox Foam::treeBoundBox::subBbox
|
||||
}
|
||||
|
||||
|
||||
bool Foam::treeBoundBox::overlaps
|
||||
(
|
||||
const point& centre,
|
||||
const scalar radiusSqr
|
||||
) const
|
||||
{
|
||||
// Find out where centre is in relation to bb.
|
||||
// Find nearest point on bb.
|
||||
scalar distSqr = 0;
|
||||
|
||||
for (direction dir = 0; dir < vector::nComponents; dir++)
|
||||
{
|
||||
scalar d0 = min()[dir] - centre[dir];
|
||||
scalar d1 = max()[dir] - centre[dir];
|
||||
|
||||
if ((d0 > 0) != (d1 > 0))
|
||||
{
|
||||
// centre inside both extrema. This component does not add any
|
||||
// distance.
|
||||
}
|
||||
else if (Foam::mag(d0) < Foam::mag(d1))
|
||||
{
|
||||
distSqr += d0*d0;
|
||||
}
|
||||
else
|
||||
{
|
||||
distSqr += d1*d1;
|
||||
}
|
||||
|
||||
if (distSqr > radiusSqr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// line intersection. Returns true if line (start to end) inside
|
||||
// bb or intersects bb. Sets pt to intersection.
|
||||
//
|
||||
|
@ -272,9 +272,6 @@ public:
|
||||
//- Overlaps other bounding box?
|
||||
using boundBox::overlaps;
|
||||
|
||||
//- Overlaps boundingSphere (centre + sqr(radius))?
|
||||
bool overlaps(const point&, const scalar radiusSqr) const;
|
||||
|
||||
//- Intersects segment; set point to intersection position and face,
|
||||
// return true if intersection found.
|
||||
// (pt argument used during calculation even if not intersecting).
|
||||
|
Loading…
Reference in New Issue
Block a user