src/util/Util.js
/**
 * Convert the position to height units.
 *
 * @name module:util.to_height
 * @function
 * @public
 * @param {number[]} pos - the input position
 * @param {string} posUnit - the position units
 * @param {Window} win - the associated Window
 * @returns {number[]} the position in height units
 */
Convert the position to height units.
Convert the position to height units .
function to_height(pos, posUnit, win)
{
	const response = {
		origin: "util.to_height",
		context: "when converting a position to height units",
	};
	if (posUnit === "height")
	{
		return pos;
	}
	if (posUnit === "pix")
	{
		const minSize = Math.min(win.size[0], win.size[1]);
		return [pos[0] / minSize, pos[1] / minSize];
	}
	if (posUnit === "norm")
	{
		const minSize = Math.min(win.size[0], win.size[1]);
		return [pos[0] * win.size[0] / 2.0 / minSize, pos[1] * win.size[1] / 2.0 / minSize];
	}
	throw Object.assign(response, { error: `unknown position units: ${posUnit}` });
}
function to_height ( pos , posUnit , win ) { const response = { origin : "util.to_height" , context : "when converting a position to height units" , } ; if ( posUnit === "height" ) { return pos ; } if ( posUnit === "pix" ) { const minSize = Math . min ( win . size [ 0 ] , win . size [ 1 ] ) ; return [ pos [ 0 ] / minSize , pos [ 1 ] / minSize ] ; } if ( posUnit === "norm" ) { const minSize = Math . min ( win . size [ 0 ] , win . size [ 1 ] ) ; return [ pos [ 0 ] * win . size [ 0 ] / 2.0 / minSize , pos [ 1 ] * win . size [ 1 ] / 2.0 / minSize ] ; } throw Object . assign ( response , { error : ` ${ posUnit } ` } ) ; }
Convert the position to height units.
Convert the position to height units .