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