ShearAbout

This commit is contained in:
Michael Fogleman 2016-02-20 14:53:33 -05:00
parent 1d5fd3d775
commit b77c5f2881
3 changed files with 20 additions and 4 deletions

View File

@ -101,10 +101,11 @@ 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)
ScaleAbout(sx, sy, x, y float64)
RotateAbout(angle, x, y float64)
ShearAbout(sx, sy, x, y float64)
TransformPoint(x, y float64) (tx, ty float64)
InvertY()
Push()

View File

@ -404,6 +404,10 @@ func (dc *Context) Shear(x, y float64) {
dc.matrix = dc.matrix.Shear(x, y)
}
func (dc *Context) ShearAbout(sx, sy, x, y float64) {
dc.matrix = dc.matrix.ShearAbout(sx, sy, x, y)
}
func (dc *Context) TransformPoint(x, y float64) (tx, ty float64) {
return dc.matrix.TransformPoint(x, y)
}

View File

@ -56,12 +56,19 @@ func RotateAbout(angle, x, y float64) Matrix {
func Shear(x, y float64) Matrix {
return Matrix{
1, x,
y, 1,
1, y,
x, 1,
0, 0,
}
}
func ShearAbout(sx, sy, x, y float64) Matrix {
a := Translate(-x, -y)
b := Shear(sx, sy)
c := Translate(x, y)
return a.Multiply(b).Multiply(c)
}
func (a Matrix) Multiply(b Matrix) Matrix {
return Matrix{
a.XX*b.XX + a.YX*b.XY,
@ -108,3 +115,7 @@ func (a Matrix) RotateAbout(angle, x, y float64) Matrix {
func (a Matrix) Shear(x, y float64) Matrix {
return Shear(x, y).Multiply(a)
}
func (a Matrix) ShearAbout(sx, sy, x, y float64) Matrix {
return ShearAbout(sx, sy, x, y).Multiply(a)
}