pub struct SimpleRPolygon<T> { /* private fields */ }
Expand description

A SimpleRPolygon is a rectilinear polygon. It does not contain holes but can be self-intersecting. The vertices are stored in an implicit format (one coordinate of two neighbour vertices is always the same for rectilinear polygons). This reduces memory usage but has the drawback that edges must alternate between horizontal and vertical. Vertices between two edges of the same orientation will be dropped.

Implementations

Create empty polygon without any vertices.

Get the number of vertices.

Reverse the order of the vertices in-place.

Create a copy of this polygon whose vertices are ordered in reversed order.

Iterate over the points.

Get all exterior edges of the polygon.

Examples
use iron_shapes::simple_rpolygon::SimpleRPolygon;
use iron_shapes::redge::REdge;
let coords = vec![(0, 0), (1, 0), (1, 1), (0, 1)];

let poly = SimpleRPolygon::try_new(coords).unwrap();
let edges: Vec<_> = poly.edges().collect();
assert_eq!(edges, vec![
    REdge::new((0, 0), (1, 0)),
    REdge::new((1, 0), (1, 1)),
    REdge::new((1, 1), (0, 1)),
    REdge::new((0, 1), (0, 0)),
]);

Create new rectilinear polygon from points. Returns None if the polygon defined by the points is not rectilinear.

use iron_shapes::simple_rpolygon::SimpleRPolygon;

let poly1 = SimpleRPolygon::try_new(vec![(0, 0), (1, 0), (1, 1), (0, 1)]);
assert!(poly1.is_some());

// A triangle cannot be rectilinear.
let poly1 = SimpleRPolygon::try_new(vec![(0, 0), (1, 0), (1, 1)]);
assert!(poly1.is_none());

Apply the transformation to this rectilinear polygon.

Convert to a SimplePolygon.

Get the convex hull of the polygon.

Implements Andrew’s Monotone Chain algorithm. See: http://geomalgorithms.com/a10-_hull-1.html

Get the vertex with lowest x-coordinate. Prefer lower y-coordinates to break ties.

Examples
use iron_shapes::simple_rpolygon::SimpleRPolygon;
use iron_shapes::point::Point;
let coords = vec![(0, 0), (1, 0), (1, 1), (0, 1)];

let poly = SimpleRPolygon::try_new(coords).unwrap();

assert_eq!(poly.lower_left_vertex(), Point::new(0, 0));

Get the orientation of the polygon, i.e. check if it is wound clock-wise or counter-clock-wise.

Examples
use iron_shapes::simple_rpolygon::SimpleRPolygon;
use iron_shapes::point::Point;
use iron_shapes::types::Orientation;
let coords = vec![(0, 0), (1, 0), (1, 1), (0, 1)];

let poly = SimpleRPolygon::try_new(coords).unwrap();

assert_eq!(poly.orientation(), Orientation::CounterClockWise);

Check if the polygon is an axis-aligned rectangle.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Calculates the doubled oriented area.

Using doubled area allows to compute in the integers because the area of a polygon with integer coordinates is either integer or half-integer.

The area will be positive if the vertices are listed counter-clockwise, negative otherwise.

Complexity: O(n)

Examples
use iron_shapes::traits::DoubledOrientedArea;
use iron_shapes::simple_rpolygon::SimpleRPolygon;
let coords = vec![(0, 0), (1, 0), (1, 1), (0, 1)];

let poly = SimpleRPolygon::try_new(coords).unwrap();

assert_eq!(poly.area_doubled_oriented(), 2);

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Equality test for simple polygons.

Two polygons are equal iff a cyclic shift on their vertices can be applied such that the both lists of vertices match exactly.

Complexity: O(n^2)

TODO: Normalized ordering of vertices for faster comparison.

This method tests for !=.

Return the bounding box of this geometry if a bounding box is defined.

Output type of the cast. This is likely the same geometrical type just with other coordinate types. Read more

Try to cast to target data type. Read more

Cast to target data type. Read more

Calculate the winding number of the polygon around this point.

TODO: Define how point on edges and vertices is handled.

See: http://geomalgorithms.com/a03-_inclusion.html

Check if point is inside the polygon, i.e. the polygons winds around the point a non-zero number of times. Read more

Check if point is inside the polygon, i.e. the polygon winds around the point an odd number of times. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.