Skip to content

Commit f5c8b59

Browse files
committed
Added source for polygon generator and shortened code
1 parent 305b279 commit f5c8b59

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

content/geometry/insidePolygon.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
template<class P>
2121
bool inPolygon(vector<P> &p, P a, bool strict = true) {
22-
int nCross = 0, n = sz(p);
22+
int cnt = 0, n = sz(p);
2323
rep(i, 0, n) {
24-
if (onSegment(p[i], p[(i + 1) % n], a)) return !strict;
25-
nCross += (sgn(a.y >= p[(i + 1) % n].y) -
26-
sgn(a.y>=p[i].y)) * sgn(a.cross(p[i], p[(i+1)%n])) > 0;
24+
P np = p[(i + 1) % n];
25+
if (onSegment(p[i], np, a)) return !strict;
26+
cnt += ((a.y>=np.y)-(a.y>=p[i].y))*a.cross(p[i],np) > 0;
2727
}
28-
return nCross & 1;
28+
return cnt & 1;
2929
}

fuzz-tests/geometry/insidePolygon.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef pair<int, int> pii;
1111
typedef vector<int> vi;
1212

1313

14+
const double EPS =1e-8;
1415
#include "../utilities/genPolygon.h"
1516
#include "../../content/geometry/insidePolygon.h"
1617
namespace old {

fuzz-tests/utilities/genPolygon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
// Translated from Python code posted here: https://codeforces.com/blog/entry/63058?#comment-472788
34
#include "../../content/geometry/Point.h"
45

56
mt19937_64 rng(time(0));

0 commit comments

Comments
 (0)