File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change 1
-
2
1
/**
3
2
* Author: chilli
4
3
* Date: 2019-05-05
@@ -31,16 +30,15 @@ vector<P> halfPlaneIntersection(vector<Line> vs) {
31
30
vector < Line > deq (sz (vs ) + 5 );
32
31
vector < P > ans (sz (vs ) + 5 );
33
32
deq [0 ] = vs [0 ];
34
- int ah = 0 , at = 0 ;
35
- #define fix (a , b ) \
36
- while (ah<at && sideOf(sp(a),ans[at-1]) < 0) at--;\
37
- while (ah<at && sideOf(sp(b),ans[ah]) < 0) ah++;\
38
- ans[at++] = lineInter(sp(a), sp(deq[at])).second;
39
- rep (i ,1 ,sz (vs )){
33
+ int ah = 0 , at = 0 , n = sz (vs );
34
+ rep (i ,1 ,n + 1 ) {
35
+ if (i == n ) vs .push_back (deq [ah ]);
40
36
if (angDiff (vs [i ], vs [i - 1 ]) == 0 ) continue ;
41
- fix (vs [i ], vs [i ]); deq [at ] = vs [i ];
37
+ while (ah < at && sideOf (sp (vs [i ]),ans [at - 1 ]) < 0 ) at -- ;
38
+ while (i != n && ah < at && sideOf (sp (vs [i ]),ans [ah ])< 0 ) ah ++ ;
39
+ ans [at ++ ] = lineInter (sp (vs [i ]), sp (deq [at ])).second ;
40
+ deq [at ] = vs [i ];
42
41
}
43
- fix (deq [ah ], deq [at ]);
44
42
if (at - ah <= 2 ) return {};
45
43
return {ans .begin () + ah , ans .begin () + at };
46
44
}
You can’t perform that action at this time.
0 commit comments