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