[cairo] Polyline overshoot

Frans Meulenbroeks fransmeulenbroeks at yahoo.com
Wed Mar 9 13:34:44 UTC 2022


 Apparently according to the email archive this never made it to the list. Retrying

    Op woensdag 23 februari 2022 08:58:47 CET schreef Frans Meulenbroeks <fransmeulenbroeks at yahoo.com>:  
 
 Hi,
I'm trying to draw a polyline using the following C++ code:
    std::vector<Position> points; // Position is just a struct with <x,y> coordinates
     points2.emplace_back(Position{3, 0});
    points2.emplace_back(Position{5, 1});
    points2.emplace_back(Position{9, 2});
    points2.emplace_back(Position{8, 3});
    points2.emplace_back(Position{4, 4});
    points2.emplace_back(Position{0, 5});
    points2.emplace_back(Position{7, 6});
    points2.emplace_back(Position{6, 7});

    cairo_set_antialias(_cr, CAIRO_ANTIALIAS_NONE);  // my context is named _cr, not cr
    cairo_set_source_rgba(_cr, 1.0, 1.0, 0.0, 1.0);    cairo_set_line_width(_cr, lineWidth);

    cairo_move_to(_cr, startpos.x + points[0].x + 0.5, startpos.y + points[0].y + 0.5);
    for (int i = 1; i < points.size(); i++)
    {
        cairo_line_to(_cr, startpos.x + points[i].x + 0.5, startpos.y + points[i].y + 0.5);
    }
    cairo_stroke(_cr);
startpos.x indicating the location where I want to draw the polyline is 800. y is 200

However when I look at the resulting image I get things like the image below.
E.g. I am not very happy with the pixel at 798, 205 as I am drawing no lines with x < 800 at all.As these are measurement results I would like to see less overshoot.As you can see from the code above I already added 0.5 to the coordinates.Is there a way to improve this? Or where is my expectation wrong?


Thanks! Frans
PS: this is all rendered using an ARGB32 surface of 1920x1080 pixels

 



  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20220309/72469a6b/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1645602531329blob.jpg
Type: image/png
Size: 20245 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20220309/72469a6b/attachment-0001.png>


More information about the cairo mailing list