#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Thu, 24 Aug 2017 12:36:52 +0200
changeset 22206 f281a8473915
parent 22205 836f6b0ef8a5
child 22207 f8fd796bb5a3
#REFACTORING by cg class: Rectangle comment/format in: #- #insetBy: #intersect: #merge: #scaledBy: #scaledBy:translatedBy: #translatedBy: refactored: #+ #areasOutside:do:
Rectangle.st
--- a/Rectangle.st	Wed Aug 23 11:08:47 2017 +0200
+++ b/Rectangle.st	Thu Aug 24 12:36:52 2017 +0200
@@ -1473,24 +1473,9 @@
     "return a new rectangle with same extent as receiver but
      origin translated by the argument, aPoint"
 
-    |amountPoint|
+    ^ self translatedBy:aPoint
 
-    (aPoint isMemberOf:SmallInteger) ifTrue:[
-	"/ this is an stc optimization
-	^ Rectangle
-	    left:(left + aPoint)
-	    top:(top + aPoint)
-	    width:width
-	    height:height
-    ].
-
-    amountPoint := aPoint asPoint.
-    ^ Rectangle left:(left + amountPoint x)
-		 top:(top + amountPoint y)
-	       width:width
-	      height:height
-
-    "Modified: 25.1.1997 / 17:29:53 / cg"
+    "Modified: / 24-08-2017 / 12:22:52 / cg"
 !
 
 - aPoint
@@ -1500,22 +1485,22 @@
     |amountPoint|
 
     (aPoint isMemberOf:SmallInteger) ifTrue:[
-	"/ this is an stc optimization
-	^ Rectangle
-	    left:(left - aPoint)
-	    top:(top - aPoint)
-	    width:width
-	    height:height
+        "/ this is an stc optimization (isMemberOf:SmallInteger is a hint to inline addition!!)
+        ^ Rectangle
+            left:(left - aPoint)
+            top:(top - aPoint)
+            width:width
+            height:height
     ].
 
     amountPoint := aPoint asPoint.
     ^ Rectangle left:(left - amountPoint x)
-		 top:(top - amountPoint y)
-	       width:width
-	      height:height
+                 top:(top - amountPoint y)
+               width:width
+              height:height
 
-    "Modified: 25.1.1997 / 17:29:53 / cg"
-    "Created: 25.1.1997 / 17:30:21 / cg"
+    "Created: / 25-01-1997 / 17:30:21 / cg"
+    "Modified (format): / 24-08-2017 / 12:23:53 / cg"
 !
 
 areasOutside:aRectangle
@@ -1600,30 +1585,34 @@
      not intersecting aRectangle.
      That is all areas with no common pixels."
 
-    |yOrigin yCorner origin corner|
+    |yOrigin yCorner origin corner rectOrigin rectCorner|
 
     origin := self origin.
     corner := self corner.
-
+    rectOrigin := aRectangle origin.
+    rectCorner := aRectangle corner.
+    
     "Make sure the intersection is non-empty"
-    (origin <= aRectangle corner and: [aRectangle origin <= corner])
-            ifFalse: [ aBlock value:self. ^ self].
+    (origin <= rectCorner and: [rectOrigin <= corner]) ifFalse: [ 
+        aBlock value:self. 
+        ^ self
+    ].
 
