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