UNPKG

transformation-matrix

Version:

2d transformation matrix functions written in ES6 syntax. Tree shaking ready!

29 lines (27 loc) 919 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.applyToPoint = applyToPoint; exports.applyToPoints = applyToPoints; /** * Calculate a point transformed with an affine matrix * @param matrix {Matrix} Affine Matrix * @param point {Point} Point * @returns {Point} Point */ function applyToPoint(matrix, point) { return Array.isArray(point) ? [matrix.a * point[0] + matrix.c * point[1] + matrix.e, matrix.b * point[0] + matrix.d * point[1] + matrix.f] : { x: matrix.a * point.x + matrix.c * point.y + matrix.e, y: matrix.b * point.x + matrix.d * point.y + matrix.f }; } /** * Calculate an array of points transformed with an affine matrix * @param matrix {Matrix} Affine Matrix * @param points {Point[]} Array of point * @returns {Point[]} Array of point */ function applyToPoints(matrix, points) { return points.map(point => applyToPoint(matrix, point)); }