Re: Shouldn't Cairo use/offer degrees rather than radians?
David Kastrup <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Organization | Organization?!? |
| Message-ID | <[email protected]> |
Lawrence D'Oliveiro <[email protected]> writes: > On Wed, 28 Jun 2017 12:34:34 +0200, David Kastrup wrote: > >> That is more than Cairo can deliver right now. > > Only by special-casing > <http://git.ghostscript.com/?p=ghostpdl.git;a=blob;f=base/gsmisc.c;h=1ade8db12a9f0ac685396421107333e9347404a2;hb=HEAD>: > > static const int isincos[5] = > {0, 1, 0, -1, 0}; > > /* GCC with -ffast-math compiles ang/90. as ang*(1/90.), losing precission. > * This doesn't happen when the numeral is replaced with a non-const variable. > * So we define the variable to work around the GCC problem. > */ > double const_90_degrees = 90.; > > double > gs_sin_degrees(double ang) > { > double quot = ang / const_90_degrees; > > if (floor(quot) == quot) { > /* > * We need 4.0, rather than 4, here because of non-ANSI compilers. > * The & 3 is because quot might be negative. > */ > return isincos[(int)fmod(quot, 4.0) & 3]; > } > return sin(ang * (M_PI / 180)); > } > > double > gs_cos_degrees(double ang) > { > double quot = ang / const_90_degrees; > > if (floor(quot) == quot) { > /* See above re the following line. */ > return isincos[((int)fmod(quot, 4.0) & 3) + 1]; > } > return cos(ang * (M_PI / 180)); > } > > Do you really want to see hacks like that in the Cairo code? No: I already showed the kind of code I was going to use instead and that would avoid any discontinuities and would make for perfect periodicity (the "discontinuity" would get stuffed into sin(pi/2+eps) which is approximately 1+eps^2/2 and thus not likely to show any staircasing). But of course having to create seeming perfection from underlying imperfection will remain a hack. -- David Kastrup -- cairo mailing list [email protected] https://lists.cairographics.org/mailman/listinfo/cairo