Rectangle.st
author Claus Gittinger <cg@exept.de>
Thu, 04 Jan 1996 02:24:09 +0100
changeset 829 fc386319f41c
parent 637 f71df465819c
child 835 8bd6f4aa8130
permissions -rw-r--r--
removed external function defs (soon no longer allowed)
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
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    14
	 instanceVariableNames:'left top width height'
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    15
	 classVariableNames:''
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    16
	 poolDictionaries:''
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
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
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
    49
	left           <Number>        the left coordinate (i.e origin x)
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
    50
	top            <Number>        the top coordinate (i.e origin y)
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
    51
	width          <Number>        the width of the rectangle
a4c3032fc825 *** empty log message ***
claus
parents: 93
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.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    57
"
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    58
! !
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
    59
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    60
!Rectangle class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    61
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    62
fromUser
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    63
    "let user specify a rectangle on the screen, return it"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    64
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    65
    ^ Screen current rectangleFromUser
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    66
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    67
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    68
     Rectangle fromUser     
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    69
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    70
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
left:left right:right top:top bottom:bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    73
    "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
    74
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    75
    ^ (self basicNew) left:left right:right top:top bottom:bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    76
!
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
left:left top:top right:right bottom:bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
    "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
    80
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
    ^ (self basicNew) left:left top:top right:right bottom:bottom
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
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
left:left top:top width:w height:h
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    85
    "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
    86
     and width, height"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
%{  /* NOCONTEXT */
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
    REGISTER OBJ newRect;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    90
    OBJ t;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    91
    int spc;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
    if (_CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) {
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    94
	if (self == Rectangle) {
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
	/* short cut - rectangles are created so often ... */
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
	    _qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ));
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    97
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    98
	    _InstPtr(newRect)->o_class = Rectangle;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    99
	    _InstPtr(newRect)->i_instvars[0] = left;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
	    _InstPtr(newRect)->i_instvars[1] = top;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   101
	    _InstPtr(newRect)->i_instvars[2] = w;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
	    _InstPtr(newRect)->i_instvars[3] = h;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
	    if (! (__bothSmallInteger(left, top) && 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   105
		   __bothSmallInteger(w, h))) {
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   106
		spc = __qSpace(newRect);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
		__STORE_SPC(newRect, left, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
		__STORE_SPC(newRect, top, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
		__STORE_SPC(newRect, w, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
		__STORE_SPC(newRect, h, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
	    }
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
	    RETURN ( newRect );
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
	}
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
    }
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
%}
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
    ^ (self basicNew) left:left top:top width:w height:h
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   121
origin:origin corner:corner
a27a279701f8 Initial revision
claus
parents:
diff changeset
   122
    "create and return a new Rectangle giving top-left and bottom-right points"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   123
a27a279701f8 Initial revision
claus
parents:
diff changeset
   124
    ^ (self basicNew) origin:origin corner:corner
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   126
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
origin:origin extent:extent
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
    "create and return a new Rectangle giving top-left point and extent point"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
a27a279701f8 Initial revision
claus
parents:
diff changeset
   130
%{  /* NOCONTEXT */
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   131
    REGISTER OBJ newRect;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   132
    OBJ t;
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   133
    int spc;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
    /* short cut - rectangles are created so often ... */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
    if (_CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) {
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   137
	if (self == Rectangle) {
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   138
	    if (__isPoint(origin) && __isPoint(extent)) {
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   139
		_qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ));
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   140
		_InstPtr(newRect)->o_class = Rectangle;
325
claus
parents: 308
diff changeset
   141
		spc = __qSpace(newRect);
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   142
325
claus
parents: 308
diff changeset
   143
		t = _PointInstPtr(origin)->p_x;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   144
		_InstPtr(newRect)->i_instvars[0] = t;
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   145
		__STORE_SPC(newRect, t, spc);
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   146
325
claus
parents: 308
diff changeset
   147
		t = _PointInstPtr(origin)->p_y;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   148
		_InstPtr(newRect)->i_instvars[1] = t;
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   149
		__STORE_SPC(newRect, t, spc);
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   150
325
claus
parents: 308
diff changeset
   151
		t = _PointInstPtr(extent)->p_x;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   152
		_InstPtr(newRect)->i_instvars[2] = t;
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   153
		__STORE_SPC(newRect, t, spc);
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   154
325
claus
parents: 308
diff changeset
   155
		t = _PointInstPtr(extent)->p_y;
293
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   156
		_InstPtr(newRect)->i_instvars[3] = t;
31df3850e98c *** empty log message ***
claus
parents: 259
diff changeset
   157
		__STORE_SPC(newRect, t, spc);
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   158
		RETURN ( newRect );
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   159
	    }
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   160
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   161
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   164
    ^ (self basicNew) origin:origin extent:extent
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
!Rectangle methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
area
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   170
    "return the area 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
     - for screen Rectangles this is the number of pixels"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   172
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   173
    ^ width * height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   174
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   175
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   177
    "return the y coordinate of the bottom"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
    ^ (top + height)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
bottom:aNumber
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
    "set the bottom edge"
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
    height := aNumber - top
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
bottomCenter
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   189
    "return the bottom center point"
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
    ^ (left + (width // 2)) @ (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
bottomLeft
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   195
    "return the bottom-left point"
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
    ^ left @ (top + height)
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
bottomRight
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   201
    "return the bottom-right 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) @ (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
center
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   207
    "return the point in the center of the receiver"
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 + (width // 2)) @ (top + (height // 2))
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
corner
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   213
    "return the corner"
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
corner:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
    "set the bottom-right corner"
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
    width := aPoint x - left.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   222
    height := aPoint y - top
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
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   225
extent
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   226
    "return the extent"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
    ^ width @ height
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
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   231
extent:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   232
    "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
   233
     and height taken from aPoint y"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   234
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   235
    width := aPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
    height := aPoint y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   237
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   238
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   239
height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   240
    "return the height of the rectangle"
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
    ^ height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   243
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   244
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   245
left
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   246
    "return the x-coordinate of the top-left origin"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   247
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   248
    ^ left
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
left:aNumber
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   252
    "set the left edge"
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
    width := width + (left - aNumber).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   255
    left := aNumber
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
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   258
left:newLeft right:right top:newTop bottom:bottom
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   259
    "set the rectangle given left, top, right and bottom coordinates."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   260
a27a279701f8 Initial revision
claus
parents:
diff changeset
   261
    left := newLeft.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
    top := newTop.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
    width := right - left.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
    height := bottom - top
a27a279701f8 Initial revision
claus
parents:
diff changeset
   265
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   266
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
left:newLeft top:newTop right:right bottom:bottom
a27a279701f8 Initial revision
claus
parents:
diff changeset
   268
    "set the rectangle given left, top, right and bottom coordinates"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   269
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
    left := newLeft.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   271
    top := newTop.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   272
    width := right - left.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
    height := bottom - top
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
left:newLeft top:newTop width:newWidth height:newHeight
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
    "set the rectangle given left, top coordinates and width, height"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
a27a279701f8 Initial revision
claus
parents:
diff changeset
   279
    left := newLeft.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   280
    top := newTop.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   281
    width := newWidth.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
    height := newHeight
a27a279701f8 Initial revision
claus
parents:
diff changeset
   283
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   285
leftCenter
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   286
    "return the left center point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
    ^ left @ (top + (height // 2))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   289
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   290
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
origin
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   292
    "return the origin"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
    ^ left @ top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   297
origin:aPoint
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   298
    "set the top-left origin. The corner remains unchanged."
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   299
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   300
    |newTop newLeft|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   301
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   302
    newTop := aPoint y.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   303
    newLeft := aPoint x.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   304
    height := height + (top - newTop).
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   305
    width := width + (left - newLeft).
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   306
    left := newLeft.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   307
    top := newTop
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   308
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   309
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
origin:origin corner:corner
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
    "set both origin and corner"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
    left := origin x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   314
    top := origin y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
    width := corner x - left.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   316
    height := corner y - top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   318
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   319
origin:origin extent:extent
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
    "set both origin and extent"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
    left := origin x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    top := origin y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
    width := extent x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   325
    height := extent y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   327
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
right
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   329
    "return the x coordinate of the right"
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
    ^ (left + width)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   332
!
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
right:aNumber
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
    "set the right edge"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
    width := aNumber - left
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   338
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
rightCenter
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
    "return the right center point"
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) @ (top + (height // 2))
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
top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   347
    "return the y-coordinate of the top-left"
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
    ^ top
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   350
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   351
a27a279701f8 Initial revision
claus
parents:
diff changeset
   352
top:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   353
    "set the top edge"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   354
a27a279701f8 Initial revision
claus
parents:
diff changeset
   355
    height := height + (top - aNumber).
a27a279701f8 Initial revision
claus
parents:
diff changeset
   356
    top := aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   357
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   358
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   359
topCenter
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   360
    "return the top center point"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   361
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   362
    ^ (left + (width // 2)) @ top
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   363
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   364
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   365
topLeft
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   366
    "return the top-left point - the same as origin"
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   367
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   368
    ^ left @ top
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   369
!
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   370
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   371
topLeft:aPoint
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   372
    "Set the top and left edges.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   373
     The bottom right remains unchanged."
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   374
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   375
    |newTop|
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   376
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   377
    newTop := aPoint y.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   378
    height := height + (top - newTop).
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   379
    top := newTop.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   380
    width := aPoint x - left
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   381
!
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   382
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   383
topRight
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   384
    "return the top-right point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   385
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   386
    ^ (left + width) @ top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   387
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   388
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   389
topRight:aPoint
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   390
    "Set the top and right edges. 
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   391
     The bottom left remains unchanged."
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   392
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   393
    |newTop|
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   394
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   395
    newTop := aPoint y.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   396
    height := height + (top - newTop).
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   397
    top := newTop.
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   398
    width := aPoint x - left
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   399
!
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   400
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   401
width
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   402
    "return the width of the rectangle"
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   403
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   404
    ^ width
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   405
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   406
a27a279701f8 Initial revision
claus
parents:
diff changeset
   407
!Rectangle methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   408
a27a279701f8 Initial revision
claus
parents:
diff changeset
   409
= aRectangle
a27a279701f8 Initial revision
claus
parents:
diff changeset
   410
    "return true, if the argument aRectangle represents the same
a27a279701f8 Initial revision
claus
parents:
diff changeset
   411
     rectangle as the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   412
a27a279701f8 Initial revision
claus
parents:
diff changeset
   413
%{  /* NOCONTEXT */
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   414
    /*
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   415
     * handle the common case quickly
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   416
     */
329
claus
parents: 326
diff changeset
   417
    if (__isNonNilObject(aRectangle) 
claus
parents: 326
diff changeset
   418
     && __qClass(aRectangle) == Rectangle) {
325
claus
parents: 308
diff changeset
   419
	if ((_InstPtr(self)->i_instvars[0] == _InstPtr(aRectangle)->i_instvars[0])
claus
parents: 308
diff changeset
   420
	 && (_InstPtr(self)->i_instvars[1] == _InstPtr(aRectangle)->i_instvars[1])
claus
parents: 308
diff changeset
   421
	 && (_InstPtr(self)->i_instvars[2] == _InstPtr(aRectangle)->i_instvars[2])
claus
parents: 308
diff changeset
   422
	 && (_InstPtr(self)->i_instvars[3] == _InstPtr(aRectangle)->i_instvars[3])) {
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   423
	    RETURN ( true );
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   424
	}
325
claus
parents: 308
diff changeset
   425
	if (__bothSmallInteger(_InstPtr(self)->i_instvars[0], _InstPtr(aRectangle)->i_instvars[0])
claus
parents: 308
diff changeset
   426
	 && __bothSmallInteger(_InstPtr(self)->i_instvars[1], _InstPtr(aRectangle)->i_instvars[1])
claus
parents: 308
diff changeset
   427
	 && __bothSmallInteger(_InstPtr(self)->i_instvars[2], _InstPtr(aRectangle)->i_instvars[2])
claus
parents: 308
diff changeset
   428
	 && __bothSmallInteger(_InstPtr(self)->i_instvars[3], _InstPtr(aRectangle)->i_instvars[3])) {
claus
parents: 308
diff changeset
   429
	    RETURN ( false );
claus
parents: 308
diff changeset
   430
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   431
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   432
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   433
.
259
   434
    (aRectangle species ~~ self species) ifTrue:[^ false].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   435
a27a279701f8 Initial revision
claus
parents:
diff changeset
   436
    left = aRectangle left ifFalse:[^ false].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   437
    top = aRectangle top ifFalse:[^ false].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   438
    width = aRectangle width ifFalse:[^ false].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   439
    height = aRectangle height ifFalse:[^ false].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   440
    ^ true
59
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   441
!
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   442
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   443
hash
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   444
    "return an integer useful for hashing -
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   445
     redefined since = is redefined here"
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   446
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   447
    ^ ((left hash bitShift:16) bitXor:(top hash bitShift:16))
4a86aad06603 *** empty log message ***
claus
parents: 32
diff changeset
   448
      + ((width hash) bitXor:(height hash))
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   449
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   450
356
claus
parents: 329
diff changeset
   451
!Rectangle methodsFor:'converting'!
claus
parents: 329
diff changeset
   452
claus
parents: 329
diff changeset
   453
asFractionalLayout
claus
parents: 329
diff changeset
   454
    "return a layoutFrame in which fractions (top, left, bottom, right)
claus
parents: 329
diff changeset
   455
     are taken from corresponding edges of the receiver.
claus
parents: 329
diff changeset
   456
     You have to make certain that those are in 0..1."
claus
parents: 329
diff changeset
   457
claus
parents: 329
diff changeset
   458
    |l|
claus
parents: 329
diff changeset
   459
claus
parents: 329
diff changeset
   460
    l := LayoutFrame new.
claus
parents: 329
diff changeset
   461
    l
claus
parents: 329
diff changeset
   462
	leftFraction:(self left);
claus
parents: 329
diff changeset
   463
	rightFraction:(self right);
claus
parents: 329
diff changeset
   464
	topFraction:(self top);
claus
parents: 329
diff changeset
   465
	bottomFraction:(self bottom).
claus
parents: 329
diff changeset
   466
    ^ l
claus
parents: 329
diff changeset
   467
claus
parents: 329
diff changeset
   468
    "
claus
parents: 329
diff changeset
   469
     (0.5@0.5 corner:0.75@0.75) asFractionalLayout 
claus
parents: 329
diff changeset
   470
     (0.5@0.5 corner:0.75@0.75) asOffsetLayout      
claus
parents: 329
diff changeset
   471
     (0.5@0.5 corner:0.75@0.75) asLayout        
claus
parents: 329
diff changeset
   472
    "
claus
parents: 329
diff changeset
   473
!
claus
parents: 329
diff changeset
   474
claus
parents: 329
diff changeset
   475
asLayout
claus
parents: 329
diff changeset
   476
    "return a layoutFrame in which offsets (top, left, bottom, right)
claus
parents: 329
diff changeset
   477
     are taken from corresponding edges of the receiver.
claus
parents: 329
diff changeset
   478
     If all values are between 0..1, a fractionalLayout is created,
claus
parents: 329
diff changeset
   479
     otherwise, an offsetLayout"
claus
parents: 329
diff changeset
   480
claus
parents: 329
diff changeset
   481
    |l left right top bot|
claus
parents: 329
diff changeset
   482
claus
parents: 329
diff changeset
   483
    l := LayoutFrame new.
claus
parents: 329
diff changeset
   484
    left := (self left).
claus
parents: 329
diff changeset
   485
    right := (self right).
claus
parents: 329
diff changeset
   486
    top := (self top).
claus
parents: 329
diff changeset
   487
    bot := (self bottom).
claus
parents: 329
diff changeset
   488
    ((left between:0 and:1)
claus
parents: 329
diff changeset
   489
    and:[(right between:0 and:1)
claus
parents: 329
diff changeset
   490
    and:[(top between:0 and:1)
claus
parents: 329
diff changeset
   491
    and:[(bot between:0 and:1)]]]) ifTrue:[
claus
parents: 329
diff changeset
   492
	l
claus
parents: 329
diff changeset
   493
	    leftFraction:left;
claus
parents: 329
diff changeset
   494
	    rightFraction:right;
claus
parents: 329
diff changeset
   495
	    topFraction:top;
claus
parents: 329
diff changeset
   496
	    bottomFraction:bot.
claus
parents: 329
diff changeset
   497
    ] ifFalse:[
claus
parents: 329
diff changeset
   498
	l
claus
parents: 329
diff changeset
   499
	    leftOffset:left;
claus
parents: 329
diff changeset
   500
	    rightFraction:0 offset:right;
claus
parents: 329
diff changeset
   501
	    topOffset:top;
claus
parents: 329
diff changeset
   502
	    bottomFraction:0 offset:bot.
claus
parents: 329
diff changeset
   503
    ].
claus
parents: 329
diff changeset
   504
    ^ l
claus
parents: 329
diff changeset
   505
claus
parents: 329
diff changeset
   506
    "
claus
parents: 329
diff changeset
   507
     (0.5@0.5 corner:0.75@0.75) asFractionalLayout  
claus
parents: 329
diff changeset
   508
     (0.5@0.5 corner:0.75@0.75) asOffsetLayout       
claus
parents: 329
diff changeset
   509
     (0.5@0.5 corner:0.75@0.75) asLayout              
claus
parents: 329
diff changeset
   510
     (0@0 corner:1@1) asLayout                      
claus
parents: 329
diff changeset
   511
     (0@0 corner:1@1) asFractionalLayout             
claus
parents: 329
diff changeset
   512
     (0@0 corner:1@1) asOffsetLayout                 
claus
parents: 329
diff changeset
   513
    "
claus
parents: 329
diff changeset
   514
!
claus
parents: 329
diff changeset
   515
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   516
asOffsetLayout
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   517
    "return a layoutFrame in which offsets (top, left, bottom, right)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   518
     are taken from corresponding edges of the receiver.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   519
     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
   520
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   521
    |l|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   522
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   523
    l := LayoutFrame new.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   524
    l
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   525
	leftOffset:(self left);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   526
	rightFraction:0 offset:(self right);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   527
	topOffset:(self top);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   528
	bottomFraction:0 offset:(self bottom).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   529
    ^ l
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   530
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   531
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   532
     (0.5@0.5 corner:0.75@0.75) asFractionalLayout 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   533
     (0.5@0.5 corner:0.75@0.75) asOffsetLayout      
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   534
     (0.5@0.5 corner:0.75@0.75) asLayout        
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   535
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   536
     (10@10 corner:20@20) asFractionalLayout 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   537
     (10@10 corner:20@20) asOffsetLayout     
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   538
     (10@10 corner:20@20) asLayout             
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   539
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   540
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   541
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   542
356
claus
parents: 329
diff changeset
   543
asPointArray
claus
parents: 329
diff changeset
   544
    "return an array containing my corners (clockwise) and
claus
parents: 329
diff changeset
   545
     the origin again as 5th element. Can be used to convert
claus
parents: 329
diff changeset
   546
     a rectangle into a polygon."
claus
parents: 329
diff changeset
   547
claus
parents: 329
diff changeset
   548
    |org|
claus
parents: 329
diff changeset
   549
claus
parents: 329
diff changeset
   550
    ^ Array with:(org := self origin)
claus
parents: 329
diff changeset
   551
	    with:self topRight
claus
parents: 329
diff changeset
   552
	    with:self corner
claus
parents: 329
diff changeset
   553
	    with:self bottomLeft
claus
parents: 329
diff changeset
   554
	    with:org 
claus
parents: 329
diff changeset
   555
claus
parents: 329
diff changeset
   556
    "
claus
parents: 329
diff changeset
   557
     (10@10 corner:100@100) asPointArray 
claus
parents: 329
diff changeset
   558
    "
claus
parents: 329
diff changeset
   559
!
claus
parents: 329
diff changeset
   560
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   561
fromLiteralArrayEncoding:encoding
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   562
    "read my values from an encoding.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   563
     The encoding is supposed to be of the form: (Rectangle orgX orgY cornX cornY)"
356
claus
parents: 329
diff changeset
   564
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   565
    left := encoding at:2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   566
    top := encoding at:3.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   567
    width := (encoding at:4) - left.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   568
    height := (encoding at:5) - top
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   569
356
claus
parents: 329
diff changeset
   570
claus
parents: 329
diff changeset
   571
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   572
     Rectangle new fromLiteralArrayEncoding:#(Rectangle 100 200 300 500) 
356
claus
parents: 329
diff changeset
   573
    "
379
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   574
!
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   575
421
claus
parents: 384
diff changeset
   576
literalArrayEncoding
claus
parents: 384
diff changeset
   577
    "encode myself as an array.
claus
parents: 384
diff changeset
   578
     The encoding is: (Rectangle orgX orgY cornX cornY)"
claus
parents: 384
diff changeset
   579
claus
parents: 384
diff changeset
   580
    ^ Array
claus
parents: 384
diff changeset
   581
	with:#Rectangle
claus
parents: 384
diff changeset
   582
	with:left
claus
parents: 384
diff changeset
   583
	with:top
claus
parents: 384
diff changeset
   584
	with:width
claus
parents: 384
diff changeset
   585
	with:height
claus
parents: 384
diff changeset
   586
claus
parents: 384
diff changeset
   587
claus
parents: 384
diff changeset
   588
    "
claus
parents: 384
diff changeset
   589
     Rectangle new fromLiteralArrayEncoding:#(Rectangle 100 200 300 500) 
claus
parents: 384
diff changeset
   590
     (100@200 corner:300@500) literalArrayEncoding 
claus
parents: 384
diff changeset
   591
    "
claus
parents: 384
diff changeset
   592
claus
parents: 384
diff changeset
   593
    "Modified: 1.9.1995 / 02:16:54 / claus"
claus
parents: 384
diff changeset
   594
!
claus
parents: 384
diff changeset
   595
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   596
rectangleRelativeTo:aRectangle preferred:prefRect
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   597
    "compute a displayRectangle, treating the receiver like a
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   598
     layoutorigin. This allows point to be used interchangable with
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   599
     LayoutOrigins."
379
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   600
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   601
    ^ (self asLayout) rectangleRelativeTo:aRectangle preferred:prefRect
379
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   602
5b5a130ccd09 revision added
claus
parents: 362
diff changeset
   603
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   604
     (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
   605
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   606
     (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
   607
    "
356
claus
parents: 329
diff changeset
   608
! !
claus
parents: 329
diff changeset
   609
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   610
!Rectangle methodsFor:'destructive rectangle operations'!
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   611
356
claus
parents: 329
diff changeset
   612
expandBy:delta
claus
parents: 329
diff changeset
   613
    "destructively expanded the receiver in all directions
claus
parents: 329
diff changeset
   614
     by amount, a Point, Rectangle or Number.
claus
parents: 329
diff changeset
   615
     Warning: this is a destructive operation, modifying the receiver
claus
parents: 329
diff changeset
   616
     NOT returning a copy. You have to be certain to be the exclusive
claus
parents: 329
diff changeset
   617
     owner of the receiver to avoid side effects. See also: #expandedBy:"
claus
parents: 329
diff changeset
   618
claus
parents: 329
diff changeset
   619
    |amountPoint deltaLeft deltaTop deltaWidth deltaHeight|
claus
parents: 329
diff changeset
   620
claus
parents: 329
diff changeset
   621
    delta isNumber ifTrue:[
claus
parents: 329
diff changeset
   622
	deltaLeft := deltaTop := delta.
claus
parents: 329
diff changeset
   623
	deltaWidth := deltaHeight := delta * 2.
claus
parents: 329
diff changeset
   624
    ] ifFalse:[
claus
parents: 329
diff changeset
   625
	delta isRectangle ifTrue:[
claus
parents: 329
diff changeset
   626
	    deltaLeft := delta left.
claus
parents: 329
diff changeset
   627
	    deltaTop := delta top.
claus
parents: 329
diff changeset
   628
	    deltaWidth := deltaLeft + delta right.
claus
parents: 329
diff changeset
   629
	    deltaHeight := deltaTop + delta bottom
claus
parents: 329
diff changeset
   630
	] ifFalse:[
claus
parents: 329
diff changeset
   631
	    amountPoint := delta asPoint.
claus
parents: 329
diff changeset
   632
	    deltaLeft := amountPoint x.
claus
parents: 329
diff changeset
   633
	    deltaTop := amountPoint y.
claus
parents: 329
diff changeset
   634
	    deltaWidth := deltaLeft * 2.
claus
parents: 329
diff changeset
   635
	    deltaHeight := deltaTop * 2.
claus
parents: 329
diff changeset
   636
	]
claus
parents: 329
diff changeset
   637
    ].
claus
parents: 329
diff changeset
   638
claus
parents: 329
diff changeset
   639
    left := (left - deltaLeft).
claus
parents: 329
diff changeset
   640
    top := (top - deltaTop).
claus
parents: 329
diff changeset
   641
    width := (width + deltaWidth).
claus
parents: 329
diff changeset
   642
    height := (height + deltaHeight).
claus
parents: 329
diff changeset
   643
claus
parents: 329
diff changeset
   644
    "
claus
parents: 329
diff changeset
   645
     |r|
claus
parents: 329
diff changeset
   646
     r := Rectangle origin:10@10 corner:100@100.
claus
parents: 329
diff changeset
   647
     r expandBy:5.
claus
parents: 329
diff changeset
   648
claus
parents: 329
diff changeset
   649
     r := Rectangle origin:10@10 corner:100@100.
claus
parents: 329
diff changeset
   650
     r expandBy:(5 @ 0).
claus
parents: 329
diff changeset
   651
claus
parents: 329
diff changeset
   652
     r := Rectangle origin:10@10 corner:100@100.
claus
parents: 329
diff changeset
   653
     r expandBy:(10 @ 10).
claus
parents: 329
diff changeset
   654
claus
parents: 329
diff changeset
   655
     r := Rectangle origin:10@10 corner:100@100.
claus
parents: 329
diff changeset
   656
     r expandBy:( 10@10 corner:20@20 )
claus
parents: 329
diff changeset
   657
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   658
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   659
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   660
moveBy:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   661
    "destructively translate the rectangle by some distance.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   662
     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
   663
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   664
    left := left + aPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   665
    top := top + aPoint y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   666
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   667
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   668
moveTo:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   669
    "destructively translate the rectangle to have its origin at aPoint."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   670
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   671
    |diff|
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
    diff := aPoint - self origin.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   674
    self origin:aPoint corner:self corner + diff
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   675
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   676
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   677
scaleBy:scale
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   678
    "scale the receiver rectangle by scale (a Number or Point).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   679
     This is destructive (modifies the receiver, not a copy) and 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   680
     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
   681
     of the receiver. (use scaledBy if in doubt)"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   682
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   683
    |scalePoint sx sy|
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
    (scale isMemberOf:Point) ifTrue:[  "type hint to stc"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   686
	sx := scale x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   687
	sy := scale y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   688
    ] ifFalse:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   689
	scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   690
	sx := scalePoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   691
	sy := scalePoint y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   692
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   693
    width := width * sx.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   694
    height := height * sy.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   695
    left := left * sx.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   696
    top := top * sy
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   697
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
     (Rectangle origin:10@10 corner:50@50) scaleBy:2 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   700
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   701
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   702
    "its destructive:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   703
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   704
     |r1 r2|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   705
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   706
     r1 := Rectangle origin:10@10 corner:50@50.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   707
     r2 := r1 scaleBy:2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   708
     r1 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   709
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   710
!
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
translateBy:amount
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   713
    "translate (i.e. move) the receiver rectangle 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   714
     by amount, a Point or Number.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   715
     This is destructive (modifies the receiver, not a copy) and 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   716
     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
   717
     of the receiver. (use translatedBy if in doubt)"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   718
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   719
    |amountPoint|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   720
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   721
    (amount isMemberOf:Point) ifTrue:[  "type hint to stc"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   722
	left := left + amount x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   723
	top := top + amount y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   724
    ] ifFalse:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   725
	amountPoint := amount asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   726
	left := left + amountPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   727
	top := top + amountPoint y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   728
    ]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   729
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   730
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   731
     (Rectangle origin:10@10 corner:50@50) translateBy:10
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
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   734
    "its destructive:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   735
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   736
     |r1 r2|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   737
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   738
     r1 := Rectangle origin:10@10 corner:50@50.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   739
     r2 := r1 translateBy:10.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   740
     r1 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   741
    "
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
!Rectangle methodsFor:'displaying'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   745
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   746
displayFilledOn:aGC
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   747
    aGC fillRectangleX:left y:top width:width height:height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   748
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
     |v|
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
     v := View new open.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   753
     [v shown] whileFalse:[Processor yield].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   754
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   755
     (Rectangle origin:10@10 corner:50@50) displayFilledOn:v
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
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   759
displayStrokedOn:aGC
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   760
    aGC displayRectangleX:left y:top width:width height:height
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   761
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   762
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   763
     |v|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   764
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   765
     v := View new open.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   766
     [v shown] whileFalse:[Processor yield].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   767
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   768
     (Rectangle origin:10@10 corner:50@50) displayStrokedOn:v
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   769
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   770
! !
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 methodsFor:'printing & storing'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   773
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   774
printOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   775
    "print the receiver on aStream"
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
    aStream nextPutAll:(self class name).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   778
    aStream nextPutAll:' origin:'.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   779
    (self origin) printOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   780
    aStream nextPutAll:' corner:'.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   781
    (self corner) printOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   782
!
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
storeOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   785
    "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
   786
     reconstruct the receiver"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   787
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   788
    aStream nextPut:$(.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   789
    aStream nextPutAll:(self class name).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   790
    aStream nextPutAll:' origin:'.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   791
    (self origin) storeOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   792
    aStream nextPutAll:' corner:'.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   793
    (self corner) storeOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   794
    aStream nextPut:$)
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
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   797
!Rectangle methodsFor:'queries'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   798
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   799
isRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   800
    "return true, if the receiver is some kind of rectangle"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   801
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   802
    ^ true
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   803
! !
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   804
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   805
!Rectangle methodsFor:'rectangle operations'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   806
a27a279701f8 Initial revision
claus
parents:
diff changeset
   807
+ aPoint
356
claus
parents: 329
diff changeset
   808
    "return a new rectangle with same extent as receiver but
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   809
     origin translated by the argument, aPoint"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   810
217
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   811
    |amountPoint|
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   812
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   813
    amountPoint := aPoint asPoint.
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   814
    ^ Rectangle left:(left + amountPoint x)
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   815
		 top:(top + amountPoint y)
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   816
	       width:width
a0400fdbc933 *** empty log message ***
claus
parents: 208
diff changeset
   817
	      height:height
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   818
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   819
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   820
align:offset with:someCoordinate
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   821
    "return a new rectangle which is translated (i.e. moved)
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   822
     such that the point offset in mySelf is placed on someCoordinate."
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   823
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   824
    ^ Rectangle origin:(someCoordinate - offset + self origin)
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   825
		extent:(self extent)
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   826
    "
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   827
     |r|
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   828
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   829
     r := Rectangle origin:10@10 corner:50@50.
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   830
     r align:(r center) with:100@100.
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   831
    "
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   832
!
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   833
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   834
amountToTranslateWithin: aRectangle
a27a279701f8 Initial revision
claus
parents:
diff changeset
   835
    "for GNU-ST compatibility"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   836
a27a279701f8 Initial revision
claus
parents:
diff changeset
   837
    ^(aRectangle origin) - self origin
a27a279701f8 Initial revision
claus
parents:
diff changeset
   838
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   839
a27a279701f8 Initial revision
claus
parents:
diff changeset
   840
areasOutside: aRectangle
a27a279701f8 Initial revision
claus
parents:
diff changeset
   841
    "----------------------------------------------------------------
a27a279701f8 Initial revision
claus
parents:
diff changeset
   842
    | added for GNU-ST compatibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
   843
    |
a27a279701f8 Initial revision
claus
parents:
diff changeset
   844
    | author: Doug McCallum <uunet!!ico.isc.com!!dougm>
a27a279701f8 Initial revision
claus
parents:
diff changeset
   845
    |
a27a279701f8 Initial revision
claus
parents:
diff changeset
   846
    |areasOutside: aRectangle
a27a279701f8 Initial revision
claus
parents:
diff changeset
   847
    | most complicated of the Rectangle primitives
a27a279701f8 Initial revision
claus
parents:
diff changeset
   848
    | The basic methodology is to first determine that there is an 
a27a279701f8 Initial revision
claus
parents:
diff changeset
   849
    | intersection by finding the overlapping rectangle.  From the
a27a279701f8 Initial revision
claus
parents:
diff changeset
   850
    | overlapping rectangle, first determine if it runs along an edge.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   851
    | If it doesn't, extend the rectangle up to the top edge and add
a27a279701f8 Initial revision
claus
parents:
diff changeset
   852
    | the new rectangle to the collection and start the rest of the
a27a279701f8 Initial revision
claus
parents:
diff changeset
   853
    | process.  If the left edge does not touch the left edge of self,
a27a279701f8 Initial revision
claus
parents:
diff changeset
   854
    | extend it to the edge saving the new rectangle.  Then do the 
a27a279701f8 Initial revision
claus
parents:
diff changeset
   855
    | same to the right edge.  Then check top and bottom edges.  Most
a27a279701f8 Initial revision
claus
parents:
diff changeset
   856
    | of the time only 2 or 3 rectangles get formed, occasionally 4.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   857
    | It should be possible to never get more than 3 but requires more
a27a279701f8 Initial revision
claus
parents:
diff changeset
   858
    | work.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   859
     ----------------------------------------------------------------"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   860
a27a279701f8 Initial revision
claus
parents:
diff changeset
   861
    | collect iRect tmp |
360
claus
parents: 359
diff changeset
   862
    iRect := self intersect: aRectangle.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   863
    (iRect = nil) ifTrue: [^nil]. "case of no intersection"
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   864
				"the collect collection gathers Rectangles"
360
claus
parents: 359
diff changeset
   865
    collect := OrderedCollection new: 4.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   866
				"is it floating or on the edge?"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   867
    (((((iRect top) ~= self top) 
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   868
	 and: [ (iRect bottom) ~= self bottom ])
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   869
	 and: [ (iRect left) ~= self left ])
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   870
	 and: [ (iRect right) ~= self right ] )
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   871
	ifTrue: "entirely in the center."
360
claus
parents: 359
diff changeset
   872
	    [tmp := Rectangle origin: (Point x: iRect left y: self top)
claus
parents: 359
diff changeset
   873
			      corner: iRect bottomRight.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   874
	     collect add: tmp.
360
claus
parents: 359
diff changeset
   875
	     iRect := iRect merge: tmp].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   876
    ((iRect left) ~= self left)
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   877
	ifTrue:                 "doesn't touch left edge so make it touch"
360
claus
parents: 359
diff changeset
   878
	    [tmp := Rectangle origin: (Point x: self left y: iRect top)
claus
parents: 359
diff changeset
   879
			      corner: iRect bottomLeft.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   880
		 collect add: tmp.
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   881
				"merge new (tmp) with overlap to keep track"
360
claus
parents: 359
diff changeset
   882
		 iRect := iRect merge: tmp].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   883
    ((iRect right) ~= self right)
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   884
	ifTrue:                 "doesn't touch right edge so extend it"
360
claus
parents: 359
diff changeset
   885
	    [tmp := Rectangle origin: iRect topRight
claus
parents: 359
diff changeset
   886
			      corner: (Point x: self right y: iRect bottom).
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   887
		 collect add: tmp.
360
claus
parents: 359
diff changeset
   888
		 iRect := iRect merge: tmp].
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   889
    (((iRect left) ~= self left) or: [(iRect top) ~= self top])
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   890
	ifTrue:                 "whole top part can be taken now"
360
claus
parents: 359
diff changeset
   891
	    [tmp := Rectangle origin: self origin corner: iRect topRight.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   892
		 collect add: tmp].
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   893
    (((iRect right) ~= self right) or: [(iRect bottom) ~= self bottom])
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   894
	ifTrue:                 "whole bottom open and can be taken"
360
claus
parents: 359
diff changeset
   895
	    [tmp := Rectangle origin: iRect bottomLeft corner: self corner.
186
a4c3032fc825 *** empty log message ***
claus
parents: 93
diff changeset
   896
		 collect add: tmp].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   897
    ^collect
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
   898
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   899
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   900
expandedBy:delta
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   901
    "return a new rectangle which is expanded in all directions
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   902
     by amount, a Point, Rectangle or Number"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   903
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   904
    ^ self copy expandBy:delta
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   905
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   906
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   907
     |r|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   908
     r := Rectangle origin:10@10 corner:100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   909
     r expandedBy:5.   
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   910
     r expandedBy:(5 @ 0).  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   911
     r expandedBy:(10 @ 10).  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   912
     r expandedBy:( 10@10 corner:20@20 )  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   913
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   914
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   915
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   916
insetBy: delta
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   917
    "return a new rectangle which is inset in all directions
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   918
     by delta, a Point, Rectangle or Number"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   919
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   920
    |amountPoint deltaLeft deltaTop deltaWidth deltaHeight|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   921
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   922
    delta isNumber ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   923
	deltaLeft := deltaTop := delta.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   924
	deltaWidth := deltaHeight := delta * 2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   925
    ] ifFalse:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   926
	delta isRectangle ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   927
	    deltaLeft := delta left.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   928
	    deltaTop := delta top.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   929
	    deltaWidth := deltaLeft + delta right.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   930
	    deltaHeight := deltaTop + delta bottom
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   931
	] ifFalse:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   932
	    amountPoint := delta asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   933
	    deltaLeft := amountPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   934
	    deltaTop := amountPoint y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   935
	    deltaWidth := deltaLeft * 2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   936
	    deltaHeight := deltaTop * 2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   937
	]
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
    ^ Rectangle left:(left + deltaLeft)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   941
		 top:(top + deltaTop)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   942
	       width:(width - deltaWidth)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   943
	      height:(height - deltaHeight)
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
     |r|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   946
     r := Rectangle origin:10@10 corner:100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   947
     r insetBy:5.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   948
     r insetBy:(5 @ 0).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   949
     r insetBy:(10 @ 10).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   950
     r insetBy:( 10@10 corner:20@20 )
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   951
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   952
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   953
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   954
insetOriginBy:originDelta cornerBy:cornerDelta
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   955
    "return a new rectangle which is inset by originDelta 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   956
     and cornerDelta; both may be instances of Point or Number"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   957
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   958
    |amountPoint deltaLeft deltaTop deltaWidth deltaHeight|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   959
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   960
    ^ Rectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   961
	origin:(left @ top) + originDelta asPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   962
	corner:(self corner - cornerDelta asPoint)
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
     |r|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   965
     r := Rectangle origin:10@10 corner:100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   966
     r insetOriginBy:5 cornerBy:10. 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   967
     r insetOriginBy:10@5 cornerBy:10.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   968
     r insetOriginBy:10 cornerBy:10@5. 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   969
     r insetOriginBy:10@10 cornerBy:20@20.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   970
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   971
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   972
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   973
intersect:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   974
    "return a new rectangle covering the intersection of the receiver
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   975
     and the argument, aRectangle.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   976
     the rectangles must intersect for a valid return"
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
    ^ Rectangle left:(left max:(aRectangle left))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   979
	       right:((left + width) min:(aRectangle right))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   980
		 top:(top max:(aRectangle top))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   981
	      bottom:((top + height) min:(aRectangle bottom))
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
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   984
     |r1 r2|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   985
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   986
     r1 := Rectangle origin:10@10 corner:100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   987
     r2 := Rectangle origin:50@50 corner:150@75.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   988
     r1 intersect:r2
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   989
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   990
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   991
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   992
merge:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   993
    "return a new rectangle covering both the receiver 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   994
     and the argument, aRectangle"
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
    ^ Rectangle left:(left min:(aRectangle left))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   997
	       right:((left + width) max:(aRectangle right))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   998
		 top:(top min:(aRectangle top))
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   999
	      bottom:((top + height) max:(aRectangle bottom))
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
77
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
  1002
nonIntersections:aRectangle
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
  1003
    "this is the same as areasOutside: - for ST/V compatibility only"
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
  1004
6c38ca59927f *** empty log message ***
claus
parents: 59
diff changeset
  1005
    ^ self areasOutside:aRectangle
637
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
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1008
rounded
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1009
    "return a copy of the receiver with rounded coordinates"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1010
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1011
    ^ Rectangle left:(left rounded) 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1012
		 top:(top rounded)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1013
	       width:(width rounded) 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1014
	      height:(height rounded)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1015
!
356
claus
parents: 329
diff changeset
  1016
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1017
scaledBy:scale
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1018
    "return a new rectangle which is the receiver
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1019
     scaled by scale"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1020
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1021
    |scalePoint sx sy|
356
claus
parents: 329
diff changeset
  1022
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1023
    scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1024
    sx := scalePoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1025
    sy := scalePoint y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1026
    ^ Rectangle left:left * sx
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1027
		 top:top * sy
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1028
	       width:(width * sx)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1029
	      height:(height * sy)
356
claus
parents: 329
diff changeset
  1030
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1031
     (Rectangle origin:10@10 corner:50@50) scaledBy:2   
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1032
    "
356
claus
parents: 329
diff changeset
  1033
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1034
    "its NOT destructive:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1035
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1036
     |r1 r2|
356
claus
parents: 329
diff changeset
  1037
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1038
     r1 := Rectangle origin:10@10 corner:50@50.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1039
     r2 := r1 scaledBy:2.    
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1040
     r1  
356
claus
parents: 329
diff changeset
  1041
    "
claus
parents: 329
diff changeset
  1042
!
claus
parents: 329
diff changeset
  1043
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1044
translatedBy:amount
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1045
    "return a new rectangle which is translated (i.e. moved)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1046
     by amount, aPoint or Number"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1047
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1048
    |amountPoint|
356
claus
parents: 329
diff changeset
  1049
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1050
    amountPoint := amount asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1051
    ^ Rectangle left:(left + amountPoint x) 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1052
		 top:(top + amountPoint y)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1053
	       width:width
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1054
	      height:height
356
claus
parents: 329
diff changeset
  1055
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1056
     (Rectangle origin:10@10 corner:50@50) translatedBy:10
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1057
    "
356
claus
parents: 329
diff changeset
  1058
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1059
    "its NOT destructive:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1060
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1061
     |r1 r2|
356
claus
parents: 329
diff changeset
  1062
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1063
     r1 := Rectangle origin:10@10 corner:50@50.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1064
     r2 := r1 translatedBy:10.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1065
     r1 
356
claus
parents: 329
diff changeset
  1066
    "
claus
parents: 329
diff changeset
  1067
! !
claus
parents: 329
diff changeset
  1068
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1069
!Rectangle methodsFor:'testing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1070
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1071
contains:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1072
    "return true, if the argument, aRectangle is equal to or
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1073
     is contained fully within the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1074
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1075
    (left <= aRectangle left) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1076
      ((left + width) >= aRectangle right) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1077
	(top <= aRectangle top) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1078
	  ((top + height) >= aRectangle bottom) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1079
	    ^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1080
	  ]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1081
	]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1082
      ]
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
    ^ false
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1085
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1086
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1087
containsPoint:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1088
    "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
  1089
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1090
    |px py|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1091
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1092
    px := aPoint x.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1093
    (px < left)           ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1094
    (px > (left + width)) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1095
    py := aPoint y.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1096
    (py < top)            ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1097
    (py > (top + height)) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1098
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1099
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1100
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1101
containsPointX:x y:y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1102
    "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
  1103
     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
  1104
     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
  1105
     temporary point."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1106
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1107
    (x < left)           ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1108
    (x > (left + width)) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1109
    (y < top)            ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1110
    (y > (top + height)) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1111
    ^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1112
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1113
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1114
intersects:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1115
    "return true, if the intersection between the argument, aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1116
     and the receiver is not empty"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1117
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1118
    |b r|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1119
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1120
    (aRectangle right)  < left ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1121
    (aRectangle bottom) < top  ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1122
    r := left + width.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1123
    (aRectangle left)   > r    ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1124
    b := top + height.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1125
    (aRectangle top)    > b    ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1126
    ^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1127
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1128
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1129
isContainedIn:aRectangle
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1130
    "return true, if the receiver is fully contained within 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1131
     the argument, aRectangle"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1132
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1133
    (aRectangle left <= left) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1134
      (aRectangle right >= (left + width)) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1135
	(aRectangle top <= top) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1136
	  (aRectangle bottom >= (top + height)) ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1137
	    ^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1138
	  ]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1139
	]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1140
      ]
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1141
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1142
    ^ false
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1143
! !
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1144
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1145
!Rectangle class methodsFor:'documentation'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1146
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1147
version
829
fc386319f41c removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents: 637
diff changeset
  1148
    ^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.29 1996-01-04 01:23:33 cg Exp $'
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1149
! !