Closed asmwarrior closed 4 years ago
Using the bounding box of the complete circle seems reasonable to me. The bounding box is an upper limit to the extent of the drawing, so that the entire drawing will be visible when first opened. Thereafter, user can zoom in to see details.
@JamesBremner using the bounding box of a entire circle will cause some problems. For example, in the screenshots below, if you consider the entire circle, the bounding rectangle of the entire dxf will exceed from the actual bound thanks to the arc at the bottom. Here's our possible fix:
void CArc::Update( cBoundingRectangle& rect )
{
uint8_t start_quadrant = (int)sa % 360 / 90 + 1;
uint8_t end_quadrant = (int)ea % 360 / 90 + 1;
if(end_quadrant < start_quadrant || (end_quadrant == start_quadrant && (int)sa % 360 >(int)ea % 360 ))
{
end_quadrant += 4;
}
for(int i = 0; i < end_quadrant - start_quadrant; i ++)
{
int j = start_quadrant + i;
if(j > 4)
{
j %= 4;
}
switch(j)
{
case 1:
rect.Update(x, y + r);
break;
case 2:
rect.Update(x - r, y);
break;
case 3:
rect.Update(x, y - r);
break;
case 4:
rect.Update(x + r, y);
break;
}
}
rect.Update( x + r * cos(sa * M_PI / 180), y + r * sin(sa * M_PI / 180) );
rect.Update( x + r * cos(ea * M_PI / 180), y + r * sin(ea * M_PI / 180) );
}
Some suggestions for your code:
There are no comments! You should add comments that describe what is going on.
Please use variable names that indicate their purpose. Never use variable names such as i, j, etc.
Have you tested this code? A unit test would be good.
Here is the procedure for making contributions to open source code on Github
@JamesBremner Hi, sorry for the uncommented code. I will post the codes with comments soon. I tested the code on 5 different arcs with start anlge at first or second quadrant. Here're the examples I tested with second quadrant start angle, blue points indicate the four corner of the bounding rectangle.
Please test and close this issue if OK.
I think this issue can be closed, thanks everyone.
Hi, I see such code:
I see that if the arc is a very tiny piece of a circle, the bounding box of the circle will be used.
Something like such code need to be used: math - formula to calculate bounding coordinates of an arc in space - Stack Overflow