UNPKG

convex-pixel

Version:

The library for creating pseudo 3d interactive scenes based on webgl

57 lines 2.25 kB
import { Vector4D } from "./geom/vector"; export var RatioFitTypes; (function (RatioFitTypes) { RatioFitTypes[RatioFitTypes["NONE"] = 0] = "NONE"; RatioFitTypes[RatioFitTypes["FILL"] = 1] = "FILL"; RatioFitTypes[RatioFitTypes["SHOW_ALL"] = 2] = "SHOW_ALL"; RatioFitTypes[RatioFitTypes["O_FILL"] = 3] = "O_FILL"; RatioFitTypes[RatioFitTypes["O_SHOW_ALL"] = 4] = "O_SHOW_ALL"; })(RatioFitTypes || (RatioFitTypes = {})); export const getRatio = (width1, height1, width2, height2, type = RatioFitTypes.NONE) => { let ratioX; let ratioY; switch (type) { case RatioFitTypes.SHOW_ALL: ratioX = width2 / width1; ratioY = height2 / height1; return Math.min(ratioX, ratioY); case RatioFitTypes.FILL: ratioX = width2 / width1; ratioY = height2 / height1; return Math.max(ratioX, ratioY); case RatioFitTypes.O_SHOW_ALL: ratioX = width2 < width1 ? width2 / width1 : width1 / width2; ratioY = height2 < height1 ? height2 / height1 : height1 / height2; return Math.min(ratioX, ratioY); case RatioFitTypes.O_FILL: ratioX = width2 < width1 ? width2 / width1 : width1 / width2; ratioY = height2 < height1 ? height2 / height1 : height1 / height2; return Math.min(ratioX, ratioY); case RatioFitTypes.NONE: default: return 1; } }; export const getAbsolutePosition = (object, options, iteration = 0) => { let _to; if (options && options.to) { _to = options.to; } if (!object) { return Vector4D.new(); } const result = Vector4D.new(object.x, object.y, object.scale.x, object.scale.y); if (object.parent) { const isVect = _to && object.parent instanceof _to; // if (!isVect) { const parentPos = getAbsolutePosition(object.parent, options, iteration++); result.x += parentPos.x || 0; result.y += parentPos.y || 0; result.z *= parentPos.z || 1; result.t *= parentPos.t || 1; parentPos.free(); // } } return result; }; //# sourceMappingURL=display.js.map