[sdf, bsdf] Use shared FT_SqrtFixed.

FT_SqrtFixed (95b0fe2a6d) is faster and does not overflow.

* src/sdf/ftsdfcommin.h (square_root): Replace with a macro.
* src/sdf/ftsdfcommin.c (square_root): Remove function.
This commit is contained in:
Alexei Podtelezhnikov 2024-05-06 13:39:06 +00:00
parent 2edfd7e168
commit d0e3239f32
2 changed files with 1 additions and 45 deletions

View File

@ -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

View File

@ -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,