#2333 Canvas co-ordinate rounding e.g. 118.0 -> 117.99999

open-fixed
5
2008-12-21
2007-10-15
Steven
No

Hmmmm... In the latest beta (8.5b1) canvas co-ordinate rounding has changed, (and is breaking my polypuzzle program). This wasn't the case in 8.5a[5|6]. I know this is a weak point of tcl... but perhaps as it is , lots of apps will break ? Below is a simple line created on a canvas in wish8.4 and then wish8.5b1. I then retrieve the coords.. Notice that in wish8.5 the
410.99999999999994 -> 410.9999999999999
, but *worse*, the
118.0 -> 117.99999999999999
Hmmm.. This last one is nasty. The rounding behaviour in 8.4 was very well behaved, and *never* gave me horrible point nines recurring.

Anyway, thank-you for your time.
Steven.

Linux 2.6.23 #1 PREEMPT Fri Oct 12 19:07:53 UTC 2007
i686 i386 GNU/Linux, xorg-x11-6.8.2-31, glibc-2.3.5-10, Fedora 4

----------------------------------------------------------------
#wish8.4
--------
% canvas .c
.c
% .c creat line 0 0 410.99999999999994 118.0
1
% .c coords 1
0.0 0.0 411.0 118.0
----------------------------------------------------------------
#wish8.5b1
--------
% canvas .c
.c
% .c creat line 0 0 410.99999999999994 118.0
1
% .c coords 1
0.0 0.0 410.9999999999999 117.99999999999999
----------------------------------------------------------------

Discussion

  • Larry W. Virden

    Larry W. Virden - 2007-10-16

    Logged In: YES
    user_id=15949
    Originator: NO

    Note that I see something similar in the tk test suite. For example:
    canvRect.test

    ==== canvRect-9.1 ScaleRectOval procedure FAILED
    ==== Contents of test case:

    .c delete withtag all
    .c create rect 100 300 200 350 -tags x
    .c scale x 50 100 2 4
    .c coords x

    ---- Result was:
    150.0 900.0 350.0 1099.9999999999998
    ---- Result should have been (exact matching):
    150.0 900.0 350.0 1100.0
    ==== canvRect-9.1 FAILED

    ==== canvRect-10.1 TranslateRectOval procedure FAILED
    ==== Contents of test case:

    .c delete withtag all
    .c create rect 100 300 200 350 -tags x
    .c move x 100 -10
    .c coords x

    ---- Result was:
    200.0 290.0 300.0 339.99999999999994
    ---- Result should have been (exact matching):
    200.0 290.0 300.0 340.0
    ==== canvRect-10.1 FAILED

     
  • Steven

    Steven - 2007-10-17

    Logged In: YES
    user_id=1043388
    Originator: YES

    Hmmmm , i've found the cause of this issue. This seems related to tcl_precision:
    Tcl8.4 "tclvars" man-page:
    tcl_precision
    This variable controls the number of digits to generate when con-
    verting floating-point values to strings. It defaults to 12.
    tcl8.5:
    tcl_precision
    This variable controls the number of digits to generate when con-
    verting floating-point values to strings. It defaults to 0.
    Applications should not change this value; it is provided for com-
    patibility with legacy code.

    Well.. this is breaking my "legacy" canvas app, polypuzzle. "set tcl_precision
    12" fixes my problem, but the doco explicitly says not to do this. Perhaps
    some work needs still to be done here.... Could someone please let me know
    what i should be doing ?

     
  • Peter Spjuth

    Peter Spjuth - 2007-10-17

    Logged In: YES
    user_id=98900
    Originator: NO

    The basic problem is that canvas coordinates goes
    through the "mm" object type leading to slight rounding
    errors, and probably some shimmering. This becomes
    visible in 8.5 with the new exact string reps of floats.
    If Tk_CanvasGetCoordFromObj checked for double/int
    objects, in the same manner as SetMMFromAny does, before
    calling Tk_GetMMFromObj it would make things nicer
    and probably faster.

     
  • Peter Spjuth

    Peter Spjuth - 2007-10-17

    Logged In: YES
    user_id=98900
    Originator: NO

    Another alternative would be to make a double
    version of Tk_GetPixelFromObj and use that in
    canvas instead, skipping the mm object altogether.

     
  • Steven

    Steven - 2008-05-17

    Logged In: YES
    user_id=1043388
    Originator: YES

    Under Wish 8.5.2 this seems better. Most of the time there's no problem... But under fedora 7 , ONLY AT 1154 screen resolution, it still happens. It's unusual that there shold still be a problem at this resolution only. !&^%$

     
  • Alexandre Ferrieux

    Fully agreeing with Peter. As it turns out, GetDoublePixels is ready for the job.
    I'd only want a green light from Jeff before submitting the patch.

     
  • Alexandre Ferrieux

    In fact, GetDoublePixels is a pure-string thing from pre-obj times.
    Instead, the attached patch defines a double version of Tk_GetPixelsFromObj as suggested by Peter.
    Passes the test suite.
    File Added: doublepixels.patch

     
  • Pat Thoyts

    Pat Thoyts - 2008-11-24

    This fixes some broken tests for me on WinXP using the 8.6 HEAD. Seems good.

     
  • Pat Thoyts

    Pat Thoyts - 2008-11-24

    Oops I spoke too soon.
    Checking the canvas demo - the first one in the canvas section (1. The cavas item types) all the items are drawn up at the top left. They should be spread around the whole canvas.

     
  • Alexandre Ferrieux

    Funny that the test suite failed to capture that !
    Investigating...

     
  • Alexandre Ferrieux

    OK, got it. I forgot to force the unit back to pixels (internal unit-shimmering). Sorry about that. Expect fix shortly.

     
  • Alexandre Ferrieux

    Fixed patch. Refactored a bit to avoid duplication while staying at full speed.
    File Added: doublepixels2.patch

     
  • Alexandre Ferrieux

    Pat, can you review ?

     
  • Alexandre Ferrieux

    Patch now extended to the only other client of the millimeter type, tkText.c
    So now mmObjType is unused in the core. Cannot be deprecated though, because (1) there is a stub entry mentioning it, and (2) it is registered. But not using it at all is enough to make me happy.
    File Added: doublepixels3.patch

     
  • Alexandre Ferrieux

    Committed to HEAD. Would appreciate help for backports.

     
  • Alexandre Ferrieux

    • status: open --> closed-fixed
     
  • Pat Thoyts

    Pat Thoyts - 2008-11-28

    There are still some problems in the demos. The Canvas 5 (A ruler with adjustible tab stops) demo is wrong and Animation 3 (Pendulum swing) is failing to draw the phase space graph.

     
  • Alexandre Ferrieux

    Fixed, and committed as revision 1.24 of tkObj.c
    A stupid bug (uninited var in one condition).

     
  • Don Porter

    Don Porter - 2008-12-21

    backport for 8.5.6 ?

     
  • Don Porter

    Don Porter - 2008-12-21
    • status: closed-fixed --> open-fixed
     
  • Alexandre Ferrieux

    Done :)
    No misbehavior detected, but I'd appreciate a review of the demos, because the test suite has a needle-haystack issue on my system.
    Also, I see I committed late... feel free to bump the tag or not.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks