
Class: TranslationTransform
Object

+DisplayTransform

+TranslationTransform
 Package:
 stx:libview
 Category:
 GraphicsTransformations
 Version:
 rev:
1.3
date: 2019/06/28 07:22:37
 user: cg
 file: TranslationTransform.st directory: libview
 module: stx stcclassLibrary: libview
 Author:
 Claus Gittinger
instances of WindowingTransformation can be used to scale, translate or
generally transform other objects in 2D space.
They can also be set as the translation in a graphic context,
which will then apply this to all of its drawing operations
(see GraphicContext>>transformation:).
All 2D objects are supposed to be able to be transformed using
instances of me. Multiple instances of me can also be combined to form a
single composite transformation.
[Instance variables:]
scale <Number> or <Point> representing a linear scaling factor.
nil is interpreted as 1@1
translation <Number> or <Point> representing a translation in 2D.
nil is interpreted as 0@0
instance creation

identity

returns a windowing transformation with no scaling (1@1)
and no translation (0@0).
usage example(s):
WindowingTransformation identity


translation: aTranslation

returns a windowing transformation with no scaling and a translation offset of aTranslation.
accessing

translation

return a copy of the receiver's translation.

translation: aTranslation

Set the receiver's translation to aTranslation, a Point or Number.

translationX

return the receiver's xtranslation.

translationY

return the receiver's xtranslation.
applying transform

applyInverseTo: anObject

Apply the inverse of the receiver to anObject
and return the result. This can be used to map back from logical
to physical coordinates, for example.

applyInverseToX: aNumber

Apply the receiver to a number representing an xcoordinate
and return the result.

applyInverseToY: aNumber

Apply the receiver to a number representing an ycoordinate
and return the result.

applyTo: anObject

Apply the receiver to anObject and return the result.

applyToX: aNumber

Apply the receiver to a number representing an xcoordinate
and return the result.

applyToY: aNumber

Apply the receiver to a number representing an ycoordinate
and return the result.

compose: aTransformation

return a new WindowingTransformation that is the
composition of the receiver and aTransformation.
The effect of applying the resulting WindowingTransformation
to an object is the same as that of first applying
aTransformation to the object and then applying the
receiver to its result.

composedWithLocal: aTransformation


transformPoint: p

Apply the receiver to a point, returning a new point.

transformRectangle: aRectangle

Apply the receiver to a rectangle, returning a new rectangle.
printing & storing

printOn: aStream

append a user printed representation of the receiver to aStream.
The format is suitable for a human  not meant to be read back.
private

inverseTranslation

return with a Point or Number representing the inverse of my translation.
testing

isIdentityTransformation

return true if this is an identity transformation;
return false, otherwise.

isNoScale

return true if the identity scale is in effect (i.e. saleFactor is 1);
return false, otherwise.
transformations

scaleBy: aScale

scale the receiver.
This is a destructive operation, modifying the transformation
represented by the receiver

scaledBy: aScale

return a new WindowingTransformation with the scale and translation of
the receiver both scaled by aScale.

translateBy: aTranslation

translate the receiver.
This is a destructive operation, modifying the transformation
represented by the receiver

translatedBy: aPoint

return a new WindowingTransformation with the same scale and
rotations as the receiver and with a translation of the current
translation plus aPoint.
example (drawing in inches):
v
v := View new realize.
(Delay forSeconds:3) wait.
v transformation:(WindowingTransformation unit:#inch on:Display).
'now, we can think of drawing in inches ...'.
v displayLineFrom:0.5@0.5 to:1@1

example (drawing in millimeters):
v
v := View new realize.
(Delay forSeconds:3) wait.
v transformation:(WindowingTransformation unit:#mm on:Display).
'now, we can think of drawing in millimeters ...'.
v displayLineFrom:5@5 to:20@5

example (drawing magnified):
v
v := View new realize.
(Delay forSeconds:3) wait.
v transformation:(WindowingTransformation scale:2 translation:0).
'now, everything is magnfied by 2'.
v displayLineFrom:10@10 to:30@30

example (drawing shrunk):
v
v := View new realize.
(Delay forSeconds:3) wait.
v transformation:(WindowingTransformation scale:0.5 translation:0).
'now, everything is shrunk by 2'.
v displayLineFrom:10@10 to:30@30

