Skip to content

Instantly share code, notes, and snippets.

View ThePhD's full-sized avatar
🐑
Ready to roll!

The Phantom Derpstorm ThePhD

🐑
Ready to roll!
View GitHub Profile
template <typename T, typename TValue, typename TIntermediate = double>
T color_normalize( TValue value, TValue valuemax = color_limits<TValue>::max( ), TValue valuemin = color_limits<TValue>::max( ), T max = color_limits<T>::max( ), T min = color_limits<T>::min( ) ) {
TIntermediate valuerange = static_cast<TIntermediate>( value - valuemin ) / static_cast<TIntermediate>( valuemax );
return static_cast<T>( valuerange * ( max - min ) );
}
@ThePhD
ThePhD / lerp.c++
Last active August 29, 2015 13:55
Lerp
template <typename T, ulword n, typename Tw>
RVector<T, n> lerp( const RVector<T, n>& from, const RVector<T, n>& towards, Tw weight ) {
weight = Mathema<Tw>::MiniMax( weight, static_cast<Tw>( 0 ), static_cast<Tw>( 1 ) );
Tw affweight = 1.0f - weight;
RVector<T, n> r;
for ( ulword i = 0; i < n; ++i ) {
r[ i ] = static_cast<T>( from[i] * weight + affweight * towards[i] );
}
return r;
}
namespace foo {
struct bar {
bar(qux a,
quux b);
int xxx;
double yyy;
};
}
#pragma once
struct adder {
template <typename Tl, typename Tr>
auto operator()( Tl&& left, Tr&& right )
-> decltype( left + right ) {
return left + right;
}
};
@ThePhD
ThePhD / lua_class.c++
Last active August 29, 2015 14:00
lua_class.c++
namespace sol {
template <typename... Tn>
struct constructors { };
template <typename T>
class lua_class {
public:
static const std::string classname;
static const std::string meta;
@ThePhD
ThePhD / lua_class.c++
Last active August 29, 2015 14:00
lua_class.c++ final
#include <sol/state.hpp>
#include <sol/lua_function.hpp>
#include <sol/demangle.hpp>
#include <vector>
namespace sol {
template <typename... Tn>
struct constructors { };
@ThePhD
ThePhD / Bleh.c++
Created May 21, 2014 22:27
Lame initializer_list and its rules
SeparableKernelFilter( std::initializer_list<float> kx, std::initializer_list<float> ky )
: SeparableKernelFilter( std::move( kx ), std::move( ky ), dummy ) {
}
template <typename Tx, typename Ty>
SeparableKernelFilter ( Tx&& xkern, Ty&& ykern, dummy_t = dummy ) {
for ( auto& x : xkern ) {
xkernel.push_back( static_cast<float>( x ) );
}
for ( auto& y : ykern ) {
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\x86_64-w64-mingw32\include\accctrl.h"
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\x86_64-w64-mingw32\include\aclapi.h"
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\x86_64-w64-mingw32\include\aclui.h"
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\x86_64-w64-mingw32\include\activation.h"
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\x86_64-w64-mingw32\include\activaut.h"
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\x86_64-w64-mingw32\include\activecf.h"
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\x86_64-w64-mingw32\include\activeds.h"
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\x86_64-w64-mingw32\include\activprof.h"
skip file "C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\min
bool present;
struct storage_t {
T& ref;
} storage;
template <typename... Tn>
void place( Tn&&... argn ) {
assert( !present );
unchecked_place( std::forward<Tn>( argn )... );
}
T& value( ) const {
typedef decltype( std::addressof( storage ) ) storage_address_t;
typedef typename std::conditional<std::is_const<T>::value, const void, void>::type void_t;
typedef typename std::remove_const<storage_address_t>::type address_t;
return *static_cast<T*>( static_cast<void_t*>( const_cast<address_t>( std::addressof( storage ) ) ) );
}