Rectangle center rounding

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Rectangle center rounding

Jan Blizničenko
Hello

I came to problem with Roassal which originates in Rectangle class. Although rectangle holds its points (origin and corner) in float (not rounded) numbers, the Rectangle>>#center method rounds it down to integers. It causes wierd behavior in Roassal where moving elements in some ocasions are "jumping" to all directions like a jelly. I understand it is for performance reasons, but I think this optimisation is not on the right place. Rectangle origin: 0.9@0.9 corner: 3@3 just does not have center 1@1, it is way too far from the real center. Shouldn't the rounded method be separated as for example roundedCenter or something like that to eliminate the confusion?

Jan
Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

Stephan Eggermont-3
On 17/07/15 18:16, Jan Blizničenko wrote:
> Shouldn't the rounded method be separated as for
> example roundedCenter or something like that to eliminate the confusion?

I think I've seen discussions about this before and vaguely
remember the conclusion that there was too much current
code depending on it for this to be an easy change at the
moment

Stephan



Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

Peter Uhnak
The discussion was that Rectangle is used by Morphic which uses integer coordinates so rounding is required. I think the idea was to split the two classes?

Peter

On Sat, Jul 18, 2015 at 9:50 AM, Stephan Eggermont <[hidden email]> wrote:
On 17/07/15 18:16, Jan Blizničenko wrote:
Shouldn't the rounded method be separated as for
example roundedCenter or something like that to eliminate the confusion?

I think I've seen discussions about this before and vaguely
remember the conclusion that there was too much current
code depending on it for this to be an easy change at the
moment

Stephan




Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

Nicolai Hess


2015-07-18 10:25 GMT+02:00 Peter Uhnák <[hidden email]>:
The discussion was that Rectangle is used by Morphic which uses integer coordinates so rounding is required. I think the idea was to split the two classes?

Peter

On Sat, Jul 18, 2015 at 9:50 AM, Stephan Eggermont <[hidden email]> wrote:
On 17/07/15 18:16, Jan Blizničenko wrote:
Shouldn't the rounded method be separated as for
example roundedCenter or something like that to eliminate the confusion?

I would like to keep Rectangles current implementation, because the Rectangle class
is used for Screen-Rectangles and the screen only knows about integer/pixel positions.

But on the other hand, you are right, we already use and allow rectangles with non-integer corners.
And changing that (resp. enforcing integer coordinates) is maybe much more difficult.
And at latest when we use Athens for rendering the full world, Rectangles with integer rounded position for every shape, does'nt make much sense.


If you do some time comparsions, can you use

center
    "Answer the point at the center of the receiver."

    ^self topLeft + self bottomRight /  2.0

(instead of "/ 2" ) (fraction vs. float)



 

I think I've seen discussions about this before and vaguely
remember the conclusion that there was too much current
code depending on it for this to be an easy change at the
moment

Stephan





Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

abergel
Maybe we can introduce a new rectangle class.

Alexandre


> On Jul 19, 2015, at 6:33 PM, Nicolai Hess <[hidden email]> wrote:
>
>
>
> 2015-07-18 10:25 GMT+02:00 Peter Uhnák <[hidden email]>:
> The discussion was that Rectangle is used by Morphic which uses integer coordinates so rounding is required. I think the idea was to split the two classes?
>
> Peter
>
> On Sat, Jul 18, 2015 at 9:50 AM, Stephan Eggermont <[hidden email]> wrote:
> On 17/07/15 18:16, Jan Blizničenko wrote:
> Shouldn't the rounded method be separated as for
> example roundedCenter or something like that to eliminate the confusion?
>
> I would like to keep Rectangles current implementation, because the Rectangle class
> is used for Screen-Rectangles and the screen only knows about integer/pixel positions.
>
> But on the other hand, you are right, we already use and allow rectangles with non-integer corners.
> And changing that (resp. enforcing integer coordinates) is maybe much more difficult.
> And at latest when we use Athens for rendering the full world, Rectangles with integer rounded position for every shape, does'nt make much sense.
>
>
> If you do some time comparsions, can you use
>
> center
>     "Answer the point at the center of the receiver."
>
>     ^self topLeft + self bottomRight /  2.0
>
> (instead of "/ 2" ) (fraction vs. float)
>
>
>
>  
>
> I think I've seen discussions about this before and vaguely
> remember the conclusion that there was too much current
> code depending on it for this to be an easy change at the
> moment
>
> Stephan
>
>
>
>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

Peter Uhnak

On Thu, Apr 30, 2015 at 9:52 PM, stepharo <[hidden email]> wrote:
The best would be to have ScaledRectangle but with all vector graphics operations.
and independent from Rectangle just reimplementing the right part of the rectangle API.

Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

stepharo
In reply to this post by abergel
It would be nice to design a new one test first.

Stef

Le 19/7/15 18:41, Alexandre Bergel a écrit :

