From 95ff64fdbd08070bd56227e820202201de024890 Mon Sep 17 00:00:00 2001 From: zenozeng Date: Tue, 4 May 2021 10:59:54 +0000 Subject: [PATCH] feat: translate --- canvas2svg.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/canvas2svg.js b/canvas2svg.js index 3aa63b3..ad96031 100644 --- a/canvas2svg.js +++ b/canvas2svg.js @@ -1213,7 +1213,10 @@ }; /** - * rotates the current element + * Rotate adds a rotation to the transformation matrix. + * + * @param angle The rotation angle, clockwise in radians. You can use degree * Math.PI / 180 to calculate a radian from a degree. + * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/rotate */ ctx.prototype.rotate = function (angle) { var degrees = (angle * 180 / Math.PI); @@ -1221,10 +1224,15 @@ }; /** - * translates the current element + * Translate adds a translation transformation to the current matrix. + * + * @param x Distance to move in the horizontal direction. Positive values are to the right, and negative to the left. + * @param y Distance to move in the vertical direction. Positive values are down, and negative are up. + * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/translate */ ctx.prototype.translate = function (x, y) { - this.__addTransform(format("translate({x},{y})", {x:x,y:y})); + const matrix = this.getTransform().translate(x, y); + this.setTransform(matrix); }; /**