decompose_maximal_rectangles

Function decompose_maximal_rectangles 

Source
pub fn decompose_maximal_rectangles<T, I>(redges: I) -> Vec<Rect<T>>
where T: Ord + Bounded + Copy + Zero, I: Iterator<Item = REdge<T>>,
Expand description

Decompose a set of manhattanized polygons into maximal rectangles. The polygons in form of an iterator over all the edges. A point is considered inside the polygon when the polygon wraps around it a non-zero number of times.

ยงExample

    use iron_shapes::prelude::*;
    use iron_shapes_algorithms::rectangle_decomposition::decompose_maximal_rectangles;
    // Use a polygon like the following.
    //    +--+
    //    |  |
    // +--+  |
    // |     |
    // +-----+
    let poly = SimpleRPolygon::try_new([
        (0, 0), (2, 0), (2, 2), (1, 2), (1, 1), (0, 1)
    ]).unwrap();

    // Decompose the polygon into non-overlapping horizontal rectangles.
    let rects = decompose_maximal_rectangles(poly.edges());
    assert_eq!(rects, vec![Rect::new((0, 0), (2, 1)), Rect::new((1, 0), (2, 2))]);