author | Claus Gittinger <cg@exept.de> |
Wed, 28 Jan 1998 17:44:42 +0100 | |
changeset 3238 | f96eaf89d55d |
parent 2894 | 344aec8ba014 |
child 3488 | 6e1feb9ead68 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
180 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ArithmeticValue subclass:#Point |
|
1245 | 14 |
instanceVariableNames:'x y' |
15 |
classVariableNames:'PointZero PointOne' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Geometry' |
|
1 | 18 |
! |
19 |
||
2273 | 20 |
!Point class methodsFor:'documentation'! |
77 | 21 |
|
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
180 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
77 | 36 |
documentation |
37 |
" |
|
38 |
I represent a point in 2D space. Or I can be used to represent |
|
39 |
an extent (of a rectangle, for example), in which case my x-coordinate |
|
40 |
represents the width, and y-coordinate the height of something. |
|
41 |
||
42 |
The x and y coordinate are usually numbers. |
|
43 |
||
1290 | 44 |
[Instance variables:] |
77 | 45 |
|
1290 | 46 |
x <Number> the x-coordinate of myself |
47 |
y <Number> the y-coordinate of myself |
|
48 |
||
49 |
[author:] |
|
50 |
Claus Gittinger |
|
1314 | 51 |
|
52 |
[see also:] |
|
53 |
Rectangle Polygon |
|
54 |
LayoutOrigin LayoutFrame AlignmentOrigin Layout |
|
55 |
View GraphicsContext |
|
77 | 56 |
" |
57 |
! ! |
|
58 |
||
2273 | 59 |
!Point class methodsFor:'initialization'! |
1 | 60 |
|
61 |
initialize |
|
302 | 62 |
PointZero isNil ifTrue:[ |
63 |
PointZero := 0 @ 0. |
|
64 |
PointOne := 1 @ 1 |
|
65 |
] |
|
1 | 66 |
! ! |
67 |
||
2273 | 68 |
!Point class methodsFor:'instance creation'! |
1 | 69 |
|
3238
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
70 |
decodeFromLiteralArray:anArray |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
71 |
"create & return a new instance from information encoded in anArray. |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
72 |
Redefined for faster creation." |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
73 |
|
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
74 |
^ self x:(anArray at:2) y:(anArray at:3) |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
75 |
|
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
76 |
" |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
77 |
Point |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
78 |
decodeFromLiteralArray:#(Point 10 10) |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
79 |
" |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
80 |
|
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
81 |
"Created: / 28.1.1998 / 17:44:08 / cg" |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
82 |
! |
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
83 |
|
1354 | 84 |
r:distance angle:angle |
85 |
"create and return a new point given polar coordinates. |
|
86 |
The angle is given in degrees" |
|
87 |
||
88 |
|x y rad| |
|
89 |
||
90 |
rad := angle degreesToRadians. |
|
91 |
x := distance * rad cos. |
|
92 |
y := distance * rad sin. |
|
93 |
^ x @ y |
|
94 |
||
95 |
" |
|
96 |
Point r:100 angle:0 |
|
97 |
Point r:100 angle:90 |
|
98 |
Point r:100 angle:45 |
|
99 |
Point r:100 angle:180 |
|
100 |
" |
|
101 |
||
102 |
"Modified: 8.5.1996 / 20:01:50 / cg" |
|
103 |
! |
|
104 |
||
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
105 |
r:distance theta:angleInRadians |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
106 |
"create and return a new point given polar coordinates. |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
107 |
The angle is given in radians" |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
108 |
|
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
109 |
|x y| |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
110 |
|
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
111 |
x := distance * angleInRadians cos. |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
112 |
y := distance * angleInRadians sin. |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
113 |
^ x @ y |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
114 |
|
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
115 |
" |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
116 |
Point r:100 theta:0 |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
117 |
" |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
118 |
|
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
119 |
"Modified: 2.4.1997 / 00:01:40 / cg" |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
120 |
! |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
121 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
122 |
readFrom:aStringOrStream onError:exceptionBlock |
1 | 123 |
"return the next Point from the (character-)stream aStream; |
202 | 124 |
skipping all whitespace first; return the value of exceptionBlock, |
125 |
if no point can be read." |
|
1 | 126 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
127 |
ErrorSignal handle:[:ex | |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
128 |
^ exceptionBlock value |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
129 |
] do:[ |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
130 |
|str newX newY| |
1 | 131 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
132 |
str := aStringOrStream readStream. |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
133 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
134 |
newX := Number readFrom:str onError:nil. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
135 |
newX notNil ifTrue:[ |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
136 |
(str skipSeparators == $@) ifTrue:[ |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
137 |
str next. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
138 |
newY := Number readFrom:str onError:nil. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
139 |
newY notNil ifTrue:[ |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
140 |
^ self x:newX y:newY |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
141 |
] |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
142 |
] |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
143 |
]. |
345 | 144 |
]. |
145 |
^ exceptionBlock value |
|
77 | 146 |
|
202 | 147 |
" |
148 |
Point readFrom:('1.234 @ 5.678' readStream) |
|
345 | 149 |
Point readFrom:('1' readStream) |
150 |
Point readFrom:('1' readStream) onError:[1@1] |
|
202 | 151 |
Point readFrom:('fooBar' readStream) onError:[0@0] |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
152 |
" |
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
153 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
154 |
"Modified: 8.10.1996 / 19:31:39 / cg" |
637 | 155 |
! |
156 |
||
157 |
x:newX y:newY |
|
158 |
"create and return a new point with coordinates newX and newY" |
|
159 |
||
160 |
%{ /* NOCONTEXT */ |
|
161 |
||
162 |
/* |
|
163 |
* claus: I am no longer certain, if this primitive is worth the effort |
|
164 |
*/ |
|
2894 | 165 |
if (__CanDoQuickNew(sizeof(struct __point))) { /* OBJECT ALLOCATION */ |
1133 | 166 |
if (self == @global(Point)) { |
637 | 167 |
OBJ newPoint; |
168 |
int spc; |
|
169 |
||
835 | 170 |
__qCheckedAlignedNew(newPoint, sizeof(struct __point)); |
1133 | 171 |
__InstPtr(newPoint)->o_class = self; |
172 |
__PointInstPtr(newPoint)->p_x = newX; |
|
173 |
__PointInstPtr(newPoint)->p_y = newY; |
|
637 | 174 |
if (! __bothSmallInteger(newX, newY)) { |
175 |
spc = __qSpace(newPoint); |
|
176 |
__STORE_SPC(newPoint, newX, spc); |
|
177 |
__STORE_SPC(newPoint, newY, spc); |
|
178 |
} |
|
179 |
RETURN ( newPoint ); |
|
180 |
} |
|
181 |
} |
|
1133 | 182 |
%}. |
637 | 183 |
^ (self basicNew) x:newX y:newY |
1 | 184 |
! ! |
185 |
||
2273 | 186 |
!Point class methodsFor:'constants'! |
356 | 187 |
|
637 | 188 |
unity |
189 |
"return the neutral element for multiplication" |
|
190 |
||
191 |
^ PointOne |
|
192 |
! |
|
193 |
||
356 | 194 |
zero |
195 |
"return the neutral element for addition" |
|
196 |
||
197 |
^ PointZero |
|
198 |
! ! |
|
199 |
||
2273 | 200 |
!Point class methodsFor:'queries'! |
356 | 201 |
|
202 |
isBuiltInClass |
|
1264 | 203 |
"return true if this class is known by the run-time-system. |
204 |
Here, true is returned for myself, false for subclasses." |
|
356 | 205 |
|
206 |
^ self == Point |
|
1264 | 207 |
|
208 |
"Modified: 23.4.1996 / 16:00:18 / cg" |
|
356 | 209 |
! ! |
210 |
||
637 | 211 |
!Point methodsFor:'accessing'! |
212 |
||
213 |
x |
|
214 |
"return the x coordinate" |
|
215 |
||
216 |
^ x |
|
217 |
! |
|
356 | 218 |
|
637 | 219 |
x:newX |
220 |
"set the x coordinate to be the argument, aNumber. |
|
221 |
This is destructive (modifies the receiver, not a copy) and |
|
222 |
should only be used if you know, that you are the exclusive owner |
|
223 |
of the receiver." |
|
356 | 224 |
|
637 | 225 |
x := newX |
356 | 226 |
! |
227 |
||
637 | 228 |
x:newX y:newY |
229 |
"set both the x and y coordinates. |
|
230 |
This is destructive (modifies the receiver, not a copy) and |
|
231 |
should only be used if you know, that you are the exclusive owner |
|
232 |
of the receiver." |
|
1 | 233 |
|
637 | 234 |
x := newX. |
235 |
y := newY |
|
236 |
! |
|
237 |
||
238 |
y |
|
239 |
"return the y coordinate" |
|
240 |
||
241 |
^ y |
|
356 | 242 |
! |
243 |
||
637 | 244 |
y:newY |
245 |
"set the y coordinate to be the argument, aNumber. |
|
246 |
This is destructive (modifies the receiver, not a copy) and |
|
247 |
should only be used if you know, that you are the exclusive owner |
|
248 |
of the receiver." |
|
356 | 249 |
|
637 | 250 |
y := newY |
251 |
! ! |
|
252 |
||
253 |
!Point methodsFor:'coercing'! |
|
254 |
||
255 |
coerce:anObject |
|
256 |
"return aNumber converted into receivers type" |
|
257 |
||
258 |
^ anObject asPoint |
|
356 | 259 |
! |
1 | 260 |
|
637 | 261 |
generality |
262 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
263 |
||
264 |
^ 120 |
|
265 |
! ! |
|
356 | 266 |
|
637 | 267 |
!Point methodsFor:'comparing'! |
268 |
||
269 |
< aPoint |
|
270 |
"return true if the receiver is above and to the left |
|
271 |
of the argument, aPoint" |
|
272 |
||
273 |
|p| |
|
356 | 274 |
|
637 | 275 |
p := aPoint asPoint. |
1339 | 276 |
x < (p x) ifTrue:[ |
277 |
y < (p y) ifTrue:[^ true]. |
|
278 |
]. |
|
279 |
^ false |
|
280 |
||
281 |
"notice the funny result if one coordinate has the same value ... |
|
282 |
||
283 |
(3@4) < (4@4) |
|
284 |
(3@4) <= (4@4) |
|
285 |
(3@4) > (4@4) |
|
286 |
(4@4) >= (3@4) |
|
287 |
(4@4) > (3@4) |
|
288 |
" |
|
289 |
||
290 |
"Modified: 7.5.1996 / 12:14:25 / cg" |
|
637 | 291 |
! |
292 |
||
293 |
= aPoint |
|
294 |
"return true if the receiver represents the same point as |
|
295 |
the argument, aPoint" |
|
356 | 296 |
|
637 | 297 |
|p| |
298 |
||
299 |
(aPoint isMemberOf:Point) ifTrue:[ "this is a hint to STC" |
|
300 |
x ~= (aPoint x) ifTrue:[^ false]. |
|
301 |
y ~= (aPoint y) ifTrue:[^ false]. |
|
302 |
^ true |
|
303 |
]. |
|
304 |
aPoint respondsToArithmetic ifFalse:[ ^ false]. |
|
305 |
p := aPoint asPoint. |
|
306 |
x ~= (p x) ifTrue:[^ false]. |
|
307 |
y ~= (p y) ifTrue:[^ false]. |
|
308 |
^ true |
|
1 | 309 |
! |
310 |
||
637 | 311 |
> aPoint |
312 |
"return true if the receiver is below and to the right |
|
313 |
of the argument, aPoint" |
|
314 |
||
315 |
|p| |
|
356 | 316 |
|
637 | 317 |
p := aPoint asPoint. |
1339 | 318 |
(p x) < x ifTrue:[ |
319 |
(p y) < y ifTrue:[^ true]. |
|
320 |
]. |
|
321 |
^ false |
|
322 |
||
323 |
"Modified: 7.5.1996 / 12:11:15 / cg" |
|
637 | 324 |
! |
356 | 325 |
|
637 | 326 |
hash |
327 |
"return a number for hashing" |
|
356 | 328 |
|
637 | 329 |
x = y ifTrue:[^ x hash]. |
330 |
" |
|
331 |
used to be: |
|
332 |
^ (x hash) bitXor:(y hash) |
|
333 |
the following handles 1@x vs. x@1 better: |
|
334 |
" |
|
335 |
^ (x hash) bitXor:(y hash bitShift:12) |
|
336 |
! |
|
356 | 337 |
|
637 | 338 |
max:aPoint |
339 |
"return the lower right corner of the rectangle uniquely defined by |
|
340 |
the receiver and the argument, aPoint" |
|
341 |
||
342 |
|p maxX maxY| |
|
356 | 343 |
|
637 | 344 |
p := aPoint asPoint. |
345 |
maxX := x max:(p x). |
|
346 |
maxY := y max:(p y). |
|
347 |
^ maxX @ maxY |
|
348 |
! |
|
349 |
||
350 |
min:aPoint |
|
351 |
"return the upper left corner of the rectangle uniquely defined by |
|
352 |
the receiver and the argument, aPoint" |
|
353 |
||
354 |
|p minX minY| |
|
355 |
||
356 |
p := aPoint asPoint. |
|
357 |
minX := x min:(p x). |
|
358 |
minY := y min:(p y). |
|
359 |
^ minX @ minY |
|
356 | 360 |
! ! |
361 |
||
362 |
!Point methodsFor:'converting'! |
|
363 |
||
637 | 364 |
asFractionalLayout |
365 |
"return a LayoutOrigin from the receiver, |
|
366 |
treating the receiver coordinates as fractional parts |
|
367 |
(i.e. relative to superview). |
|
368 |
Notice: in 10.5.x LayoutOrigin is not yet officially released." |
|
369 |
||
370 |
^ LayoutOrigin fractionalFromPoint:self |
|
356 | 371 |
|
637 | 372 |
" |
373 |
(0@0.5) asFractionalLayout |
|
374 |
(0@0.5) asLayout |
|
375 |
(0@10) asLayout |
|
376 |
(0@10) asOffsetLayout |
|
377 |
" |
|
356 | 378 |
|
379 |
! |
|
1 | 380 |
|
356 | 381 |
asLayout |
382 |
"return a LayoutOrigin from the receiver. |
|
383 |
If the receiver coordinates are between 0 and 1, take |
|
384 |
them as fractional parts (relative to superview). |
|
385 |
Otherwise, treat them as absolute offsets. |
|
386 |
Notice: in 10.5.x LayoutOrigin is not yet released." |
|
387 |
||
388 |
^ LayoutOrigin fromPoint:self |
|
389 |
||
390 |
" |
|
391 |
(0@0.5) asFractionalLayout |
|
392 |
(0@0.5) asLayout |
|
393 |
(0@10) asLayout |
|
394 |
(0@10) asOffsetLayout |
|
395 |
" |
|
396 |
||
397 |
! |
|
398 |
||
399 |
asOffsetLayout |
|
400 |
"return a LayoutOrigin from the receiver, |
|
401 |
treating the receiver coordinates as absolute offsets. |
|
402 |
Notice: in 10.5.x LayoutOrigin is not yet released." |
|
403 |
||
404 |
^ LayoutOrigin offsetFromPoint:self |
|
405 |
||
406 |
" |
|
407 |
(0@0.5) asFractionalLayout |
|
408 |
(0@0.5) asLayout |
|
409 |
(0@10) asLayout |
|
410 |
(0@10) asOffsetLayout |
|
411 |
" |
|
412 |
||
1 | 413 |
! |
414 |
||
637 | 415 |
asPoint |
416 |
"return the receiver as Point - this is the receiver" |
|
356 | 417 |
|
637 | 418 |
^ self |
356 | 419 |
! |
420 |
||
421 |
asRectangle |
|
422 |
"return a zero-width rectangle consisting of origin |
|
423 |
and corner being the receiver" |
|
424 |
||
425 |
^ self corner:self |
|
426 |
||
427 |
" |
|
428 |
(0@10) asRectangle |
|
429 |
" |
|
430 |
! |
|
431 |
||
637 | 432 |
corner:aPoint |
433 |
"return a rectangle whose origin is self and corner is aPoint" |
|
434 |
||
435 |
^ Rectangle origin:self corner:aPoint |
|
436 |
! |
|
437 |
||
438 |
extent:aPoint |
|
439 |
"return a rectangle whose origin is self and extent is aPoint" |
|
356 | 440 |
|
637 | 441 |
^ Rectangle origin:self extent:aPoint |
442 |
! |
|
443 |
||
444 |
fromLiteralArrayEncoding:encoding |
|
445 |
"read my values from an encoding. |
|
446 |
The encoding is supposed to be of the form: (Point xValue yValue)" |
|
447 |
||
448 |
x := encoding at:2. |
|
449 |
y := encoding at:3. |
|
356 | 450 |
|
451 |
" |
|
637 | 452 |
Point new fromLiteralArrayEncoding:#(Point 10 20) |
356 | 453 |
" |
379 | 454 |
! |
455 |
||
421 | 456 |
literalArrayEncoding |
1245 | 457 |
"encode myself as an array, from which a copy of the receiver |
458 |
can be reconstructed with #decodeAsLiteralArray. |
|
421 | 459 |
The encoding is: (Point xValue yValue)" |
460 |
||
461 |
^ Array |
|
1245 | 462 |
with:#Point |
463 |
with:x |
|
464 |
with:y |
|
421 | 465 |
|
466 |
||
467 |
" |
|
468 |
Point new fromLiteralArrayEncoding:#(Point 10 20) |
|
469 |
(10@20) literalArrayEncoding |
|
470 |
" |
|
471 |
||
472 |
"Modified: 1.9.1995 / 02:18:29 / claus" |
|
1245 | 473 |
"Modified: 22.4.1996 / 13:00:32 / cg" |
421 | 474 |
! |
475 |
||
637 | 476 |
rectangleRelativeTo:aRectangle preferred:prefRect |
477 |
"compute a displayRectangle, treating the receiver like a |
|
478 |
layoutorigin. This allows point to be used interchangable with |
|
479 |
LayoutOrigins." |
|
379 | 480 |
|
637 | 481 |
^ (self asLayout) rectangleRelativeTo:aRectangle preferred:prefRect |
379 | 482 |
|
483 |
" |
|
637 | 484 |
consider the case, where a view has a preferred extent of 50@50 |
485 |
and is to be positioned in its superview which has size 100@100. |
|
486 |
For absolute origin: |
|
487 |
(10@20) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) |
|
1 | 488 |
|
637 | 489 |
for relative origin: |
490 |
(0.5@0.5) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) |
|
491 |
" |
|
1 | 492 |
! ! |
493 |
||
77 | 494 |
!Point methodsFor:'destructive transformations'! |
495 |
||
496 |
scaleBy:aScale |
|
497 |
"scale the receiver, by replacing coordinates by the product |
|
180 | 498 |
of the receivers coordinates and the scale (a Point or Number). |
499 |
This is destructive (modifies the receiver, not a copy) and |
|
500 |
should only be used if you know, that you are the exclusive owner |
|
501 |
of the receiver." |
|
77 | 502 |
|
503 |
|scalePoint| |
|
504 |
||
180 | 505 |
(aScale isMemberOf:Point) ifTrue:[ "type hint to stc" |
506 |
x := x * aScale x. |
|
507 |
y := y * aScale y. |
|
508 |
^ self |
|
77 | 509 |
]. |
510 |
aScale isNumber ifTrue:[ |
|
180 | 511 |
x := x * aScale. |
512 |
y := y * aScale. |
|
513 |
^ self |
|
77 | 514 |
]. |
515 |
||
516 |
"this is the general (& clean) code ..." |
|
517 |
||
518 |
scalePoint := aScale asPoint. |
|
519 |
x := x * scalePoint x. |
|
520 |
y := y * scalePoint y |
|
521 |
! |
|
522 |
||
523 |
translateBy:anOffset |
|
524 |
"translate the receiver, by replacing coordinates by the sum |
|
180 | 525 |
of the receivers coordinated and the scale (a Point or Number). |
526 |
This is destructive (modifies the receiver, not a copy) and |
|
527 |
should only be used if you know, that you are the exclusive owner |
|
528 |
of the receiver." |
|
77 | 529 |
|
530 |
|offsetPoint| |
|
531 |
||
180 | 532 |
(anOffset isMemberOf:Point) ifTrue:[ "type hint to stc" |
533 |
x := x + anOffset x. |
|
534 |
y := y + anOffset y. |
|
535 |
^ self |
|
77 | 536 |
]. |
537 |
anOffset isNumber ifTrue:[ |
|
180 | 538 |
x := x + anOffset. |
539 |
y := y + anOffset. |
|
540 |
^ self |
|
77 | 541 |
]. |
542 |
||
543 |
"this is the general (& clean) code ..." |
|
544 |
||
545 |
offsetPoint := anOffset asPoint. |
|
546 |
x := x + anOffset x. |
|
547 |
y := y + anOffset y |
|
548 |
! ! |
|
549 |
||
637 | 550 |
!Point methodsFor:'misc'! |
551 |
||
552 |
abs |
|
553 |
"return a new point with my coordinates taken from the absolute values." |
|
554 |
||
555 |
^ (x abs) @ (y abs) |
|
556 |
! |
|
557 |
||
558 |
quadrant |
|
559 |
"return the number of the quadrant containing the receiver. |
|
560 |
quadrants are named as follows: |
|
356 | 561 |
|
637 | 562 |
^ 2 | 3 |
563 |
Y ------ |
|
564 |
1 | 0 |
|
565 |
||
566 |
X > |
|
567 |
||
568 |
Q: what is to be returned if any coordinate is 0 ? |
|
569 |
" |
|
77 | 570 |
|
637 | 571 |
^ 0@0 quadrantContaining:self |
572 |
||
573 |
" |
|
574 |
(0@0) quadrant |
|
575 |
(1@1) quadrant |
|
576 |
(-1@1) quadrant |
|
577 |
(-1@-1) quadrant |
|
578 |
(1@-1) quadrant |
|
579 |
" |
|
356 | 580 |
! |
77 | 581 |
|
637 | 582 |
quadrantContaining:aPoint |
583 |
"return the number of the quadrant containing aPoint placing |
|
584 |
the receiver at the origin, where the quadrants are numbered as |
|
585 |
follows: |
|
586 |
^ 2 | 3 |
|
587 |
Y ------ |
|
588 |
1 | 0 |
|
589 |
||
590 |
X > |
|
591 |
This can be used for polygon operations (see Foley for examples). |
|
592 |
" |
|
593 |
||
594 |
aPoint x > x ifTrue:[ |
|
595 |
aPoint y >= y ifTrue:[^ 3]. |
|
596 |
^ 0 |
|
597 |
]. |
|
598 |
aPoint y >= y ifTrue: [^ 2]. |
|
599 |
^ 1 |
|
356 | 600 |
|
637 | 601 |
" |
602 |
(10 @ 10) quadrantContaining:(15 @ 15) |
|
603 |
(10 @ 10) quadrantContaining:(5 @ 5) |
|
604 |
(10 @ 10) quadrantContaining:(5 @ 15) |
|
605 |
(10 @ 10) quadrantContaining:(15 @ 5) |
|
606 |
" |
|
607 |
! |
|
608 |
||
609 |
rounded |
|
610 |
"return a new point with my coordinates rounded to the next integer |
|
611 |
coordinated (use for gridding) or the receiver of already rounded." |
|
612 |
||
613 |
(x isInteger and:[y isInteger]) ifTrue:[^ self]. |
|
614 |
^ (x rounded) @ (y rounded) |
|
615 |
! |
|
616 |
||
617 |
truncated |
|
618 |
"return a new point with my coordinates truncated as integer or the |
|
619 |
receiver, if already truncated." |
|
620 |
||
621 |
(x isInteger and:[y isInteger]) ifTrue:[^ self]. |
|
622 |
^ (x truncated) @ (y truncated) |
|
77 | 623 |
! ! |
624 |
||
356 | 625 |
!Point methodsFor:'point functions'! |
1 | 626 |
|
627 |
dist:aPoint |
|
628 |
"return the distance between aPoint and the receiver." |
|
629 |
||
630 |
^ (aPoint - self) r |
|
631 |
! |
|
632 |
||
633 |
dotProduct:aPoint |
|
57 | 634 |
"return a number that is the dot product of the receiver and |
1 | 635 |
the argument, aPoint. That is, the two points are |
57 | 636 |
multiplied and the coordinates of the result summed." |
1 | 637 |
|
638 |
|temp| |
|
639 |
||
640 |
temp := self * aPoint. |
|
641 |
^ temp x abs + temp y abs |
|
642 |
! |
|
643 |
||
644 |
grid:gridPoint |
|
645 |
"return a new point with coordinates grided (i.e. rounded to the |
|
646 |
nearest point on the grid)" |
|
647 |
||
648 |
|newX newY gridX gridY| |
|
649 |
||
650 |
gridX := gridPoint x. |
|
651 |
(gridX <= 1) ifTrue:[ |
|
180 | 652 |
newX := x asInteger |
1 | 653 |
] ifFalse:[ |
180 | 654 |
newX := ((x + (gridX // 2)) // gridX) * gridX |
1 | 655 |
]. |
656 |
gridY := gridPoint y. |
|
657 |
(gridY <= 1) ifTrue:[ |
|
180 | 658 |
newY := y asInteger |
1 | 659 |
] ifFalse:[ |
180 | 660 |
newY := ((y + (gridY // 2)) // gridY) * gridY |
1 | 661 |
]. |
662 |
^ newX @ newY |
|
77 | 663 |
! |
664 |
||
276 | 665 |
nearestIntegerPointOnLineFrom: point1 to: point2 |
666 |
"return the closest integer point to the receiver on the line |
|
667 |
determined by (point1, point2)--much faster than the more |
|
668 |
accurate version if the receiver and arguments are integer points. |
|
669 |
This method was found in the Manchester goody library." |
|
670 |
||
671 |
| dX dY newX newY dX2 dY2 intersect scale coeff | |
|
672 |
||
673 |
dX := point2 x - point1 x. |
|
674 |
dY := point2 y - point1 y. |
|
675 |
(dX = 0)ifTrue: [ |
|
676 |
(dY = 0) ifTrue: [ |
|
677 |
intersect := point1 |
|
678 |
] ifFalse: [ |
|
679 |
newX := point1 x. |
|
680 |
scale := (y - point1 y) / dY. |
|
359 | 681 |
scale > 1 ifTrue:[ |
682 |
newY := point2 y |
|
683 |
] ifFalse: [ |
|
684 |
scale < 0 ifTrue: [ |
|
685 |
newY := point1 y |
|
686 |
] ifFalse: [ |
|
687 |
newY := y |
|
688 |
] |
|
689 |
]. |
|
276 | 690 |
|
691 |
^ (newX @ newY) rounded |
|
692 |
] |
|
693 |
] ifFalse: [ |
|
694 |
(dY = 0) ifTrue: [ |
|
695 |
intersect := x @ point1 y |
|
696 |
] ifFalse:[ |
|
697 |
dX2 := dX * dX. |
|
698 |
dY2 := dY * dY. |
|
699 |
coeff := ((dX * (y - point1 y)) - |
|
700 |
((x - point1 x) * dY)) / (dX2 + dY2). |
|
701 |
newX := x + (dY * coeff). |
|
702 |
newY := y - (dX * coeff). |
|
703 |
intersect := newX @ newY |
|
704 |
] |
|
705 |
]. |
|
706 |
||
707 |
scale := (intersect x - point1 x) / dX. |
|
708 |
||
709 |
^ (scale > 1 ifTrue: [point2] ifFalse: [ |
|
710 |
scale < 0 ifTrue: [point1] ifFalse: [intersect]]) rounded |
|
711 |
||
712 |
" |
|
713 |
120@40 nearestIntegerPointOnLineFrom: 30@120 to: 100@120 |
|
714 |
0@0 nearestIntegerPointOnLineFrom: 10@10 to: 100@100 |
|
715 |
" |
|
1 | 716 |
! ! |
717 |
||
356 | 718 |
!Point methodsFor:'polar coordinates'! |
719 |
||
637 | 720 |
angle |
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
721 |
"return the receiver's angle (in degrees) in a polar coordinate system. |
637 | 722 |
(i.e. the angle of a vector from 0@0 to the receiver). |
723 |
OBSOLETE ST/X interface; use theta for ST-80 compatibility." |
|
724 |
||
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
725 |
^ self theta radiansToDegrees |
637 | 726 |
|
727 |
" |
|
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
728 |
(1@1) angle |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
729 |
(2@1) angle |
637 | 730 |
" |
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
731 |
|
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
732 |
"Modified: 2.4.1997 / 00:02:17 / cg" |
637 | 733 |
! |
734 |
||
356 | 735 |
r |
736 |
"return the receiver's radius in a polar coordinate system. |
|
737 |
(i.e. the length of a vector from 0@0 to the receiver)" |
|
738 |
||
2578 | 739 |
^ ((x*x) + (y*y)) sqrt |
1 | 740 |
|
356 | 741 |
" |
2578 | 742 |
(1@1) r |
743 |
(2@1) r |
|
744 |
(2@0) r |
|
745 |
(0@2) r |
|
746 |
(-2@-2) r |
|
747 |
(2@2) r |
|
356 | 748 |
" |
1 | 749 |
! |
750 |
||
356 | 751 |
theta |
752 |
"return the receiver's angle (in radians) in a polar coordinate system. |
|
753 |
(i.e. the angle of a vector from 0@0 to the receiver)" |
|
1 | 754 |
|
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
755 |
|theta t| |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
756 |
|
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
757 |
x = 0 ifTrue:[ |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
758 |
y >= 0 ifTrue:[ |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
759 |
^ Float pi * 0.5 |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
760 |
]. |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
761 |
^ Float pi * 1.5. |
356 | 762 |
]. |
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
763 |
|
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
764 |
t := y asFloat / x asFloat. |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
765 |
theta := t arcTan. |
356 | 766 |
x < 0 ifTrue:[ |
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
767 |
^ theta +Float pi |
356 | 768 |
]. |
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
769 |
theta < 0 ifTrue:[ |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
770 |
^ theta + (Float pi * 2.0) |
356 | 771 |
]. |
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
772 |
^ theta. |
356 | 773 |
" |
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
774 |
(1@1) theta |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
775 |
(2@1) theta |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
776 |
(-2@1) theta |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
777 |
(-2@-1) theta |
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
778 |
(0@-1) theta |
356 | 779 |
" |
2517
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
780 |
|
e8d65844587e
fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents:
2273
diff
changeset
|
781 |
"Modified: 2.4.1997 / 00:15:12 / cg" |
1 | 782 |
! ! |
356 | 783 |
|
637 | 784 |
!Point methodsFor:'printing & storing'! |
785 |
||
786 |
printOn:aStream |
|
787 |
"append a printed representation of the receiver to aStream" |
|
788 |
||
789 |
x printOn:aStream. |
|
790 |
aStream nextPut:$@. |
|
791 |
y printOn:aStream |
|
792 |
! |
|
793 |
||
794 |
storeOn:aStream |
|
795 |
"append my storeString to aStream" |
|
796 |
||
797 |
aStream nextPut:$(. |
|
798 |
x storeOn:aStream. |
|
799 |
aStream nextPut:$@. |
|
800 |
y storeOn:aStream. |
|
801 |
aStream nextPut:$) |
|
802 |
! ! |
|
803 |
||
804 |
!Point methodsFor:'queries'! |
|
805 |
||
806 |
isPoint |
|
807 |
"return true, if the receiver is some kind of point" |
|
808 |
||
809 |
^ true |
|
810 |
! ! |
|
811 |
||
812 |
!Point methodsFor:'transformations'! |
|
813 |
||
814 |
* scale |
|
815 |
"Return a new Point that is the product of the |
|
816 |
receiver and scale (which is a Point or Number)." |
|
817 |
||
818 |
|scalePoint| |
|
819 |
||
820 |
"speedup for common cases ..." |
|
821 |
||
822 |
(scale isMemberOf:Point) ifTrue:[ |
|
2273 | 823 |
^ Point x:(x * scale x) y:(y * scale y) |
637 | 824 |
]. |
825 |
(scale isMemberOf:SmallInteger) ifTrue:[ |
|
2273 | 826 |
^ Point x:(x * scale) y:(y * scale) |
637 | 827 |
]. |
828 |
scale isNumber ifTrue:[ |
|
2273 | 829 |
^ Point x:(x * scale) y:(y * scale) |
637 | 830 |
]. |
831 |
||
832 |
"this is the general (& clean) code ..." |
|
833 |
||
834 |
scalePoint := scale asPoint. |
|
835 |
^ (x * scalePoint x) @ (y * scalePoint y) |
|
2273 | 836 |
|
837 |
"Modified: 25.1.1997 / 17:28:11 / cg" |
|
637 | 838 |
! |
839 |
||
840 |
+ scale |
|
841 |
"Return a new Point that is the sum of the |
|
842 |
receiver and scale (which is a Point or Number)." |
|
843 |
||
844 |
|scalePoint| |
|
845 |
||
846 |
"speedup for common cases ..." |
|
847 |
||
848 |
(scale isMemberOf:Point) ifTrue:[ |
|
2273 | 849 |
^ Point x:(x + scale x) y:(y + scale y) |
637 | 850 |
]. |
851 |
(scale isMemberOf:SmallInteger) ifTrue:[ |
|
2273 | 852 |
"/ same as below, but stc can do better here |
853 |
^ Point x:(x + scale) y:(y + scale) |
|
637 | 854 |
]. |
855 |
scale isNumber ifTrue:[ |
|
2273 | 856 |
^ Point x:(x + scale) y:(y + scale) |
637 | 857 |
]. |
858 |
||
859 |
"this is the general (& clean) code ..." |
|
860 |
||
861 |
scalePoint := scale asPoint. |
|
862 |
^ (x + scalePoint x) @ (y + scalePoint y) |
|
2273 | 863 |
|
864 |
"Modified: 25.1.1997 / 17:27:46 / cg" |
|
637 | 865 |
! |
866 |
||
867 |
- scale |
|
868 |
"Return a new Point that is the difference of the |
|
869 |
receiver and scale (which is a Point or Number)." |
|
870 |
||
871 |
|scalePoint| |
|
872 |
||
873 |
"speedup for common cases ..." |
|
874 |
||
875 |
(scale isMemberOf:Point) ifTrue:[ |
|
2273 | 876 |
^ Point x:(x - scale x) y:(y - scale y) |
637 | 877 |
]. |
878 |
(scale isMemberOf:SmallInteger) ifTrue:[ |
|
2273 | 879 |
"/ same as below, but stc can do better here |
880 |
^ Point x:(x - scale) y:(y - scale) |
|
637 | 881 |
]. |
882 |
scale isNumber ifTrue:[ |
|
2273 | 883 |
^ Point x:(x - scale) y:(y - scale) |
637 | 884 |
]. |
885 |
||
886 |
"this is the general (& clean) code ..." |
|
887 |
||
888 |
scalePoint := scale asPoint. |
|
889 |
^ (x - scalePoint x) @ (y - scalePoint y) |
|
2273 | 890 |
|
891 |
"Modified: 25.1.1997 / 17:27:40 / cg" |
|
637 | 892 |
! |
893 |
||
894 |
/ scale |
|
895 |
"Return a new Point that is the integer quotient of the |
|
896 |
receiver and scale (which is a Point or Number)." |
|
897 |
||
898 |
|scalePoint| |
|
899 |
||
900 |
"speedup for common cases ..." |
|
901 |
||
902 |
(scale isMemberOf:Point) ifTrue:[ |
|
903 |
^ (x / scale x) @ (y / scale y) |
|
904 |
]. |
|
905 |
scale isNumber ifTrue:[ |
|
906 |
^ (x / scale) @ (y / scale) |
|
907 |
]. |
|
908 |
||
909 |
"this is the general (& clean) code ..." |
|
910 |
||
911 |
scalePoint := scale asPoint. |
|
912 |
^ (x / scalePoint x) @ (y / scalePoint y) |
|
913 |
! |
|
914 |
||
915 |
// scale |
|
916 |
"Return a new Point that is the quotient of the |
|
917 |
receiver and scale (which is a Point or Number)." |
|
918 |
||
919 |
|scalePoint| |
|
920 |
||
921 |
scalePoint := scale asPoint. |
|
922 |
^ (x // scalePoint x) @ (y // scalePoint y) |
|
923 |
! |
|
924 |
||
925 |
negated |
|
926 |
"return a new point with my coordinates negated |
|
927 |
i.e. the receiver mirrored at the origin" |
|
928 |
||
929 |
^ (x negated) @ (y negated) |
|
930 |
! |
|
931 |
||
932 |
reciprocal |
|
933 |
"return a new point where the coordinates are |
|
934 |
the reciproce of mine" |
|
935 |
||
936 |
^ (1 / x) @ (1 / y) |
|
937 |
! |
|
938 |
||
939 |
scaledBy:aScale |
|
940 |
"return a new Point that is the product of the |
|
941 |
receiver and scale (which is a Point or Number)." |
|
942 |
||
943 |
^ self * aScale |
|
944 |
! |
|
945 |
||
946 |
translatedBy:anOffset |
|
947 |
"return a new Point that is the sum of the |
|
948 |
receiver and scale (which is a Point or Number)." |
|
949 |
||
950 |
^ self + anOffset |
|
951 |
! ! |
|
952 |
||
2273 | 953 |
!Point class methodsFor:'documentation'! |
637 | 954 |
|
955 |
version |
|
3238
f96eaf89d55d
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
956 |
^ '$Header: /cvs/stx/stx/libbasic/Point.st,v 1.44 1998-01-28 16:44:42 cg Exp $' |
637 | 957 |
! ! |
356 | 958 |
Point initialize! |