From e08199f06f86f9e25277ea3095be81413fb95005 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Sat, 20 Feb 2016 14:45:17 -0500 Subject: [PATCH] ScaleAbout --- README.md | 1 + context.go | 4 ++++ matrix.go | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 8b144a0..9b5715e 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ SetFillRule(fillRule FillRule) Identity() Translate(x, y float64) Scale(x, y float64) +ScaleAbout(sx, sy, x, y float64) Rotate(angle float64) RotateAbout(angle, x, y float64) Shear(x, y float64) diff --git a/context.go b/context.go index 4f65f71..6abb827 100644 --- a/context.go +++ b/context.go @@ -388,6 +388,10 @@ func (dc *Context) Scale(x, y float64) { dc.matrix = dc.matrix.Scale(x, y) } +func (dc *Context) ScaleAbout(sx, sy, x, y float64) { + dc.matrix = dc.matrix.ScaleAbout(sx, sy, x, y) +} + func (dc *Context) Rotate(angle float64) { dc.matrix = dc.matrix.Rotate(angle) } diff --git a/matrix.go b/matrix.go index 6694247..601fb45 100644 --- a/matrix.go +++ b/matrix.go @@ -30,6 +30,13 @@ func Scale(x, y float64) Matrix { } } +func ScaleAbout(sx, sy, x, y float64) Matrix { + a := Translate(-x, -y) + b := Scale(sx, sy) + c := Translate(x, y) + return a.Multiply(b).Multiply(c) +} + func Rotate(angle float64) Matrix { c := math.Cos(angle) s := math.Sin(angle) @@ -86,6 +93,10 @@ func (a Matrix) Scale(x, y float64) Matrix { return Scale(x, y).Multiply(a) } +func (a Matrix) ScaleAbout(sx, sy, x, y float64) Matrix { + return ScaleAbout(sx, sy, x, y).Multiply(a) +} + func (a Matrix) Rotate(angle float64) Matrix { return Rotate(angle).Multiply(a) }