Skip to content

Instantly share code, notes, and snippets.

@RicoP
Created August 7, 2022 11:38
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 RicoP/1ac4030eee42624a91fbce5b600caf39 to your computer and use it in GitHub Desktop.
Save RicoP/1ac4030eee42624a91fbce5b600caf39 to your computer and use it in GitHub Desktop.
fast repeat
#pragma once
inline float repeat(float v, float min, float max)
{
v -= min;
v *= 1.0f / (max - min);
v -= (float)(int)(v);
v += 1.0f;
v -= (float)(int)(v);
v *= max - min;
v += min;
return v;
}
// Identiacal to repeat (v, 0, 1);
inline float repeat(float v)
{
v -= (float)(int)(v);
v += 1.0f;
v -= (float)(int)(v);
return v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment