|
tgen
|
Geometry utilities. More...
Classes | |
| struct | tgen::geometry::point< T > |
| Point on the plane. More... | |
Functions | |
| std::vector< point< long long > > | tgen::geometry::random_points_general_position (int n, long long min_coord, long long max_coord) |
| Generates random points in general position inside a coordinate box. | |
| std::vector< point< long long > > | tgen::geometry::random_simple_polygon_through_points (const std::vector< point< long long > > &points) |
| Generates a random simple polygon through given points. | |
| std::vector< point< long long > > | tgen::geometry::random_simple_polygon (int n, long long min_coord, long long max_coord) |
| Generates a random simple polygon given coordinate range. | |
| std::vector< point< long long > > | tgen::geometry::random_convex_polygon (int n, long long min_coord, long long max_coord, bool strict=false) |
| Generates a random convex polygon with given bounding box. | |
Geometry utilities.
Vector operations on integer coordinates.
Floating-point coordinates use epsilon-based equality (1e-9).
Generates points in general position (no three collinear) inside a box.
Generates convex polygon.
Generates a simple polygon.
Simple polygon through a grid of points.
|
inline |
Generates a random convex polygon with given bounding box.
| n | Number of vertices. |
| min_coord | Minimum allowed coordinate on each axis. |
| max_coord | Maximum allowed coordinate on each axis. |
| strict | If true, the polygon is strictly convex. If false, collinear boundary vertices may occur. |
Uses Valtr's classical construction: choose n distinct sorted x and y coordinates spanning [0, width] via tgen::distinct_range, build monotone signed edge components, shuffle the y-components, pair with the x-components, and sort by polar angle without floating point, then prefix-sum and translate so the bouding box minimum is min_coord on each axis. The grid uses endpoints 0 and width, so the polygon span is exactly width on each axis and fills the box after translation.
| std::runtime_error | if the coordinate range is not large enough. |
O(n log n).
|
inline |
Generates random points in general position inside a coordinate box.
| n | Number of points to generate. |
| min_coord | Minimum allowed coordinate on each axis. |
| max_coord | Maximum allowed coordinate on each axis. |
The construction samples n distinct values (x, x^-1) from F_p then applies several random invertible shears over F_p, then translates the result into [min_coord, max_coord]^2. Affine maps preserve (non-)collinearity, and the graph of inversion over F_p meets any line in at most two points.
| std::runtime_error | if the coordinate range is not large enough. |
O(n).
|
inline |
Generates a random simple polygon given coordinate range.
| n | Number of vertices to generate. |
| min_coord | Minimum allowed coordinate on each axis. |
| max_coord | Maximum allowed coordinate on each axis. |
The point set is built with random_points_general_position, then polygonized by random_simple_polygon_through_points.
| std::runtime_error | if the coordinate range is not large enough for random_points_general_position. |
O(n log n) expected.
|
inline |
Generates a random simple polygon through given points.
| points | Distinct points. |
Uses a randomized divide-and-conquer Hamiltonian-path construction on the leftmost and rightmost vertices.
O(|points| log|points|) expected (if points are "random"), O(|points|^2) worst case.