Skip to content

Commit

Permalink
fix: round snap grids so dragging from each side is even
Browse files Browse the repository at this point in the history
  • Loading branch information
prutje authored and mattlewis92 committed Jun 23, 2018
1 parent 2074c0a commit fa8434b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/draggable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
map(moveData => {
if (this.dragSnapGrid.x) {
moveData.x =
Math.floor(moveData.x / this.dragSnapGrid.x) *
Math.round(moveData.x / this.dragSnapGrid.x) *
this.dragSnapGrid.x;
}

if (this.dragSnapGrid.y) {
moveData.y =
Math.floor(moveData.y / this.dragSnapGrid.y) *
Math.round(moveData.y / this.dragSnapGrid.y) *
this.dragSnapGrid.y;
}

Expand Down
6 changes: 3 additions & 3 deletions test/draggable.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('draggable directive', () => {
clientY: 18
});
expect(fixture.componentInstance.dragging).to.have.been.calledWith({
x: 0,
x: 10,
y: 8
});
triggerDomEvent('mousemove', draggableElement, {
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('draggable directive', () => {
});
expect(fixture.componentInstance.dragging).to.have.been.calledWith({
x: 8,
y: 0
y: 10
});
triggerDomEvent('mousemove', draggableElement, {
clientX: 20,
Expand Down Expand Up @@ -361,7 +361,7 @@ describe('draggable directive', () => {
y: 10
});
triggerDomEvent('mousemove', draggableElement, {
clientX: 18,
clientX: 14,
clientY: 18
});
expect(fixture.componentInstance.dragging).to.have.been.calledOnce;
Expand Down

0 comments on commit fa8434b

Please sign in to comment.