class: MatrixTransform2x3
authorClaus Gittinger <cg@exept.de>
Sun, 21 Dec 2014 22:22:53 +0100
changeset 3425 ba8fa7476156
parent 3424 f7fc39b128be
child 3426 22e436474a5e
class: MatrixTransform2x3 class definition added:5 methods comment/format in:5 methods
MatrixTransform2x3.st
--- a/MatrixTransform2x3.st	Sun Dec 21 22:20:45 2014 +0100
+++ b/MatrixTransform2x3.st	Sun Dec 21 22:22:53 2014 +0100
@@ -7,11 +7,40 @@
 	category:'Graphics-Transformations'
 !
 
-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.
+!MatrixTransform2x3 class methodsFor:'documentation'!
 
-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).'
+documentation
+"
+    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).
+"
 !
 
+examples
+"
+    example :
+                                                                        [exBegin]
+     |v|
+
+     v := View new openAndWait.
+     v transformation:(MatrixTransform2x3 withAngle:5).
+     v displayLineFrom:50@50 to:100@100 
+                                                                        [exEnd]
+
+                                                                        [exBegin]
+     |v|
+
+     v := View new openAndWait.
+     v transformation:(MatrixTransform2x3 withAngle:45).
+     v fillRectangleX:10 y:10 width:100 height:100.
+                                                                        [exEnd]
+"
+! !
 
 !MatrixTransform2x3 class methodsFor:'instance creation'!
 
@@ -36,19 +65,49 @@
 !
 
 withAngle: angle
-	^self new setAngle: angle
+        "return a new transformation which rotates by angle (in degrees)"
+
+        ^self new setAngle: angle
 !
 
 withOffset: aPoint
-	^self identity setOffset: aPoint
+        "return a new transformation which translates by aPoint"
+
+        ^self identity setOffset: aPoint
 !
 
 withRotation: angle
-	^self new setAngle: angle
+        "return a new transformation which rotates by angle (in degrees)"
+
+        ^self new setAngle: angle
 !
 
 withScale: aPoint
-	^self new setScale: aPoint
+        "return a new transformation which scales by aPoint's x/y values in x/y directions"
+
+        ^self new setScale: aPoint
+! !
+
+!MatrixTransform2x3 class methodsFor:'*SVG-Morphic'!
+
+withSkew: aPoint
+	"Answer a new instancec set to skew by the given angles in the x and y directions."
+
+	^self identity setSkew: aPoint
+! !
+
+!MatrixTransform2x3 methodsFor:'*SVG-Morphic'!
+
+setSkew: aPoint
+	"Set the raw skew angles in the receiver"
+
+	| radX radY sx sy|
+	radX := aPoint x degreesToRadians.
+	radY := aPoint y degreesToRadians.
+	sx := radX tan.
+	sy  := radY  tan.
+	self a21: sx.
+	self a12: sy
 ! !
 
 !MatrixTransform2x3 methodsFor:'accessing'!
@@ -224,15 +283,16 @@
 !MatrixTransform2x3 methodsFor:'private'!
 
 setAngle: angle
-	"Set the raw rotation angle in the receiver"
-	| rad s c |
-	rad := angle degreesToRadians.
-	s := rad sin.
-	c := rad cos.
-	self a11: c.
-	self a12: s negated.
-	self a21: s.
-	self a22: c.
+        "Set the raw rotation angle (in degrees) in the receiver"
+
+        | rad s c |
+        rad := angle degreesToRadians.
+        s := rad sin.
+        c := rad cos.
+        self a11: c.
+        self a12: s negated.
+        self a21: s.
+        self a22: c.
 !
 
 setOffset: aPoint
@@ -264,6 +324,13 @@
 	^true
 !
 
+isNoScale
+    "Return true if the receiver has an identity scale; i.e. the scale factor is 1.
+     Return false otherwise."
+
+    ^ self a11 = 1 and:[ self a22 = 1 ]
+!
+
 isPureTranslation
         "Return true if the receiver specifies no rotation or scaling."
 "/        <primitive: 'm23PrimitiveIsPureTranslation'>
@@ -343,6 +410,6 @@
 !MatrixTransform2x3 class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/MatrixTransform2x3.st,v 1.3 2013-03-30 00:54:53 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/MatrixTransform2x3.st,v 1.4 2014-12-21 21:22:53 cg Exp $'
 ! !