1250
|
1 |
Object subclass:#DisplayTransform
|
|
2 |
instanceVariableNames:''
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Graphics-Transformations'
|
|
6 |
!
|
|
7 |
|
|
8 |
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.
|
|
9 |
|
|
10 |
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).
|
|
11 |
|
|
12 |
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:
|
|
13 |
|
|
14 |
globalPointToLocal: globalPoint
|
|
15 |
"globalPoint -> globalTransform -> localTransform -> locaPoint"
|
|
16 |
^localTransform globalPointToLocal:
|
|
17 |
(globalTransform globalPointToLocal: globalPoint)
|
|
18 |
|
|
19 |
localPointToGlobal: localPoint
|
|
20 |
"localPoint -> localTransform -> globalTransform -> globalPoint"
|
|
21 |
^globalTransform localPointToGlobal:
|
|
22 |
(localTransform localPointToGlobal: localPoint)
|
|
23 |
|
|
24 |
'!
|
|
25 |
|
|
26 |
|
|
27 |
!DisplayTransform class methodsFor:'instance creation'!
|
|
28 |
|
|
29 |
identity
|
|
30 |
^self new setIdentity! !
|
|
31 |
|
|
32 |
!DisplayTransform methodsFor:'accessing'!
|
|
33 |
|
|
34 |
inverseTransformation
|
|
35 |
"Return the inverse transformation of the receiver"
|
|
36 |
^self subclassResponsibility! !
|
|
37 |
|
|
38 |
!DisplayTransform methodsFor:'composing'!
|
|
39 |
|
|
40 |
composedWithGlobal: aTransformation
|
|
41 |
"Return the composition of the receiver and the global transformation passed in.
|
|
42 |
A 'global' transformation is defined as a transformation that takes place
|
|
43 |
between the receiver (the 'local') transformation and any 'global' point
|
|
44 |
computations, e.g., for the methods
|
|
45 |
|
|
46 |
globalPointToLocal: globalPoint
|
|
47 |
globalPoint -> globalTransform -> localTransform -> locaPoint
|
|
48 |
|
|
49 |
localPointToGlobal: localPoint
|
|
50 |
localPoint -> localTransform -> globalTransform -> globalPoint
|
|
51 |
|
|
52 |
"
|
|
53 |
^aTransformation composedWithLocal: self!
|
|
54 |
|
|
55 |
composedWithLocal: aTransformation
|
|
56 |
"Return the composition of the receiver and the local transformation passed in.
|
|
57 |
A 'local' transformation is defined as a transformation that takes place
|
|
58 |
between the receiver (the 'global') transformation and any 'local' point
|
|
59 |
computations, e.g., for the methods
|
|
60 |
|
|
61 |
globalPointToLocal: globalPoint
|
|
62 |
globalPoint -> globalTransform -> localTransform -> locaPoint
|
|
63 |
|
|
64 |
localPointToGlobal: localPoint
|
|
65 |
localPoint -> localTransform -> globalTransform -> globalPoint
|
|
66 |
|
|
67 |
"
|
|
68 |
self isIdentity ifTrue:[^ aTransformation].
|
|
69 |
aTransformation isIdentity ifTrue:[^ self].
|
|
70 |
^ CompositeTransform new globalTransform: self
|
|
71 |
localTransform: aTransformation! !
|
|
72 |
|
|
73 |
!DisplayTransform methodsFor:'converting'!
|
|
74 |
|
|
75 |
asCompositeTransform
|
|
76 |
"Represent the receiver as a composite transformation"
|
|
77 |
^CompositeTransform new
|
|
78 |
globalTransform: self
|
|
79 |
localTransform: self species identity!
|
|
80 |
|
|
81 |
asMatrixTransform2x3
|
|
82 |
"Represent the receiver as a 2x3 matrix transformation"
|
|
83 |
^self subclassResponsibility! !
|
|
84 |
|
|
85 |
!DisplayTransform methodsFor:'initialize'!
|
|
86 |
|
|
87 |
setIdentity
|
|
88 |
"Initialize the receiver to the identity transformation (e.g., not affecting points)"
|
|
89 |
^self subclassResponsibility! !
|
|
90 |
|
|
91 |
!DisplayTransform methodsFor:'testing'!
|
|
92 |
|
|
93 |
isCompositeTransform
|
|
94 |
"Return true if the receiver is a composite transformation.
|
|
95 |
Composite transformations may have impact on the accuracy."
|
|
96 |
^false!
|
|
97 |
|
|
98 |
isIdentity
|
|
99 |
"Return true if the receiver is the identity transform; that is, if applying to a point returns the point itself."
|
|
100 |
^self subclassResponsibility!
|
|
101 |
|
|
102 |
isMatrixTransform2x3
|
|
103 |
"Return true if the receiver is 2x3 matrix transformation"
|
|
104 |
^false!
|
|
105 |
|
|
106 |
isMorphicTransform
|
|
107 |
"Return true if the receiver is a MorphicTransform, that is specifies the transformation values explicitly."
|
|
108 |
^false!
|
|
109 |
|
|
110 |
isPureTranslation
|
|
111 |
"Return true if the receiver specifies no rotation or scaling."
|
|
112 |
^self subclassResponsibility! !
|
|
113 |
|
|
114 |
!DisplayTransform methodsFor:'transforming points'!
|
|
115 |
|
|
116 |
globalPointToLocal: aPoint
|
|
117 |
"Transform aPoint from global coordinates into local coordinates"
|
|
118 |
^self subclassResponsibility!
|
|
119 |
|
|
120 |
globalPointsToLocal: inArray
|
|
121 |
"Transform all the points of inArray from global into local coordinates"
|
|
122 |
^inArray collect:[:pt| self globalPointToLocal: pt]!
|
|
123 |
|
|
124 |
localPointToGlobal: aPoint
|
|
125 |
"Transform aPoint from local coordinates into global coordinates"
|
|
126 |
^self subclassResponsibility!
|
|
127 |
|
|
128 |
localPointsToGlobal: inArray
|
|
129 |
"Transform all the points of inArray from local into global coordinates"
|
|
130 |
^inArray collect:[:pt| self localPointToGlobal: pt]! !
|
|
131 |
|
|
132 |
!DisplayTransform methodsFor:'transforming rects'!
|
|
133 |
|
|
134 |
globalBoundsToLocal: aRectangle
|
|
135 |
"Transform aRectangle from global coordinates into local coordinates"
|
|
136 |
^Rectangle encompassing: (self globalPointsToLocal: aRectangle corners)!
|
|
137 |
|
|
138 |
localBoundsToGlobal: aRectangle
|
|
139 |
"Transform aRectangle from local coordinates into global coordinates"
|
|
140 |
^Rectangle encompassing: (self localPointsToGlobal: aRectangle corners)! !
|
|
141 |
|
|
142 |
!DisplayTransform class methodsFor:'documentation'!
|
|
143 |
|
|
144 |
version
|
|
145 |
^ '$Header: /cvs/stx/stx/libview2/DisplayTransform.st,v 1.1 1999-10-06 22:22:58 cg Exp $'
|
|
146 |
! !
|