What is the Raphael.transformPath analogue in svg.js?

93 Views Asked by At

Raphael has a nifty function to transform one path to another:

 R.transformPath = function (path, transform) {
   return mapPath(path, toMatrix(path, transform));
 }

Is there a similar function in svg.js?

1

There are 1 best solutions below

0
Fuzzyma On

To transform the path array you would do something along those lines:


const arr = path.array()

arr.map(segment => {
  // ... add code to get the x and y of all the points used
  // for a line it would be segment[1] and segment[2]

  const {x, y} = new SVG.Point(segment[1], segment[2]).transform(transform)
  return [segment[0], x, y]
})