use atan2 and hypot more
might be a little quicker
This commit is contained in:
parent
743b21e83e
commit
40173838d1
2
TODO
2
TODO
@ -4,7 +4,7 @@
|
||||
|
||||
try to_polar, set LBB, zoom in and scroll around a bit
|
||||
|
||||
- speed up rect with atan2?
|
||||
|
||||
|
||||
- vips_resize() should not use the anti-alias filter if vips_shrink() has
|
||||
not been called, ie. for shrinks < 2 or so
|
||||
|
@ -340,6 +340,7 @@ AC_FUNC_VPRINTF
|
||||
AC_CHECK_FUNCS([getcwd gettimeofday getwd memset munmap putenv realpath strcasecmp strchr strcspn strdup strerror strrchr strspn vsnprintf realpath mkstemp mktemp random rand sysconf atexit])
|
||||
AC_CHECK_LIB(m,cbrt,[AC_DEFINE(HAVE_CBRT,1,[have cbrt() in libm.])])
|
||||
AC_CHECK_LIB(m,hypot,[AC_DEFINE(HAVE_HYPOT,1,[have hypot() in libm.])])
|
||||
AC_CHECK_LIB(m,atan2,[AC_DEFINE(HAVE_ATAN2,1,[have atan2() in libm.])])
|
||||
|
||||
# have to have these
|
||||
# need glib 2.6 for GOption
|
||||
|
@ -131,13 +131,41 @@ G_DEFINE_TYPE( VipsComplex, vips_complex, VIPS_TYPE_UNARY );
|
||||
g_assert( 0 ); \
|
||||
}
|
||||
|
||||
static double
|
||||
vips_complex_hypot( double a, double b )
|
||||
{
|
||||
double d;
|
||||
|
||||
#ifdef HAVE_HYPOT
|
||||
d = hypot( a, b );
|
||||
#else
|
||||
d = sqrt( a * a + b * b );
|
||||
#endif
|
||||
|
||||
return( d );
|
||||
}
|
||||
|
||||
static double
|
||||
vips_complex_atan2( double a, double b )
|
||||
{
|
||||
double h;
|
||||
|
||||
#ifdef HAVE_ATAN2
|
||||
h = VIPS_DEG( atan2( b, a ) );
|
||||
#else
|
||||
h = vips_col_ab2h( a, b );
|
||||
#endif
|
||||
|
||||
return( h );
|
||||
}
|
||||
|
||||
#define POLAR( Q, X, Y ) { \
|
||||
double re = (X); \
|
||||
double im = (Y); \
|
||||
double am, ph; \
|
||||
\
|
||||
am = sqrt( re * re + im * im ); \
|
||||
ph = vips_col_ab2h( re, im ); \
|
||||
am = vips_complex_hypot( re, im ); \
|
||||
ph = vips_complex_atan2( re, im ); \
|
||||
\
|
||||
Q[0] = am; \
|
||||
Q[1] = ph; \
|
||||
|
@ -63,6 +63,9 @@ vips_col_ab2h( double a, double b )
|
||||
{
|
||||
double h;
|
||||
|
||||
#ifdef HAVE_ATAN2
|
||||
h = VIPS_DEG( atan2( b, a ) );
|
||||
#else
|
||||
/* We have to get the right quadrant!
|
||||
*/
|
||||
if( a == 0 ) {
|
||||
@ -84,6 +87,7 @@ vips_col_ab2h( double a, double b )
|
||||
else
|
||||
h = VIPS_DEG( t + VIPS_PI );
|
||||
}
|
||||
#endif
|
||||
|
||||
return( h );
|
||||
}
|
||||
@ -91,8 +95,17 @@ vips_col_ab2h( double a, double b )
|
||||
void
|
||||
vips_col_ab2Ch( float a, float b, float *C, float *h )
|
||||
{
|
||||
#ifdef HAVE_ATAN2
|
||||
*h = VIPS_DEG( atan2( b, a ) );
|
||||
#else
|
||||
*h = vips_col_ab2h( a, b );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_HYPOT
|
||||
*C = hypot( a, b );
|
||||
#else
|
||||
*C = sqrt( a * a + b * b );
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user