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