Full circle

Maybe I have just a late night brain fog, but it seems I get an error if I try to make full 0-360 circle. I can do 0-359 or 0-361 but not a simple full circle.

What am I missing? :slight_smile:

2 likes

Nothing. I missed something when I implemented the nomalizing angles to be between 0-360. For example if you hover over the ā€œerrorā€ label you will see the error:

image

What I missed is that 360 gets normalized to 0: That is 360 - 360 = 0… just like 361 -360 = 1 where 361 and 1 are the same angle. Except an angle of 360 is a special case and should not be normalized.

So what is happening is angles of 0 and 360 normalize to 0 and 0… and Error. :frowning:

I’ll work on a fix for next release. In the mean time if you used 359.9999 it would be close to 360 to not make a difference.

4 likes

If you could make it so any Angles equal would render a full circle instead of an error, that would be ideal. It seems to me like it shouldn’t be any more daunting than making a single exception, but I don’t know the code.

:unicorn:

1 like

I think the Angles equal check in the arc Arc dialog is there for a reason… I suspect that a 0 to 0 circle will yield a point? Also there are probably other tools that have a similar issue - like the Elliptical Arc. So instead of fixing all the tool dialogs this may affect, it will be easier to just fix the upstream normalize routine. Just need to check 1st in the routine if the angle is equally divisible by 360 :

double remainder = std::fmod(number, 360.0);

if (std::abs(remainder) < 1e-9)     
{
    return 360.0;
}
else
{
   normalize n as usual;
   return n;
}
2 likes

@nejcek74

It took a bit but I figured how to fix the issue. It was a bit more than just checking if the angle was 360 or not… also had to check if it was NOT 0. :roll_eyes:

Plus there were several places of the code for displaying the graphics where I had to also normalize the angles that had me baffled for awhile. :thinking:

Anyhow, once I apply the fix to the Elliptical Arc and cleanup some code I commented out… I’ll make a PR that should make the next scheuled release. :slightly_smiling_face:

For those interested here is the final generic normalize function:

qreal normalize(const qreal value, const qreal start, const qreal end)
{
    // check if value is not start value & is evenly divisble by end value
    if (qFabs(value) != start && std::fmod(qFabs(value), end) < 1e-9)
    {
        return end;
    }

    const qreal range       = end - start   ;   //
    const qreal offsetValue = value - start ;   // value relative to 0

    // add start to reset back to start of original range
    return (offsetValue - (floor(offsetValue / range) * range)) + start ;
}

and a call to the function:

result = normalize(result, 0.0, 360.0);
5 likes

thank you @Douglas for the work on so many multiple fronts!

2 likes

Bravo! Thank you @Douglas !

2 likes

@Douglas – Does this PR completely fix this issue?

3 likes

Yes. As well as cleaning up a bunch of code.

4 likes