drawLine() issue

Hi,
can anybody explain this behavior? Is this in according with manual (API) that x2 and y2 coordinates should be out of range when drawin line around watch screen?
(This occures within simulator and also appears on VAHR fw3.8 - both with SDK 2.1.x and 2.2.x .)



function TestGraphics(dc) {
dc.clear();
var bgColor = Gfx.COLOR_DK_GRAY;

// example - no pixel in bottom-right corner
dc.setColor(0xFFFF00, bgColor); // YELLOW, BLACK
var x1 = 10;
var x2 = 13;
var y1 = 10;
var y2 = 13;
dc.drawLine(x1, y1, x1, y2); // vertical line, should be from y1 to y2 4px long, but is only 3px long!!!
dc.drawLine(x1, y2, x2, y2); // horizontal line: 4-th pixel from vertical line is drawn by x1 position, but it is only 3px long (from left to right) again !!!
dc.drawLine(x2, y1, x2, y2); // vertical line starting on y1 position - missing pixel on bottom-right corner !!!

// problem description
dc.setColor(0x00FF00, bgColor); //GREEN, BLACK
x1 = 20;
x2 = 23;
y1 = 10;
y2 = 13;
dc.drawLine(x1, y1, x1, y1); // THIS DOES NOT DRAW SINGLE PIXEL, but I think is should be drawed !
// OK, let's pretend, that x1-x1=0 pixels and y1-y1=0 pixels so it is posible to draw nothing :-)
// But!
// What in case I change only one of targeting coordinate?
dc.setColor(0xFF0000, bgColor); // RED, BLACK
x1 = 30;
y1 = 10;
dc.drawLine(x1, y1, x1, y1 + 1); // this draws one pixel. But it should not because x1-x1=0, so vertical width is zero !

dc.setColor(0x8800BB, bgColor); // BLUE, BLACK
// and more: drawing rectangle accepts width and height instead of x2 and y2, so:
dc.drawRectangle(0, 0, 148, 205); // needs 148 and 205, what means x1 = 0 but x2 should be not 204 (what is last line) but 205 for drawLine() !
dc.setColor(0x55FF00, bgColor); // YELLOW, BLACK
dc.drawLine(1, 0, 1, 204); // x2 is properly 204 but bottom line of rectangle is intact - is this logical? Why use x2=205 what is outside of range?
}


Thanks for answer and explaination.
  • I've created a ticket to take a closer look at this.
  • can you tell what's the status with this? I noticed the same in the sim with some devices. I have a "fix" by either adding or not adding 1, but I need to know when to use the fix.
    Is there a way to know when it was fixed I mean on which devices or in which CIQ version?

  • This thread is 5 years old, and either things have changed or they never will.

    The things with the x/y for things like lines, is they are integers.  There is no pix at 31.7 for example.  Depending on how it's rounded, that means 31 or 32.  You can do whatever you want.

  • 1, I know it's 5 years old. Thank's to the search function we can find old but relevant threads.

    2. The fact that it's old, and that in newer devices the problem seems to be fixed is good, so Garmin probably fixed it, the question is when.

    3. No, either you're guessing incorrectly or you haven't noticed that in the example there are only Numbers, no fractions (float or double) 31 is 31 and 32 is 32. No rounding whatsoever. The question is if these are the pixels:
    00000 
    and I draw a line: dc.drawLine(2,0,2,0) that is supposed to be 2 pixels wide, then which pixels will be colored:
    00XX0 (correct)
    or
    00X00 (incorrect)

  • What device are you running on?  4.0 devices have the GPU and with 3.x devices, there is setAntiAlias() which impacts drawLine and other drawing primitives.

  • Ah, so the antialiasing can impact a straight horizontal or vertical line's last pixel? Is that documented somewhere?
    How does the GPU effect this? Again, we're talking about integers (Numbers), not floats!
    I'm trying to make my app nice on ALL devices.

  • I probably won't have a very satisfying answer for you here.

    I located the original ticket created based on this thread, and we were able to reproduce this issue. The comments essentially conclude that we can't easily fix the issue without breaking existing apps that use drawLine(), but we could document this. What's missing in the comments is any explanation about why this occurs or whether any actual documentation changes were ever made.

    Jim is probably correct that because of the age of this issue there are a lot of things that have changed since then. I'll create a new ticket to ask to have the docs updated, but I doubt this will be fixed.

    For my notes, the original ticket was WERETECH-4058, and the new one is WERETECH-12804.

  • Strange, because from what you wrote it sounds like this is a "given" thing (which would at least enable me adding 1 to to x2, y2 and that would fix it), but from what I saw yesterday in the simulator newer devices don't have the problem - but I didn't really research this.

  • I didn't mean to give that impression that it's a given - I was only relaying what I know based on the original (old) ticket. FWIW, the original report was about the vivoactive HR, which is a pretty old device. It's very possible that this was addressed in some way on newer devices but remains an issue on older devices. I just can't say for certain.

  • Yeah, that's what I saw in the simulator. I hoped that there's a list of devices where it's fixed already.