UNPKG

@egjs/axes

Version:

A module used to change the information of user action entered by various input devices such as touch screen or mouse into the logical virtual coordinates. You can easily create a UI that responds to user actions.

38 lines 1.43 kB
export var getInsidePosition = function (destPos, range, circular, bounce) { var toDestPos = destPos; var targetRange = [ circular[0] ? range[0] : bounce ? range[0] - bounce[0] : range[0], circular[1] ? range[1] : bounce ? range[1] + bounce[1] : range[1], ]; toDestPos = Math.max(targetRange[0], toDestPos); toDestPos = Math.min(targetRange[1], toDestPos); return toDestPos; }; export var isOutside = function (pos, range) { return pos < range[0] || pos > range[1]; }; export var isEndofBounce = function (pos, range, bounce, circular) { return ((!circular[0] && pos === range[0] - bounce[0]) || (!circular[1] && pos === range[1] + bounce[1])); }; export var getDuration = function (distance, deceleration) { var duration = Math.sqrt((distance / deceleration) * 2); return duration < 100 ? 0 : duration; }; export var isCircularable = function (destPos, range, circular) { return ((circular[1] && destPos > range[1]) || (circular[0] && destPos < range[0])); }; export var getCirculatedPos = function (pos, range, circular) { var toPos = pos; var min = range[0]; var max = range[1]; var length = max - min; if (circular[1] && pos > max) { toPos = ((toPos - max) % length) + min; } if (circular[0] && pos < min) { toPos = ((toPos - min) % length) + max; } return toPos; }; //# sourceMappingURL=Coordinate.js.map