UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

25 lines (21 loc) 805 B
import Vector2 from "../../../../core/geom/Vector2.js"; /** * * @param {Vector2} size * @param {AABB2} frame * @param {Vector2} margin * @param {number} x * @param {number} y * @return {Vector2} */ export function position_curve_to_canvas(size, frame, margin, x, y) { const width = size.x; const height = size.y; const curve_width = frame.width; const curve_width_multiplier = curve_width > 0 ? 1 / curve_width : 0; const u = (x - frame.x0) * curve_width_multiplier; const curve_height = frame.height; const curve_height_multiplier = curve_height > 0 ? 1 / curve_height : 0; const v = 1 - (y - frame.y0) * curve_height_multiplier; return new Vector2(margin.x + (u * (width - margin.x * 2)), margin.y + v * (height - margin.y * 2)); }