Skip to content

Commit 6606798

Browse files
committed
Merge branch 'master' of https://github.com/JannisX11/snowstorm
2 parents 0bef54a + 2a42171 commit 6606798

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/emitter.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,17 @@ Emitter.Molang.global_variables = {
130130
},
131131
'query.camera_distance_range_lerp'(a, b) {
132132
let distance = View.camera.position.length();
133-
return Math.clamp(Math.getLerp(a, b, distance), 0, 1);
133+
// Prevent division by zero
134+
const denominator = b - a;
135+
if (Math.abs(denominator) < 1e-8) {
136+
if (distance < a) {
137+
return 0;
138+
} else {
139+
return 1;
140+
}
141+
}
142+
// Interpolation of x between 0 and 1 in range [a, b]: (x-a)/(b-a)
143+
return Math.clamp((distance - a) / denominator, 0, 1);
134144
}
135145
}
136146

0 commit comments

Comments
 (0)