0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
72
|
3 |
All Rights Reserved
|
0
|
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 |
|
601
|
13 |
Object subclass:#WindowingTransformation
|
|
14 |
instanceVariableNames:'scale translation'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
2944
|
17 |
category:'Graphics-Transformations'
|
601
|
18 |
!
|
|
19 |
|
2148
|
20 |
|
601
|
21 |
!WindowingTransformation class methodsFor:'instance creation'!
|
|
22 |
|
|
23 |
identity
|
|
24 |
"returns a windowing transformation with no scaling (1@1)
|
|
25 |
and no translation (0@0)."
|
|
26 |
|
1148
|
27 |
^ self basicNew "/ scale:nil translation:nil
|
|
28 |
|
|
29 |
"
|
|
30 |
WindowingTransformation identity
|
|
31 |
"
|
|
32 |
|
|
33 |
"Modified: 30.12.1996 / 16:59:27 / cg"
|
601
|
34 |
!
|
|
35 |
|
|
36 |
scale:aScale translation:aTranslation
|
|
37 |
"returns a windowing transformation with a scale factor of
|
|
38 |
aScale and a translation offset of aTranslation."
|
|
39 |
|
|
40 |
^ self basicNew scale:aScale translation:aTranslation
|
|
41 |
|
|
42 |
"
|
|
43 |
|v|
|
|
44 |
|
|
45 |
v := View new realize.
|
|
46 |
(Delay forSeconds:3) wait.
|
|
47 |
v transformation:(WindowingTransformation scale:2 translation:0).
|
|
48 |
'now, everything is magnfied by 2'.
|
|
49 |
v displayLineFrom:10@10 to:30@30
|
|
50 |
"
|
|
51 |
"
|
|
52 |
|v|
|
|
53 |
|
|
54 |
v := View new realize.
|
|
55 |
(Delay forSeconds:3) wait.
|
|
56 |
v transformation:(WindowingTransformation scale:0.5 translation:0).
|
|
57 |
'now, everything is shrunk by 2'.
|
|
58 |
v displayLineFrom:10@10 to:30@30
|
|
59 |
"
|
|
60 |
!
|
|
61 |
|
|
62 |
unit:unitSymbol on:device
|
|
63 |
"returns a windowing transformation with scaling
|
|
64 |
for unitSymbol and no translation (0@0).
|
|
65 |
With such a transformation, you can draw in your preferred
|
|
66 |
units.
|
|
67 |
UnitSymbol may be #mm, #cm, #inch, #point, #twip or #pixel (default).
|
|
68 |
Twip is 1/20th of a point, point is 1/72th of an inch
|
|
69 |
(i.e. the print-unit which is also used for font sizes etc.)
|
|
70 |
- not to confuse with device pixels."
|
|
71 |
|
1148
|
72 |
|ppmm ppi scale|
|
|
73 |
|
|
74 |
ppmm := device pixelPerMillimeter.
|
|
75 |
ppi := device pixelPerInch.
|
72
|
76 |
|
601
|
77 |
unitSymbol == #mm ifTrue:[
|
1148
|
78 |
scale := ppmm.
|
601
|
79 |
] ifFalse:[
|
1148
|
80 |
unitSymbol == #cm ifTrue:[
|
|
81 |
scale := ppmm * 10.
|
|
82 |
] ifFalse:[
|
|
83 |
unitSymbol == #twip ifTrue:[
|
|
84 |
scale := ppi / 1440.
|
|
85 |
] ifFalse:[
|
|
86 |
unitSymbol == #point ifTrue:[
|
|
87 |
scale := ppi / 72.
|
|
88 |
] ifFalse:[
|
|
89 |
unitSymbol == #inch ifTrue:[
|
|
90 |
scale := ppi.
|
|
91 |
] ifFalse:[
|
|
92 |
"sorry: unknown unit is taken as pixel"
|
|
93 |
^ self new scale:nil translation:nil
|
|
94 |
]
|
|
95 |
]
|
|
96 |
]
|
|
97 |
]
|
601
|
98 |
].
|
1148
|
99 |
^ self basicNew scale:scale translation:nil
|
601
|
100 |
|
|
101 |
"
|
|
102 |
|v|
|
|
103 |
|
1148
|
104 |
v := View new openAndWait.
|
601
|
105 |
(Delay forSeconds:3) wait.
|
|
106 |
v transformation:(WindowingTransformation unit:#inch on:Display).
|
|
107 |
'now, we can think of drawing in inches ...'.
|
|
108 |
v displayLineFrom:0.5@0.5 to:1@1
|
|
109 |
"
|
1148
|
110 |
"
|
|
111 |
|v|
|
|
112 |
|
|
113 |
v := View new openAndWait.
|
|
114 |
(Delay forSeconds:3) wait.
|
|
115 |
v transformation:(WindowingTransformation unit:#mm on:Display).
|
|
116 |
'now, we can think of drawing in millimeters ...'.
|
|
117 |
v displayLineFrom:2@2 to:10@10
|
|
118 |
"
|
|
119 |
|
|
120 |
"Modified: 30.12.1996 / 16:57:59 / cg"
|
72
|
121 |
!
|
0
|
122 |
|
601
|
123 |
window:sourceRectangle viewport:destinationRectangle
|
|
124 |
"returns a windowing transformation with a scale and
|
|
125 |
translation computed from sourceRectangle and destinationRectangle.
|
|
126 |
The scale and transformation are computed such that sourceRectangle
|
|
127 |
is transformed to destinationRectangle. Typically sourceRectangle
|
|
128 |
represents the logical coordinateSpace while destinationRectangle
|
|
129 |
represents the device coordinateSpace."
|
|
130 |
|
|
131 |
|sX sY tX tY newScale newTranslation|
|
|
132 |
|
|
133 |
sX := destinationRectangle width / sourceRectangle width.
|
|
134 |
sY := destinationRectangle height / sourceRectangle height.
|
|
135 |
tX := destinationRectangle left - sourceRectangle left.
|
|
136 |
tY := destinationRectangle top - sourceRectangle top.
|
|
137 |
((tX = 1.0) and:[tY = 1.0]) ifTrue:[
|
|
138 |
newTranslation := nil
|
|
139 |
] ifFalse:[
|
|
140 |
newTranslation := tX @ tY
|
|
141 |
].
|
|
142 |
((sX = 1.0) and:[sY = 1.0]) ifTrue:[
|
|
143 |
newScale := nil
|
|
144 |
] ifFalse:[
|
|
145 |
newScale := sX @ sY
|
|
146 |
].
|
|
147 |
^ self basicNew scale:newScale translation:newTranslation
|
|
148 |
|
|
149 |
"
|
|
150 |
|v|
|
|
151 |
|
|
152 |
v := View new realize.
|
|
153 |
(Delay forSeconds:3) wait.
|
|
154 |
v transformation:(WindowingTransformation
|
|
155 |
window:(0@0 corner:1@1)
|
|
156 |
viewport:(0@0 corner:100@100)).
|
|
157 |
'now, we can think of drawing in 0..1/0..1 coordinates'.
|
|
158 |
v displayLineFrom:0.1@0.1 to:0.9@0.9
|
|
159 |
"
|
|
160 |
! !
|
|
161 |
|
78
|
162 |
!WindowingTransformation class methodsFor:'documentation '!
|
|
163 |
|
|
164 |
copyright
|
|
165 |
"
|
|
166 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
167 |
All Rights Reserved
|
|
168 |
|
|
169 |
This software is furnished under a license and may be used
|
|
170 |
only in accordance with the terms of that license and with the
|
|
171 |
inclusion of the above copyright notice. This software may not
|
|
172 |
be provided or otherwise made available to, or used by, any
|
|
173 |
other person. No title to or ownership of the software is
|
|
174 |
hereby transferred.
|
|
175 |
"
|
|
176 |
!
|
|
177 |
|
|
178 |
documentation
|
|
179 |
"
|
|
180 |
instances of WindowingTransformation can be used to scale, translate or
|
|
181 |
generally transform other objects in 2D space.
|
|
182 |
They can also be set as the translation in a graphic context,
|
|
183 |
which will then apply this to all of its drawing operations
|
|
184 |
(see GraphicContext>>transformation:).
|
|
185 |
|
|
186 |
All 2-D objects are supposed to be able to be transformed using
|
|
187 |
instances of me. Multiple instances of me can also be combined to form a
|
|
188 |
single composite transformation.
|
|
189 |
|
611
|
190 |
[Instance variables:]
|
|
191 |
scale <Number> or <Point> representing a linear scaling factor.
|
|
192 |
nil is interpreted as 1@1
|
|
193 |
|
|
194 |
translation <Number> or <Point> representing a translation in 2-D.
|
|
195 |
nil is interpreted as 0@0
|
78
|
196 |
|
|
197 |
|
611
|
198 |
[author:]
|
|
199 |
Claus Gittinger
|
81
|
200 |
"
|
611
|
201 |
|
|
202 |
"Modified: 25.4.1996 / 16:53:07 / cg"
|
81
|
203 |
!
|
78
|
204 |
|
81
|
205 |
examples
|
|
206 |
"
|
78
|
207 |
example (drawing in inches):
|
619
|
208 |
[exBegin]
|
78
|
209 |
|v|
|
|
210 |
|
|
211 |
v := View new realize.
|
|
212 |
(Delay forSeconds:3) wait.
|
|
213 |
v transformation:(WindowingTransformation unit:#inch on:Display).
|
|
214 |
'now, we can think of drawing in inches ...'.
|
|
215 |
v displayLineFrom:0.5@0.5 to:1@1
|
619
|
216 |
[exEnd]
|
78
|
217 |
|
|
218 |
|
|
219 |
example (drawing in millimeters):
|
619
|
220 |
[exBegin]
|
78
|
221 |
|v|
|
|
222 |
|
|
223 |
v := View new realize.
|
|
224 |
(Delay forSeconds:3) wait.
|
|
225 |
v transformation:(WindowingTransformation unit:#mm on:Display).
|
|
226 |
'now, we can think of drawing in millimeters ...'.
|
|
227 |
v displayLineFrom:5@5 to:20@5
|
619
|
228 |
[exEnd]
|
78
|
229 |
|
|
230 |
|
|
231 |
example (drawing magnified):
|
619
|
232 |
[exBegin]
|
78
|
233 |
|v|
|
|
234 |
|
|
235 |
v := View new realize.
|
|
236 |
(Delay forSeconds:3) wait.
|
|
237 |
v transformation:(WindowingTransformation scale:2 translation:0).
|
|
238 |
'now, everything is magnfied by 2'.
|
|
239 |
v displayLineFrom:10@10 to:30@30
|
619
|
240 |
[exEnd]
|
78
|
241 |
|
|
242 |
example (drawing shrunk):
|
619
|
243 |
[exBegin]
|
78
|
244 |
|v|
|
|
245 |
|
|
246 |
v := View new realize.
|
|
247 |
(Delay forSeconds:3) wait.
|
|
248 |
v transformation:(WindowingTransformation scale:0.5 translation:0).
|
|
249 |
'now, everything is shrunk by 2'.
|
|
250 |
v displayLineFrom:10@10 to:30@30
|
619
|
251 |
[exEnd]
|
|
252 |
"
|
78
|
253 |
|
619
|
254 |
"Modified: 27.4.1996 / 19:45:43 / cg"
|
78
|
255 |
! !
|
|
256 |
|
601
|
257 |
!WindowingTransformation methodsFor:'accessing'!
|
|
258 |
|
|
259 |
scale
|
|
260 |
"return a copy of the Point that represents the
|
|
261 |
current scale of the receiver."
|
72
|
262 |
|
601
|
263 |
scale isNil ifTrue:[^ (1@1) copy].
|
|
264 |
^ scale copy
|
|
265 |
!
|
72
|
266 |
|
601
|
267 |
scale:aScale
|
|
268 |
"Set the receiver's scale to aScale, a Point or Number."
|
72
|
269 |
|
2148
|
270 |
aScale isNil ifTrue:[
|
|
271 |
scale := aScale
|
|
272 |
] ifFalse:[
|
|
273 |
scale = 1 ifTrue:[
|
|
274 |
scale := nil
|
|
275 |
] ifFalse:[
|
|
276 |
scale := aScale asPoint.
|
|
277 |
]
|
72
|
278 |
].
|
2147
|
279 |
|
2148
|
280 |
"Modified: / 13.6.1998 / 14:04:51 / cg"
|
72
|
281 |
!
|
|
282 |
|
601
|
283 |
scale:aScale translation:aTranslation
|
|
284 |
"sets the scale to aScale and the translation to aTranslation."
|
78
|
285 |
|
2148
|
286 |
aScale isNil ifTrue:[
|
|
287 |
scale := aScale
|
|
288 |
] ifFalse:[
|
|
289 |
scale = 1 ifTrue:[
|
|
290 |
scale := nil
|
|
291 |
] ifFalse:[
|
|
292 |
scale := aScale asPoint.
|
|
293 |
]
|
601
|
294 |
].
|
2148
|
295 |
aTranslation isNil ifTrue:[
|
|
296 |
translation := aTranslation
|
|
297 |
] ifFalse:[
|
|
298 |
aTranslation = 0 ifTrue:[
|
|
299 |
translation := nil
|
|
300 |
] ifFalse:[
|
|
301 |
translation := aTranslation asPoint
|
|
302 |
]
|
601
|
303 |
]
|
2147
|
304 |
|
2148
|
305 |
"Modified: / 13.6.1998 / 14:04:42 / cg"
|
72
|
306 |
!
|
|
307 |
|
601
|
308 |
scaleOfOne
|
|
309 |
"Set the scale of the receiver to the identity scale"
|
72
|
310 |
|
601
|
311 |
scale := nil
|
72
|
312 |
!
|
|
313 |
|
705
|
314 |
scaleX
|
|
315 |
"return the current x-scale of the receiver."
|
|
316 |
|
|
317 |
scale isNil ifTrue:[^ 1].
|
|
318 |
^ scale x
|
|
319 |
|
|
320 |
"Created: 21.5.1996 / 21:13:49 / cg"
|
|
321 |
!
|
|
322 |
|
|
323 |
scaleY
|
|
324 |
"return the current x-scale of the receiver."
|
|
325 |
|
|
326 |
scale isNil ifTrue:[^ 1].
|
|
327 |
^ scale y
|
|
328 |
|
|
329 |
"Created: 21.5.1996 / 21:13:59 / cg"
|
|
330 |
!
|
|
331 |
|
601
|
332 |
translation
|
|
333 |
"return a copy of the receiver's translation."
|
|
334 |
|
|
335 |
translation isNil ifTrue:[^ (0@0) copy].
|
|
336 |
^ translation copy
|
|
337 |
!
|
72
|
338 |
|
601
|
339 |
translation:aTranslation
|
|
340 |
"Set the receiver's translation to aTranslation, a Point or Number."
|
|
341 |
|
2148
|
342 |
aTranslation isNil ifTrue:[
|
|
343 |
translation := aTranslation
|
|
344 |
] ifFalse:[
|
|
345 |
aTranslation = 0 ifTrue:[
|
|
346 |
translation := nil
|
|
347 |
] ifFalse:[
|
|
348 |
translation := aTranslation asPoint
|
|
349 |
]
|
601
|
350 |
]
|
2147
|
351 |
|
2148
|
352 |
"Modified: / 13.6.1998 / 14:04:15 / cg"
|
705
|
353 |
!
|
|
354 |
|
|
355 |
translationX
|
|
356 |
"return the receiver's x-translation."
|
|
357 |
|
|
358 |
translation isNil ifTrue:[^ 0].
|
|
359 |
^ translation x
|
|
360 |
|
|
361 |
"Created: 21.5.1996 / 21:13:10 / cg"
|
|
362 |
!
|
|
363 |
|
|
364 |
translationY
|
|
365 |
"return the receiver's x-translation."
|
|
366 |
|
|
367 |
translation isNil ifTrue:[^ 0].
|
|
368 |
^ translation y
|
|
369 |
|
|
370 |
"Created: 21.5.1996 / 21:13:21 / cg"
|
46
|
371 |
! !
|
0
|
372 |
|
72
|
373 |
!WindowingTransformation methodsFor:'applying transform'!
|
0
|
374 |
|
78
|
375 |
applyInverseScaleX:aNumber
|
|
376 |
"apply the scale only (if widths are to be transformed)"
|
|
377 |
|
|
378 |
scale isNil ifTrue:[^ aNumber].
|
|
379 |
^ aNumber / scale x
|
|
380 |
!
|
|
381 |
|
|
382 |
applyInverseScaleY:aNumber
|
|
383 |
"apply the scale only (if heights are to be transformed)"
|
|
384 |
|
|
385 |
scale isNil ifTrue:[^ aNumber].
|
|
386 |
^ aNumber / scale y
|
|
387 |
!
|
|
388 |
|
|
389 |
applyInverseTo:anObject
|
|
390 |
"Apply the inverse of the receiver to anObject
|
|
391 |
and return the result. This can be used to map back from logical
|
|
392 |
to physical coordinates, for example."
|
|
393 |
|
|
394 |
|transformedObject|
|
|
395 |
|
|
396 |
translation isNil ifTrue:[
|
|
397 |
scale isNil ifTrue:[
|
|
398 |
^ anObject
|
|
399 |
].
|
|
400 |
^ anObject scaledBy:self inverseScale
|
|
401 |
].
|
|
402 |
transformedObject := anObject translatedBy:(self inverseTranslation).
|
|
403 |
scale notNil ifTrue:[
|
|
404 |
transformedObject scaleBy:(self inverseScale).
|
|
405 |
].
|
|
406 |
^ transformedObject
|
|
407 |
!
|
|
408 |
|
601
|
409 |
applyInverseToX:aNumber
|
|
410 |
"Apply the receiver to a number representing an x-coordinate
|
|
411 |
and return the result."
|
|
412 |
|
|
413 |
|t s|
|
|
414 |
|
|
415 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale x].
|
|
416 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation x].
|
|
417 |
^ (aNumber - t) / s
|
|
418 |
!
|
|
419 |
|
|
420 |
applyInverseToY:aNumber
|
|
421 |
"Apply the receiver to a number representing an y-coordinate
|
|
422 |
and return the result."
|
|
423 |
|
|
424 |
|t s|
|
|
425 |
|
|
426 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale y].
|
|
427 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation y].
|
|
428 |
^ (aNumber - t) / s
|
|
429 |
!
|
|
430 |
|
|
431 |
applyScaleX:aNumber
|
|
432 |
"apply the scale only (if widths are to be transformed)"
|
|
433 |
|
|
434 |
scale isNil ifTrue:[^ aNumber].
|
|
435 |
^ aNumber * scale x
|
|
436 |
!
|
|
437 |
|
|
438 |
applyScaleY:aNumber
|
|
439 |
"apply the scale only (if heights are to be transformed)"
|
|
440 |
|
|
441 |
scale isNil ifTrue:[^ aNumber].
|
|
442 |
^ aNumber * scale y
|
|
443 |
!
|
|
444 |
|
|
445 |
applyTo:anObject
|
|
446 |
"Apply the receiver to anObject and return the result."
|
|
447 |
|
|
448 |
|transformedObject|
|
78
|
449 |
|
|
450 |
scale isNil ifTrue:[
|
|
451 |
translation isNil ifTrue:[
|
601
|
452 |
^ anObject
|
78
|
453 |
].
|
601
|
454 |
^ anObject translatedBy:translation
|
|
455 |
].
|
|
456 |
transformedObject := anObject scaledBy:scale.
|
|
457 |
translation notNil ifTrue:[
|
|
458 |
transformedObject translateBy:translation.
|
78
|
459 |
].
|
601
|
460 |
^ transformedObject
|
|
461 |
!
|
|
462 |
|
|
463 |
applyToX:aNumber
|
|
464 |
"Apply the receiver to a number representing an x-coordinate
|
|
465 |
and return the result."
|
|
466 |
|
|
467 |
|t s|
|
|
468 |
|
|
469 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale x].
|
|
470 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation x].
|
|
471 |
^ aNumber * s + t
|
|
472 |
!
|
|
473 |
|
|
474 |
applyToY:aNumber
|
|
475 |
"Apply the receiver to a number representing an y-coordinate
|
|
476 |
and return the result."
|
|
477 |
|
|
478 |
|t s|
|
|
479 |
|
|
480 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale y].
|
|
481 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation y].
|
|
482 |
^ aNumber * s + t
|
78
|
483 |
!
|
|
484 |
|
0
|
485 |
compose:aTransformation
|
|
486 |
"return a new WindowingTransformation that is the
|
|
487 |
composition of the receiver and aTransformation.
|
|
488 |
The effect of applying the resulting WindowingTransformation
|
|
489 |
to an object is the same as that of first applying
|
|
490 |
aTransformation to the object and then applying the
|
|
491 |
receiver to its result."
|
|
492 |
|
|
493 |
|aTransformationScale newScale newTranslation|
|
|
494 |
|
|
495 |
aTransformationScale := aTransformation scale.
|
78
|
496 |
scale isNil ifTrue:[
|
72
|
497 |
aTransformation noScale ifTrue:[
|
|
498 |
newScale := nil
|
|
499 |
] ifFalse:[
|
|
500 |
newScale := aTransformationScale
|
|
501 |
].
|
|
502 |
newTranslation := translation + aTransformation translation
|
0
|
503 |
] ifFalse:[
|
72
|
504 |
aTransformation noScale ifTrue:[
|
|
505 |
newScale := scale
|
|
506 |
] ifFalse:[
|
|
507 |
newScale := scale * aTransformationScale
|
|
508 |
].
|
|
509 |
newTranslation := translation
|
|
510 |
+ (scale * aTransformation translation)
|
0
|
511 |
].
|
72
|
512 |
^ (self class)
|
|
513 |
scale:newScale
|
|
514 |
translation:newTranslation
|
|
515 |
!
|
|
516 |
|
601
|
517 |
transformPoint:p
|
|
518 |
"Apply the receiver to a point.
|
|
519 |
This is destructive in that the point is being modified,
|
|
520 |
not a copy."
|
0
|
521 |
|
601
|
522 |
scale isNil ifTrue:[
|
|
523 |
translation isNil ifTrue:[
|
|
524 |
^ p
|
72
|
525 |
].
|
601
|
526 |
^ p + translation
|
|
527 |
].
|
|
528 |
translation isNil ifTrue:[
|
|
529 |
^ p * scale
|
0
|
530 |
].
|
601
|
531 |
^ (p * scale + translation)
|
|
532 |
! !
|
|
533 |
|
|
534 |
!WindowingTransformation methodsFor:'printing'!
|
0
|
535 |
|
601
|
536 |
printOn:aStream
|
2804
|
537 |
"append a user printed representation of the receiver to aStream.
|
|
538 |
The format is suitable for a human - not meant to be read back."
|
|
539 |
|
601
|
540 |
aStream nextPutAll:self class name.
|
|
541 |
aStream nextPutAll:' scale: '.
|
|
542 |
scale printOn:aStream.
|
|
543 |
aStream nextPutAll:' translation: '.
|
|
544 |
translation printOn:aStream
|
0
|
545 |
! !
|
|
546 |
|
72
|
547 |
!WindowingTransformation methodsFor:'private'!
|
0
|
548 |
|
|
549 |
checkScale:aScale
|
|
550 |
"Converts aScale to the internal format of a floating-point Point."
|
|
551 |
|
|
552 |
|checkedScale|
|
|
553 |
|
|
554 |
checkedScale := aScale asPoint.
|
|
555 |
^ Point x:checkedScale x asFloat
|
72
|
556 |
y:checkedScale y asFloat
|
0
|
557 |
!
|
|
558 |
|
|
559 |
inverseScale
|
|
560 |
"return with a Point representing the inverse of my
|
|
561 |
scale."
|
|
562 |
|
|
563 |
|newScale|
|
|
564 |
|
|
565 |
newScale := self checkScale:scale.
|
|
566 |
^ Point x:(1.0 / newScale x)
|
72
|
567 |
y:(1.0 / newScale y)
|
0
|
568 |
!
|
|
569 |
|
|
570 |
inverseTranslation
|
|
571 |
"return with a Point representing the inverse of my
|
|
572 |
translation."
|
|
573 |
|
|
574 |
|trans|
|
|
575 |
|
|
576 |
trans := translation asPoint.
|
|
577 |
^ Point x:trans x negated
|
72
|
578 |
y:trans y negated
|
|
579 |
! !
|
|
580 |
|
|
581 |
!WindowingTransformation methodsFor:'testing'!
|
|
582 |
|
|
583 |
noScale
|
|
584 |
"return true if the identity scale is in effect;
|
|
585 |
return false, otherwise."
|
0
|
586 |
|
705
|
587 |
scale isNil ifTrue:[^ true].
|
|
588 |
^ scale x = 1 and:[scale y = 1]
|
|
589 |
|
|
590 |
"Modified: 21.5.1996 / 21:15:21 / cg"
|
0
|
591 |
! !
|
72
|
592 |
|
601
|
593 |
!WindowingTransformation methodsFor:'transforming'!
|
|
594 |
|
|
595 |
scaleBy:aScale
|
|
596 |
"scale the receiver.
|
|
597 |
This is a destructive operation, modifying the transformation
|
|
598 |
represented by the receiver"
|
|
599 |
|
|
600 |
|newScale|
|
|
601 |
|
|
602 |
aScale isNil ifTrue:[^ self].
|
|
603 |
|
|
604 |
scale isNil ifTrue:[
|
|
605 |
newScale := aScale asPoint
|
|
606 |
] ifFalse:[
|
|
607 |
newScale := scale * aScale
|
|
608 |
].
|
|
609 |
translation notNil ifTrue:[
|
|
610 |
translation := translation * aScale.
|
|
611 |
].
|
|
612 |
scale := newScale.
|
|
613 |
!
|
|
614 |
|
|
615 |
scaledBy:aScale
|
|
616 |
"return a new WindowingTransformation with the scale and translation of
|
|
617 |
the receiver both scaled by aScale."
|
|
618 |
|
|
619 |
|checkedScale newScale newTranslation|
|
72
|
620 |
|
601
|
621 |
aScale isNil ifTrue:[
|
|
622 |
newScale := scale.
|
|
623 |
newTranslation := translation
|
|
624 |
] ifFalse:[
|
|
625 |
checkedScale := self checkScale:aScale.
|
|
626 |
scale isNil ifTrue:[
|
|
627 |
newScale := checkedScale
|
|
628 |
] ifFalse:[
|
|
629 |
newScale := scale * checkedScale
|
|
630 |
].
|
|
631 |
translation notNil ifTrue:[
|
|
632 |
newTranslation := checkedScale * translation
|
|
633 |
]
|
|
634 |
].
|
|
635 |
^ (self class)
|
|
636 |
scale:newScale
|
|
637 |
translation:newTranslation
|
|
638 |
!
|
|
639 |
|
|
640 |
translateBy:aTranslation
|
|
641 |
"translate the receiver.
|
|
642 |
This is a destructive operation, modifying the transformation
|
|
643 |
represented by the receiver"
|
|
644 |
|
|
645 |
aTranslation isNil ifTrue:[^ self].
|
|
646 |
|
|
647 |
translation isNil ifTrue:[
|
|
648 |
translation := 0@0
|
|
649 |
].
|
|
650 |
scale isNil ifTrue:[
|
|
651 |
translation := translation + aTranslation asPoint
|
|
652 |
] ifFalse:[
|
|
653 |
translation := translation + (scale * aTranslation)
|
|
654 |
].
|
|
655 |
!
|
|
656 |
|
|
657 |
translatedBy:aPoint
|
|
658 |
"return a new WindowingTransformation with the same scale and
|
|
659 |
rotations as the receiver and with a translation of the current
|
|
660 |
translation plus aPoint."
|
|
661 |
|
|
662 |
^ (self class)
|
|
663 |
scale:scale
|
|
664 |
translation:(translation + aPoint)
|
72
|
665 |
! !
|
|
666 |
|
2148
|
667 |
!WindowingTransformation class methodsFor:'documentation'!
|
|
668 |
|
|
669 |
version
|
2944
|
670 |
^ '$Header: /cvs/stx/stx/libview/WindowingTransformation.st,v 1.19 1999-10-06 22:22:00 cg Exp $'
|
2148
|
671 |
! !
|