开发者

Help with connected outlines

开发者 https://www.devze.com 2023-01-07 11:38 出处:网络
I\'m making a vector drawing application. I use this algorithm to generate outlines. This algorthm works well, except it does not close the outline as seen here:

I'm making a vector drawing application. I use this algorithm to generate outlines.

This algorthm works well, except it does not close the outline as seen here: alt text http://img716.imageshack.us/img716/2633/noclosure.png

I'm not sure what I should do to ensure that it always closes the outline. I tried inserting the last vertex at positi开发者_JAVA百科on[0] in the std::vector but this did not help.

DOUBLEPOINT looks like:

struct DOUBLEPOINT {
double point[2];
};

How can I make it so it always properly closes the shape even on sharp corners?

Thanks


Try appending a copy of the first and second points to the end of the vector before plotting it. Your first and last line segment will overlap, but it should ensure that all the points are connected and all corners are rounded similarly.


I usually just use modulus:

nxt = input[(i+1) % input.size()];


How about:

for( size_t i = 0; i < input.size(); ++i )
{
    POINTFLOAT cur;
    POINTFLOAT nxt;

    if( i == input.size() - 1 )
    {
       cur.x = input[i].point[0];
       cur.y = input[i].point[1];

       nxt.x = input[0].point[0];
       nxt.y = input[0].point[1];
    }
    else
    {
       cur.x = input[i].point[0];
       cur.y = input[i].point[1];

       nxt.x = input[i+1].point[0];
       nxt.y = input[i+1].point[1];
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消