File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -32,16 +32,15 @@ vector<P> halfPlaneIntersection(vector<Line> vs) {
32
32
vector < P > ans (sz (vs ) + 5 );
33
33
deq [0 ] = vs [0 ];
34
34
int ah = 0 , at = 0 ;
35
- for (int i = 1 ; i < sz (vs ); ++ i ) {
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 )){
36
40
if (angDiff (vs [i ], vs [i - 1 ]) == 0 ) continue ;
37
- while (ah < at && sideOf (sp (vs [i ]),ans [at - 1 ]) < 0 ) at -- ;
38
- while (ah < at && sideOf (sp (vs [i ]),ans [ah ]) < 0 ) ah ++ ;
39
- ans [at ++ ] = lineInter (sp (deq [at ]), sp (vs [i ])).second ;
40
- deq [at ] = vs [i ];
41
+ fix (vs [i ], vs [i ]); deq [at ] = vs [i ];
41
42
}
42
- while (ah < at && sideOf (sp (deq [ah ]),ans [at - 1 ]) < 0 ) at -- ;
43
- while (ah < at && sideOf (sp (deq [at ]),ans [ah ]) < 0 ) ah ++ ;
44
- ans [at ++ ] = lineInter (sp (deq [ah ]), sp (deq [at ])).second ;
45
- if (at - ah <= 2 ) return {};
43
+ fix (deq [ah ], deq [at ]);
44
+ if (at - ah <= 2 ) return {};
46
45
return {ans .begin () + ah , ans .begin () + at };
47
46
}
You can’t perform that action at this time.
0 commit comments