I’ve started into a textured triangle rendering function again. In the

process I’ve written a few functions that I’m going to suggest adding

to SDL, simply for their utility value:

/*

Simple DirectMedia Layer

Copyright © 1997-2014 Sam Lantinga

This software is provided ‘as-is’, without any express or implied

warranty. In no event will the authors be held liable for any damages

arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,

including commercial applications, and to alter it and redistribute it

freely, subject to the following restrictions:

- The origin of this software must not be misrepresented; you must not

claim that you wrote the original software. If you use this software

in a product, an acknowledgment in the product documentation would be

appreciated but is not required. - Altered source versions must be plainly marked as such, and must not be

misrepresented as being the original software. - This notice may not be removed or altered from any source distribution.

*/*

/*/*common_float.h

/*/*

/*/*This file provides a set of C functions for dealing with floating-point

/*/*numbers. */

/

```
/* For FLT_EPSILON, DBL_EPSILON and LDBL_EPSILON. */
```

#include <float.h>

#if defined( USE_FLT ) || ( !defined( USE_DBL ) && !defined( USE_LDBL ) )

# define FLT_TYPE float

# define NAMESPACE flt_

# define EPSILON FLT_EPSILON

#elif defined( USE_DBL )

# define FLT_TYPE double

# define NAMESPACE dbl_

# define EPSILON DBL_EPSILON

#else

# define FLT_TYPE long double

# define NAMESPACE ldbl_

# define EPSILON LDBL_EPSILON

#endif

/* These are designed to provide PROPER floating-point comparisons. */

int NAMESPACE##r_eq( FLT_TYPE a, FLT_TYPE b, FLT_TYPE range )

{

return

(

(int)( a + range >= b ) ==

(int)( a <= b + range )

);

}

int NAMESPACE##r_gr( FLT_TYPE a, FLT_TYPE b, FLT_TYPE range )

{

return

(

(int)( a + range >= b ) ==

(int)( a >= b + range )

);

}

int NAMESPACE##r_ls( FLT_TYPE a, FLT_TYPE b, FLT_TYPE range )

{

return

(

(int)( a + range <= b ) ==

(int)( a <= b + range)

);

}

int NAMESPACE##r_greq( FLT_TYPE a, FLT_TYPE b, FLT_TYPE range )

{

return

(

(

a + range >= b ||

a >= b + range

) ?

(int)1 : (int)0

);

}

int NAMESPACE##r_ls( FLT_TYPE a, FLT_TYPE b, FLT_TYPE range )

{

return

(

(

a + range <= b ||

a <= b + range

) ?

(int)1 : (int)0

);

}

int NAMESPACE##tween( FLT_TYPE *f1, FLT_TYPE *f2, FLT_TYPE *fdest,

size_t elem_count, FLT_TYPE twval )

{

if( f1 && f2 && fdest )

{

size_t iter = 0;

```
while( iter < elem_count )
{
fdest[ iter ] = twval * ( f2[ iter ] - f1[ iter ] ) + f1[ iter ];
++iter;
}
return( 1 );
}
return( -1 );
```

}

int NAMESPACE##int_constraints( size_t vertcount, FLT_TYPE *vals,

long *ldest, long *hdest )

{

if( vertcount && vals && ldest && hdest )

{

size_t i = 0;

```
ldest = vals[ 0 ];
hdest = vals[ 0 ];
while( i < vertcount )
{
*ldest = ( NAMESPACE##r_gr( vals[ i ], *ldest, EPSILON ) ?
```

*ldest : vals[ i ] );

*hdest = ( NAMESPACE##r_ls( vals[ i ], *hdest, EPSILON ) ?

*hdest : vals[ i ] );

```
*ldest -= ( NAMESPACE##r_ls( vals[ i ], *ldest, EPSILON ) ? 1 : 0 );
*hdest += ( NAMESPACE##r_gr( vals[ i ], *hdest, EPSILON ) ? 1 : 0 );
++i;
}
return( 1 );
}
return( -1 );
```

}

There’s some other stuff that was at one point in the same file, but

it’s more geometric in nature so I moved it. If my textured triangle

code is eventually accepted, then SOME VERSION (this version is

designed to allow higher-accuracy implementations if so desired) of

this will make it’s way into SDL. I propose it now because I consider

it to be of general interest & utility.