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