Skip to content

Instantly share code, notes, and snippets.

@fwilleke80
Last active April 19, 2017 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwilleke80/f014f1eb5fd6090292f92aae4ce1f846 to your computer and use it in GitHub Desktop.
Save fwilleke80/f014f1eb5fd6090292f92aae4ce1f846 to your computer and use it in GitHub Desktop.
[C4D] Round a value to the nearest grid point
/// 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