aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2017-12-22 10:00:57 +0000
committerparamat <mat.gregory@virginmedia.com>2017-12-26 21:55:08 +0000
commit026ad912af0ad147071da79201a335ec84bd6ce9 (patch)
tree430b97ea4eec13f9a3bc565e231bd38572fd7ebb /src/util
parent0bcc2f33ebe382a1dafbe6edaf00f476f2584b74 (diff)
downloadminetest-026ad912af0ad147071da79201a335ec84bd6ce9.tar.gz
minetest-026ad912af0ad147071da79201a335ec84bd6ce9.tar.bz2
minetest-026ad912af0ad147071da79201a335ec84bd6ce9.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 be3e49c56..ff4d89ec4 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)