Rectangle.st
author Claus Gittinger <cg@exept.de>
Sat, 27 Apr 1996 19:51:06 +0200
changeset 1314 18fabbc0e0a6
parent 1290 15ba3221b89b
child 1349 275388fd5271
permissions -rw-r--r--
examples
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
356
claus
parents: 329
diff changeset
    13
Geometric subclass:#Rectangle
1149
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    14
	instanceVariableNames:'left top width height'
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    15
	classVariableNames:''
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	poolDictionaries:''
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	category:'Graphics-Geometry'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    20
!Rectangle class methodsFor:'documentation'!
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    36
documentation
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    37
"
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    38
    Rectangles represent a rectangular area in 2D space.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    39
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    40
    notice, my implementation does not use origin/corner as instance objects
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    41
    but left/top/width/height to save space and allocations. This means, that my
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    42
    Rectangles cannot be used to represent Rectangles in a higher than 2D
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    43
    space. (i.e. only valid if origin/corner are 2D Points)
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    44
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    45
    (aside from that, you will not see any difference from the outside)
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    46
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    47
    Instance variables:
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    48
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    49
        left           <Number>        the left coordinate (i.e origin x)
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    50
        top            <Number>        the top coordinate (i.e origin y)
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    51
        width          <Number>        the width of the rectangle
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    52
        height         <Number>        the height of the rectangle
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    53
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    54
    I am not certain, if implementing Rectangle different was a good idea - 
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    55
    subclasses may expect things to be different ...
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    56
    Therefore, this may change.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    57
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    58
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    59
        Claus Gittinger
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    60
1314
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    61
    [see also:]
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    62
        Point Polygon
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    63
        LayoutOrigin LayoutFrame AlignmentOrigin Layout 
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    64
        View
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    65
"
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    66
! !
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    67
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
!Rectangle class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    70
fromUser
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
    "let user specify a rectangle on the screen, return it"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    73
    ^ Screen current rectangleFromUser
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    74
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    75
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    76
     Rectangle fromUser     
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    77
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    78
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    80
left:left right:right top:top bottom:bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
    "create and return a new Rectangle giving left, top, right and bottom coordinates"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    82
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    83
    ^ (self basicNew) left:left right:right top:top bottom:bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    85
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    86
left:left top:top right:right bottom:bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
    "create and return a new Rectangle giving left, top, right and bottom coordinates"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
    ^ (self basicNew) left:left top:top right:right bottom:bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    90
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    91
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
left:left top:top width:w height:h
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
    "create and return a new Rectangle giving left and top coordinates
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    94
     and width, height"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
