]> source.dussan.org Git - svg.js.git/commitdiff
Add PointArray.transform by analogy to Point.transform
authorErik Demaine <edemaine@mit.edu>
Thu, 13 Dec 2018 16:09:20 +0000 (11:09 -0500)
committerErik Demaine <edemaine@mit.edu>
Thu, 13 Dec 2018 16:09:20 +0000 (11:09 -0500)
src/types/PointArray.js

index 9e7406dadc06491fee160bce106956c3503fa714..6488c2970f93039a24ba85c3c44711a07a83f6ea 100644 (file)
@@ -71,6 +71,20 @@ extend(PointArray, {
     return points
   },
 
+  // transform points with matrix (similar to Point.transform)
+  transform (m) {
+    let points = []
+
+    for (let point of this) {
+      // Perform the matrix multiplication
+      points.push([m.a * point.x + m.c * point.y + m.e,
+                   m.b * point.x + m.d * point.y + m.f])
+    }
+
+    // Return the required point
+    return new PointArray(points)
+  }
+
   // Move point string
   move (x, y) {
     var box = this.bbox()