From 21733d0858db0722bf0855851cd7a34c001da05e Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Fri, 2 Dec 2016 17:36:36 +0100
Subject: [PATCH] add Transform.ScaleXY method

---
 transform.go | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/transform.go b/transform.go
index a88c09c..5e96fab 100644
--- a/transform.go
+++ b/transform.go
@@ -15,15 +15,15 @@ import "github.com/go-gl/mathgl/mgl32"
 //
 //   pixel.Position(pixel.V(100, 100)).Rotate(math.Pi / 3).Scale(1.5)
 type Transform struct {
-	pos, anc Vec
-	sca, rot float64
+	pos, anc, sca Vec
+	rot           float64
 }
 
 // Position creates a Transformation object with specified position. Anchor is (0, 0), rotation is 0 and scale is 1.
 func Position(position Vec) Transform {
 	return Transform{
 		pos: position,
-		sca: 1,
+		sca: V(1, 1),
 	}
 }
 
@@ -50,6 +50,15 @@ func (t Transform) MoveAnchor(delta Vec) Transform {
 // Note, that subsequent calls to this method accumulate the final scale factor. Scaling two times by 2 is equivalent
 // to scaling once by 4.
 func (t Transform) Scale(scale float64) Transform {
+	t.sca *= V(scale, scale)
+	return t
+}
+
+// ScaleXY scales the transform by the supplied X and Y factor. Note, that scale is applied before rotation.
+//
+// Note, that subsequent calls to this method accumulate the final scale factor. Scaling two times by 2 is equivalent
+// to scaling once by 4.
+func (t Transform) ScaleXY(scale Vec) Transform {
 	t.sca *= scale
 	return t
 }
@@ -67,8 +76,8 @@ func (t Transform) Rotate(angle float64) Transform {
 func (t Transform) Mat3() mgl32.Mat3 {
 	mat := mgl32.Ident3()
 	mat = mat.Mul3(mgl32.Translate2D(float32(t.pos.X()), float32(t.pos.Y())))
-	mat = mat.Mul3(mgl32.Scale2D(float32(t.sca), float32(t.sca)))
 	mat = mat.Mul3(mgl32.Rotate3DZ(float32(t.rot)))
+	mat = mat.Mul3(mgl32.Scale2D(float32(t.sca.X()), float32(t.sca.Y())))
 	mat = mat.Mul3(mgl32.Translate2D(float32(t.anc.X()), float32(t.anc.Y())))
 	return mat
 }
-- 
GitLab