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