mpri-graphics-project/common_structures.cpp

38 lines
811 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::length(unsigned dim) const {
assert(dim < 3);
return high(dim) - low(dim);
}
2018-02-07 17:59:41 +01:00
double Cuboid::volume() const {
return length(0) * length(1) * length(2);
2018-02-07 17:59:41 +01:00
}
bool Cuboid::is_empty() const {
return volume() < 1e-8;
}