[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] anuj-distance-field 4690b0d 20/95: * src/sdf/ftsdf.c (cube_r
From: |
Anuj Verma |
Subject: |
[freetype2] anuj-distance-field 4690b0d 20/95: * src/sdf/ftsdf.c (cube_root, arc_cos): Added a few math functions. |
Date: |
Sun, 2 Aug 2020 01:10:27 -0400 (EDT) |
branch: anuj-distance-field
commit 4690b0d421315113b9f35f3b231da2836a93a9d1
Author: Anuj Verma <anujv@iitbhilai.ac.in>
Commit: Anuj Verma <anujv@iitbhilai.ac.in>
* src/sdf/ftsdf.c (cube_root, arc_cos): Added a few math functions.
---
[GSoC]ChangeLog | 5 +++++
src/sdf/ftsdf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index 60258af..22c1fe1 100644
--- a/[GSoC]ChangeLog
+++ b/[GSoC]ChangeLog
@@ -1,5 +1,10 @@
2020-06-30 Anuj Verma <anujv@iitbhilai.ac.in>
+ * src/sdf/ftsdf.c (cube_root, arc_cos): Added a few
+ essential math functions.
+
+2020-06-30 Anuj Verma <anujv@iitbhilai.ac.in>
+
[sdf] Fixed compilation under gnumake.
* src/sdf/rules.mk (DRV_OBJ_ => DRV_OBJS_): Fixed varialbe
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index 2f676be..6ee6bcc 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -2,6 +2,7 @@
#include <freetype/internal/ftobjs.h>
#include <freetype/internal/ftdebug.h>
#include <freetype/ftlist.h>
+#include <freetype/fttrigon.h>
#include "ftsdf.h"
#include "ftsdferrs.h"
@@ -624,6 +625,57 @@
return q;
}
+ /* This function uses newton's iteration to find */
+ /* cube root of a fixed point integer. */
+ static FT_Fixed
+ cube_root( FT_Fixed val )
+ {
+ /* [IMPORTANT]: This function is not good as it may */
+ /* not break, so use a lookup table instead. */
+
+ FT_Int v, g, c;
+
+
+ if ( val == 0 ||
+ val == -FT_INT_16D16( 1 ) ||
+ val == FT_INT_16D16( 1 ) )
+ return val;
+
+ v = val < 0 ? -val : val;
+ g = square_root( v );
+ c = 0;
+
+ while ( 1 )
+ {
+ c = FT_MulFix( FT_MulFix( g, g ), g ) - v;
+ c = FT_DivFix( c, 3 * FT_MulFix( g, g ) );
+
+ g -= c;
+
+ if ( ( c < 0 ? -c : c ) < 30 )
+ break;
+ }
+
+ return val < 0 ? -g : g;
+ }
+
+ /* returns cos inverse of a value */
+ static FT_Fixed
+ arc_cos( FT_Fixed val )
+ {
+ FT_Fixed p, b = val;
+ FT_Fixed one = FT_INT_16D16( 1 );
+
+
+ if ( b > one ) b = one;
+ if ( b < -one ) b = -one;
+
+ p = one - FT_MulFix( b, b );
+ p = square_root( p );
+
+ return FT_Atan2( b, p );
+ }
+
/*************************************************************************/
/*************************************************************************/
/** **/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] anuj-distance-field 4690b0d 20/95: * src/sdf/ftsdf.c (cube_root, arc_cos): Added a few math functions.,
Anuj Verma <=