Changeset 6b8b767


Ignore:
Timestamp:
Jul 13, 2018, 6:35:06 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
0a73148
Parents:
dffaeac
Message:

add math routines lerp, step, smoothstep

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/math

    rdffaeac r6b8b767  
    1010// Created On       : Mon Apr 18 23:37:04 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 11 21:12:54 2018
    13 // Update Count     : 109
     12// Last Modified On : Fri Jul 13 11:02:15 2018
     13// Update Count     : 116
    1414//
    1515
     
    352352#include "common"
    353353
     354//---------------------------------------
     355
     356forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )
     357T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; }
     358
     359forall( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )
     360T step( T edge, T x ) { return x < edge ? (T){0} : (T){1}; }
     361
     362forall( otype T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )
     363T smoothstep( T edge0, T edge1, T x ) { T t = clamp( (x - edge0) / (edge1 - edge0), (T){0}, (T){1} ); return t * t * ((T){3} - (T){2} * t); }
     364
    354365// Local Variables: //
    355366// mode: c //
Note: See TracChangeset for help on using the changeset viewer.