light: make GLM_InterpolateNormal return failure on degenerate input

This commit is contained in:
Eric Wasylishen 2018-01-28 02:19:09 -07:00
parent 95e9fdcd21
commit 6b14e166b8
2 changed files with 9 additions and 0 deletions

View File

@ -704,6 +704,9 @@ std::pair<bool, qvec3f> GLM_InterpolateNormal(const std::vector<qvec3f> &points,
{
Q_assert(points.size() == normals.size());
if (points.size() < 3)
return make_pair(false, qvec3f(0));
// Step through the triangles, being careful to handle zero-size ones
const qvec3f &p0 = points.at(0);

View File

@ -319,6 +319,12 @@ TEST(mathlib, ProjectPointOntoPlane) {
EXPECT_FLOAT_EQ(10, projected[2]);
}
TEST(mathlib, InterpolateNormalsDegenerate) {
EXPECT_FALSE(GLM_InterpolateNormal({}, {}, qvec3f(0,0,0)).first);
EXPECT_FALSE(GLM_InterpolateNormal({qvec3f(0,0,0)}, {qvec3f(0,0,1)}, qvec3f(0,0,0)).first);
EXPECT_FALSE(GLM_InterpolateNormal({qvec3f(0,0,0), qvec3f(10,0,0)}, {qvec3f(0,0,1), qvec3f(0,0,1)}, qvec3f(0,0,0)).first);
}
TEST(mathlib, InterpolateNormals) {
// This test relies on the way GLM_InterpolateNormal is implemented