From bf7b16e1319e308ccfe0a5549da571056a82f6bb Mon Sep 17 00:00:00 2001 From: rasha108bik Date: Tue, 19 Apr 2022 00:35:37 +0300 Subject: [PATCH] Add method for rotation around the center #65 --- README.markdown | 3 +++ svg.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/README.markdown b/README.markdown index 0526c06..ac5ffd3 100644 --- a/README.markdown +++ b/README.markdown @@ -308,6 +308,9 @@ is used to specify inputs and results for filter effects rotates the coordinate system by r degrees, end with Gend(). + RotateCenter(r float64, x, y int) + rotates arount the center coordinate system by r degrees, end with Gend() + TranslateRotate(x, y int, r float64) translates the coordinate system to (x,y), then rotates to r degrees, end with Gend(). diff --git a/svg.go b/svg.go index 03af677..b2de9a2 100644 --- a/svg.go +++ b/svg.go @@ -196,6 +196,9 @@ func (svg *SVG) SkewXY(ax, ay float64) { svg.Gtransform(skewX(ax) + " " + skewY( // Standard Reference: http://www.w3.org/TR/SVG11/coords.html#TransformAttribute func (svg *SVG) Rotate(r float64) { svg.Gtransform(rotate(r)) } +// RotateCenter rotates arount the center coordinate system by r degrees, end with Gend() +func (svg *SVG) RotateCenter(r float64, x, y int) { svg.Gtransform(rotateCenter(r, x, y)) } + // TranslateRotate translates the coordinate system to (x,y), then rotates to r degrees, end with Gend() func (svg *SVG) TranslateRotate(x, y int, r float64) { svg.Gtransform(translate(x, y) + " " + rotate(r)) @@ -1020,6 +1023,9 @@ func skewY(angle float64) string { return fmt.Sprintf(`skewY(%g)`, angle) } // rotate returns the rotate string for the transform func rotate(r float64) string { return fmt.Sprintf(`rotate(%g)`, r) } +// rotateCenter returns the rotate string for the transform +func rotateCenter(r float64, x, y int) string { return fmt.Sprintf(rotate(%g %d %d), r, x, y) } + // translate returns the translate string for the transform func translate(x, y int) string { return fmt.Sprintf(`translate(%d,%d)`, x, y) }