%{  /* NOCONTEXT */
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    97
    REGISTER OBJ newRect;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    98
    OBJ t;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    99
    int spc;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   101
    if (__CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) {
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
	if (self == Rectangle) {
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   103
	    /*
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   104
	     * short cut - rectangles are created so often ...
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   105
	     */
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   106
	    __qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ));
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   108
	    __InstPtr(newRect)->o_class = Rectangle;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   109
	    __InstPtr(newRect)->i_instvars[0] = left;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   110
	    __InstPtr(newRect)->i_instvars[1] = top;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   111
	    __InstPtr(newRect)->i_instvars[2] = w;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   112
	    __InstPtr(newRect)->i_instvars[3] = h;
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
	    if (! (__bothSmallInteger(left, top) && 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
		   __bothSmallInteger(w, h))) {
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
		spc = __qSpace(newRect);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
		__STORE_SPC(newRect, left, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
		__STORE_SPC(newRect, top, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
		__STORE_SPC(newRect, w, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
		__STORE_SPC(newRect, h, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   121
	    }
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   122
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
	    RETURN ( newRect );
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
	}
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   125
    }
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   126
%}
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   127
.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   128
    ^ (self basicNew) left:left top:top width:w height:h
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   130
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
origin:origin corner:corner
a27a279701f8 Initial revision
claus
parents:
diff changeset
   132
    "create and return a new Rectangle giving top-left and bottom-right points"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
    ^ (self basicNew) origin:origin corner:corner
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
a27a279701f8 Initial revision
claus
parents:
diff changeset
   137
origin:origin extent:extent
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
    "create and return a new Rectangle giving top-left point and extent point"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
a27a279701f8 Initial revision
claus
parents:
diff changeset
   140
%{  /* NOCONTEXT */
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   141
    REGISTER OBJ newRect;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   142
    OBJ t;
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   143
    int spc;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   145
    if (__CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) {
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   146
        /*
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   147
	 * short cut - rectangles are created so often ...
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   148
	 */
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   149
	if (self == Rectangle) {
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   150
	    if (__isPoint(origin) && __isPoint(extent)) {
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   151
		__qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   152
		__InstPtr(newRect)->o_class = Rectangle;
325
claus
parents: 308
diff changeset
   153
		spc = __qSpace(newRect);
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   154
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   155
		t = __PointInstPtr(origin)->p_x;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   156
		__InstPtr(newRect)->i_instvars[0] = t;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   157
		__STORE_SPC(newRect, t, spc);
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   158
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   159
		t = __PointInstPtr(origin)->p_y;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   160
		__InstPtr(newRect)->i_instvars[1] = t;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   161
		__STORE_SPC(newRect, t, spc);
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   162
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   163
		t = __PointInstPtr(extent)->p_x;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   164
		__InstPtr(newRect)->i_instvars[2] = t;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   165
		__STORE_SPC(newRect, t, spc);
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   166
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   167
		t = __PointInstPtr(extent)->p_y;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   168
		__InstPtr(newRect)->i_instvars[3] = t;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   169
		__STORE_SPC(newRect, t, spc);
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   170
		RETURN ( newRect );
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   171
	    }
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   172
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   173
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   174
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
    ^ (self basicNew) origin:origin extent:extent
a27a279701f8 Initial revision
claus
parents:
diff changeset
   177
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   178
a27a279701f8 Initial revision
claus
parents:
diff changeset
   179
!Rectangle methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
area
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
    "return the area 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
     - for screen Rectangles this is the number of pixels"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   184
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
    ^ width * height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   188
bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   189
    "return the y coordinate of the bottom"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   190
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
    ^ (top + height)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   192
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   193
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   194
bottom:aNumber
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   195
    "set the bottom edge"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   196
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   197
    height := aNumber - top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   198
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   199
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   200
bottomCenter
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   201
    "return the bottom center point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   202
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   203
    ^ (left + (width // 2)) @ (top + height)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   204
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   205
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   206
bottomLeft
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   207
    "return the bottom-left point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   208
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   209
    ^ left @ (top + height)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   210
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   211
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   212
bottomRight
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   213
    "return the bottom-right point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   215
    ^ (left + width) @ (top + height)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   216
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   217
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
center
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
    "return the point in the center of the receiver"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   220
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   221
    ^ (left + (width // 2)) @ (top + (height // 2))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   222
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   223
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   224
corner
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   225
    "return the corner"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   226
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
    ^ (left + width) @ (top + height)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   229
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   230
corner:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   231
    "set the bottom-right corner"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   232
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   233
    width := aPoint x - left.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   234
    height := aPoint y - top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   235
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   237
extent
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   238
    "return the extent"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   239
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   240
    ^ width @ height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   241
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   242
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   243
extent:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   244
    "set the extent from the argument, aPoint with width taken from aPoint x
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   245
     and height taken from aPoint y"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   246
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   247
    width := aPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   248
    height := aPoint y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   249
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   250
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   251
height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   252
    "return the height of the rectangle"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   253
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   254
    ^ height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   255
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   256
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   257
left
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   258
    "return the x-coordinate of the top-left origin"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   259
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   260
    ^ left
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   261
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   262
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   263
left:aNumber
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   264
    "set the left edge"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   265
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   266
    width := width + (left - aNumber).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   267
    left := aNumber
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   268
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   269
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
left:newLeft right:right top:newTop bottom:bottom
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   271
    "set the rectangle given left, top, right and bottom coordinates."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   272
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
    left := newLeft.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
    top := newTop.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
    width := right - left.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
    height := bottom - top
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
a27a279701f8 Initial revision
claus
parents:
diff changeset
   279
left:newLeft top:newTop right:right bottom:bottom
a27a279701f8 Initial revision
claus
parents:
diff changeset
   280
    "set the rectangle given left, top, right and bottom coordinates"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   281
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
    left := newLeft.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   283
    top := newTop.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
    width := right - left.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   285
    height := bottom - top
a27a279701f8 Initial revision
claus
parents:
diff changeset
   286
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   287
a27a279701f8 Initial revision
claus
parents:
diff changeset
   288
left:newLeft top:newTop width:newWidth height:newHeight
a27a279701f8 Initial revision
claus
parents:
diff changeset
   289
    "set the rectangle given left, top coordinates and width, height"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   290
a27a279701f8 Initial revision
claus
parents:
diff changeset
   291
    left := newLeft.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   292
    top := newTop.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   293
    width := newWidth.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   294
    height := newHeight
a27a279701f8 Initial revision
claus
parents:
diff changeset
   295
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   296
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   297
leftCenter
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   298
    "return the left center point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
    ^ left @ (top + (height // 2))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
origin
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
    "return the origin"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
    ^ left @ top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   309
origin:aPoint
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   310
    "set the top-left origin. The corner remains unchanged."
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   311
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   312
    |newTop newLeft|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   313
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   314
    newTop := aPoint y.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   315
    newLeft := aPoint x.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   316
    height := height + (top - newTop).
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   317
    width := width + (left - newLeft).
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   318
    left := newLeft.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   319
    top := newTop
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   320
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   321
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
origin:origin corner:corner
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    "set both origin and corner"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   325
    left := origin x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
    top := origin y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   327
    width := corner x - left.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
    height := corner y - top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   329
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   331
origin:origin extent:extent
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   332
    "set both origin and extent"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   333
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   334
    left := origin x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
    top := origin y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
    width := extent x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
    height := extent y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   338
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   339
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
right
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
    "return the x coordinate of the right"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   342
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   343
    ^ (left + width)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   344
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   345
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   346
right:aNumber
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   347
    "set the right edge"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   348
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   349
    width := aNumber - left
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   350
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   351
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   352
rightCenter
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   353
    "return the right center point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   354
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   355
    ^ (left + width) @ (top + (height // 2))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   356
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   357
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   358
top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   359
    "return the y-coordinate of the top-left"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   360
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   361
    ^ top
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   362
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   363
a27a279701f8 Initial revision
claus
parents:
diff changeset
   364
top:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   365
    "set the top edge"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   366
a27a279701f8 Initial revision
claus
parents:
diff changeset
   367
    height := height + (top - aNumber).
a27a279701f8 Initial revision
claus
parents:
diff changeset
   368
    top := aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   369
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   370
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   371
topCenter
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   372
    "return the top center point"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   373
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   374
    ^ (left + (width // 2)) @ top
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   375
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   376
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   377
topLeft
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   378
    "return the top-left point - the same as origin"
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   379
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   380
    ^ left @ top
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   381
!
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   382
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   383
topLeft:aPoint
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   384
    "Set the top and left edges.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   385
     The bottom right remains unchanged."
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   386
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   387
    |newTop|
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   388
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   389
    newTop := aPoint y.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   390
    height := height + (top - newTop).
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   391
    top := newTop.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   392
    width := aPoint x - left
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   393
!
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   394
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   395
topRight
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   396
    "return the top-right point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   397
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   398
    ^ (left + width) @ top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   399
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   400
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   401
topRight:aPoint
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   402
    "Set the top and right edges. 
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   403
     The bottom left remains unchanged."
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   404
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   405
    |newTop|
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   406
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   407
    newTop := aPoint y.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   408
    height := height + (top - newTop).
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   409
    top := newTop.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   410
    width := aPoint x - left
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   411
!
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   412
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   413
width
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   414
    "return the width of the rectangle"
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   415
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   416
    ^ width
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   417
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   418
a27a279701f8 Initial revision
claus
parents:
diff changeset
   419
!Rectangle methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   420
a27a279701f8 Initial revision
claus
parents:
diff changeset
   421
= aRectangle
a27a279701f8 Initial revision
claus
parents:
diff changeset
   422
    "return true, if the argument aRectangle represents the same
a27a279701f8 Initial revision
claus
parents:
diff changeset
   423
     rectangle as the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   424
a27a279701f8 Initial revision
claus
parents:
diff changeset
   425
%{  /* NOCONTEXT */
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   426
    /*
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   427
     * because rectangles are often compared in the graphics code,
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   428
     * handle the common case quickly
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   429
     */
329
claus
parents: 326
diff changeset
   430
    if (__isNonNilObject(aRectangle) 
claus
parents: 326
diff changeset
   431
     && __qClass(aRectangle) == Rectangle) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   432
	if ((__InstPtr(self)->i_instvars[0] == __InstPtr(aRectangle)->i_instvars[0])
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   433
	 && (__InstPtr(self)->i_instvars[1] == __InstPtr(aRectangle)->i_instvars[1])
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   434
	 && (__InstPtr(self)->i_instvars[2] == __InstPtr(aRectangle)->i_instvars[2])
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   435
	 && (__InstPtr(self)->i_instvars[3] == __InstPtr(aRectangle)->i_instvars[3])) {
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   436
	    RETURN ( true );
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   437
	}
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   438
	if (__bothSmallInteger(__InstPtr(self)->i_instvars[0], __InstPtr(aRectangle)->i_instvars[0])
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   439
	 && __bothSmallInteger(__InstPtr(self)->i_instvars[1], __InstPtr(aRectangle)->i_instvars[1])
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   440
	 && __bothSmallInteger(__InstPtr(self)->i_instvars[2], __InstPtr(aRectangle)->i_instvars[2])
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   441
	 && __bothSmallInteger(__InstPtr(self)->i_instvars[3], __InstPtr(aRectangle)->i_instvars[3])) {
325
claus
parents: 308
diff changeset
   442
	    RETURN ( false );
claus
parents: 308
diff changeset
   443
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   444
    }
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   445
%}.
259
   446
    (aRectangle species ~~ self species) ifTrue:[^ false].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   447
a27a279701f8 Initial revision
claus
parents:
diff changeset
   448
    left = aRectangle left ifFalse:[^ false].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   449
    top = aRectangle top ifFalse:[^ false].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   450
    width = aRectangle width ifFalse:[^ false].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   451
    height = aRectangle height ifFalse:[^ false].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   452
    ^ true
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   453
!
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   454
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   455
hash
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   456
    "return an integer useful for hashing -
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   457
     redefined since = is redefined here"
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   458
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   459
    ^ ((left hash bitShift:16) bitXor:(top hash bitShift:16))
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   460
      + ((width hash) bitXor:(height hash))
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   461
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   462
356
claus
parents: 329
diff changeset
   463
!Rectangle methodsFor:'converting'!
claus
parents: 329
diff changeset
   464
claus
parents: 329
diff changeset
   465
asFractionalLayout
claus
parents: 329
diff changeset
   466
    "return a layoutFrame in which fractions (top, left, bottom, right)
claus
parents: 329
diff changeset
   467
     are taken from corresponding edges of the receiver.
claus
parents: 329
diff changeset
   468
     You have to make certain that those are in 0..1."
claus
parents: 329
diff changeset
   469
claus
parents: 329
diff changeset
   470
    |l|
claus
parents: 329
diff changeset
   471
claus
parents: 329
diff changeset
   472
    l := LayoutFrame new.
claus
parents: 329
diff changeset
   473
    l
claus
parents: 329
diff changeset
   474
	leftFraction:(self left);
claus
parents: 329
diff changeset
   475
	rightFraction:(self right);
claus
parents: 329
diff changeset
   476
	topFraction:(self top);
claus
parents: 329
diff changeset
   477
	bottomFraction:(self bottom).
claus
parents: 329
diff changeset
   478
    ^ l
claus
parents: 329
diff changeset
   479
claus
parents: 329
diff changeset
   480
    "
claus
parents: 329
diff changeset
   481
     (0.5@0.5 corner:0.75@0.75) asFractionalLayout 
claus
parents: 329
diff changeset
   482
     (0.5@0.5 corner:0.75@0.75) asOffsetLayout      
claus
parents: 329
diff changeset
   483
     (0.5@0.5 corner:0.75@0.75) asLayout        
claus
parents: 329
diff changeset
   484
    "
claus
parents: 329
diff changeset
   485
!
claus
parents: 329
diff changeset
   486
claus
parents: 329
diff changeset
   487
asLayout
claus
parents: 329
diff changeset
   488
    "return a layoutFrame in which offsets (top, left, bottom, right)
claus
parents: 329
diff changeset
   489
     are taken from corresponding edges of the receiver.
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   490
     If all values are between 0.0 .. 1.0, a fractionalLayout is created,
356
claus
parents: 329
diff changeset
   491
     otherwise, an offsetLayout"
claus
parents: 329
diff changeset
   492
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   493
    |newLayout left right top bot|
356
claus
parents: 329
diff changeset
   494
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   495
    newLayout := LayoutFrame new.
356
claus
parents: 329
diff changeset
   496
    left := (self left).
claus
parents: 329
diff changeset
   497
    right := (self right).
claus
parents: 329
diff changeset
   498
    top := (self top).
claus
parents: 329
diff changeset
   499
    bot := (self bottom).
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   500
    ((left between:0.0 and:1.0)
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   501
    and:[(right between:0.0 and:1.0)
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   502
    and:[(top between:0.0 and:1.0)
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   503
    and:[(bot between:0.0 and:1.0)]]]) ifTrue:[
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   504
	newLayout
356
claus
parents: 329
diff changeset
   505
	    leftFraction:left;
claus
parents: 329
diff changeset
   506
	    rightFraction:right;
claus
parents: 329
diff changeset
   507
	    topFraction:top;
claus
parents: 329
diff changeset
   508
	    bottomFraction:bot.
claus
parents: 329
diff changeset
   509
    ] ifFalse:[
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   510
	newLayout
356
claus
parents: 329
diff changeset
   511
	    leftOffset:left;
claus
parents: 329
diff changeset
   512
	    rightFraction:0 offset:right;
claus
parents: 329
diff changeset
   513
	    topOffset:top;
claus
parents: 329
diff changeset
   514
	    bottomFraction:0 offset:bot.
claus
parents: 329
diff changeset
   515
    ].
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   516
    ^ newLayout
356
claus
parents: 329
diff changeset
   517
claus
parents: 329
diff changeset
   518
    "
claus
parents: 329
diff changeset
   519
     (0.5@0.5 corner:0.75@0.75) asFractionalLayout  
claus
parents: 329
diff changeset
   520
     (0.5@0.5 corner:0.75@0.75) asOffsetLayout       
claus
parents: 329
diff changeset
   521
     (0.5@0.5 corner:0.75@0.75) asLayout              
claus
parents: 329
diff changeset
   522
     (0@0 corner:1@1) asLayout                      
claus
parents: 329
diff changeset
   523
     (0@0 corner:1@1) asFractionalLayout             
claus
parents: 329
diff changeset
   524
     (0@0 corner:1@1) asOffsetLayout                 
claus
parents: 329
diff changeset
   525
    "
claus
parents: 329
diff changeset
   526
!
claus
parents: 329
diff changeset
   527
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   528
asOffsetLayout
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   529
    "return a layoutFrame in which offsets (top, left, bottom, right)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   530
     are taken from corresponding edges of the receiver.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   531
     You have to make certain that those are in 0..1."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   532
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   533
    |newLayout|
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   534
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   535
    newLayout := LayoutFrame new.
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   536
    newLayout
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   537
	leftOffset:(self left);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   538
	rightFraction:0 offset:(self right);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   539
	topOffset:(self top);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   540
	bottomFraction:0 offset:(self bottom).
1151
7991d983b17d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1149
diff changeset
   541
    ^ newLayout
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   542
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   543
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   544
     (0.5@0.5 corner:0.75@0.75) asFractionalLayout 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   545
     (0.5@0.5 corner:0.75@0.75) asOffsetLayout      
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   546
     (0.5@0.5 corner:0.75@0.75) asLayout        
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   547
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   548
     (10@10 corner:20@20) asFractionalLayout 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   549
     (10@10 corner:20@20) asOffsetLayout     
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   550
     (10@10 corner:20@20) asLayout             
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   551
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   552
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   553
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   554
356
claus
parents: 329
diff changeset
   555
asPointArray
claus
parents: 329
diff changeset
   556
    "return an array containing my corners (clockwise) and
claus
parents: 329
diff changeset
   557
     the origin again as 5th element. Can be used to convert
claus
parents: 329
diff changeset
   558
     a rectangle into a polygon."
claus
parents: 329
diff changeset
   559
claus
parents: 329
diff changeset
   560
    |org|
claus
parents: 329
diff changeset
   561
claus
parents: 329
diff changeset
   562
    ^ Array with:(org := self origin)
claus
parents: 329
diff changeset
   563
	    with:self topRight
claus
parents: 329
diff changeset
   564
	    with:self corner
claus
parents: 329
diff changeset
   565
	    with:self bottomLeft
claus
parents: 329
diff changeset
   566
	    with:org 
claus
parents: 329
diff changeset
   567
claus
parents: 329
diff changeset
   568
    "
claus
parents: 329
diff changeset
   569
     (10@10 corner:100@100) asPointArray 
claus
parents: 329
diff changeset
   570
    "
claus
parents: 329
diff changeset
   571
!
claus
parents: 329
diff changeset
   572
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   573
fromLiteralArrayEncoding:encoding
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   574
    "read my values from an encoding.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   575
     The encoding is supposed to be of the form: (Rectangle orgX orgY cornX cornY)"
356
claus
parents: 329
diff changeset
   576
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   577
    left := encoding at:2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   578
    top := encoding at:3.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   579
    width := (encoding at:4) - left.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   580
    height := (encoding at:5) - top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   581
356
claus
parents: 329
diff changeset
   582
claus
parents: 329
diff changeset
   583
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   584
     Rectangle new fromLiteralArrayEncoding:#(Rectangle 100 200 300 500) 
356
claus
parents: 329
diff changeset
   585
    "
379
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   586
!
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   587
421
claus
parents: 384
diff changeset
   588
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1151
diff changeset
   589
    "encode myself as an array, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1151
diff changeset
   590
     can be reconstructed with #decodeAsLiteralArray.
421
claus
parents: 384
diff changeset
   591
     The encoding is: (Rectangle orgX orgY cornX cornY)"
claus
parents: 384
diff changeset
   592
claus
parents: 384
diff changeset
   593
    ^ Array
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1151
diff changeset
   594
        with:#Rectangle
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1151
diff changeset
   595
        with:left
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1151
diff changeset
   596
        with:top
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1151
diff changeset
   597
        with:width
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1151
diff changeset
   598
        with:height
421
claus
parents: 384
diff changeset
   599
claus
parents: 384
diff changeset
   600
claus
parents: 384
diff changeset
   601
    "
claus
parents: 384
diff changeset
   602
     Rectangle new fromLiteralArrayEncoding:#(Rectangle 100 200 300 500) 
claus
parents: 384
diff changeset
   603
     (100@200 corner:300@500) literalArrayEncoding 
claus
parents: 384
diff changeset
   604
    "
claus
parents: 384
diff changeset
   605
claus
parents: 384
diff changeset
   606
    "Modified: 1.9.1995 / 02:16:54 / claus"
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1151
diff changeset
   607
    "Modified: 22.4.1996 / 13:00:36 / cg"
421
claus
parents: 384
diff changeset
   608
!
claus
parents: 384
diff changeset
   609
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   610
rectangleRelativeTo:aRectangle preferred:prefRect
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   611
    "compute a displayRectangle, treating the receiver like a
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   612
     layoutorigin. This allows point to be used interchangable with
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   613
     LayoutOrigins."
379
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   614
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   615
    ^ (self asLayout) rectangleRelativeTo:aRectangle preferred:prefRect
379
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   616
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   617
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   618
     (10@20 corner:20@30) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   619
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   620
     (0.5@0.5) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) 
379
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   621
    "
356
claus
parents: 329
diff changeset
   622
! !
claus
parents: 329
diff changeset
   623
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   624
!Rectangle methodsFor:'destructive rectangle operations'!
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   625
356
claus
parents: 329
diff changeset
   626
expandBy:delta
claus
parents: 329
diff changeset
   627
    "destructively expanded the receiver in all directions
claus
parents: 329
diff changeset
   628
     by amount, a Point, Rectangle or Number.
claus
parents: 329
diff changeset
   629
     Warning: this is a destructive operation, modifying the receiver
claus
parents: 329
diff changeset
   630
     NOT returning a copy. You have to be certain to be the exclusive
claus
parents: 329
diff changeset
   631
     owner of the receiver to avoid side effects. See also: #expandedBy:"
claus
parents: 329
diff changeset
   632
claus
parents: 329
diff changeset
   633
    |amountPoint deltaLeft deltaTop deltaWidth deltaHeight|
claus
parents: 329
diff changeset
   634
claus
parents: 329
diff changeset
   635
    delta isNumber ifTrue:[
claus
parents: 329
diff changeset
   636
	deltaLeft := deltaTop := delta.
claus
parents: 329
diff changeset
   637
	deltaWidth := deltaHeight := delta * 2.
claus
parents: 329
diff changeset
   638
    ] ifFalse:[
claus
parents: 329
diff changeset
   639
	delta isRectangle ifTrue:[
claus
parents: 329
diff changeset
   640
	    deltaLeft := delta left.
claus
parents: 329
diff changeset
   641
	    deltaTop := delta top.
claus
parents: 329
diff changeset
   642
	    deltaWidth := deltaLeft + delta right.
claus
parents: 329
diff changeset
   643
	    deltaHeight := deltaTop + delta bottom
claus
parents: 329
diff changeset
   644
	] ifFalse:[
claus
parents: 329
diff changeset
   645
	    amountPoint := delta asPoint.
claus
parents: 329
diff changeset
   646
	    deltaLeft := amountPoint x.
claus
parents: 329
diff changeset
   647
	    deltaTop := amountPoint y.
claus
parents: 329
diff changeset
   648
	    deltaWidth := deltaLeft * 2.
claus
parents: 329
diff changeset
   649
	    deltaHeight := deltaTop * 2.
claus
parents: 329
diff changeset
   650
	]
claus
parents: 329
diff changeset
   651
    ].
claus
parents: 329
diff changeset
   652
claus
parents: 329
diff changeset
   653
    left := (left - deltaLeft).
claus
parents: 329
diff changeset
   654
    top := (top - deltaTop).
claus
parents: 329
diff changeset
   655
    width := (width + deltaWidth).
claus
parents: 329
diff changeset
   656
    height := (height + deltaHeight).
claus
parents: 329
diff changeset
   657
claus
parents: 329
diff changeset
   658
    "
claus
parents: 329
diff changeset
   659
     |r|
claus
parents: 329
diff changeset
   660
     r := Rectangle origin:10@10 corner:100@100.
claus
parents: 329
diff changeset
   661
     r expandBy:5.
claus
parents: 329
diff changeset
   662
claus
parents: 329
diff changeset
   663
     r := Rectangle origin:10@10 corner:100@100.
claus
parents: 329
diff changeset
   664
     r expandBy:(5 @ 0).
claus
parents: 329
diff changeset
   665
claus
parents: 329
diff changeset
   666
     r := Rectangle origin:10@10 corner:100@100.
claus
parents: 329
diff changeset
   667
     r expandBy:(10 @ 10).
claus
parents: 329
diff changeset
   668
claus
parents: 329
diff changeset
   669
     r := Rectangle origin:10@10 corner:100@100.
claus
parents: 329
diff changeset
   670
     r expandBy:( 10@10 corner:20@20 )
claus
parents: 329
diff changeset
   671
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   672
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   673
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   674
moveBy:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   675
    "destructively translate the rectangle by some distance.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   676
     sorry for the name inconsistency - but GNU-ST named it that way"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   677
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   678
    left := left + aPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   679
    top := top + aPoint y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   680
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   681
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   682
moveTo:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   683
    "destructively translate the rectangle to have its origin at aPoint."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   684
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   685
    |diff|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   686
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   687
    diff := aPoint - self origin.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   688
    self origin:aPoint corner:self corner + diff
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   689
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   690
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   691
scaleBy:scale
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   692
    "scale the receiver rectangle by scale (a Number or Point).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   693
     This is destructive (modifies the receiver, not a copy) and 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   694
     should only be used if you know, that you are the exclusive owner 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   695
     of the receiver. (use scaledBy if in doubt)"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   696
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   697
    |scalePoint sx sy|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   698
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   699
    (scale isMemberOf:Point) ifTrue:[  "type hint to stc"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   700
	sx := scale x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   701
	sy := scale y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   702
    ] ifFalse:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   703
	scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   704
	sx := scalePoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   705
	sy := scalePoint y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   706
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   707
    width := width * sx.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   708
    height := height * sy.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   709
    left := left * sx.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   710
    top := top * sy
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   711
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   712
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   713
     (Rectangle origin:10@10 corner:50@50) scaleBy:2 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   714
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   715
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   716
    "its destructive:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   717
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   718
     |r1 r2|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   719
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   720
     r1 := Rectangle origin:10@10 corner:50@50.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   721
     r2 := r1 scaleBy:2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   722
     r1 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   723
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   724
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   725
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   726
translateBy:amount
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   727
    "translate (i.e. move) the receiver rectangle 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   728
     by amount, a Point or Number.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   729
     This is destructive (modifies the receiver, not a copy) and 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   730
     should only be used if you know, that you are the exclusive owner 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   731
     of the receiver. (use translatedBy if in doubt)"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   732
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   733
    |amountPoint|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   734
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   735
    (amount isMemberOf:Point) ifTrue:[  "type hint to stc"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   736
	left := left + amount x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   737
	top := top + amount y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   738
    ] ifFalse:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   739
	amountPoint := amount asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   740
	left := left + amountPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   741
	top := top + amountPoint y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   742
    ]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   743
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   744
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   745
     (Rectangle origin:10@10 corner:50@50) translateBy:10
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   746
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   747
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   748
    "its destructive:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   749
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   750
     |r1 r2|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   751
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   752
     r1 := Rectangle origin:10@10 corner:50@50.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   753
     r2 := r1 translateBy:10.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   754
     r1 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   755
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   756
! !
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   757
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   758
!Rectangle methodsFor:'displaying'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   759
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   760
displayFilledOn:aGC
1314
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   761
    "display a filled rectangle as represented by the receiver in 
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   762
     the graphicsContext, aGC"
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   763
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   764
    aGC fillRectangleX:left y:top width:width height:height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   765
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   766
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   767
     |v|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   768
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   769
     v := View new open.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   770
     [v shown] whileFalse:[Processor yield].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   771
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   772
     (Rectangle origin:10@10 corner:50@50) displayFilledOn:v
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   773
    "
1314
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   774
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   775
    "Modified: 27.4.1996 / 14:52:38 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   776
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   777
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   778
displayStrokedOn:aGC
1314
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   779
    "display an unfilled rectangle as represented by the receiver in 
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   780
     the graphicsContext, aGC"
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   781
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   782
    aGC displayRectangleX:left y:top width:width height:height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   783
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   784
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   785
     |v|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   786
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   787
     v := View new open.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   788
     [v shown] whileFalse:[Processor yield].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   789
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   790
     (Rectangle origin:10@10 corner:50@50) displayStrokedOn:v
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   791
    "
1314
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   792
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   793
    "Modified: 27.4.1996 / 14:52:45 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   794
! !
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   795
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   796
!Rectangle methodsFor:'printing & storing'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   797
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   798
printOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   799
    "print the receiver on aStream"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   800
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   801
    aStream nextPutAll:(self class name).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   802
    aStream nextPutAll:' origin:'.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   803
    (self origin) printOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   804
    aStream nextPutAll:' corner:'.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   805
    (self corner) printOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   806
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   807
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   808
storeOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   809
    "store the receiver on aStream; i.e. print an expression which will
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   810
     reconstruct the receiver"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   811
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   812
    aStream nextPut:$(.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   813
    aStream nextPutAll:(self class name).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   814
    aStream nextPutAll:' origin:'.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   815
    (self origin) storeOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   816
    aStream nextPutAll:' corner:'.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   817
    (self corner) storeOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   818
    aStream nextPut:$)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   819
! !
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   820
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   821
!Rectangle methodsFor:'queries'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   822
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   823
isRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   824
    "return true, if the receiver is some kind of rectangle"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   825
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   826
    ^ true
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   827
! !
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   828
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   829
!Rectangle methodsFor:'rectangle operations'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   830
a27a279701f8 Initial revision
claus
parents:
diff changeset
   831
+ aPoint
356
claus
parents: 329
diff changeset
   832
    "return a new rectangle with same extent as receiver but
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   833
     origin translated by the argument, aPoint"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   834
217
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   835
    |amountPoint|
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   836
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   837
    amountPoint := aPoint asPoint.
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   838
    ^ Rectangle left:(left + amountPoint x)
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   839
		 top:(top + amountPoint y)
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   840
	       width:width
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   841
	      height:height
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   842
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   843
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   844
align:offset with:someCoordinate
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   845
    "return a new rectangle which is translated (i.e. moved)
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   846
     such that the point offset in mySelf is placed on someCoordinate."
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   847
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   848
    ^ Rectangle origin:(someCoordinate - offset + self origin)
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   849
		extent:(self extent)
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   850
    "
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   851
     |r|
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   852
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   853
     r := Rectangle origin:10@10 corner:50@50.
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   854
     r align:(r center) with:100@100.
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   855
    "
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   856
!
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   857
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   858
amountToTranslateWithin: aRectangle
a27a279701f8 Initial revision
claus
parents:
diff changeset
   859
    "for GNU-ST compatibility"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   860
a27a279701f8 Initial revision
claus
parents:
diff changeset
   861
    ^(aRectangle origin) - self origin
a27a279701f8 Initial revision
claus
parents:
diff changeset
   862
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   863
a27a279701f8 Initial revision
claus
parents:
diff changeset
   864
areasOutside: aRectangle
a27a279701f8 Initial revision
claus
parents:
diff changeset
   865
    "----------------------------------------------------------------
a27a279701f8 Initial revision
claus
parents:
diff changeset
   866
    | added for GNU-ST compatibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
   867
    |
a27a279701f8 Initial revision
claus
parents:
diff changeset
   868
    | author: Doug McCallum <uunet!!ico.isc.com!!dougm>
a27a279701f8 Initial revision
claus
parents:
diff changeset
   869
    |
a27a279701f8 Initial revision
claus
parents:
diff changeset
   870
    |areasOutside: aRectangle
a27a279701f8 Initial revision
claus
parents:
diff changeset
   871
    | most complicated of the Rectangle primitives
a27a279701f8 Initial revision
claus
parents:
diff changeset
   872
    | The basic methodology is to first determine that there is an 
a27a279701f8 Initial revision
claus
parents:
diff changeset
   873
    | intersection by finding the overlapping rectangle.  From the
a27a279701f8 Initial revision
claus
parents:
diff changeset
   874
    | overlapping rectangle, first determine if it runs along an edge.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   875
    | If it doesn't, extend the rectangle up to the top edge and add
a27a279701f8 Initial revision
claus
parents:
diff changeset
   876
    | the new rectangle to the collection and start the rest of the
a27a279701f8 Initial revision
claus
parents:
diff changeset
   877
    | process.  If the left edge does not touch the left edge of self,
a27a279701f8 Initial revision
claus
parents:
diff changeset
   878
    | extend it to the edge saving the new rectangle.  Then do the 
a27a279701f8 Initial revision
claus
parents:
diff changeset
   879
    | same to the right edge.  Then check top and bottom edges.  Most
a27a279701f8 Initial revision
claus
parents:
diff changeset
   880
    | of the time only 2 or 3 rectangles get formed, occasionally 4.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   881
    | It should be possible to never get more than 3 but requires more
a27a279701f8 Initial revision
claus
parents:
diff changeset
   882
    | work.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   883
     ----------------------------------------------------------------"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   884
a27a279701f8 Initial revision
claus
parents:
diff changeset
   885
    | collect iRect tmp |
1124
53f6970d9d7d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   886
360
claus
parents: 359
diff changeset
   887
    iRect := self intersect: aRectangle.
1124
53f6970d9d7d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   888
    iRect isNil ifTrue: [^nil]. "case of no intersection"
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   889
				"the collect collection gathers Rectangles"
360
claus
parents: 359
diff changeset
   890
    collect := OrderedCollection new: 4.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   891
				"is it floating or on the edge?"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   892
    (((((iRect top) ~= self top) 
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   893
	 and: [ (iRect bottom) ~= self bottom ])
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   894
	 and: [ (iRect left) ~= self left ])
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   895
	 and: [ (iRect right) ~= self right ] )
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   896
	ifTrue: "entirely in the center."
360
claus
parents: 359
diff changeset
   897
	    [tmp := Rectangle origin: (Point x: iRect left y: self top)
claus
parents: 359
diff changeset
   898
			      corner: iRect bottomRight.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   899
	     collect add: tmp.
360
claus
parents: 359
diff changeset
   900
	     iRect := iRect merge: tmp].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   901
    ((iRect left) ~= self left)
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   902
	ifTrue:                 "doesn't touch left edge so make it touch"
360
claus
parents: 359
diff changeset
   903
	    [tmp := Rectangle origin: (Point x: self left y: iRect top)
claus
parents: 359
diff changeset
   904
			      corner: iRect bottomLeft.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   905
		 collect add: tmp.
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   906
				"merge new (tmp) with overlap to keep track"
360
claus
parents: 359
diff changeset
   907
		 iRect := iRect merge: tmp].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   908
    ((iRect right) ~= self right)
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   909
	ifTrue:                 "doesn't touch right edge so extend it"
360
claus
parents: 359
diff changeset
   910
	    [tmp := Rectangle origin: iRect topRight
claus
parents: 359
diff changeset
   911
			      corner: (Point x: self right y: iRect bottom).
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   912
		 collect add: tmp.
360
claus
parents: 359
diff changeset
   913
		 iRect := iRect merge: tmp].
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   914
    (((iRect left) ~= self left) or: [(iRect top) ~= self top])
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   915
	ifTrue:                 "whole top part can be taken now"
360
claus
parents: 359
diff changeset
   916
	    [tmp := Rectangle origin: self origin corner: iRect topRight.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   917
		 collect add: tmp].
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   918
    (((iRect right) ~= self right) or: [(iRect bottom) ~= self bottom])
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   919
	ifTrue:                 "whole bottom open and can be taken"
360
claus
parents: 359
diff changeset
   920
	    [tmp := Rectangle origin: iRect bottomLeft corner: self corner.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   921
		 collect add: tmp].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   922
    ^collect
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   923
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   924
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   925
expandedBy:delta
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   926
    "return a new rectangle which is expanded in all directions
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   927
     by amount, a Point, Rectangle or Number"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   928
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   929
    ^ self copy expandBy:delta
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   930
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   931
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   932
     |r|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   933
     r := Rectangle origin:10@10 corner:100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   934
     r expandedBy:5.   
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   935
     r expandedBy:(5 @ 0).  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   936
     r expandedBy:(10 @ 10).  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   937
     r expandedBy:( 10@10 corner:20@20 )  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   938
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   939
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   940
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   941
insetBy: delta
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   942
    "return a new rectangle which is inset in all directions
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   943
     by delta, a Point, Rectangle or Number"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   944
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   945
    |amountPoint deltaLeft deltaTop deltaWidth deltaHeight|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   946
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   947
    delta isNumber ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   948
	deltaLeft := deltaTop := delta.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   949
	deltaWidth := deltaHeight := delta * 2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   950
    ] ifFalse:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   951
	delta isRectangle ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   952
	    deltaLeft := delta left.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   953
	    deltaTop := delta top.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   954
	    deltaWidth := deltaLeft + delta right.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   955
	    deltaHeight := deltaTop + delta bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   956
	] ifFalse:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   957
	    amountPoint := delta asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   958
	    deltaLeft := amountPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   959
	    deltaTop := amountPoint y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   960
	    deltaWidth := deltaLeft * 2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   961
	    deltaHeight := deltaTop * 2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   962
	]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   963
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   964
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   965
    ^ Rectangle left:(left + deltaLeft)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   966
		 top:(top + deltaTop)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   967
	       width:(width - deltaWidth)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   968
	      height:(height - deltaHeight)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   969
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   970
     |r|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   971
     r := Rectangle origin:10@10 corner:100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   972
     r insetBy:5.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   973
     r insetBy:(5 @ 0).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   974
     r insetBy:(10 @ 10).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   975
     r insetBy:( 10@10 corner:20@20 )
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   976
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   977
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   978
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   979
insetOriginBy:originDelta cornerBy:cornerDelta
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   980
    "return a new rectangle which is inset by originDelta 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   981
     and cornerDelta; both may be instances of Point or Number"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   982
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   983
    ^ Rectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   984
	origin:(left @ top) + originDelta asPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   985
	corner:(self corner - cornerDelta asPoint)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   986
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   987
     |r|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   988
     r := Rectangle origin:10@10 corner:100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   989
     r insetOriginBy:5 cornerBy:10. 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   990
     r insetOriginBy:10@5 cornerBy:10.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   991
     r insetOriginBy:10 cornerBy:10@5. 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   992
     r insetOriginBy:10@10 cornerBy:20@20.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   993
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   994
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   995
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   996
intersect:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   997
    "return a new rectangle covering the intersection of the receiver
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   998
     and the argument, aRectangle.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   999
     the rectangles must intersect for a valid return"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1000
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1001
    ^ Rectangle left:(left max:(aRectangle left))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1002
	       right:((left + width) min:(aRectangle right))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1003
		 top:(top max:(aRectangle top))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1004
	      bottom:((top + height) min:(aRectangle bottom))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1005
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1006
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1007
     |r1 r2|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1008
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1009
     r1 := Rectangle origin:10@10 corner:100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1010
     r2 := Rectangle origin:50@50 corner:150@75.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1011
     r1 intersect:r2
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1012
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1013
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1014
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1015
merge:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1016
    "return a new rectangle covering both the receiver 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1017
     and the argument, aRectangle"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1018
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1019
    ^ Rectangle left:(left min:(aRectangle left))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1020
	       right:((left + width) max:(aRectangle right))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1021
		 top:(top min:(aRectangle top))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1022
	      bottom:((top + height) max:(aRectangle bottom))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1023
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1024
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
  1025
nonIntersections:aRectangle
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
  1026
    "this is the same as areasOutside: - for ST/V compatibility only"
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
  1027
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
  1028
    ^ self areasOutside:aRectangle
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1029
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1030
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1031
rounded
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1032
    "return a copy of the receiver with rounded coordinates"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1033
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1034
    ^ Rectangle left:(left rounded) 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1035
		 top:(top rounded)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1036
	       width:(width rounded) 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1037
	      height:(height rounded)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1038
!
356
claus
parents: 329
diff changeset
  1039
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1040
scaledBy:scale
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1041
    "return a new rectangle which is the receiver
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1042
     scaled by scale"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1043
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1044
    |scalePoint sx sy|
356
claus
parents: 329
diff changeset
  1045
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1046
    scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1047
    sx := scalePoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1048
    sy := scalePoint y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1049
    ^ Rectangle left:left * sx
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1050
		 top:top * sy
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1051
	       width:(width * sx)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1052
	      height:(height * sy)
356
claus
parents: 329
diff changeset
  1053
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1054
     (Rectangle origin:10@10 corner:50@50) scaledBy:2   
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1055
    "
356
claus
parents: 329
diff changeset
  1056
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1057
    "its NOT destructive:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1058
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1059
     |r1 r2|
356
claus
parents: 329
diff changeset
  1060
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1061
     r1 := Rectangle origin:10@10 corner:50@50.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1062
     r2 := r1 scaledBy:2.    
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1063
     r1  
356
claus
parents: 329
diff changeset
  1064
    "
claus
parents: 329
diff changeset
  1065
!
claus
parents: 329
diff changeset
  1066
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1067
translatedBy:amount
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1068
    "return a new rectangle which is translated (i.e. moved)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1069
     by amount, aPoint or Number"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1070
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1071
    |amountPoint|
356
claus
parents: 329
diff changeset
  1072
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1073
    amountPoint := amount asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1074
    ^ Rectangle left:(left + amountPoint x) 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1075
		 top:(top + amountPoint y)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1076
	       width:width
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1077
	      height:height
356
claus
parents: 329
diff changeset
  1078
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1079
     (Rectangle origin:10@10 corner:50@50) translatedBy:10
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1080
    "
356
claus
parents: 329
diff changeset
  1081
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1082
    "its NOT destructive:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1083
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1084
     |r1 r2|
356
claus
parents: 329
diff changeset
  1085
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1086
     r1 := Rectangle origin:10@10 corner:50@50.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1087
     r2 := r1 translatedBy:10.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1088
     r1 
356
claus
parents: 329
diff changeset
  1089
    "
claus
parents: 329
diff changeset
  1090
! !
claus
parents: 329
diff changeset
  1091
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1092
!Rectangle methodsFor:'testing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1093
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1094
contains:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1095
    "return true, if the argument, aRectangle is equal to or
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1096
     is contained fully within the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1097
1149
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1098
%{  /* NOCONTEXT */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1099
    /*
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1100
     * claus: this may be often called by objectView
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1101
     * the primitive code below (although lookung ugly)
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1102
     * speeds that up by almost a factor of 2 ...
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1103
     */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1104
    OBJ slf = self;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1105
    OBJ rct = aRectangle;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1106
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1107
    if (__isNonNilObject(rct) 
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1108
     && __qClass(rct) == Rectangle) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1109
        OBJ r_l, r_w, r_t, r_h, l, w, t, h;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1110
        int r_ir, r_il, r_ib, r_it;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1111
        int il, it, ir, ib, iw, ih;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1112
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1113
        r_l = __OINST(rct, left);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1114
        l = __OINST(slf, left);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1115
        if (__bothSmallInteger(r_l, l)) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1116
#ifndef POSITIVE_ADDRESSES      /* tag in low-bit */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1117
            il = (int)(l);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1118
            r_il = (int)(r_l);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1119
#else
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1120
            il = __intVal(l);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1121
            r_il = __intVal(r_l);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1122
#endif
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1123
            if (il > r_il) { RETURN (false); }   /* left > aRectangle left */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1124
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1125
            r_t = __OINST(rct, top);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1126
            t = __OINST(slf, top);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1127
            if (__bothSmallInteger(r_t, t)) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1128
#ifndef POSITIVE_ADDRESSES      /* tag in low-bit */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1129
                it = (int)(t);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1130
                r_it = (int)(r_t);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1131
#else
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1132
                it = __intVal(t);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1133
                r_it = __intVal(r_t);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1134
#endif
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1135
                if (it > r_it) { RETURN (false); }   /* top > aRectangle top */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1136
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1137
                r_w = __OINST(rct, width);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1138
                w = __OINST(slf, width);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1139
                if (__bothSmallInteger(r_w, w)) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1140
#ifndef POSITIVE_ADDRESSES      /* tag in low-bit */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1141
                    ir = il + (int)(w);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1142
                    r_ir = r_il + (int)(r_w);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1143
#else
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1144
                    ir = il + __intVal(w);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1145
                    r_ir = r_il + __intVal(r_w);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1146
#endif
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1147
                    if (ir < r_ir) { RETURN (false); }   /* (left + width) < aRectangle right */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1148
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1149
                    r_h = __OINST(rct, height);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1150
                    h = __OINST(slf, height);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1151
                    if (__bothSmallInteger(r_h, h)) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1152
#ifndef POSITIVE_ADDRESSES      /* tag in low-bit */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1153
                        ib = it + (int)(h);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1154
                        r_ib = r_it + (int)(r_h);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1155
#else
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1156
                        ib = it + __intVal(h);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1157
                        r_ib = r_it + __intVal(r_h);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1158
#endif
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1159
                        if (ib < r_ib) { RETURN (false); }   /* (top + height) < aRectangle bottom */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1160
                        RETURN (true);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1161
                    }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1162
                }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1163
            }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1164
        }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1165
    }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1166
%}.
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1167
    (left <= aRectangle left) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1168
      ((left + width) >= aRectangle right) ifTrue:[
1149
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1169
        (top <= aRectangle top) ifTrue:[
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1170
          ((top + height) >= aRectangle bottom) ifTrue:[
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1171
            ^ true
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1172
          ]
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1173
        ]
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1174
      ]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1175
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1176
    ^ false
1149
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1177
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1178
    "
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1179
     (0@0 corner:100@100) contains:(10@10 corner:90@90) 
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1180
     (0@0 corner:100@100) contains:(10@10 corner:100@100)  
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1181
     (0@0 corner:100@100) contains:(10@10 corner:110@100) 
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1182
     (0@0 corner:100@100) contains:(10@10 corner:100@110) 
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1183
     (10@10 corner:100@100) contains:(0@10 corner:100@100) 
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1184
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1185
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1186
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1187
containsPoint:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1188
    "return true, if the argument, aPoint is contained in the receiver"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1189
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1190
    |px py|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1191
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1192
    px := aPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1193
    (px < left)           ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1194
    (px > (left + width)) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1195
    py := aPoint y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1196
    (py < top)            ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1197
    (py > (top + height)) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1198
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1199
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1200
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1201
containsPointX:x y:y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1202
    "return true, if the point defined by x@y is contained in the receiver.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1203
     This is the same as containsPoint:, but can be used if the coordinates
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1204
     are already available as separate numbers to avoid useless creation of a
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1205
     temporary point."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1206
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1207
    (x < left)           ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1208
    (x > (left + width)) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1209
    (y < top)            ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1210
    (y > (top + height)) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1211
    ^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1212
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1213
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1214
intersects:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1215
    "return true, if the intersection between the argument, aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1216
     and the receiver is not empty"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1217
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1218
    |b r|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1219
1149
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1220
%{  /* NOCONTEXT */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1221
    /*
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1222
     * claus: this is one of the mostly called methods in
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1223
     * the objectView - the primitive code below (although lookung ugly)
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1224
     * speeds up drawing by almost a factor of 2 ...
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1225
     */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1226
    OBJ slf = self;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1227
    OBJ rct = aRectangle;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1228
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1229
    if (__isNonNilObject(rct) 
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1230
     && __qClass(rct) == Rectangle) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1231
        OBJ r_l, r_w, r_t, r_h, l, w, t, h;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1232
        int r_ir, r_il, r_ib, r_it;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1233
        int il, it, ir, ib, iw, ih;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1234
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1235
        r_l = __OINST(rct, left);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1236
        r_w = __OINST(rct, width);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1237
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1238
        if (__bothSmallInteger(r_l, r_w)) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1239
            r_t = __OINST(rct, top);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1240
            r_h = __OINST(rct, height);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1241
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1242
            l = __OINST(slf, left);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1243
            w = __OINST(slf, width);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1244
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1245
            if (__bothSmallInteger(l, w)) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1246
                t = __OINST(slf, top);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1247
                h = __OINST(slf, height);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1248
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1249
#ifndef POSITIVE_ADDRESSES      /* tag in low-bit */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1250
                r_il = (int)(r_l);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1251
                r_ir = r_il + (int)(r_w) - 1;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1252
                il = (int)(l);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1253
                if (r_ir < il) { RETURN (false); }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1254
                ir = il + (int)(w) - 1;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1255
                if (r_il > ir) { RETURN (false); }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1256
#else                           /* tag in hi-bit */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1257
                r_il = __intVal(r_l);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1258
                r_ir = r_il + __intVal(r_w);        /* aRectangle right */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1259
                il = __intVal(l);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1260
                if (r_ir < il) { RETURN (false); }  /* (aRectangle right) < left */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1261
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1262
                ir = il + __intVal(w);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1263
                if (r_il > ir) { RETURN (false); }   /* (aRectangle left) > r */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1264
#endif
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1265
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1266
                if (__bothSmallInteger(r_t, r_h)) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1267
                    if (__bothSmallInteger(t, h)) {
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1268
#ifndef POSITIVE_ADDRESSES
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1269
                        r_it = (int)(r_t);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1270
                        r_ib = r_it + (int)(r_h) - 1; /* aRectangle bottom */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1271
                        it = (int)(t);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1272
                        if (r_ib < it) { RETURN (false); } /* (aRectangle bottom) < top */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1273
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1274
                        ib = it + (int)(h) - 1;
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1275
                        if (r_it > ib) { RETURN (false); } /* (aRectangle top) > b */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1276
#else
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1277
                        r_it = __intVal(r_t);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1278
                        r_ib = r_it + __intVal(r_h); /* aRectangle bottom */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1279
                        it = __intVal(t);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1280
                        if (r_ib < it) { RETURN (false); } /* (aRectangle bottom) < top */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1281
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1282
                        ib = it + __intVal(h);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1283
                        if (r_it > ib) { RETURN (false); } /* (aRectangle top) > b */
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1284
#endif
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1285
                        RETURN (true);
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1286
                    }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1287
                }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1288
            }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1289
        }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1290
    }
69b30e3494fa added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1291
%}.
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1292
    (aRectangle right)  < left ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1293
    (aRectangle bottom) < top  ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1294
    r := left + width.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1295
    (aRectangle left)   > r    ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1296
    b := top + height.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1297
    (aRectangle top)    > b    ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1298
    ^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1299
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1300
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1301
isContainedIn:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1302
    "return true, if the receiver is fully contained within 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1303
     the argument, aRectangle"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1304
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1305
    (aRectangle left <= left) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1306
      (aRectangle right >= (left + width)) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1307
	(aRectangle top <= top) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1308
	  (aRectangle bottom >= (top + height)) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1309
	    ^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1310
	  ]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1311
	]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1312
      ]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1313
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1314
    ^ false
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1315
! !
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1316
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1317
!Rectangle class methodsFor:'documentation'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1318
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1319
version
1314
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
  1320
    ^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.38 1996-04-27 17:51:06 cg Exp $'
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1321
! !