Skip to content

Instantly share code, notes, and snippets.

@ThePhD
Last active August 29, 2015 14:01
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 ThePhD/5fb0b979a355f87c3760 to your computer and use it in GitHub Desktop.
Save ThePhD/5fb0b979a355f87c3760 to your computer and use it in GitHub Desktop.
#pragma once
#include <Furrovine++/Mathema.h>
namespace Furrovine {
struct wrap_addresser {
template <typename Ta, typename Tu>
auto operator()( Ta&& a, Tu&& upper ) {
return modulus( std::forward<Ta>( a ), std::forward<Tu>( upper ) );
}
};
struct clamp_addresser {
template <typename Ta, typename Tu>
auto operator()( Ta&& a, Tu&& upper ) {
typedef typename std::decay<Ta>::type Tad;
return std::min( std::max( static_cast<Tad>( 0 ), std::forward<Ta>( a ) ), std::forward<Tu>( upper ) );
}
};
struct mirror_addresser {
template <typename Ta, typename Tu>
auto operator()( Ta&& a, Tu&& upper ) {
auto mult = ( a / upper );
typedef decltype( mult ) mult_t;
auto x = static_cast<mult_t>( modulus( mult, static_cast<mult_t>( 2 ) ) < 1 );
x = ( 2 * x ) - 1;
return ( a - ( upper * mult ) ) * x;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment