7414
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
6698
|
3 |
"{ Package: 'stx:libview' }"
|
|
4 |
|
7414
|
5 |
"{ NameSpace: Smalltalk }"
|
|
6 |
|
6698
|
7 |
Object subclass:#DisplayTransform
|
|
8 |
instanceVariableNames:''
|
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
|
11 |
category:'Graphics-Transformations'
|
|
12 |
!
|
|
13 |
|
|
14 |
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.
|
|
15 |
|
|
16 |
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).
|
|
17 |
|
|
18 |
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:
|
|
19 |
|
|
20 |
globalPointToLocal: globalPoint
|
|
21 |
"globalPoint -> globalTransform -> localTransform -> locaPoint"
|
|
22 |
^localTransform globalPointToLocal:
|
|
23 |
(globalTransform globalPointToLocal: globalPoint)
|
|
24 |
|
|
25 |
localPointToGlobal: localPoint
|
|
26 |
"localPoint -> localTransform -> globalTransform -> globalPoint"
|
|
27 |
^globalTransform localPointToGlobal:
|
|
28 |
(localTransform localPointToGlobal: localPoint)
|
|
29 |
|
|
30 |
'
|
|
31 |
!
|
|
32 |
|
|
33 |
|
|
34 |
!DisplayTransform class methodsFor:'instance creation'!
|
|
35 |
|
|
36 |
identity
|
|
37 |
^self new setIdentity
|
|
38 |
! !
|
|
39 |
|
|
40 |
!DisplayTransform methodsFor:'accessing'!
|
|
41 |
|
|
42 |
inverseTransformation
|
|
43 |
"Return the inverse transformation of the receiver"
|
|
44 |
^self subclassResponsibility
|
|
45 |
! !
|
|
46 |
|
|
47 |
!DisplayTransform methodsFor:'composing'!
|
|
48 |
|
|
49 |
composedWithGlobal: aTransformation
|
|
50 |
"Return the composition of the receiver and the global transformation passed in.
|
|
51 |
A 'global' transformation is defined as a transformation that takes place
|
|
52 |
between the receiver (the 'local') transformation and any 'global' point
|
|
53 |
computations, e.g., for the methods
|
|
54 |
|
|
55 |
globalPointToLocal: globalPoint
|
|
56 |
globalPoint -> globalTransform -> localTransform -> locaPoint
|
|
57 |
|
|
58 |
localPointToGlobal: localPoint
|
|
59 |
localPoint -> localTransform -> globalTransform -> globalPoint
|
|
60 |
|
|
61 |
"
|
|
62 |
^aTransformation composedWithLocal: self
|
|
63 |
!
|
|
64 |
|
|
65 |
composedWithLocal: aTransformation
|
7414
|
66 |
"Return the composition of the receiver and the local transformation passed in.
|
|
67 |
A 'local' transformation is defined as a transformation that takes place
|
|
68 |
between the receiver (the 'global') transformation and any 'local' point
|
|
69 |
computations, e.g., for the methods
|
6698
|
70 |
|
7414
|
71 |
globalPointToLocal: globalPoint
|
|
72 |
globalPoint -> globalTransform -> localTransform -> locaPoint
|
6698
|
73 |
|
7414
|
74 |
localPointToGlobal: localPoint
|
|
75 |
localPoint -> localTransform -> globalTransform -> globalPoint
|
6698
|
76 |
|
7414
|
77 |
"
|
|
78 |
self isIdentity ifTrue:[^ aTransformation].
|
|
79 |
aTransformation isIdentityTransformation ifTrue:[^ self].
|
|
80 |
^ CompositeTransform new globalTransform: self
|
|
81 |
localTransform: aTransformation
|
6698
|
82 |
! !
|
|
83 |
|
|
84 |
!DisplayTransform methodsFor:'converting'!
|
|
85 |
|
|
86 |
asCompositeTransform
|
|
87 |
"Represent the receiver as a composite transformation"
|
|
88 |
^CompositeTransform new
|
|
89 |
globalTransform: self
|
|
90 |
localTransform: self species identity
|
|
91 |
!
|
|
92 |
|
|
93 |
asMatrixTransform2x3
|
|
94 |
"Represent the receiver as a 2x3 matrix transformation"
|
|
95 |
^self subclassResponsibility
|
|
96 |
! !
|
|
97 |
|
|
98 |
!DisplayTransform methodsFor:'initialize'!
|
|
99 |
|
|
100 |
setIdentity
|
|
101 |
"Initialize the receiver to the identity transformation (e.g., not affecting points)"
|
|
102 |
|
|
103 |
^self subclassResponsibility
|
|
104 |
! !
|
|
105 |
|
|
106 |
!DisplayTransform methodsFor:'testing'!
|
|
107 |
|
|
108 |
isCompositeTransform
|
|
109 |
"Return true if the receiver is a composite transformation.
|
|
110 |
Composite transformations may have impact on the accuracy."
|
|
111 |
^false
|
|
112 |
!
|
|
113 |
|
7414
|
114 |
isIdentityTransformation
|
|
115 |
"Return true if the receiver is the identity transform; that is, if applying to a point returns the point itself."
|
|
116 |
|
|
117 |
^ self subclassResponsibility
|
6698
|
118 |
!
|
|
119 |
|
|
120 |
isMatrixTransform2x3
|
|
121 |
"Return true if the receiver is 2x3 matrix transformation"
|
|
122 |
^false
|
|
123 |
!
|
|
124 |
|
|
125 |
isMorphicTransform
|
|
126 |
"Return true if the receiver is a MorphicTransform, that is specifies the transformation values explicitly."
|
|
127 |
^false
|
|
128 |
!
|
|
129 |
|
|
130 |
isNoScale
|
|
131 |
"return true if the identity scale is in effect (i.e. saleFactor is 1);
|
|
132 |
return false, otherwise."
|
|
133 |
|
7414
|
134 |
^ self subclassResponsibility
|
6698
|
135 |
!
|
|
136 |
|
|
137 |
noScale
|
|
138 |
"return true if the identity scale is in effect (i.e. saleFactor is 1);
|
|
139 |
return false, otherwise.
|
|
140 |
Obsolete: use isNoScale"
|
|
141 |
|
|
142 |
<resource: #obsolete>
|
|
143 |
|
|
144 |
^ self isNoScale
|
|
145 |
! !
|
|
146 |
|
|
147 |
!DisplayTransform methodsFor:'transforming points'!
|
|
148 |
|
|
149 |
applyInverseTo:aPoint
|
|
150 |
^ self invertPoint: aPoint
|
|
151 |
!
|
|
152 |
|
|
153 |
applyScaleX:aNumber
|
|
154 |
^ (self transformPoint: aNumber @ 0) x
|
|
155 |
!
|
|
156 |
|
|
157 |
applyScaleY:aNumber
|
|
158 |
^ (self transformPoint: 0 @ aNumber) y
|
|
159 |
!
|
|
160 |
|
|
161 |
applyTo:aPoint
|
|
162 |
^ self transformPoint: aPoint
|
|
163 |
!
|
|
164 |
|
|
165 |
globalPointToLocal: aPoint
|
|
166 |
"Transform aPoint from global coordinates into local coordinates"
|
|
167 |
^self subclassResponsibility
|
|
168 |
!
|
|
169 |
|
|
170 |
globalPointsToLocal: inArray
|
|
171 |
"Transform all the points of inArray from global into local coordinates"
|
|
172 |
^inArray collect:[:pt| self globalPointToLocal: pt]
|
|
173 |
!
|
|
174 |
|
|
175 |
localPointToGlobal: aPoint
|
|
176 |
"Transform aPoint from local coordinates into global coordinates"
|
|
177 |
^self subclassResponsibility
|
|
178 |
!
|
|
179 |
|
|
180 |
localPointsToGlobal: inArray
|
|
181 |
"Transform all the points of inArray from local into global coordinates"
|
|
182 |
^inArray collect:[:pt| self localPointToGlobal: pt]
|
|
183 |
! !
|
|
184 |
|
|
185 |
!DisplayTransform methodsFor:'transforming rects'!
|
|
186 |
|
|
187 |
globalBoundsToLocal: aRectangle
|
|
188 |
"Transform aRectangle from global coordinates into local coordinates"
|
|
189 |
^Rectangle encompassing: (self globalPointsToLocal: aRectangle corners)
|
|
190 |
!
|
|
191 |
|
|
192 |
localBoundsToGlobal: aRectangle
|
|
193 |
"Transform aRectangle from local coordinates into global coordinates"
|
|
194 |
^Rectangle encompassing: (self localPointsToGlobal: aRectangle corners)
|
|
195 |
! !
|
|
196 |
|
|
197 |
!DisplayTransform class methodsFor:'documentation'!
|
|
198 |
|
|
199 |
version
|
7414
|
200 |
^ '$Header$'
|
6698
|
201 |
!
|
|
202 |
|
|
203 |
version_CVS
|
7414
|
204 |
^ '$Header$'
|
6698
|
205 |
! !
|
|
206 |
|