Small refactoring into ClippingPlane to ensure that the normal is always a unit vector

This commit is contained in:
enricoturri1966 2021-09-15 13:36:44 +02:00
parent 554aa70edc
commit 57749d6f09

View File

@ -30,11 +30,8 @@ public:
ClippingPlane(const Vec3d& direction, double offset) ClippingPlane(const Vec3d& direction, double offset)
{ {
Vec3d norm_dir = direction.normalized(); set_normal(direction);
m_data[0] = norm_dir(0); set_offset(offset);
m_data[1] = norm_dir(1);
m_data[2] = norm_dir(2);
m_data[3] = offset;
} }
bool operator==(const ClippingPlane& cp) const { bool operator==(const ClippingPlane& cp) const {
@ -48,7 +45,13 @@ public:
} }
bool is_point_clipped(const Vec3d& point) const { return distance(point) < 0.; } bool is_point_clipped(const Vec3d& point) const { return distance(point) < 0.; }
void set_normal(const Vec3d& normal) { for (size_t i=0; i<3; ++i) m_data[i] = normal(i); } void set_normal(const Vec3d& normal)
{
const Vec3d norm_dir = normal.normalized();
m_data[0] = norm_dir.x();
m_data[1] = norm_dir.y();
m_data[2] = norm_dir.z();
}
void set_offset(double offset) { m_data[3] = offset; } void set_offset(double offset) { m_data[3] = offset; }
Vec3d get_normal() const { return Vec3d(m_data[0], m_data[1], m_data[2]); } Vec3d get_normal() const { return Vec3d(m_data[0], m_data[1], m_data[2]); }
bool is_active() const { return m_data[3] != DBL_MAX; } bool is_active() const { return m_data[3] != DBL_MAX; }