Polygonical
A library for interacting with polygons on a 2d plane.
Examples
Rotate a polygon:
use Polygon;
use Point;
let poly = new;
// get the area of the polygon
let area = poly.area;
// rotate the polygon around its own center by 90 degrees
let rotated = poly.rotate_around_center;
println!;
Create an approximation of a circle:
use Polygon;
use Point;
let num_points = 16;
let radius = 2.0;
let center = new;
// Note: we use an integer number of degrees here because rust won't let you iterate over floats like this.
let points = .step_by
.map
.collect;
let circle = new;
let approx_area = circle.area;
let area = PI * radius * radius;
println!;
Features
- Points
- Polygons
- Bounding boxes
- Translations of points
- Polygons contain points
- Polygon is_self_intersecting
- Polygon area
- Translations of polygons
- Rotations of points
- Rotations of polygons
- Overlap detection
- Contains detection
Wanted Features
Things we want to implement but haven't yet.
- Scale of points
- Scale of polygons
- Polygon unions
- Polygon subtraction
Unwanted Features
Things this library won't do.
- 3d Geometry
- Output to things like svg (that is for another library)
- Coordinate system transforms, epsg codes, pixel space to world space etc.
Design goals
- Correct
- Safe
- Fast
In that order
Limitations / Warnings
Polygons must be specified with the points going clockwise around them. Due to the way the contains point algorithm handles angles rolling over 360/0 degrees any function that relies on that algorithm will not work as expected.