From 62a248f7add66c3dc4e70d26b3f05e4e58455c12 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Thu, 13 Dec 2018 11:09:20 -0500 Subject: [PATCH] Add PointArray.transform by analogy to Point.transform --- src/types/PointArray.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/types/PointArray.js b/src/types/PointArray.js index 9e7406d..6488c29 100644 --- a/src/types/PointArray.js +++ b/src/types/PointArray.js @@ -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() -- 2.39.5