mpri-graphics-project/common_structures.cpp

35 lines
753 B
C++
Raw Normal View History

2018-02-07 17:59:41 +01:00
#include "common_structures.hpp"
Cuboid::Cuboid(Point bd1, Point bd2)
: lowBound(0, 0, 0), highBound(0, 0, 0)
{
lowBound = Point(
std::min(bd1.x, bd2.x),
std::min(bd1.y, bd2.y),
std::min(bd1.z, bd2.z));
highBound = Point(
std::max(bd1.x, bd2.x),
std::max(bd1.y, bd2.y),
std::max(bd1.z, bd2.z));
}
double Cuboid::low(unsigned dim) const {
assert(dim < 3);
return lowBound[dim];
}
double Cuboid::high(unsigned dim) const {
assert(dim < 3);
return highBound[dim];
}
double Cuboid::volume() const {
return (high(0) - low(0))
* (high(1) - low(1))
* (high(2) - low(2));
}
bool Cuboid::is_empty() const {
return volume() < 1e-8;
}