Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible simplification in create/sines.c #3365

Open
andreas-kupries opened this issue Feb 27, 2023 · 1 comment
Open

Possible simplification in create/sines.c #3365

andreas-kupries opened this issue Feb 27, 2023 · 1 comment

Comments

@andreas-kupries
Copy link

Looking at

theta = sines->hfreq == 0.0 ?
VIPS_PI / 2.0 : atan( sines->vfreq / sines->hfreq );
factor = sqrt( sines->hfreq * sines->hfreq +
sines->vfreq * sines->vfreq );

I believe that this may be simpler written as

theta = atan2( sines->vfreq, sines->hfreq );
factor = hypot( sines->hfreq, sines->vfreq);
@jcupitt
Copy link
Member

jcupitt commented Feb 28, 2023

Hi @andreas-kupries,

You're right, that's some crusty old code left over from before atan2 and hypot became a thing. We still work on platforms without these functions, so we'd need ifdefs around them.

arithmetic/complex.c defines wrapper functions, perhaps these should be exported and reused.

https://github.com/libvips/libvips/blob/master/libvips/arithmetic/complex.c#L134-L167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants