The Inbox: Graphics-ct.437.mcz

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

The Inbox: Graphics-ct.437.mcz

commits-2
Christoph Thiede uploaded a new version of Graphics to project The Inbox:
http://source.squeak.org/inbox/Graphics-ct.437.mcz

==================== Summary ====================

Name: Graphics-ct.437
Author: ct
Time: 24 August 2020, 1:26:40.516818 pm
UUID: 66c6c2fd-6978-6d43-8eda-c22f0a5defca
Ancestors: Graphics-kfr.436

Proposal: Add Point >> #exactCenter:, complementing Graphics-cbc.372. Refine relevant method comments in Point and Rectangle.

Usage example:

        m := Morph new.
        m changeProportionalLayout.
       
        n := Morph new.
        n color: Color red.
        m addMorph: n fullFrame: (LayoutFrame fractions: (
                0.5 @ 0.25 exactCenter: 0.5 @ 0.5)).
       
        m openInHand.

=============== Diff against Graphics-kfr.436 ===============

Item was changed:
  ----- Method: Point>>center: (in category 'converting to rectangle') -----
  center: aPoint
+ "Answer a Rectangle whose extent is the receiver and whose center is approximately aPoint (after rounding to integers). This is one of the infix ways of expressing the creation of a rectangle."
- "Answer a Rectangle whose extent is the receiver and whose center is
- aPoint. This is one of the infix ways of expressing the creation of a
- rectangle."
 
+ ^ Rectangle center: aPoint extent: self!
- ^Rectangle center: aPoint extent: self!

Item was added:
+ ----- Method: Point>>exactCenter: (in category 'converting to rectangle') -----
+ exactCenter: aPoint
+ "Answer a Rectangle whose extent is the receiver and whose center is exactly aPoint. This is one of the infix ways of expressing the creation of a rectangle."
+
+ ^ Rectangle exactCenter: aPoint extent: self!

Item was changed:
  ----- Method: Rectangle class>>center:extent: (in category 'instance creation') -----
  center: centerPoint extent: extentPoint
+ "Answer an instance of me whose center is approximately centerPoint (after rounding to integers) and whose extent is extentPoint."
- "Answer an instance of me whose center is centerPoint and width
- by height is extentPoint.  "
 
