[cairo] Shouldn't Cairo use/offer degrees rather than radians?
cecashon at aol.com
cecashon at aol.com
Mon Jul 10 19:48:18 UTC 2017
Has anyone figured out a good explanation for this? I haven't been able to figure it out. It looks like the problem is tied to only one particular precision point. I don't know why that is. If I change the size of the surface, radius, y-point or even pi I get the same problem point. If I run with valgrind I get a different repetitive problem point. Maybe on some hardware this doesn't happen? I am testing on a Intel 32 bit Atom CPU N270 1.60GHz × 2 with Ubuntu16.04. This is my latest to try to figure out what is happening.
Eric
#include <cairo.h>
#include <stdio.h>
#include <math.h>
int main()
{
printf("%s\n", cairo_version_string());
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 30, 20);
cairo_t *cr = cairo_create (surface);
cairo_set_line_width (cr, 2);
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
double test_number=0.0;
double increment=0.1;
int channels=4;
int width=cairo_image_surface_get_width(surface);
int height=cairo_image_surface_get_height(surface);
int stride=cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, width);
printf("width %i, height %i, stride %i\n", width, height, stride);
unsigned char *s=cairo_image_surface_get_data(surface);
unsigned char *pixels=s;
//Safety for do loop.
int safety=0;
int counter=0;
int i=0;
int j=0;
//Change the arc radius for each loop. Use i to change the test number for new search also.
for(i=0;i<5;i++)
{
do
{
test_number+=increment;
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_paint(cr);
cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
//Test changing arc radius to see if this changes the numbers.
cairo_arc(cr, 15, test_number, 5+i, 0, M_PI);
cairo_stroke(cr);
cairo_surface_flush(surface);
//Look for the color pixels in the row.
counter=0;
for(j=0;j<width;j++)
{
if(pixels[i*stride+j*channels+1]!=0) counter++;
}
//Refine precision if the row was all 0's. Backup and start looking again.
if(counter==0)
{
//Go back one.
test_number-=increment;
increment=increment*0.1;
printf("%i %i %i %.15f, %.15f\n", i, counter, safety, test_number, increment);
}
if(safety>100)
{
printf("Couldn't find partial arc.\n");
break;
}
safety++;
}while(counter<1||counter>3);
printf("Row %i %.15f ", i, test_number);
for(j=0;j<width;j++)
{
printf("%i, ", pixels[i*stride+j*channels+1]);
}
printf("\n");
safety=0;
test_number=(double)i+1;
increment=0.1;
}
cairo_destroy(cr);
cairo_surface_destroy(surface);
cairo_debug_reset_static_data();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20170710/4b195305/attachment.html>
More information about the cairo
mailing list