From 026ad912af0ad147071da79201a335ec84bd6ce9 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 22 Dec 2017 10:00:57 +0000 Subject: Fix rounding error in g/set_node caused by truncation to float --- src/util/numeric.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/util/numeric.h') 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 @@ -254,6 +254,17 @@ inline v3s16 floatToInt(v3f p, f32 d) (p.Z + (p.Z > 0 ? d / 2 : -d / 2)) / 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 */ -- cgit v1.2.3