Skip to content

Commit

Permalink
修复未绘制图形时添加手势造成的脚本错误
Browse files Browse the repository at this point in the history
Ref:#17
  • Loading branch information
sunlianghua authored and sunlianghua committed Oct 31, 2016
1 parent 873e563 commit 6cc0958
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let lastPoints = [];
const options = {
el: document.getElementById('test'),
enablePath: true,
timeDelay: 500,
timeDelay: 100,
triggerMouseKey: 'left',
onSwipe: (list) => {
document.getElementById('result0').innerHTML = list.join('');
Expand Down
7 changes: 4 additions & 3 deletions src/dollarOne/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ const pathLength = (points) => {
const centroid = (points) => {
let x = 0.0;
let y = 0.0;
for (let i = 0; i < points.length; i++) {
let len = points.length;
for (let i = 0; i < len; i++) {
x += points[i].x;
y += points[i].y;
}
x /= points.length;
y /= points.length;
x /= len;
y /= len;
return new Point(x, y);
};

Expand Down
15 changes: 13 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,19 @@ class Canvas {

addGesture(ges = {}) {
const { name, points } = ges;
if (!name || !points || !Array.isArray(points)) {
console.warn('invalid params. addGesture fail.');
const safeName = name.trim();
const msgMap = {
'EMPTY_NAME':'Invalid Gesture Name. `addGesture` failed.',
'EMPTY_POINT':'Invalid Points. `addGesture` failed.'
};

if(!safeName){
console.warn(msgMap['EMPTY_NAME']);
return false;
}

if (!points || !Array.isArray(points) || !points.length) {
console.warn(msgMap['EMPTY_POINT']);
return false;
}

Expand Down

0 comments on commit 6cc0958

Please sign in to comment.