138 lines
2.6 KiB
C++
138 lines
2.6 KiB
C++
#include "area.hh"
|
|
|
|
|
|
using namespace std ;
|
|
|
|
|
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
Area::Area(const Building *_building, const string &_name,
|
|
const float &_x1, const float &_y1, const float &_z1,
|
|
const float &_x2, const float &_y2, const float &_z2)
|
|
{
|
|
building = (Building *) _building ;
|
|
name = _name ;
|
|
|
|
float x_min, x_max, y_min, y_max, z_min, z_max ;
|
|
|
|
if (_x1 < _x2 && _y1 > _y2) // Le premier point de la pièce
|
|
{
|
|
// est en haut à gauche
|
|
x_min = _x1 ;
|
|
x_max = _x2 ;
|
|
y_min = _y2 ; // on inverse les Y
|
|
y_max = _y1 ;
|
|
}
|
|
|
|
else if (_x1 > _x2 && _y1 < _y2) // Le premier point de la pièce
|
|
{
|
|
// est en bas à droite
|
|
x_min = _x2 ; // on inverse les X
|
|
x_max = _x1 ;
|
|
y_min = _y1 ;
|
|
y_max = _y2 ;
|
|
}
|
|
|
|
else if (_x1 > _x2 && _z1 > _z2) // Le premier point de la pièce
|
|
{
|
|
// est en haut à droite
|
|
x_min = _x2 ; // on inverse les X
|
|
x_max = _x1 ;
|
|
z_min = _z2 ; // on inverse les Y
|
|
z_max = _z1 ;
|
|
}
|
|
|
|
else // Le premier point de la pièce est en bas à gauche
|
|
{
|
|
// ou autres cas (par ex. coordonnées nulles)
|
|
x_min = _x1 ;
|
|
x_max = _x2 ;
|
|
y_min = _y1 ;
|
|
y_max = _y2 ;
|
|
}
|
|
|
|
if (_z1 < _z2)
|
|
{
|
|
z_min = _z1 ;
|
|
z_max = _z2 ;
|
|
}
|
|
else
|
|
{
|
|
z_min = _z2 ;
|
|
z_max = _z1 ;
|
|
}
|
|
|
|
p_min = Point3D(x_min, y_min, z_min) ;
|
|
p_max = Point3D(x_max, y_max, z_max) ;
|
|
|
|
#ifdef DEBUG_2
|
|
cout << "Area created : "<< area_name << p_min << "," << p_max << endl ;
|
|
#endif // DEBUG_2
|
|
}
|
|
|
|
|
|
Area::Area(const Area &a)
|
|
{
|
|
building = a.building ;
|
|
name = a.name ;
|
|
p_min = a.p_min ;
|
|
p_max = a.p_max ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
/**
|
|
* @return \em true if \em p is into the Area.
|
|
* @return \em false if \em p is not into the Area.
|
|
*/
|
|
bool Area::contains_point(const Point3D &p) const
|
|
{
|
|
return
|
|
p.get_x() >= p_min.get_x() &&
|
|
p.get_x() <= p_max.get_x() &&
|
|
p.get_y() >= p_min.get_y() &&
|
|
p.get_y() <= p_max.get_y() &&
|
|
p.get_z() >= p_min.get_z() &&
|
|
p.get_z() <= p_max.get_z() ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Operators *** */
|
|
|
|
|
|
bool Area::operator==(const Area &a) const
|
|
{
|
|
if (this == &a)
|
|
return true ;
|
|
|
|
return
|
|
building == a.building &&
|
|
name == a.name &&
|
|
p_min == a.p_min &&
|
|
p_max == a.p_max ;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Note: to avoid looping, the Building associated with the Area is
|
|
* not displayed.
|
|
*/
|
|
ostream &operator<<(ostream &os, const Area &a)
|
|
{
|
|
os << a.name << ';'
|
|
<< a.p_min.get_x() << ';'
|
|
<< a.p_max.get_x() << ';'
|
|
<< a.p_min.get_y() << ';'
|
|
<< a.p_max.get_y() << ';'
|
|
<< a.p_min.get_z() << ';'
|
|
<< a.p_max.get_z() ;
|
|
return os ;
|
|
}
|