Skip to content

Commit

Permalink
Merge pull request #7 from nickschot/feature/initial-tests
Browse files Browse the repository at this point in the history
Initial tests & function docs
  • Loading branch information
nickschot authored Jul 28, 2018
2 parents 1271add + ab91ae0 commit b604820
Show file tree
Hide file tree
Showing 16 changed files with 2,163 additions and 2,011 deletions.
3 changes: 2 additions & 1 deletion addon/mixins/pan-recognizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { get, set } from '@ember/object';
import { inject as service } from '@ember/service';

import RunOnRafMixin from 'ember-mobile-core/mixins/run-on-raf';
import parseTouchData, {
import {
parseInitialTouchData,
parseTouchData,
isHorizontal,
isVertical
} from 'ember-mobile-core/utils/parse-touch-data';
Expand Down
7 changes: 6 additions & 1 deletion addon/utils/get-window-height.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Return the current window width
* NOTE: do not use in FastBoot
* @returns {number}
*/
export default function getWindowHeight() {
return window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
return window.innerHeight;
}
7 changes: 6 additions & 1 deletion addon/utils/get-window-width.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Return the current window width
* NOTE: do not use in FastBoot
* @returns {number}
*/
export default function getWindowWidth() {
return window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
return window.innerWidth;
}
35 changes: 34 additions & 1 deletion addon/utils/parse-touch-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function parseInitialTouchData(touch, e){
* @param e The touch{start,move,end} event
* @returns {*} The new touch data
*/
export default function parseTouchData(previousTouchData, touch, e) {
export function parseTouchData(previousTouchData, touch, e) {
const touchData = assign({}, previousTouchData);
const data = touchData.data;

Expand Down Expand Up @@ -87,15 +87,32 @@ export default function parseTouchData(previousTouchData, touch, e) {
return touchData;
}

/**
* Calculates whether the movement went either left or right
* @param touchData A POJO as returned from `parseInitialTouchData` or `parseTouchData`
* @returns {boolean} true, false
*/
export function isHorizontal(touchData){
const direction = getDirection(touchData.data.current.distanceX, touchData.data.current.distanceY);
return direction === 'left' || direction === 'right';
}

/**
* Calculates whether the movement went either up or down
* @param touchData A POJO as returned from `parseInitialTouchData` or `parseTouchData`
* @returns {boolean} true, false
*/
export function isVertical(touchData){
const direction = getDirection(touchData.data.current.distanceX, touchData.data.current.distanceY);
return direction === 'down' || direction === 'up';
}

/**
* Calculates the direction of the touch movement
* @param x Number denoting the distance moved from the origin on the X axis
* @param y Number denoting the distance moved from the origin on the Y axis
* @returns {string} up, right, down, left
*/
function getDirection(x, y) {
if(x === y){
return 'none';
Expand All @@ -106,10 +123,26 @@ function getDirection(x, y) {
}
}

/**
* Calculates the distance between two points
* @param x0 X coordinate of the origin
* @param x1 X coordinate of the current position
* @param y0 Y coordinate of the origin
* @param y1 Y coordinate of the current position
* @returns {number} Distance between the two points
*/
function getPointDistance(x0, x1, y0, y1) {
return (Math.sqrt(((x1 - x0) * (x1 - x0)) + ((y1 - y0) * (y1 - y0))));
}

/**
* Calculates the angle between two points
* @param originX
* @param originY
* @param projectionX
* @param projectionY
* @returns {number} Angle between the two points
*/
function getAngle(originX, originY, projectionX, projectionY) {
const angle = Math.atan2(projectionY - originY, projectionX - originX) * ((180) / Math.PI);
return 360 - ((angle < 0) ? (360 + angle) : angle);
Expand Down
Loading

0 comments on commit b604820

Please sign in to comment.