--- a/Rectangle.st Wed Jun 03 16:04:55 2009 +0200
+++ b/Rectangle.st Sat Jun 06 12:10:04 2009 +0200
@@ -9,7 +9,6 @@
other person. No title to or ownership of the software is
hereby transferred.
"
-
"{ Package: 'stx:libbasic' }"
Geometric subclass:#Rectangle
@@ -1104,15 +1103,6 @@
"Modified: 8.5.1996 / 14:06:38 / cg"
!
-canBeFilled
- "return true, if the receiver can be drawn as a filled geometric.
- Always true here."
-
- ^ true
-
- "Created: 8.5.1996 / 08:16:47 / cg"
-!
-
computeBounds
"return the smallest enclosing rectangle"
@@ -1122,6 +1112,126 @@
"Created: 12.2.1997 / 11:44:45 / cg"
!
+contains:aRectangle
+ "return true, if the argument, aRectangle is equal to or
+ is contained fully within the receiver"
+
+%{ /* NOCONTEXT */
+ /*
+ * claus: this may be often called by objectView
+ * the primitive code below (although lookung ugly)
+ * speeds that up by almost a factor of 2 ...
+ */
+ OBJ slf = self;
+ OBJ rct = aRectangle;
+
+ if (__isNonNilObject(rct)
+ && __qClass(rct) == Rectangle) {
+ OBJ r_l, r_w, r_t, r_h, l, w, t, h;
+ INT r_ir, r_il, r_ib, r_it;
+ INT il, it, ir, ib, iw, ih;
+
+ r_l = __OINST(rct, left);
+ l = __OINST(slf, left);
+ if (__bothSmallInteger(r_l, l)) {
+#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
+ il = (INT)(l);
+ r_il = (INT)(r_l);
+#else
+ il = __intVal(l);
+ r_il = __intVal(r_l);
+#endif
+ if (il > r_il) { RETURN (false); } /* left > aRectangle left */
+
+ r_t = __OINST(rct, top);
+ t = __OINST(slf, top);
+ if (__bothSmallInteger(r_t, t)) {
+#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
+ it = (INT)(t);
+ r_it = (INT)(r_t);
+#else
+ it = __intVal(t);
+ r_it = __intVal(r_t);
+#endif
+ if (it > r_it) { RETURN (false); } /* top > aRectangle top */
+
+ r_w = __OINST(rct, width);
+ w = __OINST(slf, width);
+ if (__bothSmallInteger(r_w, w)) {
+#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
+ ir = il + (INT)(w);
+ r_ir = r_il + (INT)(r_w);
+#else
+ ir = il + __intVal(w);
+ r_ir = r_il + __intVal(r_w);
+#endif
+ if (ir < r_ir) { RETURN (false); } /* (left + width) < aRectangle right */
+
+ r_h = __OINST(rct, height);
+ h = __OINST(slf, height);
+ if (__bothSmallInteger(r_h, h)) {
+#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
+ ib = it + (INT)(h);
+ r_ib = r_it + (INT)(r_h);
+#else
+ ib = it + __intVal(h);
+ r_ib = r_it + __intVal(r_h);
+#endif
+ if (ib < r_ib) { RETURN (false); } /* (top + height) < aRectangle bottom */
+ RETURN (true);
+ }
+ }
+ }
+ }
+ }
+%}.
+ (left <= aRectangle left) ifTrue:[
+ ((left + width) >= aRectangle right) ifTrue:[
+ (top <= aRectangle top) ifTrue:[
+ ((top + height) >= aRectangle bottom) ifTrue:[
+ ^ true
+ ]
+ ]
+ ]
+ ].
+ ^ false
+
+ "
+ (0@0 corner:100@100) contains:(10@10 corner:90@90)
+ (0@0 corner:100@100) contains:(10@10 corner:100@100)
+ (0@0 corner:100@100) contains:(10@10 corner:110@100)
+ (0@0 corner:100@100) contains:(10@10 corner:100@110)
+ (10@10 corner:100@100) contains:(0@10 corner:100@100)
+ "
+!
+
+containsPoint:aPoint
+ "return true, if the argument, aPoint is contained in the receiver"
+
+ |px py|
+
+ px := aPoint x.
+ (px < left) ifTrue:[^ false].
+ (px > (left + width)) ifTrue:[^ false].
+ py := aPoint y.
+ (py < top) ifTrue:[^ false].
+ (py > (top + height)) ifTrue:[^ false].
+ ^ true
+!
+
+containsPointX:x y:y
+ "return true, if the point defined by x@y is contained in the receiver.
+ This is the same as containsPoint:, but can be used if the coordinates
+ are already available as separate numbers to avoid useless creation of a
+ temporary point."
+
+ (x < left) ifTrue:[^ false].
+ (x > (left + width)) ifTrue:[^ false].
+ (y < top) ifTrue:[^ false].
+ (y > (top + height)) ifTrue:[^ false].
+ ^ true
+!
+
corners
"Return an array of corner points"
@@ -1147,10 +1257,116 @@
"
!
-isRectangle
- "return true, if the receiver is some kind of rectangle"
+intersects:aRectangle
+ "return true, if the intersection between the argument, aRectangle
+ and the receiver is not empty"
+
+ |b r|
+
+%{ /* NOCONTEXT */
+ /*
+ * claus: this is one of the mostly called methods in
+ * the objectView - the primitive code below (although lookung ugly)
+ * speeds up drawing by almost a factor of 2 ...
+ */
+ OBJ slf = self;
+ OBJ rct = aRectangle;
+
+ if (__isNonNilObject(rct)
+ && __qClass(rct) == Rectangle) {
+ OBJ r_l, r_w, r_t, r_h, l, w, t, h;
+ INT r_ir, r_il, r_ib, r_it;
+ INT il, it, ir, ib, iw, ih;
+
+ r_l = __OINST(rct, left);
+ r_w = __OINST(rct, width);
+
+ if (__bothSmallInteger(r_l, r_w)) {
+ r_t = __OINST(rct, top);
+ r_h = __OINST(rct, height);
+
+ l = __OINST(slf, left);
+ w = __OINST(slf, width);
+
+ if (__bothSmallInteger(l, w)) {
+ t = __OINST(slf, top);
+ h = __OINST(slf, height);
+
+#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
+ r_il = (INT)(r_l);
+ r_ir = r_il + (INT)(r_w) - 1;
+ il = (INT)(l);
+ if (r_ir < il) { RETURN (false); }
+ ir = il + (INT)(w) - 1;
+ if (r_il > ir) { RETURN (false); }
+#else /* tag in hi-bit */
+ r_il = __intVal(r_l);
+ r_ir = r_il + __intVal(r_w); /* aRectangle right */
+ il = __intVal(l);
+ if (r_ir < il) { RETURN (false); } /* (aRectangle right) < left */
+
+ ir = il + __intVal(w);
+ if (r_il > ir) { RETURN (false); } /* (aRectangle left) > r */
+#endif
+ if (__bothSmallInteger(r_t, r_h)) {
+ if (__bothSmallInteger(t, h)) {
+#ifndef POSITIVE_ADDRESSES
+ r_it = (INT)(r_t);
+ r_ib = r_it + (INT)(r_h) - 1; /* aRectangle bottom */
+ it = (INT)(t);
+ if (r_ib < it) { RETURN (false); } /* (aRectangle bottom) < top */
+
+ ib = it + (INT)(h) - 1;
+ if (r_it > ib) { RETURN (false); } /* (aRectangle top) > b */
+#else
+ r_it = __intVal(r_t);
+ r_ib = r_it + __intVal(r_h); /* aRectangle bottom */
+ it = __intVal(t);
+ if (r_ib < it) { RETURN (false); } /* (aRectangle bottom) < top */
+
+ ib = it + __intVal(h);
+ if (r_it > ib) { RETURN (false); } /* (aRectangle top) > b */
+#endif
+ RETURN (true);
+ }
+ }
+ }
+ }
+ }
+%}.
+ (aRectangle right) < left ifTrue:[^ false].
+ (aRectangle bottom) < top ifTrue:[^ false].
+ r := left + width.
+ (aRectangle left) > r ifTrue:[^ false].
+ b := top + height.
+ (aRectangle top) > b ifTrue:[^ false].
^ true
+!
+
+isContainedIn:aRectangle
+ "return true, if the receiver is fully contained within
+ the argument, aRectangle"
+
+ (aRectangle left <= left) ifTrue:[
+ (aRectangle right >= (left + width)) ifTrue:[
+ (aRectangle top <= top) ifTrue:[
+ (aRectangle bottom >= (top + height)) ifTrue:[
+ ^ true
+ ]
+ ]
+ ]
+ ].
+ ^ false
+
+ "
+ |r|
+
+ r := Rectangle origin:10@10 corner:100@100.
+ r isContainedIn: (Rectangle origin:10@10 corner:100@100).
+ r isContainedIn: (Rectangle origin:11@10 corner:100@100).
+ r isContainedIn: (Rectangle origin:9@10 corner:100@100).
+ "
! !
!Rectangle methodsFor:'rectangle operations'!
@@ -1530,236 +1746,19 @@
!Rectangle methodsFor:'testing'!
-contains:aRectangle
- "return true, if the argument, aRectangle is equal to or
- is contained fully within the receiver"
-
-%{ /* NOCONTEXT */
- /*
- * claus: this may be often called by objectView
- * the primitive code below (although lookung ugly)
- * speeds that up by almost a factor of 2 ...
- */
- OBJ slf = self;
- OBJ rct = aRectangle;
-
- if (__isNonNilObject(rct)
- && __qClass(rct) == Rectangle) {
- OBJ r_l, r_w, r_t, r_h, l, w, t, h;
- INT r_ir, r_il, r_ib, r_it;
- INT il, it, ir, ib, iw, ih;
-
- r_l = __OINST(rct, left);
- l = __OINST(slf, left);
- if (__bothSmallInteger(r_l, l)) {
-#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
- il = (INT)(l);
- r_il = (INT)(r_l);
-#else
- il = __intVal(l);
- r_il = __intVal(r_l);
-#endif
- if (il > r_il) { RETURN (false); } /* left > aRectangle left */
-
- r_t = __OINST(rct, top);
- t = __OINST(slf, top);
- if (__bothSmallInteger(r_t, t)) {
-#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
- it = (INT)(t);
- r_it = (INT)(r_t);
-#else
- it = __intVal(t);
- r_it = __intVal(r_t);
-#endif
- if (it > r_it) { RETURN (false); } /* top > aRectangle top */
+canBeFilled
+ "return true, if the receiver can be drawn as a filled geometric.
+ Always true here."
- r_w = __OINST(rct, width);
- w = __OINST(slf, width);
- if (__bothSmallInteger(r_w, w)) {
-#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
- ir = il + (INT)(w);
- r_ir = r_il + (INT)(r_w);
-#else
- ir = il + __intVal(w);
- r_ir = r_il + __intVal(r_w);
-#endif
- if (ir < r_ir) { RETURN (false); } /* (left + width) < aRectangle right */
+ ^ true
- r_h = __OINST(rct, height);
- h = __OINST(slf, height);
- if (__bothSmallInteger(r_h, h)) {
-#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
- ib = it + (INT)(h);
- r_ib = r_it + (INT)(r_h);
-#else
- ib = it + __intVal(h);
- r_ib = r_it + __intVal(r_h);
-#endif
- if (ib < r_ib) { RETURN (false); } /* (top + height) < aRectangle bottom */
- RETURN (true);
- }
- }
- }
- }
- }
-%}.
- (left <= aRectangle left) ifTrue:[
- ((left + width) >= aRectangle right) ifTrue:[
- (top <= aRectangle top) ifTrue:[
- ((top + height) >= aRectangle bottom) ifTrue:[
- ^ true
- ]
- ]
- ]
- ].
- ^ false
-
- "
- (0@0 corner:100@100) contains:(10@10 corner:90@90)
- (0@0 corner:100@100) contains:(10@10 corner:100@100)
- (0@0 corner:100@100) contains:(10@10 corner:110@100)
- (0@0 corner:100@100) contains:(10@10 corner:100@110)
- (10@10 corner:100@100) contains:(0@10 corner:100@100)
- "
-!
-
-containsPoint:aPoint
- "return true, if the argument, aPoint is contained in the receiver"
-
- |px py|
-
- px := aPoint x.
- (px < left) ifTrue:[^ false].
- (px > (left + width)) ifTrue:[^ false].
- py := aPoint y.
- (py < top) ifTrue:[^ false].
- (py > (top + height)) ifTrue:[^ false].
- ^ true
+ "Created: 8.5.1996 / 08:16:47 / cg"
!
-containsPointX:x y:y
- "return true, if the point defined by x@y is contained in the receiver.
- This is the same as containsPoint:, but can be used if the coordinates
- are already available as separate numbers to avoid useless creation of a
- temporary point."
-
- (x < left) ifTrue:[^ false].
- (x > (left + width)) ifTrue:[^ false].
- (y < top) ifTrue:[^ false].
- (y > (top + height)) ifTrue:[^ false].
- ^ true
-!
-
-intersects:aRectangle
- "return true, if the intersection between the argument, aRectangle
- and the receiver is not empty"
-
- |b r|
-
-%{ /* NOCONTEXT */
- /*
- * claus: this is one of the mostly called methods in
- * the objectView - the primitive code below (although lookung ugly)
- * speeds up drawing by almost a factor of 2 ...
- */
- OBJ slf = self;
- OBJ rct = aRectangle;
-
- if (__isNonNilObject(rct)
- && __qClass(rct) == Rectangle) {
- OBJ r_l, r_w, r_t, r_h, l, w, t, h;
- INT r_ir, r_il, r_ib, r_it;
- INT il, it, ir, ib, iw, ih;
-
- r_l = __OINST(rct, left);
- r_w = __OINST(rct, width);
-
- if (__bothSmallInteger(r_l, r_w)) {
- r_t = __OINST(rct, top);
- r_h = __OINST(rct, height);
-
- l = __OINST(slf, left);
- w = __OINST(slf, width);
-
- if (__bothSmallInteger(l, w)) {
- t = __OINST(slf, top);
- h = __OINST(slf, height);
-
-#ifndef POSITIVE_ADDRESSES /* tag in low-bit */
- r_il = (INT)(r_l);
- r_ir = r_il + (INT)(r_w) - 1;
- il = (INT)(l);
- if (r_ir < il) { RETURN (false); }
- ir = il + (INT)(w) - 1;
- if (r_il > ir) { RETURN (false); }
-#else /* tag in hi-bit */
- r_il = __intVal(r_l);
- r_ir = r_il + __intVal(r_w); /* aRectangle right */
- il = __intVal(l);
- if (r_ir < il) { RETURN (false); } /* (aRectangle right) < left */
+isRectangle
+ "return true, if the receiver is some kind of rectangle"
- ir = il + __intVal(w);
- if (r_il > ir) { RETURN (false); } /* (aRectangle left) > r */
-#endif
-
- if (__bothSmallInteger(r_t, r_h)) {
- if (__bothSmallInteger(t, h)) {
-#ifndef POSITIVE_ADDRESSES
- r_it = (INT)(r_t);
- r_ib = r_it + (INT)(r_h) - 1; /* aRectangle bottom */
- it = (INT)(t);
- if (r_ib < it) { RETURN (false); } /* (aRectangle bottom) < top */
-
- ib = it + (INT)(h) - 1;
- if (r_it > ib) { RETURN (false); } /* (aRectangle top) > b */
-#else
- r_it = __intVal(r_t);
- r_ib = r_it + __intVal(r_h); /* aRectangle bottom */
- it = __intVal(t);
- if (r_ib < it) { RETURN (false); } /* (aRectangle bottom) < top */
-
- ib = it + __intVal(h);
- if (r_it > ib) { RETURN (false); } /* (aRectangle top) > b */
-#endif
- RETURN (true);
- }
- }
- }
- }
- }
-%}.
- (aRectangle right) < left ifTrue:[^ false].
- (aRectangle bottom) < top ifTrue:[^ false].
- r := left + width.
- (aRectangle left) > r ifTrue:[^ false].
- b := top + height.
- (aRectangle top) > b ifTrue:[^ false].
^ true
-!
-
-isContainedIn:aRectangle
- "return true, if the receiver is fully contained within
- the argument, aRectangle"
-
- (aRectangle left <= left) ifTrue:[
- (aRectangle right >= (left + width)) ifTrue:[
- (aRectangle top <= top) ifTrue:[
- (aRectangle bottom >= (top + height)) ifTrue:[
- ^ true
- ]
- ]
- ]
- ].
- ^ false
-
- "
- |r|
-
- r := Rectangle origin:10@10 corner:100@100.
- r isContainedIn: (Rectangle origin:10@10 corner:100@100).
- r isContainedIn: (Rectangle origin:11@10 corner:100@100).
- r isContainedIn: (Rectangle origin:9@10 corner:100@100).
- "
! !
!Rectangle methodsFor:'truncation & rounding'!
@@ -1800,5 +1799,5 @@
!Rectangle class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.82 2005-06-13 18:35:27 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.83 2009-06-06 10:10:04 cg Exp $'
! !