File tree 1 file changed +13
-17
lines changed
1 file changed +13
-17
lines changed Original file line number Diff line number Diff line change 9
9
const sa = slope ( p , a ) ;
10
10
const sb = slope ( p , b ) ;
11
11
[ [ sa , a ] , [ sb , b ] ] . forEach ( e => {
12
- if ( ! memo . has ( e [ 0 ] ) ) {
13
- memo . set ( e [ 0 ] , new Set ( ) ) ;
14
- }
15
- memo . get ( e [ 0 ] ) . add ( e [ 1 ] ) ;
12
+ const el = memo . get ( e [ 0 ] ) ;
13
+ if ( ! el || dist ( p , el ) < dist ( p , e [ 1 ] ) ) memo . set ( e [ 0 ] , e [ 1 ] ) ;
16
14
} ) ;
17
15
return sa - sb ;
18
16
} ;
50
48
if ( a . x < c . x ) return a ;
51
49
return c ;
52
50
} ) ;
53
- const memo = new Map ( ) ;
54
- const points = all . sort ( sort . bind ( null , p , memo ) ) . filter ( c => {
55
- const s = slope ( p , c ) ;
56
- // Liner check, can consider more efficient data structure
57
- const set = Array . from ( memo . get ( s ) ) ;
58
- return ! set . some ( e => dist ( p , e ) > dist ( p , c ) ) ;
59
- } ) ;
60
51
52
+ const memo = new Map ( ) ;
61
53
const stack = [ ] ;
62
- points . forEach ( p => {
63
- while ( stack . length > 1 && ccw ( stack [ stack . length - 2 ] , stack [ stack . length - 1 ] , p ) < 0 ) {
64
- stack . pop ( ) ;
65
- }
66
- stack . push ( p ) ;
67
- } ) ;
54
+
55
+ all
56
+ . sort ( sort . bind ( null , p , memo ) )
57
+ . filter ( c => memo . get ( slope ( p , c ) ) === c )
58
+ . forEach ( p => {
59
+ while ( stack . length > 1 && ccw ( stack [ stack . length - 2 ] , stack [ stack . length - 1 ] , p ) < 0 )
60
+ stack . pop ( ) ;
61
+ stack . push ( p ) ;
62
+ } ) ;
63
+
68
64
return stack ;
69
65
} ;
70
66
You can’t perform that action at this time.
0 commit comments