Skip to content

Commit

Permalink
[sdf, bsdf] Use shared FT_SqrtFixed.
Browse files Browse the repository at this point in the history
FT_SqrtFixed (95b0fe2) is faster and does not overflow.

* src/sdf/ftsdfcommin.h (square_root): Replace with a macro.
* src/sdf/ftsdfcommin.c (square_root): Remove function.
  • Loading branch information
apodtele committed May 6, 2024
1 parent 2edfd7e commit d0e3239
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 45 deletions.
43 changes: 0 additions & 43 deletions src/sdf/ftsdfcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,6 @@
#include "ftsdfcommon.h"


/**************************************************************************
*
* common functions
*
*/

/*
* Original algorithm:
*
* https://github.com/chmike/fpsqrt
*
* Use this to compute the square root of a 16.16 fixed-point number.
*/
FT_LOCAL_DEF( FT_16D16 )
square_root( FT_16D16 val )
{
FT_ULong t, q, b, r;


r = (FT_ULong)val;
b = 0x40000000L;
q = 0;

while ( b > 0x40L )
{
t = q + b;

if ( r >= t )
{
r -= t;
q = t + b;
}

r <<= 1;
b >>= 1;
}

q >>= 8;

return (FT_16D16)q;
}


/**************************************************************************
*
* format and sign manipulating functions
Expand Down
3 changes: 1 addition & 2 deletions src/sdf/ftsdfcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ FT_BEGIN_HEADER
typedef FT_BBox FT_CBox; /* control box of a curve */


FT_LOCAL( FT_16D16 )
square_root( FT_16D16 val );
#define square_root( x ) (FT_16D16)FT_SqrtFixed( (FT_UInt32)( x ) )

FT_LOCAL( FT_SDFFormat )
map_fixed_to_sdf( FT_16D16 dist,
Expand Down

0 comments on commit d0e3239

Please sign in to comment.