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