+ ^ self origin: centerPoint - (extentPoint // 2) extent: extentPoint!
- ^self origin: centerPoint - (extentPoint//2) extent: extentPoint!

Item was changed:
  ----- Method: Rectangle class>>exactCenter:extent: (in category 'instance creation') -----
  exactCenter: centerPoint extent: extentPoint
+ "Answer an instance of me whose center is exactly centerPoint and whose extent is extentPoint."
+
- "Answer an instance of me whose center is centerPoint and width
- by height is extentPoint. "
  ^ self origin: centerPoint - (extentPoint / 2) extent: extentPoint
  !


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Graphics-ct.437.mcz

Christoph Thiede

In particular, when it comes to LayoutFrames, I have to say that I find the automatic rounding behaviors of Point/Rectangle quite confusing.


For instance, why does #scaleBy: allow producing float points/rectangles whereas #scaleFrom:to: applies rounding?

In my opinion, the integer/float arithmetic of Point and Rectangle is not really clear. If these classes are intended containing integers only, the "truncation and round off" protocol would be redundant. If they are intended to contain floats as well, it is confusing that methods such as #center and #aboveCenter apply rounding. Would it be possible and wise to eliminate that automatic rounding behavior, or is too old and popular for such a breaking change?


See also this related discussion: http://forum.world.st/The-Inbox-Graphics-cbc-372-mcz-td4940274.html


Best,
Christoph

Von: Squeak-dev <[hidden email]> im Auftrag von [hidden email] <[hidden email]>
Gesendet: Montag, 24. August 2020 13:26:55
An: [hidden email]
Betreff: [squeak-dev] The Inbox: Graphics-ct.437.mcz
 
Christoph Thiede uploaded a new version of Graphics to project The Inbox:
http://source.squeak.org/inbox/Graphics-ct.437.mcz

==================== Summary ====================

Name: Graphics-ct.437
Author: ct
Time: 24 August 2020, 1:26:40.516818 pm
UUID: 66c6c2fd-6978-6d43-8eda-c22f0a5defca
Ancestors: Graphics-kfr.436

Proposal: Add Point >> #exactCenter:, complementing Graphics-cbc.372. Refine relevant method comments in Point and Rectangle.

Usage example:

        m := Morph new.
        m changeProportionalLayout.
       
        n := Morph new.
        n color: Color red.
        m addMorph: n fullFrame: (LayoutFrame fractions: (
                0.5 @ 0.25 exactCenter: 0.5 @ 0.5)).
       
        m openInHand.

=============== Diff against Graphics-kfr.436 ===============

Item was changed:
  ----- Method: Point>>center: (in category 'converting to rectangle') -----
  center: aPoint
+        "Answer a Rectangle whose extent is the receiver and whose center is approximately aPoint (after rounding to integers). This is one of the infix ways of expressing the creation of a rectangle."
-        "Answer a Rectangle whose extent is the receiver and whose center is
-        aPoint. This is one of the infix ways of expressing the creation of a
-        rectangle."
 
+        ^ Rectangle center: aPoint extent: self!
-        ^Rectangle center: aPoint extent: self!

Item was added:
+ ----- Method: Point>>exactCenter: (in category 'converting to rectangle') -----
+ exactCenter: aPoint
+        "Answer a Rectangle whose extent is the receiver and whose center is exactly aPoint. This is one of the infix ways of expressing the creation of a rectangle."
+
+        ^ Rectangle exactCenter: aPoint extent: self!

Item was changed:
  ----- Method: Rectangle class>>center:extent: (in category 'instance creation') -----
  center: centerPoint extent: extentPoint
+        "Answer an instance of me whose center is approximately centerPoint (after rounding to integers) and whose extent is extentPoint."
-        "Answer an instance of me whose center is centerPoint and width
-        by height is extentPoint.  "
 
+        ^ self origin: centerPoint - (extentPoint // 2) extent: extentPoint!
-        ^self origin: centerPoint - (extentPoint//2) extent: extentPoint!

Item was changed:
  ----- Method: Rectangle class>>exactCenter:extent: (in category 'instance creation') -----
  exactCenter: centerPoint extent: extentPoint
+        "Answer an instance of me whose center is exactly centerPoint and whose extent is extentPoint."
+
-        "Answer an instance of me whose center is centerPoint and width
-        by height is extentPoint. "
         ^ self origin: centerPoint - (extentPoint / 2) extent: extentPoint
  !




Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Graphics-ct.437.mcz

Stéphane Rollandin
> In my opinion, the integer/float arithmetic of Point and Rectangle is
> not really clear
Indeed.

In my own images I have implemented #preciseCenter: and similar methods
both in Pont and Rectangle to bypass rounding and work with floats.

But I do not think that transitioning to an overall new convention (like
getting rid of rounding altogether) is going to be safe. A lot of
morphic code assumes that rectangles are always about pixels and expect
their dimensions to be integers.

Stef


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Graphics-ct.437.mcz

Karl Ramberg
Scaling for morphs with TransformationMorph is a little weird.
If you rotate a SystemWindow and use the scale handle, the window scales as a form


Best,
Karl

On Mon, Aug 24, 2020 at 2:25 PM Stéphane Rollandin <[hidden email]> wrote:
> In my opinion, the integer/float arithmetic of Point and Rectangle is
> not really clear
Indeed.

In my own images I have implemented #preciseCenter: and similar methods
both in Pont and Rectangle to bypass rounding and work with floats.

But I do not think that transitioning to an overall new convention (like
getting rid of rounding altogether) is going to be safe. A lot of
morphic code assumes that rectangles are always about pixels and expect
their dimensions to be integers.

Stef




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Graphics-ct.437.mcz

marcel.taeumel
Hmpf. Why can't we change Rectangle >> #center:extent: to use #/ instead of #//? What would break?

I am surprised that my values get rounded at that location. They get rounded at a later anyway. At least in the graphics system and in Morphic.

Best,
Marcel

Am 24.08.2020 21:04:26 schrieb karl ramberg <[hidden email]>:

Scaling for morphs with TransformationMorph is a little weird.
If you rotate a SystemWindow and use the scale handle, the window scales as a form


Best,
Karl

On Mon, Aug 24, 2020 at 2:25 PM Stéphane Rollandin <[hidden email]> wrote:
> In my opinion, the integer/float arithmetic of Point and Rectangle is
> not really clear
Indeed.

In my own images I have implemented #preciseCenter: and similar methods
both in Pont and Rectangle to bypass rounding and work with floats.

But I do not think that transitioning to an overall new convention (like
getting rid of rounding altogether) is going to be safe. A lot of
morphic code assumes that rectangles are always about pixels and expect
their dimensions to be integers.

Stef