Need help regarding drawArc

Hi,

I have a strange problem. I want to implement a progress bar in terms of a closing fill circle. I coded it in this way:

deg = Mat.round(90 - 360 * val).toNumber();

val can only be a value between 0 and 1.

I implemented the progress bar in this way:
dc.setPenWidth(16);
dc.drawArc(120, 120, 8, Gfx.ARC_CLOCKWISE, 90, deg);


This works perfect in the beginning. Nevertheless, if val is near 1 I can see only a small stripe in the progress bar instead of an almost full circle. I debugged it and found e. g. a value of deg=-268 which is also 92 shows that problem. I then putted instead of variable deg real values in the drawArc function and found out that deg=97 works, deg=96 shows the problem. I tried it with the latest SDK and furthermore with 2.2.6. I see the problem on the real watch as well as with the newest SDK in the simulator, but I don's know why.

Did I miss something?
  • Former Member
    Former Member
    [edit: Deleted incorrect advice]
  • grolschie, I don't understand this, since the angle of 90 degrees is 12 o clock and 92 degrees is a little bit on the left hand side of the 90 degree. Rotating clockwise has to be almost a full circle then. As I mentioned before this formula works pretty well until val is near 1. E. g. a val = 0.25 shows a quarte of a circle.
  • Former Member
    Former Member
    My apologies, I got that all wrong. So basically it seems:
    0 degrees = 3 o'clock
    90 degrees = 12 o'clock
    180 degrees = 9 o'clock
    270 degrees = 6 o'clock

    I tweaked this line and it works:
    var deg = (90 - 359 * val).toNumber();

    For some reason it doesn't like the start point equalling the end point (perhaps??), hence 359 works instead of 360. If val = 0, then that will fail also (for the same reason). I didn't bother with the rounding as toNumber() probably does it well enough??
  • Hi again,

    I putted also 359 in my code, but the same behaviour. 355 shows an almost full circle, 356 only a line. Maybe this is a bug in the SDK?
  • Former Member
    Former Member
    I do think this is an error within the SDK. Internally this API is computing a starting and ending point of the arc, and uses those as the inputs to the internal rendering API. I assume what is happening here is that when your angle gets close to a full circle, the starting and ending points become the same point, and then the API does not know the difference between a full circle and an empty one.

    There are plans to put time into the graphics APIs soon, but for now, your best bet is going to be to make two render calls in this condition. (e.g. 0 to 180 and 180 to 360)
  • It's more coding work, but this is a workaround I can live with. Thanks for clarifying this.
  • OK, that workaround did help. Do I need to write a bug report for that?


    Edit: here is the code, if someone wants to use it:
    function drawArc (dc, y, deg) {
    if (deg < 90) {
    dc.drawArc(190, y, 8, Gfx.ARC_CLOCKWISE, 90, deg);
    } else {
    dc.drawArc(190, y, 8, Gfx.ARC_CLOCKWISE, 90, 0);
    dc.drawArc(190, y, 8, Gfx.ARC_CLOCKWISE, 0, deg);

    }
    }
  • Former Member
    Former Member
    You're welcome to file a ticket for this, but it looks like we have a ticket open from a long time ago that covers the issue.