Files
pvvmud/common/lib/srvcli/bbox.C
2025-03-05 08:37:43 +01:00

69 lines
2.0 KiB
C

/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "pvvmud.H"
#include "bbox.H"
CBBox::CBBox(){
// p1 and p2 are initialized to (0,0,0)
}
CBBox::CBBox(double x1,double y1, double z1, double x2, double y2, double z2){
p1 = CPosition(MIN(x1,x2),MIN(y1,y2),MIN(z1,z2));
p2 = CPosition(MAX(x1,x2),MAX(y1,y2),MAX(z1,z2));
}
const CPosition & CBBox::getP1() const{
return p1;
}
const CPosition & CBBox::getP2() const{
return p2;
}
void CBBox::initialize(const CPosition & position){
p1 = p2 = position;
}
void CBBox::include(const CPosition & position){
int ii;
for (ii = 0; ii < 3 ; ii++){
if (position.getValue(ii) < p1.getValue(ii))
p1.setValue(ii,position.getValue(ii));
if (position.getValue(ii) > p2.getValue(ii))
p2.setValue(ii,position.getValue(ii));
}
}
int CBBox::inside(const CPosition & position) const{
return ((position >= p1) && (position <= p2));
}
int CBBox::insideXY(const CVector & position) const{
return ((position.getX() >= p1.getX()) && (position.getX() <= p2.getX()) &&
(position.getY() >= p1.getY()) && (position.getY() <= p2.getY()) );
}
ostream& operator<<(ostream&s,const CBBox& b) {
return s << "[ (" << b.getP1() << ") , (" << b.getP2() << ") ]";
}