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