-    aRectangle origin y > origin y ifTrue: [ 
-        aBlock value: (origin corner: corner x @ (yOrigin := aRectangle origin y)) 
+    rectOrigin y > origin y ifTrue: [ 
+        aBlock value: (origin corner: corner x @ (yOrigin := rectOrigin y)) 
     ] ifFalse: [ 
         yOrigin := origin y 
     ].
-    aRectangle corner y < corner y ifTrue: [ 
-        aBlock value: (origin x @ (yCorner := aRectangle corner y) corner: corner) 
+    rectCorner y < corner y ifTrue: [ 
+        aBlock value: (origin x @ (yCorner := rectCorner y) corner: corner) 
     ] ifFalse: [
         yCorner := corner y
     ].
-    aRectangle origin x > origin x ifTrue: [ 
-        aBlock value: (origin x @ yOrigin corner: aRectangle origin x @ yCorner) 
+    rectOrigin x > origin x ifTrue: [ 
+        aBlock value: (origin x @ yOrigin corner: rectOrigin x @ yCorner) 
     ].
-    aRectangle corner x < corner x ifTrue: [ 
-        aBlock value: (aRectangle corner x @ yOrigin corner: corner x @ yCorner) 
+    rectCorner x < corner x ifTrue: [ 
+        aBlock value: (rectCorner x @ yOrigin corner: corner x @ yCorner) 
     ].
 
     "
@@ -1700,6 +1689,8 @@
 "/            [tmp := Rectangle origin: iRect bottomLeft corner: self corner.
 "/                 collect add: tmp].
 "/    ^collect
+
+    "Modified: / 24-08-2017 / 12:32:42 / cg"
 !
 
 encompass:aPoint
@@ -1734,27 +1725,27 @@
     |amountPoint deltaLeft deltaTop deltaWidth deltaHeight|
 
     delta isNumber ifTrue:[
-	deltaLeft := deltaTop := delta.
-	deltaWidth := deltaHeight := delta * 2.
+        deltaLeft := deltaTop := delta.
+        deltaWidth := deltaHeight := delta * 2.
     ] ifFalse:[
-	delta isRectangle ifTrue:[
-	    deltaLeft := delta left.
-	    deltaTop := delta top.
-	    deltaWidth := deltaLeft + delta right.
-	    deltaHeight := deltaTop + delta bottom
-	] ifFalse:[
-	    amountPoint := delta asPoint.
-	    deltaLeft := amountPoint x.
-	    deltaTop := amountPoint y.
-	    deltaWidth := deltaLeft * 2.
-	    deltaHeight := deltaTop * 2.
-	]
+        delta isRectangle ifTrue:[
+            deltaLeft := delta left.
+            deltaTop := delta top.
+            deltaWidth := deltaLeft + delta right.
+            deltaHeight := deltaTop + delta bottom
+        ] ifFalse:[
+            amountPoint := delta asPoint.
+            deltaLeft := amountPoint x.
+            deltaTop := amountPoint y.
+            deltaWidth := deltaLeft * 2.
+            deltaHeight := deltaTop * 2.
+        ]
     ].
 
-    ^ Rectangle left:(left + deltaLeft)
-		 top:(top + deltaTop)
-	       width:(width - deltaWidth)
-	      height:(height - deltaHeight)
+    ^ Rectangle 
+        left:(left + deltaLeft) top:(top + deltaTop)
+        width:(width - deltaWidth) height:(height - deltaHeight)
+        
     "
      |r|
      r := Rectangle origin:10@10 corner:100@100.
@@ -1763,6 +1754,8 @@
      r insetBy:(10 @ 10).
      r insetBy:( 10@10 corner:20@20 )
     "
+
+    "Modified (format): / 24-08-2017 / 12:27:04 / cg"
 !
 
 insetOriginBy:originDelta cornerBy:cornerDelta
@@ -1787,10 +1780,11 @@
      and the argument, aRectangle (i.e. the area covered by both).
      the rectangles must intersect for a valid return"
 
-    ^ Rectangle left:(left max:(aRectangle left))
-	       right:((left + width) min:(aRectangle right))
-		 top:(top max:(aRectangle top))
-	      bottom:((top + height) min:(aRectangle bottom))
+    ^ Rectangle 
+        left:(left max:(aRectangle left))
+        right:((left + width) min:(aRectangle right))
+        top:(top max:(aRectangle top))
+        bottom:((top + height) min:(aRectangle bottom))
 
     "
      |r1 r2|
@@ -1799,24 +1793,29 @@
      r2 := Rectangle origin:50@50 corner:150@75.
      r1 intersect:r2
     "
+
+    "Modified (format): / 24-08-2017 / 12:26:42 / cg"
 !
 
 merge:aRectangle
     "return a new rectangle covering both the receiver
      and the argument, aRectangle"
 
-    ^ Rectangle left:(left min:(aRectangle left))
-	       right:((left + width) max:(aRectangle right))
-		 top:(top min:(aRectangle top))
-	      bottom:((top + height) max:(aRectangle bottom))
+    ^ Rectangle 
+        left:(left min:(aRectangle left))
+        right:((left + width) max:(aRectangle right))
+        top:(top min:(aRectangle top))
+        bottom:((top + height) max:(aRectangle bottom))
 
     "
      (Rectangle origin:10@10 corner:100@100)
-	 merge:(Rectangle origin:20@20 corner:110@110)
+         merge:(Rectangle origin:20@20 corner:110@110)
 
      (Rectangle origin:10@10 corner:100@100)
-	 merge:(Rectangle origin:20@20 corner:100@100)
+         merge:(Rectangle origin:20@20 corner:100@100)
     "
+
+    "Modified (comment): / 24-08-2017 / 12:26:28 / cg"
 !
 
 nonIntersections:aRectangle
@@ -1880,20 +1879,18 @@
     |scalePoint sx sy|
 
     (scale isMemberOf:SmallInteger) ifTrue:[
-	"/ this is an stc optimization
-	^ Rectangle left:left * scale
-		     top:top * scale
-		   width:width * scale
-		  height:height * scale
+        "/ this is an stc optimization (a hint to inline)
+        ^ Rectangle 
+            left:(left * scale) top:(top * scale)
+            width:(width * scale) height:(height * scale)
     ].
 
     scalePoint := scale asPoint.
     sx := scalePoint x.
     sy := scalePoint y.
-    ^ Rectangle left:left * sx
-		 top:top * sy
-	       width:width * sx
-	      height:height * sy
+    ^ Rectangle 
+        left:(left * sx) top:(top * sy)
+        width:(width * sx) height:(height * sy)
     "
      (Rectangle origin:10@10 corner:50@50) scaledBy:2
     "
@@ -1906,6 +1903,8 @@
      r2 := r1 scaledBy:2.
      r1
     "
+
+    "Modified (comment): / 24-08-2017 / 12:28:45 / cg"
 !
 
 scaledBy:scale translatedBy:translation
@@ -1915,7 +1914,7 @@
     |x y w h translationPoint scalePoint sx sy|
 
     (translation isNil and:[scale isNil]) ifTrue:[
-	^ self.
+        ^ self.
     ].
 
     x := left.
@@ -1924,32 +1923,32 @@
     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.
-	].
+        (scale isMemberOf:SmallInteger) ifTrue:[
+            "/ this is an stc optimization (a hint to inline)
+            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.
-	].
+        (translation isMemberOf:SmallInteger) ifTrue:[
+            "/ this is an stc optimization (to inline)
+            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.
@@ -1957,6 +1956,8 @@
     "
      (Rectangle origin:10@10 corner:50@50) scaledBy:2 translatedBy:10
     "
+
+    "Modified (format): / 24-08-2017 / 12:25:54 / cg"
 !
 
 translatedBy:amount
@@ -1966,24 +1967,21 @@
     |amountPoint|
 
     (amount isMemberOf:SmallInteger) ifTrue:[
-	"/ this is an stc optimization
-	^ Rectangle
-	    left:(left + amount)
-	    top:(top + amount)
-	    width:width
-	    height:height
+        "/ this is an stc optimization (a hint to inline)
+        ^ 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
+    ^ Rectangle 
+        left:(left + amountPoint x) top:(top + amountPoint y)
+        width:width height:height
     "
      (Rectangle origin:10@10 corner:50@50) translatedBy:10
     "
 
-    "its NOT destructive:"
+    "it's NOT destructive:"
     "
      |r1 r2|
 
@@ -1991,6 +1989,8 @@
      r2 := r1 translatedBy:10.
      r1
     "
+
+    "Modified (format): / 24-08-2017 / 12:27:46 / cg"
 ! !
 
 !Rectangle methodsFor:'testing'!