-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPI_BoundingBox.cpp
69 lines (55 loc) · 1.72 KB
/
MPI_BoundingBox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// MPI_BoundingBox.cpp
//
#include "MPI_BoundingBox.h"
MPI_BoundingBox::MPI_BoundingBox(MPI_Point2D const& firstpoint, MPI_Point2D const& secondpoint) :
lowerleft_(firstpoint),
upperright_(firstpoint)
{
this->extendToContain( secondpoint );
}
bool MPI_BoundingBox::overlaps( MPI_BoundingBox const& otherbox ) const
{
return
lowerleft_.getX() <= otherbox.upperright_.getX() &&
otherbox.lowerleft_.getX() <= upperright_.getX() &&
lowerleft_.getY() <= otherbox.upperright_.getY() &&
otherbox.lowerleft_.getY() <= upperright_.getY();
}
bool MPI_BoundingBox::contains( MPI_Point2D const& point ) const
{
return
lowerleft_.getX() <= point.getX() &&
point.getX() <= upperright_.getX() &&
lowerleft_.getY() <= point.getY() &&
point.getY() <= upperright_.getY();
}
void MPI_BoundingBox::extendToContain( MPI_Point2D const& point )
{
if ( point.getX() < lowerleft_.getX() )
lowerleft_.setX( point.getX() );
else if ( upperright_.getX() < point.getX() )
upperright_.setX( point.getX() );
if ( point.getY() < lowerleft_.getY() )
lowerleft_.setY( point.getY() );
else if ( upperright_.getY() < point.getY() )
upperright_.setY( point.getY() );
}
MPI_Point2D const& MPI_BoundingBox::getLowerLeft( void ) const
{
return lowerleft_;
}
MPI_Point2D const& MPI_BoundingBox::getUpperRight( void ) const
{
return upperright_;
}
void MPI_BoundingBox::print( std::ostream &os ) const
{
os << '[' << lowerleft_ << ','<< upperright_ << ']';
}
std::ostream &operator<<( std::ostream &os, MPI_BoundingBox const &bbox )
{
bbox.print(os);
return os;
}
// vim:sw=4:et:cindent: