7951
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
"
|
6698
|
12 |
"{ Package: 'stx:libview' }"
|
|
13 |
|
7414
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
6698
|
16 |
Object subclass:#DisplayTransform
|
|
17 |
instanceVariableNames:''
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Graphics-Transformations'
|
|
21 |
!
|
|
22 |
|
|
23 |
DisplayTransform comment:'This class represents a base for generic transformations of 2D points between different coordinate systems (including scaling and rotation). The transformations map objects between one coordinate system and another where it is assumed that a nested hierarchy of transformations can be defined.
|
|
24 |
|
|
25 |
It is assumed that transformations deal with Integer points. All transformations should return Integer coordinates (even though float points may be passed in as argument).
|
|
26 |
|
|
27 |
Compositions of transformations MUST work in the following order. A ''global'' transformation (the argument in #composedWithGlobal:) is defined as a transformation that takes place between the receiver (the ''local'') transformation and any ''global'' point computations, whereas a ''local'' transformation (e.g., the argument in #composedWithLocal:) takes place between the receiver (''global'') and any ''local'' points. For the transformation methods this means that combining a global and a local transformation will result in the following order:
|
|
28 |
|
|
29 |
globalPointToLocal: globalPoint
|
|
30 |
"globalPoint -> globalTransform -> localTransform -> locaPoint"
|
|
31 |
^localTransform globalPointToLocal:
|
|
32 |
(globalTransform globalPointToLocal: globalPoint)
|
|
33 |
|
|
34 |
localPointToGlobal: localPoint
|
|
35 |
"localPoint -> localTransform -> globalTransform -> globalPoint"
|
|
36 |
^globalTransform localPointToGlobal:
|
|
37 |
(localTransform localPointToGlobal: localPoint)
|
|
38 |
|
|
39 |
'
|
|
40 |
!
|
|
41 |
|
7951
|
42 |
!DisplayTransform class methodsFor:'documentation'!
|
|
43 |
|
|
44 |
copyright
|
|
45 |
"
|
|
46 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
47 |
All Rights Reserved
|
|
48 |
|
|
49 |
This software is furnished under a license and may be used
|
|
50 |
only in accordance with the terms of that license and with the
|
|
51 |
inclusion of the above copyright notice. This software may not
|
|
52 |
be provided or otherwise made available to, or used by, any
|
|
53 |
other person. No title to or ownership of the software is
|
|
54 |
hereby transferred.
|
|
55 |
"
|
|
56 |
! !
|
6698
|
57 |
|
|
58 |
!DisplayTransform class methodsFor:'instance creation'!
|
|
59 |
|
|
60 |
identity
|
|
61 |
^self new setIdentity
|
|
62 |
! !
|
|
63 |
|
7858
|
64 |
!DisplayTransform class methodsFor:'queries'!
|
|
65 |
|
|
66 |
isAbstract
|
|
67 |
"Return if this class is an abstract class.
|
|
68 |
True is returned here for myself only; false for subclasses.
|
|
69 |
Abstract subclasses must redefine this again."
|
|
70 |
|
|
71 |
^ self == DisplayTransform.
|
|
72 |
! !
|
|
73 |
|
6698
|
74 |
!DisplayTransform methodsFor:'accessing'!
|
|
75 |
|
|
76 |
inverseTransformation
|
|
77 |
"Return the inverse transformation of the receiver"
|
|
78 |
^self subclassResponsibility
|
|
79 |
! !
|
|
80 |
|
|
81 |
!DisplayTransform methodsFor:'composing'!
|
|
82 |
|
|
83 |
composedWithGlobal: aTransformation
|
|
84 |
"Return the composition of the receiver and the global transformation passed in.
|
|
85 |
A 'global' transformation is defined as a transformation that takes place
|
|
86 |
between the receiver (the 'local') transformation and any 'global' point
|
|
87 |
computations, e.g., for the methods
|
|
88 |
|
|
89 |
globalPointToLocal: globalPoint
|
|
90 |
globalPoint -> globalTransform -> localTransform -> locaPoint
|
|
91 |
|
|
92 |
localPointToGlobal: localPoint
|
|
93 |
localPoint -> localTransform -> globalTransform -> globalPoint
|
|
94 |
|
|
95 |
"
|
|
96 |
^aTransformation composedWithLocal: self
|
|
97 |
!
|
|
98 |
|
|
99 |
composedWithLocal: aTransformation
|
7414
|
100 |
"Return the composition of the receiver and the local transformation passed in.
|
|
101 |
A 'local' transformation is defined as a transformation that takes place
|
|
102 |
between the receiver (the 'global') transformation and any 'local' point
|
|
103 |
computations, e.g., for the methods
|
6698
|
104 |
|
7414
|
105 |
globalPointToLocal: globalPoint
|
|
106 |
globalPoint -> globalTransform -> localTransform -> locaPoint
|
6698
|
107 |
|
7414
|
108 |
localPointToGlobal: localPoint
|
|
109 |
localPoint -> localTransform -> globalTransform -> globalPoint
|
6698
|
110 |
|
7414
|
111 |
"
|
|
112 |
self isIdentity ifTrue:[^ aTransformation].
|
|
113 |
aTransformation isIdentityTransformation ifTrue:[^ self].
|
|
114 |
^ CompositeTransform new globalTransform: self
|
|
115 |
localTransform: aTransformation
|
6698
|
116 |
! !
|
|
117 |
|
|
118 |
!DisplayTransform methodsFor:'converting'!
|
|
119 |
|
|
120 |
asCompositeTransform
|
|
121 |
"Represent the receiver as a composite transformation"
|
|
122 |
^CompositeTransform new
|
|
123 |
globalTransform: self
|
|
124 |
localTransform: self species identity
|
|
125 |
!
|
|
126 |
|
|
127 |
asMatrixTransform2x3
|
|
128 |
"Represent the receiver as a 2x3 matrix transformation"
|
|
129 |
^self subclassResponsibility
|
|
130 |
! !
|
|
131 |
|
|
132 |
!DisplayTransform methodsFor:'initialize'!
|
|
133 |
|
|
134 |
setIdentity
|
|
135 |
"Initialize the receiver to the identity transformation (e.g., not affecting points)"
|
|
136 |
|
|
137 |
^self subclassResponsibility
|
|
138 |
! !
|
|
139 |
|
|
140 |
!DisplayTransform methodsFor:'testing'!
|
|
141 |
|
|
142 |
isCompositeTransform
|
|
143 |
"Return true if the receiver is a composite transformation.
|
|
144 |
Composite transformations may have impact on the accuracy."
|
|
145 |
^false
|
|
146 |
!
|
|
147 |
|
7414
|
148 |
isIdentityTransformation
|
|
149 |
"Return true if the receiver is the identity transform; that is, if applying to a point returns the point itself."
|
|
150 |
|
|
151 |
^ self subclassResponsibility
|
6698
|
152 |
!
|
|
153 |
|
|
154 |
isMatrixTransform2x3
|
|
155 |
"Return true if the receiver is 2x3 matrix transformation"
|
|
156 |
^false
|
|
157 |
!
|
|
158 |
|
|
159 |
isMorphicTransform
|
|
160 |
"Return true if the receiver is a MorphicTransform, that is specifies the transformation values explicitly."
|
|
161 |
^false
|
|
162 |
!
|
|
163 |
|
|
164 |
isNoScale
|
|
165 |
"return true if the identity scale is in effect (i.e. saleFactor is 1);
|
|
166 |
return false, otherwise."
|
|
167 |
|
7414
|
168 |
^ self subclassResponsibility
|
6698
|
169 |
!
|
|
170 |
|
|
171 |
noScale
|
|
172 |
"return true if the identity scale is in effect (i.e. saleFactor is 1);
|
|
173 |
return false, otherwise.
|
|
174 |
Obsolete: use isNoScale"
|
|
175 |
|
|
176 |
<resource: #obsolete>
|
|
177 |
|
|
178 |
^ self isNoScale
|
|
179 |
! !
|
|
180 |
|
|
181 |
!DisplayTransform methodsFor:'transforming points'!
|
|
182 |
|
|
183 |
applyInverseTo:aPoint
|
|
184 |
^ self invertPoint: aPoint
|
|
185 |
!
|
|
186 |
|
|
187 |
applyScaleX:aNumber
|
|
188 |
^ (self transformPoint: aNumber @ 0) x
|
|
189 |
!
|
|
190 |
|
|
191 |
applyScaleY:aNumber
|
|
192 |
^ (self transformPoint: 0 @ aNumber) y
|
|
193 |
!
|
|
194 |
|
|
195 |
applyTo:aPoint
|
|
196 |
^ self transformPoint: aPoint
|
|
197 |
!
|
|
198 |
|
|
199 |
globalPointToLocal: aPoint
|
|
200 |
"Transform aPoint from global coordinates into local coordinates"
|
|
201 |
^self subclassResponsibility
|
|
202 |
!
|
|
203 |
|
|
204 |
globalPointsToLocal: inArray
|
|
205 |
"Transform all the points of inArray from global into local coordinates"
|
|
206 |
^inArray collect:[:pt| self globalPointToLocal: pt]
|
|
207 |
!
|
|
208 |
|
|
209 |
localPointToGlobal: aPoint
|
|
210 |
"Transform aPoint from local coordinates into global coordinates"
|
|
211 |
^self subclassResponsibility
|
|
212 |
!
|
|
213 |
|
|
214 |
localPointsToGlobal: inArray
|
|
215 |
"Transform all the points of inArray from local into global coordinates"
|
|
216 |
^inArray collect:[:pt| self localPointToGlobal: pt]
|
|
217 |
! !
|
|
218 |
|
|
219 |
!DisplayTransform methodsFor:'transforming rects'!
|
|
220 |
|
|
221 |
globalBoundsToLocal: aRectangle
|
|
222 |
"Transform aRectangle from global coordinates into local coordinates"
|
|
223 |
^Rectangle encompassing: (self globalPointsToLocal: aRectangle corners)
|
|
224 |
!
|
|
225 |
|
|
226 |
localBoundsToGlobal: aRectangle
|
|
227 |
"Transform aRectangle from local coordinates into global coordinates"
|
|
228 |
^Rectangle encompassing: (self localPointsToGlobal: aRectangle corners)
|
|
229 |
! !
|
|
230 |
|
|
231 |
!DisplayTransform class methodsFor:'documentation'!
|
|
232 |
|
|
233 |
version
|
7414
|
234 |
^ '$Header$'
|
6698
|
235 |
!
|
|
236 |
|
|
237 |
version_CVS
|
7414
|
238 |
^ '$Header$'
|
6698
|
239 |
! !
|
|
240 |
|