@@ -22,6 +22,7 @@ goog.require('bot.dom');
2222goog . require ( 'bot.locators' ) ;
2323goog . require ( 'goog.array' ) ;
2424goog . require ( 'goog.dom' ) ;
25+ goog . require ( 'goog.math.Rect' ) ;
2526
2627
2728/**
@@ -149,7 +150,7 @@ bot.locators.relative.near_ = function (selector, opt_distance) {
149150 }
150151
151152 if ( ! distance ) {
152- distance = 100 ;
153+ distance = 50 ;
153154 }
154155
155156 /**
@@ -166,49 +167,9 @@ bot.locators.relative.near_ = function (selector, opt_distance) {
166167 var rect1 = bot . dom . getClientRect ( element ) ;
167168 var rect2 = bot . dom . getClientRect ( compareTo ) ;
168169
169- // Ascii art time!
170- //
171- // +---+
172- // | 1 |
173- // +---+ +---+
174- // | 2 |
175- // +---+
176- //
177- // As you can see, the right hand side of 1 is "left of" the left-most
178- // edge of 2. The top edge of 2 is at the same level as the bottom
179- // edge of 1. This means that 1 is "above" 2, and 2 is "below" one.
170+ var rect1_bigger = new goog . math . Rect ( rect1 . left - distance , rect1 . top - distance , rect1 . width + distance * 2 , rect1 . height + distance * 2 ) ;
180171
181- // Distance from left edge to right edge
182- var leftDistance = Math . abs ( rect1 . left - ( rect2 . left + rect2 . width ) ) ;
183-
184- // Distance from right edge to left edge
185- var rightDistance = Math . abs ( ( rect1 . left + rect1 . width ) - rect2 . left ) ;
186-
187- // Distance from top to bottom
188- var topDistance = Math . abs ( rect1 . top - ( rect2 . top + rect2 . height ) ) ;
189-
190- // Distance from bottom to top
191- var bottomDistance = Math . abs ( ( rect1 . top + rect1 . height ) - rect2 . top ) ;
192-
193- var horizontallyClose = leftDistance <= distance || rightDistance <= distance ;
194- var verticallyClose = topDistance <= distance || bottomDistance <= distance ;
195-
196- if ( horizontallyClose && verticallyClose ) {
197- return true ;
198- }
199-
200- // Distance from centre points
201- var x1 = rect1 . left + ( rect1 . width / 2 ) ;
202- var y1 = rect1 . top + ( rect1 . height / 2 ) ;
203-
204- var x2 = rect2 . left + ( rect2 . width / 2 ) ;
205- var y2 = rect2 . top + ( rect2 . height / 2 ) ;
206-
207- var xDistance = Math . abs ( x1 - x2 ) ;
208- var yDistance = Math . abs ( y1 - y2 ) ;
209-
210- var dist = Math . sqrt ( Math . pow ( xDistance , 2 ) + Math . pow ( yDistance , 2 ) ) ;
211- return dist <= distance ;
172+ return rect1_bigger . intersects ( rect2 ) ;
212173 } ;
213174
214175 return func ;
0 commit comments