mathutil: add some more assertion checks to PerlinNoise2

This commit is contained in:
rdb 2019-05-12 19:22:26 +02:00
parent 73200e0912
commit c1c74e2cd3

View File

@ -19,6 +19,9 @@
*/
double PerlinNoise2::
noise(const LVecBase2d &value) const {
// If this triggers, you passed in 0 for table_size.
nassertr(!_index.empty(), make_nan(0.0));
// Convert the vector to our local coordinate space.
LVecBase2d vec = _input_xform.xform_point(value);
@ -41,9 +44,13 @@ noise(const LVecBase2d &value) const {
double v = fade(y);
// Hash coordinates of the 4 square corners (A, B, A + 1, and B + 1)
nassertr(X >= 0 && X + 1 < _index.size(), make_nan(0.0));
int A = _index[X] + Y;
int B = _index[X + 1] + Y;
nassertr(A >= 0 && A + 1 < _index.size(), make_nan(0.0));
nassertr(B >= 0 && B + 1 < _index.size(), make_nan(0.0));
// and add blended results from 4 corners of square.
double result =
lerp(v, lerp(u, grad(_index[A], x, y),