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