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