Reputation: 54193
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 position[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
Upvotes: 0
Views: 79
Reputation: 45087
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.
Upvotes: 1
Reputation: 4390
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];
}
Upvotes: 1