> Maybe we can introduce a new rectangle class.
>
> Alexandre
>
>
>> On Jul 19, 2015, at 6:33 PM, Nicolai Hess <[hidden email]> wrote:
>>
>>
>>
>> 2015-07-18 10:25 GMT+02:00 Peter Uhnák <[hidden email]>:
>> The discussion was that Rectangle is used by Morphic which uses integer coordinates so rounding is required. I think the idea was to split the two classes?
>>
>> Peter
>>
>> On Sat, Jul 18, 2015 at 9:50 AM, Stephan Eggermont <[hidden email]> wrote:
>> On 17/07/15 18:16, Jan Blizničenko wrote:
>> Shouldn't the rounded method be separated as for
>> example roundedCenter or something like that to eliminate the confusion?
>>
>> I would like to keep Rectangles current implementation, because the Rectangle class
>> is used for Screen-Rectangles and the screen only knows about integer/pixel positions.
>>
>> But on the other hand, you are right, we already use and allow rectangles with non-integer corners.
>> And changing that (resp. enforcing integer coordinates) is maybe much more difficult.
>> And at latest when we use Athens for rendering the full world, Rectangles with integer rounded position for every shape, does'nt make much sense.
>>
>>
>> If you do some time comparsions, can you use
>>
>> center
>>      "Answer the point at the center of the receiver."
>>
>>      ^self topLeft + self bottomRight /  2.0
>>
>> (instead of "/ 2" ) (fraction vs. float)
>>
>>
>>
>>  
>>
>> I think I've seen discussions about this before and vaguely
>> remember the conclusion that there was too much current
>> code depending on it for this to be an easy change at the
>> moment
>>
>> Stephan
>>
>>
>>
>>
>>


Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

Jan Blizničenko
In reply to this post by abergel
As far as I looked, only two rounding methods are center and aboveCenter (which has no senders in my image by the way and I do not even see purpose of it)... all other (like leftCenter) are getting value from mentioned self center.

So, the easiest way seems to subclass Rectangle and make something like Precise/Float/NotRounded/I'mNotVeryGoodAtNaming Rectangle
which will have just these two methods different, so there will be also this PreciseRectangle which is not rounding down, but original one stays unchanged.

However, the rounding seems to me like an extension/addition/subtype of general rectangle and I think that it should not be default behavior of something called just Rectangle, it should be more like Rectangle (not rounded) with subclass IntegerRectangle or something like that. I know, there are many senders right now which are dependent on the rounding, but I just think it should not be like that, or should it?

Jan

abergel wrote
Maybe we can introduce a new rectangle class.
Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

abergel
Hi!

Any program on that front?

Alexandre


> On Jul 23, 2015, at 10:32 AM, Jan Blizničenko <[hidden email]> wrote:
>
> As far as I looked, only two rounding methods are center and aboveCenter
> (which has no senders in my image by the way and I do not even see purpose
> of it)... all other (like leftCenter) are getting value from mentioned self
> center.
>
> So, the easiest way seems to subclass Rectangle and make something like
> Precise/Float/NotRounded/I'mNotVeryGoodAtNaming Rectangle
> which will have just these two methods different, so there will be also this
> PreciseRectangle which is not rounding down, but original one stays
> unchanged.
>
> However, the rounding seems to me like an extension/addition/subtype of
> general rectangle and I think that it should not be default behavior of
> something called just Rectangle, it should be more like Rectangle (not
> rounded) with subclass IntegerRectangle or something like that. I know,
> there are many senders right now which are dependent on the rounding, but I
> just think it should not be like that, or should it?
>
> Jan
>
>
> abergel wrote
>> Maybe we can introduce a new rectangle class.
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/Rectangle-center-rounding-tp4837980p4838853.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

Peter Uhnak
On Mon, Sep 21, 2015 at 11:07 PM, Alexandre Bergel
<[hidden email]> wrote:
> Hi!
>
> Any program on that front?
>

There was no progress on this and I don't think that from our (me and
Jan) perspective this is even direction we should go.
(Jan is probably enjoying summer so I don't know when or even if he
will work on this.)

As far as I'm concerned I'm moving towards integer coordinates
(because it's nicer)
and trying to make things behave in Roassal...
... such as my work on RTDraggableSnapToGrid some time ago.

[[[
v := RTView new.

s := RTBox new size: 25; color: (Color blue alpha: 0.3).
es := s elementsOn: (1 to: 10).
v addAll: es.
RTGridLayout on: es.

es @ RTDraggableSnapToGrid.

v
]]]

Peter

Reply | Threaded
Open this post in threaded view
|

Re: Rectangle center rounding

abergel
Okay!

Cheers,
Alexandre


> On Sep 21, 2015, at 6:24 PM, Peter Uhnák <[hidden email]> wrote:
>
> On Mon, Sep 21, 2015 at 11:07 PM, Alexandre Bergel
> <[hidden email]> wrote:
>> Hi!
>>
>> Any program on that front?
>>
>
> There was no progress on this and I don't think that from our (me and
> Jan) perspective this is even direction we should go.
> (Jan is probably enjoying summer so I don't know when or even if he
> will work on this.)
>
> As far as I'm concerned I'm moving towards integer coordinates
> (because it's nicer)
> and trying to make things behave in Roassal...
> ... such as my work on RTDraggableSnapToGrid some time ago.
>
> [[[
> v := RTView new.
>
> s := RTBox new size: 25; color: (Color blue alpha: 0.3).
> es := s elementsOn: (1 to: 10).
> v addAll: es.
> RTGridLayout on: es.
>
> es @ RTDraggableSnapToGrid.
>
> v
> ]]]
>
> Peter
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.