added #truncated;
authorClaus Gittinger <cg@exept.de>
Thu, 07 Oct 1999 00:14:23 +0200
changeset 4861 117905eec712
parent 4860 ac3a625492b2
child 4862 5df99a53c364
added #truncated; return receiver from #rounded, if coordinates are already integral
Rectangle.st
--- a/Rectangle.st	Wed Oct 06 22:43:26 1999 +0200
+++ b/Rectangle.st	Thu Oct 07 00:14:23 1999 +0200
@@ -1279,15 +1279,6 @@
 
 !
 
-rounded
-    "return a copy of the receiver with rounded coordinates"
-
-    ^ Rectangle left:(left rounded) 
-		 top:(top rounded)
-	       width:(width rounded) 
-	      height:(height rounded)
-!
-
 scaledBy:scale
     "return a new rectangle which is the receiver
      scaled by scale"
@@ -1565,8 +1556,43 @@
     ^ false
 ! !
 
+!Rectangle methodsFor:'truncation and rounding'!
+
+rounded
+    "return a copy of the receiver with rounded coordinates.
+     Return the receiver if its coordinates are already integral."
+
+    (left isInteger 
+    and:[top isInteger 
+    and:[width isInteger 
+    and:[height isInteger]]])
+        ifTrue: [^ self].
+
+    ^ Rectangle left:(left rounded) 
+                 top:(top rounded)
+               width:(width rounded) 
+              height:(height rounded)
+!
+
+truncated
+    "return a Rectangle whose origin and corner have any fractional parts removed.
+     Return the receiver if its coordinates are already integral."
+
+    (left isInteger 
+    and:[top isInteger 
+    and:[width isInteger 
+    and:[height isInteger]]])
+        ifTrue: [^ self].
+
+    ^ Rectangle 
+        left:left truncated
+        top:top truncated
+        width:width truncated
+        height:height truncated.
+! !
+
 !Rectangle class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.60 1999-10-06 20:43:26 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.61 1999-10-06 22:14:23 cg Exp $'
 ! !