A new version of Graphics was added to project The Inbox:
http://source.squeak.org/inbox/Graphics-kfr.435.mcz==================== Summary ====================
Name: Graphics-kfr.435
Author: kfr
Time: 11 July 2020, 4:59:11.970242 pm
UUID: 2ded852c-61bf-9c45-be09-6acb12a6b592
Ancestors: Graphics-kfr.434
I wanted to subclass Rectangle with a instance variable to carry some state, but these methodes indirected to Point>>corner: so it broke the override and returned a ordinary Rectangle instead of my fancy new subclass SuperRectangle
Updated to use #first to get the first element and #allButFirstDo: to iterate over the rest.
(Suggested by Levente Uzonyi)
=============== Diff against Graphics-kfr.434 ===============
Item was changed:
----- Method: Rectangle class>>encompassing: (in category 'instance creation') -----
encompassing: listOfPoints
"A number of callers of encompass: should use this method."
| topLeft bottomRight |
+ topLeft := bottomRight := listOfPoints first.
+ listOfPoints allButFirstDo:
+ [:p |topLeft := topLeft min: p.
+ bottomRight := bottomRight max: p].
- topLeft := bottomRight := nil.
- listOfPoints do:
- [:p | topLeft == nil
- ifTrue: [topLeft := bottomRight := p]
- ifFalse: [topLeft := topLeft min: p.
- bottomRight := bottomRight max: p]].
^self origin: topLeft corner: bottomRight!
Item was changed:
----- Method: Rectangle class>>merging: (in category 'instance creation') -----
merging: listOfRects
"A number of callers of merge: should use this method."
+ | bottomRight topLeft |
+ topLeft := listOfRects first topLeft.
+ bottomRight := listOfRects first bottomRight.
- | minX minY maxX maxY |
listOfRects
+ allButFirstDo: [:r | topLeft := topLeft min: r topLeft.
+ bottomRight := bottomRight max: r bottomRight].
+ ^self origin: topLeft corner: bottomRight.
+ !
- do: [:r | minX
- ifNil: [minX := r topLeft x. minY := r topLeft y.
- maxX := r bottomRight x. maxY := r bottomRight y]
- ifNotNil: [minX := minX min: r topLeft x. minY := minY min: r topLeft y.
- maxX := maxX max: r bottomRight x. maxY := maxY max: r bottomRight y]].
- ^ self origin:minX@minY corner: maxX@maxY!