A couple thoughts:

1) if you want this to be more precise, you can adjust the scale to
integers, rather than using exactly what ZoomToBB gives you:

in __init__

        wx.CallAfter(self.Scale)

this method does the work.
    def Scale(self):

        self.canvas.ZoomToBB() # to get it close
        self.canvas.Scale = round(self.canvas.Scale)
        self.canvas.ViewPortCenter  = np.round(self.canvas.ViewPortCenter)
        self.canvas.SetToNewScale()

Kind of a klunky API -- I should probably add a cleaner way to do that.

I think I get "perfect" results when that's all set that way.

 With such a scale (nearly 103%), I was expecting having values from 0 to
> something like 308 or 307 or 306. But here 299.60 seems a bit far away,
> don't you think so ?
>

well:

In [48]: 308 / 1.03
Out[48]: 299.02912621359224

but there is antoher player here:

FloatCanvas keeps track of how the Canvas is zoomed an panned with a Scale
and the ViewPortCenter. -- so the center point was not integers, either, so
two sources of fudging.


So: if you really want exact coords, you can do that above to get them.

But the other option is simply to round the results, and accept that there
may be a off-by-one error sometimes.

If this is the only zoom level you need, then setting it like the above
might make sense. And if you want to suggest a cleaner API for that, I
could add it.

I don't think supporting "use integer scaling" as a general purpose feature
makes sense -- the whole idea of FloatCanvas is that coordinates are
floating point -- any arbitrary scale may make sense for a
given application -- there isn't really anything that special about
integers.

Do you think there is something wrong in the way I compute x and y ? :
>
>     def OnMotion(self, event):
>         x, y = event.HitCoords[0] - event.BoundingBox[0,0],
> event.BoundingBox[1,1] - event.HitCoords[1]
>          print self.canvas.Scale, x, y
>

That's correct, but perhaps unnecessary:

you've placed the image on the canvas at (0,0), so that should be the
corner. You don't need to get it from the bounding box. It's
also available from:

img.XY (and maybe img.Width and img.Height, if you need those)

HTH,

-Chris


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to