Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [gef-dev] Why is converting from double to int done using the Math.floor?

Hi Jan,

you are right, what you are facing here is one of the several inconsistencies within the current Draw2d geometry API, and one of the reasons we started to build a new one in GEF4. You would actually have to switch to integer-based precision when performing the calculation of the drawing position (i.e. y = line.y() - rect.height()) for the rectangle. I agree that in general rounding would probably lead to better results, so that's what we will do when rendering GEF4 geometries (which are completely based on double-precision) within a GEF4 Graphics.

Cheers
Alexander

Am 17.04.2013 um 12:16 schrieb Jan Krakora <jan.krakora.cz@xxxxxxxxx>:

Hi all,

since the GEF forum is basically dead I would like to ask you here. Why is used Math.floor in all Precision* classes?

Let me give you an example:

First of all, I use PrecisionPoint, PrecisionRectangle, PrecisionDimension everywhere.

So there is a line with y coordinate 31.14. You have a rectangle with height 18.315 that you would like to draw exactly above the line
so its bottom edge overlaps the line. But since the converting from double to int is done using Math.floor the coordinates
are as such:

the line:
   y: 31.14 -> 31
the rectangle
   y: 31.14 - 18.315 =  12.825 -> 12
   height: 18.315 -> 18

As you can see the rectangle will be rendered above the line. They don't overlap. Why aren't double coordinates rounded?
Do I compute the y of the rectangle in wrong way?

Thanks, Jan Krakora.
_______________________________________________
gef-dev mailing list
gef-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/gef-dev

--
Dr. Alexander Nyßen
Dipl.-Inform.
Software-Engineer

Telefon: +49 (0) 231 / 98 60-210
Telefax: +49 (0) 231 / 98 60-211
Mobil: +49 (0) 151 /  17396743

http://www.itemis.de 
alexander.nyssen@xxxxxxxxx 

itemis AG
Am Brambusch 15-24
44536 Lünen

Rechtlicher Hinweis:

Amtsgericht Dortmund, HRB 20621

Vorstand: Jens Wagener (Vors.), Wolfgang Neuhaus, Dr. Georg Pietrek, Jens Trompeter, Sebastian Neus

Aufsichtsrat: Dr. Burkhard Igel (Vors.), Stephan Grollmann, Michael Neuhaus



Back to the top