--- a/Rectangle.st Fri Nov 13 11:54:01 2015 +0100
+++ b/Rectangle.st Fri Nov 13 11:57:03 2015 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -1808,17 +1810,77 @@
"
!
+scaledBy:scale translatedBy:translation
+ "return a new rectangle which is translated (i.e. moved)
+ by translation, aPoint or Number and scaled by scale, aPoint or number."
+
+ |x y w h translationPoint scalePoint sx sy|
+
+ (translation isNil and:[scale isNil]) ifTrue:[
+ ^ self.
+ ].
+
+ x := left.
+ y := top.
+ w := width.
+ h := height.
+
+ scale notNil ifTrue:[
+ (scale isMemberOf:SmallInteger) ifTrue:[
+ "/ this is an stc optimization
+ x := x * scale.
+ y := y * scale.
+ w := w * scale.
+ h := h * scale.
+ ] ifFalse:[
+ scalePoint := scale asPoint.
+ sx := scalePoint x.
+ sy := scalePoint y.
+ x := x * sx.
+ y := y * sy.
+ w := w * sx.
+ h := h * sy.
+ ].
+ ].
+ translation notNil ifTrue:[
+ (translation isMemberOf:SmallInteger) ifTrue:[
+ "/ this is an stc optimization
+ x := x + translation.
+ y := y + translation.
+ ] ifFalse:[
+ translationPoint := translation asPoint.
+ x := x + translationPoint x.
+ y := y + translationPoint y.
+ ].
+ ].
+
+ ^ Rectangle left:x top:y width:w height:h.
+
+ "
+ (Rectangle origin:10@10 corner:50@50) translatedBy:10 scaledBy:2
+ "
+!
+
translatedBy:amount
"return a new rectangle which is translated (i.e. moved)
by amount, aPoint or Number"
|amountPoint|
+ (amount isMemberOf:SmallInteger) ifTrue:[
+ "/ this is an stc optimization
+ ^ Rectangle
+ left:(left + amount)
+ top:(top + amount)
+ width:width
+ height:height
+ ].
+
amountPoint := amount asPoint.
^ Rectangle left:(left + amountPoint x)
- top:(top + amountPoint y)
- width:width
- height:height
+ top:(top + amountPoint y)
+ width:width
+ height:height
"
(Rectangle origin:10@10 corner:50@50) translatedBy:10
"