import * as Vector from './vector'; // Vertice operations. // **Vertice** is a utility class to help with vertice operations. A vertice // is implemented as a 2-element array. Element 0 is *x* and element 1 is *y*. // Translate a vertice from an origin point using rotation and scale. export function translate (vertice, origin, rotation = 0, scale = 1) { // nop? if (0 === rotation && 1 === scale) { return vertice; } // Rotate. const difference = Vector.sub(vertice, origin); rotation += Vector.angle(difference); const magnitude = Vector.magnitude(vertice, origin); vertice = Vector.add( origin, Vector.scale([Math.cos(rotation), Math.sin(rotation)], magnitude) ); // Scale. vertice = Vector.scale(vertice, scale); return vertice; }