55 lines
934 B
C++
55 lines
934 B
C++
#ifndef BBOX3_H
|
|
#define BBOX3_H
|
|
|
|
#include "Point3.h"
|
|
|
|
class BBox3 {
|
|
|
|
private:
|
|
|
|
static constexpr float MAX = +99999;
|
|
static constexpr float MIN = -99999;
|
|
|
|
/** minimum */
|
|
Point3 p1;
|
|
|
|
/** maximum */
|
|
Point3 p2;
|
|
|
|
public:
|
|
|
|
BBox3() : p1(MAX,MAX,MAX), p2(MIN,MIN,MIN) {;}
|
|
|
|
/** adjust the bounding-box by adding this point */
|
|
void add(const Point3& p) {
|
|
|
|
if (p.x > p2.x) {p2.x = p.x;}
|
|
if (p.y > p2.y) {p2.y = p.y;}
|
|
if (p.z > p2.z) {p2.z = p.z;}
|
|
|
|
if (p.x < p1.x) {p1.x = p.x;}
|
|
if (p.y < p1.y) {p1.y = p.y;}
|
|
if (p.z < p1.z) {p1.z = p.z;}
|
|
|
|
}
|
|
|
|
/** get the bbox's minimum */
|
|
const Point3& getMin() const {return p1;}
|
|
|
|
/** get the bbox's maximum */
|
|
const Point3& getMax() const {return p2;}
|
|
|
|
/** equal? */
|
|
bool operator == (const BBox3& o) const {
|
|
return (p1.x == o.p1.x) &&
|
|
(p1.y == o.p1.y) &&
|
|
(p1.z == o.p1.z) &&
|
|
(p2.x == o.p2.x) &&
|
|
(p2.y == o.p2.y) &&
|
|
(p2.z == o.p2.z);
|
|
}
|
|
|
|
};
|
|
|
|
#endif // BBOX3_H
|