summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2017-12-22 10:00:57 +0000
committerSmallJoker <mk939@ymail.com>2018-06-03 17:32:00 +0200
commitdf0a8574dcef24e5a12a366cb10f7ac5d69a8b79 (patch)
treea9c22c93f6f208ce2d43c667454ce7f8709932ac /src/util
parent669806725637a7e97ae884b7983da6e19fcaa6f5 (diff)
downloadminetest-df0a8574dcef24e5a12a366cb10f7ac5d69a8b79.tar.gz
minetest-df0a8574dcef24e5a12a366cb10f7ac5d69a8b79.tar.bz2
minetest-df0a8574dcef24e5a12a366cb10f7ac5d69a8b79.zip
Fix rounding error in g/set_node caused by truncation to float
Diffstat (limited to 'src/util')
-rw-r--r--src/util/numeric.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util/numeric.h b/src/util/numeric.h
index 4a27f657d..573f03788 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -255,6 +255,17 @@ inline v3s16 floatToInt(v3f p, f32 d)
}
/*
+ Returns integer position of node in given double precision position
+ */
+inline v3s16 doubleToInt(v3d p, double d)
+{
+ return v3s16(
+ (p.X + (p.X > 0 ? d / 2 : -d / 2)) / d,
+ (p.Y + (p.Y > 0 ? d / 2 : -d / 2)) / d,
+ (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / d);
+}
+
+/*
Returns floating point position of node in given integer position
*/
inline v3f intToFloat(v3s16 p, f32 d)