|
tgen 1.1.0
|
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, bool strict=false) |
| 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 coordinate range. | |
| std::vector< point< long long > > | tgen::geometry::random_orthogonal_polygon (int n, long long min_coord, long long max_coord, bool strict=false) |
| Generates a random orthogonal simple polygon. | |
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.
Generates a random orthogonal (axis-aligned) simple polygon.
|
inline |
Generates a random convex polygon with given coordinate range.
| 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 vertices may occur. |
Uses Valtr's classical construction: choose m distinct sorted x and y coordinates in [min_coord, max_coord] via tgen::distinct_range (with m = n when strict is false, and m > n when strict is true), build monotone signed edge components, shuffle the y-components, pair with the x-components, and sort by polar angle, then prefix-sum to obtain vertex coordinates. When strict is true, collinear boundary vertices are removed and the walk is subsampled to n vertices. The polygon is then translated by a random amount so it lies inside the requested box.
| std::runtime_error | if the coordinate range is not large enough. |
O(n log n).
|
inline |
Generates a random orthogonal simple polygon.
| n | Target number of boundary vertices. |
| min_coord | Minimum allowed coordinate on each axis. |
| max_coord | Maximum allowed coordinate on each axis. |
| strict | If true, every vertex turns 90 degrees (no three consecutive collinear vertices). If false, collinear vertices may appear on straight horizontal or vertical edges. |
The polygon starts as a small axis-aligned square. The implementation then applies local boundary edits inspired by inflate/cut operations:
Each step picks a boundary edge (favoring longer segments and edges that were not edited recently), chooses a subsegment and depth, then splices the rectangle if validation passes. When strict is true, collinear vertices are removed.
| std::runtime_error | if the coordinate range is too small. |
O(n^2) for n <= 1000;
O(n) otherwise.
|
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. |
| strict | If true, the vertex set has no three collinear points. If false, there might be collinear triplets and three consecutive collinear points in the polygon. |
When strict is true, the point set is built with random_points_general_position, othwerwise randomly generated. Points are polygonized by random_simple_polygon_through_points.
| std::runtime_error | if the coordinate range is not large enough. |
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.