Skip to content

Commit

Permalink
geo2d/circle_min
Browse files Browse the repository at this point in the history
  • Loading branch information
teapotd committed Apr 1, 2024
1 parent 0f970f3 commit b78fbaa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/geo2d/circle_min.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include "../template.h"
#include "vector.h" // FLOATING_POINT_GEOMETRY
#include "circle.h"

mt19937 rnd(123);

// Minimum circle enclosing a set of points.
//! Source: https://github.com/kth-competitive-programming/kactl/blob/main/content/geometry/MinimumEnclosingCircle.h
circle minDisk(vector<vec> p) { // time: O(n)
circle c;
shuffle(all(p), rnd);
rep(i, 0, sz(p)) if (c.side(p[i]) < 0) {
c = {p[i], 0};
rep(j, 0, i) if (c.side(p[j]) < 0) {
c = {(p[i]+p[j])/2,(p[i]-p[j]).len2()/4};
rep(k, 0, j) if (c.side(p[k]) < 0)
c = circum(p[i], p[j], p[k]);
}
}
return c;
}
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
| | deterministic | fuzz | benchmark | yosupo |
|------------------------------------|:-------------:|:---------------:|:---------:|:--------------------:|
| geo2d/circle | partial | partial | | |
| geo2d/circle | | | | |
| geo2d/convex_hull | | &check; | &check; | |
| geo2d/halfplanes | &check; | &check; | &check; | |
| geo2d/line | &check; | | | |
Expand Down

0 comments on commit b78fbaa

Please sign in to comment.