class: MatrixTransform2x3
authorClaus Gittinger <cg@exept.de>
Sat, 30 Mar 2013 01:54:53 +0100
changeset 3111 d4e7cc019d23
parent 3110 721f2bb58301
child 3112 d6fbee4954ca
class: MatrixTransform2x3 added: #transformDirection: comment/format in: #setOffset: #setScale: #transformPoint:
MatrixTransform2x3.st
--- a/MatrixTransform2x3.st	Sun Mar 24 12:46:18 2013 +0100
+++ b/MatrixTransform2x3.st	Sat Mar 30 01:54:53 2013 +0100
@@ -9,16 +9,19 @@
 
 MatrixTransform2x3 comment:'This class represents a transformation for points, that is a combination of scale, offset, and rotation. It is implemented as a 2x3 matrix containing the transformation from the local coordinate system in the global coordinate system. Thus, transforming points from local to global coordinates is fast and cheap whereas transformations from global to local coordinate systems are relatively expensive.
 
-Implementation Note: It is assumed that the transformation deals with Integer points. All transformations will return Integer coordinates (even though float points may be passed in here).'!
+Implementation Note: It is assumed that the transformation deals with Integer points. All transformations will return Integer coordinates (even though float points may be passed in here).'
+!
 
 
 !MatrixTransform2x3 class methodsFor:'instance creation'!
 
 identity
-	^self new setScale: 1.0!
+	^self new setScale: 1.0
+!
 
 new
-	^self new: 6!
+	^self new: 6
+!
 
 transformFromLocal: localBounds toGlobal: globalBounds
 	^((self withOffset: (globalBounds center)) composedWithLocal:
@@ -29,19 +32,24 @@
 		setScale: (globalBounds extent / localBounds extent) asFloatPoint;
 		setOffset: localBounds center negated asFloatPoint;
 		composedWithGlobal:(self withOffset: globalBounds center asFloatPoint)
-"!
+"
+!
 
 withAngle: angle
-	^self new setAngle: angle!
+	^self new setAngle: angle
+!
 
 withOffset: aPoint
-	^self identity setOffset: aPoint!
+	^self identity setOffset: aPoint
+!
 
 withRotation: angle
-	^self new setAngle: angle!
+	^self new setAngle: angle
+!
 
 withScale: aPoint
-	^self new setScale: aPoint! !
+	^self new setScale: aPoint
+! !
 
 !MatrixTransform2x3 methodsFor:'accessing'!
 
@@ -73,14 +81,17 @@
 	m
 		a11: r1 x; a12: r2 x; a13: r3 x;
 		a21: r1 y; a22: r2 y; a23: r3 y.
-	^m!
+	^m
+!
 
 offset
-	^self a13 @ self a23!
+	^self a13 @ self a23
+!
 
 offset: aPoint
 	self a13: aPoint x asFloat.
-	self a23: aPoint y asFloat.! !
+	self a23: aPoint y asFloat.
+! !
 
 !MatrixTransform2x3 methodsFor:'comparing'!
 
@@ -110,7 +121,8 @@
 composedWithLocal: aTransformation
 	"Return the composition of the receiver and the local transformation passed in"
 	aTransformation isMatrixTransform2x3 ifFalse:[^super composedWith: aTransformation].
-	^self composedWithLocal: aTransformation asMatrixTransform2x3 into: self class new!
+	^self composedWithLocal: aTransformation asMatrixTransform2x3 into: self class new
+!
 
 composedWithLocal: aTransformation into: result
         "Return the composition of the receiver and the local transformation passed in.
@@ -136,45 +148,58 @@
 !MatrixTransform2x3 methodsFor:'converting'!
 
 asMatrixTransform2x3
-	^self! !
+	^self
+! !
 
 !MatrixTransform2x3 methodsFor:'element access'!
 
 a11
-	^self at: 1!
+	^self at: 1
+!
 
 a11: value
-	 self at: 1 put: value!
+	 self at: 1 put: value
+!
 
 a12
-	^self at: 2!
+	^self at: 2
+!
 
 a12: value
-	 self at: 2 put: value!
+	 self at: 2 put: value
+!
 
 a13
-	^self at: 3!
+	^self at: 3
+!
 
 a13: value
-	 self at: 3 put: value!
+	 self at: 3 put: value
+!
 
 a21
-	 ^self at: 4!
+	 ^self at: 4
+!
 
 a21: value
-	 self at: 4 put: value!
+	 self at: 4 put: value
+!
 
 a22
-	 ^self at: 5!
+	 ^self at: 5
+!
 
 a22: value
-	 self at: 5 put: value!
+	 self at: 5 put: value
+!
 
 a23
-	 ^self at: 6!
+	 ^self at: 6
+!
 
 a23: value
-	 self at: 6 put: value! !
+	 self at: 6 put: value
+! !
 
 !MatrixTransform2x3 methodsFor:'initialize'!
 
@@ -182,7 +207,8 @@
 	"Initialize the receiver to the identity transformation (e.g., not affecting points)"
 	self
 		a11: 1.0; a12: 0.0; a13: 0.0;
-		a21: 0.0; a22: 1.0; a23: 0.0.! !
+		a21: 0.0; a22: 1.0; a23: 0.0.
+! !
 
 !MatrixTransform2x3 methodsFor:'printing'!
 
@@ -192,7 +218,8 @@
 		nextPut: $(;
 		cr; print: self a11; tab; print: self a12; tab; print: self a13;
 		cr; print: self a21; tab; print: self a22; tab; print: self a23;
-		cr; nextPut:$).! !
+		cr; nextPut:$).
+! !
 
 !MatrixTransform2x3 methodsFor:'private'!
 
@@ -205,21 +232,24 @@
 	self a11: c.
 	self a12: s negated.
 	self a21: s.
-	self a22: c.!
+	self a22: c.
+!
 
 setOffset: aPoint
-	"Set the raw offset in the receiver"
-	| pt |
-	pt _ aPoint asPoint.
-	self a13: pt x asFloat.
-	self a23: pt y asFloat.!
+        "Set the raw offset in the receiver"
+        | pt |
+        pt := aPoint asPoint.
+        self a13: pt x asFloat.
+        self a23: pt y asFloat.
+!
 
 setScale: aPoint
-	"Set the raw scale in the receiver"
-	| pt |
-	pt _ aPoint asPoint.
-	self a11: pt x asFloat.
-	self a22: pt y asFloat.! !
+        "Set the raw scale in the receiver"
+        | pt |
+        pt := aPoint asPoint.
+        self a11: pt x asFloat.
+        self a22: pt y asFloat.
+! !
 
 !MatrixTransform2x3 methodsFor:'testing'!
 
@@ -231,7 +261,8 @@
 
 isMatrixTransform2x3
 	"Return true if the receiver is 2x3 matrix transformation"
-	^true!
+	^true
+!
 
 isPureTranslation
         "Return true if the receiver specifies no rotation or scaling."
@@ -259,7 +290,8 @@
 	det _ 1.0 / det.
 	detX _ (x * a22) - (a12 * y).
 	detY _ (a11 * y) - (x * a21).
-	^(detX * det) @ (detY * det)!
+	^(detX * det) @ (detY * det)
+!
 
 localPointToGlobal: aPoint
         "Transform aPoint from local coordinates into global coordinates"
@@ -267,12 +299,22 @@
         ^(self transformPoint: aPoint) rounded
 !
 
+transformDirection: aPoint
+        "Transform aPoint from local coordinates into global coordinates;
+         Ignores the offset."
+        | x y |
+        x := (aPoint x * self a11) + (aPoint y * self a12).
+        y := (aPoint x * self a21) + (aPoint y * self a22).
+        ^x @ y
+!
+
 transformPoint: aPoint
-	"Transform aPoint from local coordinates into global coordinates"
-	| x y |
-	x _ (aPoint x * self a11) + (aPoint y * self a12) + self a13.
-	y _ (aPoint x * self a21) + (aPoint y * self a22) + self a23.
-	^x @ y! !
+        "Transform aPoint from local coordinates into global coordinates"
+        | x y |
+        x := (aPoint x * self a11) + (aPoint y * self a12) + self a13.
+        y := (aPoint x * self a21) + (aPoint y * self a22) + self a23.
+        ^x @ y
+! !
 
 !MatrixTransform2x3 methodsFor:'transforming rects'!
 
@@ -284,7 +326,8 @@
 
 globalBoundsToLocal: aRectangle
 	"Transform aRectangle from global coordinates into local coordinates"
-	^self globalBounds: aRectangle toLocal: Rectangle new!
+	^self globalBounds: aRectangle toLocal: Rectangle new
+!
 
 localBounds: srcRect toGlobal: dstRect
         "Transform aRectangle from local coordinates into global coordinates"
@@ -294,10 +337,12 @@
 
 localBoundsToGlobal: aRectangle
 	"Transform aRectangle from local coordinates into global coordinates"
-	^self localBounds: aRectangle toGlobal: Rectangle new! !
+	^self localBounds: aRectangle toGlobal: Rectangle new
+! !
 
 !MatrixTransform2x3 class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/MatrixTransform2x3.st,v 1.2 2000-07-18 12:21:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/MatrixTransform2x3.st,v 1.3 2013-03-30 00:54:53 cg Exp $'
 ! !
+