Struct libreda_db::prelude::SimpleRPolygon[][src]

pub struct SimpleRPolygon<T> where
    T: CoordinateType
{ /* fields omitted */ }

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

impl<T> SimpleRPolygon<T> where
    T: CoordinateType
[src]

pub fn try_new<P>(points: Vec<P, Global>) -> Option<SimpleRPolygon<T>> where
    P: Copy + Into<Point<T>>, 
[src]

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());

pub fn empty() -> SimpleRPolygon<T>[src]

Create empty polygon without any vertices.

pub fn num_points(&self) -> usize[src]

Get the number of vertices.

pub fn points(&self) -> impl Iterator<Item = Point<T>>[src]

Iterate over the points.

pub fn convex_hull(&self) -> SimplePolygon<T> where
    T: Ord
[src]

Get the convex hull of the polygon.

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

pub fn edges(&self) -> impl Iterator<Item = REdge<T>>[src]

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)),
]);

pub fn lower_left_vertex(&self) -> Point<T>[src]

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));

pub fn orientation(&self) -> Orientation[src]

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);

Trait Implementations

impl<T> Clone for SimpleRPolygon<T> where
    T: Clone + CoordinateType
[src]

impl<T> Debug for SimpleRPolygon<T> where
    T: Debug + CoordinateType
[src]

impl<T> DoubledOrientedArea<T> for SimpleRPolygon<T> where
    T: CoordinateType
[src]

pub fn area_doubled_oriented(&self) -> T[src]

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);

impl<T> Eq for SimpleRPolygon<T> where
    T: Eq + CoordinateType
[src]

impl<T> From<Rect<T>> for SimpleRPolygon<T> where
    T: CoordinateType
[src]

impl<T> Hash for SimpleRPolygon<T> where
    T: Hash + CoordinateType
[src]

impl<T> PartialEq<SimpleRPolygon<T>> for SimpleRPolygon<T> where
    T: CoordinateType
[src]

pub fn eq(&self, rhs: &SimpleRPolygon<T>) -> bool[src]

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.

impl<T> StructuralEq for SimpleRPolygon<T> where
    T: CoordinateType
[src]

impl<T> TryBoundingBox<T> for SimpleRPolygon<T> where
    T: CoordinateType
[src]

impl<T, Dst> TryCastCoord<T, Dst> for SimpleRPolygon<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = SimpleRPolygon<Dst>

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

impl<T> WindingNumber<T> for SimpleRPolygon<T> where
    T: CoordinateType
[src]

pub fn winding_number(&self, point: Point<T>) -> isize[src]

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

Auto Trait Implementations

impl<T> RefUnwindSafe for SimpleRPolygon<T> where
    T: RefUnwindSafe

impl<T> Send for SimpleRPolygon<T> where
    T: Send

impl<T> Sync for SimpleRPolygon<T> where
    T: Sync

impl<T> Unpin for SimpleRPolygon<T> where
    T: Unpin

impl<T> UnwindSafe for SimpleRPolygon<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> TextType for T where
    T: Clone + Eq + Debug + Hash
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.