Last active
April 19, 2017 00:51
-
-
Save fwilleke80/f014f1eb5fd6090292f92aae4ce1f846 to your computer and use it in GitHub Desktop.
[C4D] Round a value to the nearest grid point
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Round a value to a grid. | |
/// This is an extended version of Round(), rounding not just to the nearest whole number but to the nearest point in a grid with arbitrary spacing. | |
/// Using "1.0" as value for grid will give the same results as Round(). | |
/// | |
/// @param[in] value The input value | |
/// @param[in] grid The grid spacing | |
/// @return The rounded value | |
static inline Float RoundGrid(Float value, Float grid = 1.0) | |
{ | |
if (grid == 0.0) | |
return 0.0; | |
value = value / grid + 0.5; | |
value = Floor(value); | |
value = value * grid; | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment