mpri-graphics-project/common_structures.cpp

37 lines
811 B
C++

#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::length(unsigned dim) const {
assert(dim < 3);
return high(dim) - low(dim);
}
double Cuboid::volume() const {
return length(0) * length(1) * length(2);
}
bool Cuboid::is_empty() const {
return volume() < 1e-8;
}