## polygonical

2d polygon geometry and operations

### 5 releases(breaking)

 0.5.0 Feb 6, 2023 Feb 5, 2023 Feb 4, 2023 Jan 25, 2023 Jan 24, 2023

#125 in Graphics APIs

Used in esvg

37KB
886 lines

# Polygonical

A library for interacting with polygons on a 2d plane.

## Examples

Rotate a polygon:

``````    use polygonical::polygon::Polygon;
use polygonical::point::Point;

let poly = Polygon::new(vec![
Point::new(0.0, 1.0),
Point::new(1.0, 1.0),
Point::new(1.0, 0.0),
]);

// get the area of the polygon
let area = poly.area();

// rotate the polygon around its own center by 90 degrees

println!("area: {} rotated: {}", area, rotated);
``````

Create an approximation of a circle:

``````    use polygonical::polygon::Polygon;
use polygonical::point::Point;

let num_points = 16;
let center = Point::new(10.0, 20.0);

// Note: we use an integer number of degrees here because rust won't let you iterate over floats like this.
let points = (0..360).step_by(360/num_points)
.collect();

let circle = Polygon::new(points);

let approx_area = circle.area();

println!("area: {} aprox_area: {} difference: {}", area, approx_area, area - approx_area);
``````

## 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
• Polygon unions

## Wanted Features

Things we want to implement but haven't yet.

• Scale of points
• Scale of polygons
• 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.

• Correct
• Safe
• Fast

In that order

## Limitations / Warnings

Polygons must be specified with the points going clockwise around them. Several algorithms only work when points are defined clockwise. There is no detection of this, it will probably cause weird results, it has not been tested.

~45KB