From 32cd0ee97288817c08bcd23e986e5a344b9adf9c Mon Sep 17 00:00:00 2001 From: probablycorey Date: Wed, 29 Jan 2014 12:10:15 -0800 Subject: [PATCH] Make distance a local method --- src/pane-container-view.coffee | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/pane-container-view.coffee b/src/pane-container-view.coffee index 2f52c8e4f..fbb77c262 100644 --- a/src/pane-container-view.coffee +++ b/src/pane-container-view.coffee @@ -112,6 +112,11 @@ class PaneContainerView extends View @nearestPaneInDirection('right')?.focus() nearestPaneInDirection: (direction) -> + distance: (pointA, pointB) -> + x = pointB.x - pointA.x + y = pointB.y - pointA.y + Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); + pane = @getActivePane() box = @boundingBoxForPane(pane) panes = @getPanes() @@ -126,14 +131,10 @@ class PaneContainerView extends View boxA = @boundingBoxForPane(paneA) boxB = @boundingBoxForPane(paneB) switch direction - when 'left' - @distanceBetweenPoints(box.left, boxA.right) - @distanceBetweenPoints(box.left, boxB.right) - when 'right' - @distanceBetweenPoints(box.right, boxA.left) - @distanceBetweenPoints(box.right, boxB.left) - when 'above' - @distanceBetweenPoints(box.top, boxA.bottom) - @distanceBetweenPoints(box.top, boxB.bottom) - when 'below' - @distanceBetweenPoints(box.bottom, boxA.top) - @distanceBetweenPoints(box.bottom, boxB.top) + when 'left' then @distance(box.left, boxA.right) - @distance(box.left, boxB.right) + when 'right' then @distance(box.right, boxA.left) - @distance(box.right, boxB.left) + when 'above' then @distance(box.top, boxA.bottom) - @distance(box.top, boxB.bottom) + when 'below' then @distance(box.bottom, boxA.top) - @distance(box.bottom, boxB.top) panes[0] @@ -144,8 +145,3 @@ class PaneContainerView extends View right: {x: boundingBox.right, y: boundingBox.top} top: {x: boundingBox.left, y: boundingBox.top} bottom: {x: boundingBox.left, y: boundingBox.bottom} - - distanceBetweenPoints: (pointA, pointB) -> - x = pointB.x - pointA.x - y = pointB.y - pointA.y - Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));