-
Notifications
You must be signed in to change notification settings - Fork 811
Halfplane Intersection #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Chillee
wants to merge
48
commits into
kth-competitive-programming:main
Choose a base branch
from
Chillee:halfplane
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
93c9b26
Updated onSegment.h and both segment intersections
Chillee 3b6ac0e
Updated headers
Chillee 0a0261b
Updated some line width issues
Chillee bccd1cb
Fixed broken dependency
Chillee d2e700a
removed automatic epsilon checks
Chillee 59f8511
Put it on one line now
Chillee 1bdf870
Moved template up a line to fit parameters on one line
Chillee 2f32d63
Changed tabs to spaces so it'll align
Chillee 28456a1
Fixed some misc issues
Chillee b7a8157
Readded relevant description
Chillee ba9395d
Fixed formatting issue
Chillee fab7b2e
made change
Chillee e99191f
Added first commit of halfPlane
Chillee 95b770b
merged
Chillee 63425c3
Simplified/shortened the code
Chillee 888dd17
merged
Chillee ed75bf9
Fixed some issues
Chillee 8571390
Added some unit tests for halfplane
Chillee e5b85b7
Add failure example for MIT's halfplane code
Chillee 0a4e8d3
Added fuzz tests with SJTU code
Chillee 4df6e0e
Fit stuff within 63 columns
Chillee 19c70ac
Added option for long double in Halfplane tests
Chillee cbd17e8
Abstracted away the angle comparison
Chillee 2eee5c1
Added newline
Chillee a1d85bb
Updated header
Chillee b0b03a9
Responded to comments and tried a macro
Chillee 81f9cd3
removed extraneous deque variables
Chillee d283267
Updated description and such
Chillee 8c6bb7c
Shortened half plane through macros
Chillee bf838c6
Shortened half plane a bit
Chillee 1c47a37
Started fixing the bugs
Chillee 1aa4b39
Fixed bugs/found bugs
Chillee e61acd5
Doing some precision analysis
Chillee 4cb642a
Updated with current version
Chillee 50a3915
Shortened a bit
Chillee 3d7e6f0
removed binary
Chillee a8b3ec7
Removed some debug code
Chillee b6f7c82
merged
Chillee 8971c03
some debugging stuff
Chillee 5f4ff5a
Added some experimentation code
Chillee 3a94b90
merged
Chillee 74faa81
remove unintended
Chillee f3916db
removed test cases
Chillee 4330561
removed test cases
Chillee 908a313
Added my current guess about the condition for failure
Chillee 34c550e
Warning fixes
simonlindholm 5fb4588
Use .angle()
simonlindholm 26b50ee
Fix cmp to not say a < a
simonlindholm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Author: chilli | ||
* Date: 2019-05-05 | ||
* License: CC0 | ||
* Source: https://github.com/zimpha/algorithmic-library/blob/master/computational-geometry/polygon.cc | ||
* Description: Computes the intersection of a set of half-planes. Input is given as a set of planes, facing left. | ||
* Output is the convex polygon representing the intersection. The points may have duplicates and be collinear. | ||
* Will not fail catastrophically if `eps > sqrt(2)(line intersection error)`. Likely to work for more ranges if | ||
* 3 half planes are never guaranteed to intersect at the same point. | ||
* Time: O(n \log n) | ||
* Status: fuzz-tested, submitted on https://maps19.kattis.com/problems/marshlandrescues | ||
* Usage: | ||
*/ | ||
#pragma once | ||
|
||
#include "Point.h" | ||
#include "sideOf.h" | ||
#include "lineIntersection.h" | ||
|
||
typedef Point<double> P; | ||
typedef array<P, 2> Line; | ||
#define sp(a) a[0], a[1] | ||
#define ang(a) (a[1] - a[0]).angle() | ||
|
||
int angDiff(Line a, Line b) { return sgn(ang(a) - ang(b)); } | ||
bool cmp(Line a, Line b) { | ||
int s = angDiff(a, b); | ||
return (s ? s : sideOf(sp(a), b[0])) < 0; | ||
} | ||
vector<P> halfPlaneIntersection(vector<Line> vs) { | ||
const double EPS = sqrt(2) * 1e-8; | ||
sort(all(vs), cmp); | ||
vector<Line> deq(sz(vs) + 5); | ||
vector<P> ans(sz(vs) + 5); | ||
deq[0] = vs[0]; | ||
int ah = 0, at = 0, n = sz(vs); | ||
rep(i,1,n+1) { | ||
if (i == n) vs.push_back(deq[ah]); | ||
if (angDiff(vs[i], vs[i - 1]) == 0) continue; | ||
while (ah<at && sideOf(sp(vs[i]), ans[at-1], EPS) < 0) | ||
at--; | ||
while (i!=n && ah<at && sideOf(sp(vs[i]),ans[ah],EPS)<0) | ||
ah++; | ||
auto res = lineInter(sp(vs[i]), sp(deq[at])); | ||
if (res.first != 1) continue; | ||
ans[at++] = res.second, deq[at] = vs[i]; | ||
} | ||
if (at - ah <= 2) return {}; | ||
return {ans.begin() + ah, ans.begin() + at}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.