--- a/Rectangle.st Wed Oct 06 21:32:48 1999 +0200
+++ b/Rectangle.st Wed Oct 06 22:22:28 1999 +0200
@@ -1213,9 +1213,17 @@
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))
+ 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)
+
+ (Rectangle origin:10@10 corner:100@100)
+ merge:(Rectangle origin:20@20 corner:100@100)
+ "
!
nonIntersections:aRectangle
@@ -1224,6 +1232,36 @@
^ self areasOutside:aRectangle
!
+quickMerge: aRectangle
+ "return the receiver if it encloses the given rectangle,
+ or the merge of the two rectangles if it doesn't.
+ This method is an optimization to reduce extra rectangle creations."
+
+ | useRcvr rLeft rTop rRight rBottom Origin rCorner minX maxX minY maxY |
+
+ useRcvr := true.
+ rLeft := aRectangle left.
+ rTop := aRectangle top.
+ rRight := aRectangle right.
+ rBottom := aRectangle bottom.
+ minX := rLeft < left ifTrue: [useRcvr := false. rLeft] ifFalse: [left].
+ maxX := rRight > self right ifTrue: [useRcvr := false. rRight] ifFalse: [self right].
+ minY := rTop < top ifTrue: [useRcvr := false. rTop] ifFalse: [top].
+ maxY := rBottom > self bottom ifTrue: [useRcvr := false. rBottom] ifFalse: [self bottom].
+
+ useRcvr ifTrue: [^ self].
+ ^ Rectangle left:minX top:minY right:maxX bottom:maxY.
+
+ "
+ (Rectangle origin:10@10 corner:100@100)
+ quickMerge:(Rectangle origin:20@20 corner:110@110)
+
+ (Rectangle origin:10@10 corner:100@100)
+ quickMerge:(Rectangle origin:20@20 corner:100@100)
+ "
+
+!
+
rounded
"return a copy of the receiver with rounded coordinates"
@@ -1513,5 +1551,5 @@
!Rectangle class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.58 1998-05-27 09:22:00 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.59 1999-10-06 20:22:28 cg Exp $'
! !