--- a/Rectangle.st Fri Jun 29 11:42:52 2018 +0200
+++ b/Rectangle.st Fri Jun 29 17:15:48 2018 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -392,32 +394,38 @@
"return the corner"
%{ /* NOCONTEXT */
- if (self == @global(Rectangle)) {
- OBJ _tleft = __INST(left);
- OBJ _ttop = __INST(top);
- OBJ _twidth = __INST(width);
- OBJ _theight = __INST(height);
+ if (__qClass(self) == @global(Rectangle)) {
+ OBJ _tleft = __INST(left);
+ OBJ _ttop = __INST(top);
+ OBJ _twidth = __INST(width);
+ OBJ _theight = __INST(height);
- if (__bothSmallInteger(_tleft, _ttop)
- && __bothSmallInteger(_twidth, _theight)) {
- if (__CanDoQuickNew(sizeof(struct __Point))) { /* OBJECT ALLOCATION */
- OBJ newPoint;
- int spc;
- int cX = __intVal(_tleft) + __intVal(_twidth);
- int cY = __intVal(_ttop) + __intVal(_theight);
+ if (__bothSmallInteger(_tleft, _ttop)
+ && __bothSmallInteger(_twidth, _theight)) {
+ if (__CanDoQuickNew(sizeof(struct __Point))) { /* OBJECT ALLOCATION */
+ OBJ newPoint;
+ int spc;
+ int cX = __intVal(_tleft) + __intVal(_twidth);
+ int cY = __intVal(_ttop) + __intVal(_theight);
- if (__ISVALIDINTEGER(cX) && __ISVALIDINTEGER(cY)) {
- __qCheckedNew(newPoint, sizeof(struct __Point));
- __InstPtr(newPoint)->o_class = self; __qSTORE(newPoint, self);
- __PointInstPtr(newPoint)->p_x = __MKSMALLINT(cX);
- __PointInstPtr(newPoint)->p_y = __MKSMALLINT(cY);
- RETURN ( newPoint );
- }
- }
- }
+ if (__ISVALIDINTEGER(cX) && __ISVALIDINTEGER(cY)) {
+ __qCheckedNew(newPoint, sizeof(struct __Point));
+ __InstPtr(newPoint)->o_class = @global(Point); __qSTORE(newPoint, @global(Point));
+ __PointInstPtr(newPoint)->p_x = __MKSMALLINT(cX);
+ __PointInstPtr(newPoint)->p_y = __MKSMALLINT(cY);
+ RETURN ( newPoint );
+ }
+ }
+ }
}
%}.
^ (left + width) @ (top + height)
+
+ "
+ (self origin:0@0 corner:100@100) corner
+ (self origin:0@0 corner:100@100) origin
+ (self origin:5@5 corner:100@100) extent
+ "
!
corner:aPoint
@@ -433,23 +441,23 @@
%{ /* NOCONTEXT */
if (__CanDoQuickNew(sizeof(struct __Point))) { /* OBJECT ALLOCATION */
- if (self == @global(Rectangle)) {
- OBJ newPoint;
- int spc;
- OBJ newX = __INST(width);
- OBJ newY = __INST(height);
+ if (__qClass(self) == @global(Rectangle)) {
+ OBJ newPoint;
+ int spc;
+ OBJ newX = __INST(width);
+ OBJ newY = __INST(height);
- __qCheckedNew(newPoint, sizeof(struct __Point));
- __InstPtr(newPoint)->o_class = self; __qSTORE(newPoint, self);
- __PointInstPtr(newPoint)->p_x = newX;
- __PointInstPtr(newPoint)->p_y = newY;
- if (! __bothSmallInteger(newX, newY)) {
- spc = __qSpace(newPoint);
- __STORE_SPC(newPoint, newX, spc);
- __STORE_SPC(newPoint, newY, spc);
- }
- RETURN ( newPoint );
- }
+ __qCheckedNew(newPoint, sizeof(struct __Point));
+ __InstPtr(newPoint)->o_class = @global(Point); __qSTORE(newPoint, @global(Point));
+ __PointInstPtr(newPoint)->p_x = newX;
+ __PointInstPtr(newPoint)->p_y = newY;
+ if (! __bothSmallInteger(newX, newY)) {
+ spc = __qSpace(newPoint);
+ __STORE_SPC(newPoint, newX, spc);
+ __STORE_SPC(newPoint, newY, spc);
+ }
+ RETURN ( newPoint );
+ }
}
%}.
^ Point x:width y:height
@@ -557,23 +565,23 @@
* claus: I am no longer certain, if this primitive is worth the effort
*/
if (__CanDoQuickNew(sizeof(struct __Point))) { /* OBJECT ALLOCATION */
- if (self == @global(Rectangle)) {
- OBJ newPoint;
- int spc;
- OBJ newX = __INST(left);
- OBJ newY = __INST(top);
+ if (__qClass(self) == @global(Rectangle)) {
+ OBJ newPoint;
+ int spc;
+ OBJ newX = __INST(left);
+ OBJ newY = __INST(top);
- __qCheckedNew(newPoint, sizeof(struct __Point));
- __InstPtr(newPoint)->o_class = self; __qSTORE(newPoint, self);
- __PointInstPtr(newPoint)->p_x = newX;
- __PointInstPtr(newPoint)->p_y = newY;
- if (! __bothSmallInteger(newX, newY)) {
- spc = __qSpace(newPoint);
- __STORE_SPC(newPoint, newX, spc);
- __STORE_SPC(newPoint, newY, spc);
- }
- RETURN ( newPoint );
- }
+ __qCheckedNew(newPoint, sizeof(struct __Point));
+ __InstPtr(newPoint)->o_class = @global(Point); __qSTORE(newPoint, @global(Point));
+ __PointInstPtr(newPoint)->p_x = newX;
+ __PointInstPtr(newPoint)->p_y = newY;
+ if (! __bothSmallInteger(newX, newY)) {
+ spc = __qSpace(newPoint);
+ __STORE_SPC(newPoint, newX, spc);
+ __STORE_SPC(newPoint, newY, spc);
+ }
+ RETURN ( newPoint );
+ }
}
%}.
^ Point x:left y:top
@@ -707,12 +715,19 @@
The bottom right remains unchanged.
warning: destructive"
- |newTop|
+ |newTop newLeft|
newTop := aPoint y.
height := height + (top - newTop).
top := newTop.
- width := aPoint x - left
+ newLeft := aPoint x.
+ width := width + (left - newLeft).
+ left := newLeft.
+
+ "
+ ((self origin:0@0 corner:100@100) topLeft:(10@20))
+ corner
+ "
!
topRight
@@ -732,6 +747,11 @@
height := height + (top - newTop).
top := newTop.
width := aPoint x - left
+
+ "
+ ((self origin:0@0 corner:100@100) topRight:(10@20))
+ corner
+ "
!
vertices
@@ -819,15 +839,12 @@
are taken from corresponding edges of the receiver.
You have to make certain that those are in 0..1."
- |l|
-
- l := LayoutFrame new.
- l
+ ^ LayoutFrame new
leftFraction:(self left);
rightFraction:(self right);
topFraction:(self top);
- bottomFraction:(self bottom).
- ^ l
+ bottomFraction:(self bottom);
+ yourself.
"
(0.5@0.5 corner:0.75@0.75) asFractionalLayout
@@ -887,15 +904,12 @@
are taken from corresponding edges of the receiver.
You have to make certain that those are in 0..1."
- |newLayout|
-
- newLayout := LayoutFrame new.
- newLayout
- leftOffset:(self left);
- rightFraction:0 offset:(self right);
- topOffset:(self top);
- bottomFraction:0 offset:(self bottom).
- ^ newLayout
+ ^ LayoutFrame new
+ leftOffset:(self left);
+ rightFraction:0 offset:(self right);
+ topOffset:(self top);
+ bottomFraction:0 offset:(self bottom);
+ yourself.
"
(0.5@0.5 corner:0.75@0.75) asFractionalLayout
@@ -906,7 +920,6 @@
(10@10 corner:20@20) asOffsetLayout
(10@10 corner:20@20) asLayout
"
-
!
asPointArray
@@ -939,6 +952,10 @@
"Modified: 8.5.1996 / 20:14:44 / cg"
!
+asRectangle
+ ^ self
+!
+
fromLiteralArrayEncoding:encoding
"read my values from an encoding.
The encoding is supposed to be of the form: (Rectangle orgX orgY cornX cornY)"
@@ -1134,6 +1151,12 @@
!Rectangle methodsFor:'displaying'!
+ascentOn:aGC
+ "displayOn: does draw above baseline"
+
+ ^ aGC fontAscent
+!
+
displayFilledOn:aGC
"display a filled rectangle as represented by the receiver in
the graphicsContext, aGC"
@@ -1494,7 +1517,7 @@
(aPoint isMemberOf:SmallInteger) ifTrue:[
"/ this is an stc optimization (isMemberOf:SmallInteger is a hint to inline addition!!)
- ^ Rectangle
+ ^ self class
left:(left - aPoint)
top:(top - aPoint)
width:width
@@ -1704,10 +1727,9 @@
encompass:aPoint
"return a Rectangle that contains both the receiver and aPoint."
- ^ Rectangle
- origin: (self origin min: aPoint)
- corner: (self corner max: aPoint)
-
+ ^ self class
+ origin: (self origin min: aPoint)
+ corner: (self corner max: aPoint)
!
expandedBy:delta
@@ -1750,7 +1772,7 @@
]
].
- ^ Rectangle
+ ^ self class
left:(left + deltaLeft) top:(top + deltaTop)
width:(width - deltaWidth) height:(height - deltaHeight)
@@ -1770,9 +1792,9 @@
"return a new rectangle which is inset by originDelta
and cornerDelta; both may be instances of Point or Number"
- ^ Rectangle
- origin:(left @ top) + originDelta asPoint
- corner:(self corner - cornerDelta asPoint)
+ ^ self class
+ origin:(left @ top) + originDelta asPoint
+ corner:(self corner - cornerDelta asPoint)
"
|r|
r := Rectangle origin:10@10 corner:100@100.
@@ -1788,7 +1810,7 @@
and the argument, aRectangle (i.e. the area covered by both).
the rectangles must intersect for a valid return"
- ^ Rectangle
+ ^ self class
left:(left max:(aRectangle left))
right:((left + width) min:(aRectangle right))
top:(top max:(aRectangle top))
@@ -1809,7 +1831,7 @@
"return a new rectangle covering both the receiver
and the argument, aRectangle"
- ^ Rectangle
+ ^ self class
left:(left min:(aRectangle left))
right:((left + width) max:(aRectangle right))
top:(top min:(aRectangle top))
@@ -1856,27 +1878,27 @@
rBottom > maxY ifTrue: [useRcvr := false. maxY := rBottom].
useRcvr ifTrue: [
- ^ self
+ ^ self
].
minX = rLeft ifTrue:[
- maxX = rRight ifTrue:[
- minY = rTop ifTrue:[
- maxY = rBottom ifTrue:[
- ^ aRectangle
- ].
- ].
- ].
+ maxX = rRight ifTrue:[
+ minY = rTop ifTrue:[
+ maxY = rBottom ifTrue:[
+ ^ aRectangle
+ ].
+ ].
+ ].
].
- ^ Rectangle left:minX top:minY right:maxX bottom:maxY.
+ ^ self class left:minX top:minY right:maxX bottom:maxY.
"
(Rectangle origin:10@10 corner:100@100)
- quickMerge:(Rectangle origin:20@20 corner:110@110)
+ quickMerge:(Rectangle origin:20@20 corner:110@110)
(Rectangle origin:10@10 corner:100@100)
- quickMerge:(Rectangle origin:20@20 corner:100@100)
+ quickMerge:(Rectangle origin:20@20 corner:100@100)
"
!
@@ -1888,7 +1910,7 @@
(scale isMemberOf:SmallInteger) ifTrue:[
"/ this is an stc optimization (a hint to inline)
- ^ Rectangle
+ ^ self class
left:(left * scale) top:(top * scale)
width:(width * scale) height:(height * scale)
].
@@ -1896,7 +1918,7 @@
scalePoint := scale asPoint.
sx := scalePoint x.
sy := scalePoint y.
- ^ Rectangle
+ ^ self class
left:(left * sx) top:(top * sy)
width:(width * sx) height:(height * sy)
"
@@ -1959,7 +1981,7 @@
].
].
- ^ Rectangle left:x top:y width:w height:h.
+ ^ self class left:x top:y width:w height:h.
"
(Rectangle origin:10@10 corner:50@50) scaledBy:2 translatedBy:10
@@ -1976,13 +1998,13 @@
(amount isMemberOf:SmallInteger) ifTrue:[
"/ this is an stc optimization (a hint to inline)
- ^ Rectangle
+ ^ self class
left:(left + amount) top:(top + amount)
width:width height:height
].
amountPoint := amount asPoint.
- ^ Rectangle
+ ^ self class
left:(left + amountPoint x) top:(top + amountPoint y)
width:width height:height
"
@@ -2024,8 +2046,8 @@
"return a new rectangle which is translated (i.e. moved)
such that the point offset in mySelf is placed on someCoordinate."
- ^ Rectangle origin:(someCoordinate - offset + self origin)
- extent:(self extent)
+ ^ self class origin:(someCoordinate - offset + self origin)
+ extent:(self extent)
"
|r|
@@ -2044,12 +2066,12 @@
and:[top isInteger
and:[width isInteger
and:[height isInteger]]])
- ifTrue: [^ self].
+ ifTrue: [^ self].
- ^ Rectangle left:(left rounded)
- top:(top rounded)
- width:(width rounded)
- height:(height rounded)
+ ^ self class left:(left rounded)
+ top:(top rounded)
+ width:(width rounded)
+ height:(height rounded)
!
truncated
@@ -2060,13 +2082,13 @@
and:[top isInteger
and:[width isInteger
and:[height isInteger]]])
- ifTrue: [^ self].
+ ifTrue: [^ self].
- ^ Rectangle
- left:left truncated
- top:top truncated
- width:width truncated
- height:height truncated.
+ ^ self class
+ left:left truncated
+ top:top truncated
+ width:width truncated
+ height:height truncated.
! !
!Rectangle class methodsFor:'documentation'!