File tree Expand file tree Collapse file tree 5 files changed +42
-41
lines changed Expand file tree Collapse file tree 5 files changed +42
-41
lines changed Original file line number Diff line number Diff line change 151151 return contains ( point , this . root ) ;
152152 } ;
153153
154+ function intersects ( a , b ) {
155+ return ( a [ 0 ] <= b [ 0 ] && a [ 1 ] >= b [ 0 ] ) || ( a [ 0 ] <= b [ 1 ] && a [ 1 ] >= b [ 1 ] ) ||
156+ ( b [ 0 ] <= a [ 0 ] && b [ 1 ] >= a [ 0 ] ) || ( b [ 0 ] <= a [ 1 ] && b [ 1 ] >= a [ 1 ] ) ;
157+ }
158+
154159 function intersectsHelper ( interval , node ) {
155160 if ( ! node ) {
156161 return false ;
169174 return result ;
170175 }
171176
172- function intersects ( a , b ) {
173- return ( a [ 0 ] <= b [ 0 ] && a [ 1 ] >= b [ 0 ] ) || ( a [ 0 ] <= b [ 1 ] && a [ 1 ] >= b [ 1 ] ) ||
174- ( b [ 0 ] <= a [ 0 ] && b [ 1 ] >= a [ 0 ] ) || ( b [ 0 ] <= a [ 1 ] && b [ 1 ] >= a [ 1 ] ) ;
175- }
176-
177177 /**
178178 * Checks or interval belongs to at least one intarval from the tree.<br><br>
179179 * Complexity: O(log N).
Original file line number Diff line number Diff line change 11( function ( exports ) {
22 'use strict' ;
33
4+ /**
5+ * Draws (prints) the given coordinates
6+ * @param {number } x The first coordinate of the point
7+ * @param {number } y The second coordinate of the point
8+ */
9+ function drawPoint ( x , y ) {
10+ console . log ( x , y ) ;
11+ }
12+
413 /**
514 * Bresenham's line drawing algorithm.
615 * It has complexity O(n)
3342 }
3443 }
3544
36- /**
37- * Draws (prints) the given coordinates
38- * @param {number } x The first coordinate of the point
39- * @param {number } y The second coordinate of the point
40- */
41- function drawPoint ( x , y ) {
42- console . log ( x , y ) ;
43- }
44-
4545 exports . drawLine = drawLine ;
4646
4747} ( typeof exports === 'undefined' ? window : exports ) ) ;
Original file line number Diff line number Diff line change 7171 exports . Graph . prototype . prim = ( function ( ) {
7272 var queue ;
7373
74- /**
75- * Initialize the algorithm.
76- *
77- * @private
78- */
79- function init ( ) {
80- queue = new Heap ( compareEdges ) ;
81- }
82-
8374 /**
8475 * Used for comparitions in the heap
8576 *
9485 return b . distance - a . distance ;
9586 }
9687
88+ /**
89+ * Initialize the algorithm.
90+ *
91+ * @private
92+ */
93+ function init ( ) {
94+ queue = new Heap ( compareEdges ) ;
95+ }
96+
9797 return function ( ) {
9898 init . call ( this ) ;
9999 var inTheTree = { } ;
Original file line number Diff line number Diff line change 11( function ( exports ) {
22 'use strict' ;
33
4+ function id ( val ) { return val ; }
5+ function get ( key ) { return function ( val ) { return val [ key ] ; } ; }
6+
47 /**
58 * Searchs for specific element in a given array using
69 * the binary search algorithm.<br><br>
3740 }
3841 return - middle - 1 ;
3942 }
40- function id ( val ) { return val ; }
41- function get ( key ) { return function ( val ) { return val [ key ] ; } ; }
4243
4344 exports . binarySearch = binarySearch ;
4445
Original file line number Diff line number Diff line change 1313 return a - b ;
1414 }
1515
16+ /**
17+ * Swap the places of two elements
18+ *
19+ * @private
20+ * @param {array } array The array which contains the elements
21+ * @param {number } i The index of the first element
22+ * @param {number } j The index of the second element
23+ * @returns {array } array The array with swaped elements
24+ */
25+ function swap ( array , i , j ) {
26+ var temp = array [ i ] ;
27+ array [ i ] = array [ j ] ;
28+ array [ j ] = temp ;
29+ return array ;
30+ }
31+
1632 /**
1733 * Partitions given subarray using Lomuto's partitioning algorithm.
1834 *
3551 return minEnd ;
3652 }
3753
38- /**
39- * Swap the places of two elements
40- *
41- * @private
42- * @param {array } array The array which contains the elements
43- * @param {number } i The index of the first element
44- * @param {number } j The index of the second element
45- * @returns {array } array The array with swaped elements
46- */
47- function swap ( array , i , j ) {
48- var temp = array [ i ] ;
49- array [ i ] = array [ j ] ;
50- array [ j ] = temp ;
51- return array ;
52- }
53-
5454 /**
5555 * Sorts given array.
5656 *
You can’t perform that action at this time.
0 commit comments