Macro geo_types::polygon

source ·
macro_rules! polygon {
    () => { ... };
    (
        exterior: [
            $(( $($exterior_tag:tt : $exterior_val:expr),* $(,)? )),*
            $(,)?
        ],
        interiors: [
            $([
                $(( $($interior_tag:tt : $interior_val:expr),* $(,)? )),*
                $(,)?
            ]),*
            $(,)?
        ]
        $(,)?
    ) => { ... };
    (
        exterior: [
            $($exterior_coord:expr),*
            $(,)?
        ],
        interiors: [
            $([
                $($interior_coord:expr),*
                $(,)?
            ]),*
            $(,)?
        ]
        $(,)?
    ) => { ... };
    (
        $(( $($tag:tt : $val:expr),* $(,)? )),*
        $(,)?
    ) => { ... };
    (
        $($coord:expr),*
        $(,)?
    ) => { ... };
}
Expand description

Creates a Polygon containing the given coordinates.

polygon![Coord OR (x: <number>, y: <number>), …]

// or

polygon!(
    exterior: [Coord OR (x: <number>, y: <number>), …],
    interiors: [
        [Coord OR (x: <number>, y: <number>), …],
        …
    ],
)

§Examples

Creating a Polygon without interior rings, supplying x/y values:

use geo_types::polygon;

let poly = polygon![
    (x: -111., y: 45.),
    (x: -111., y: 41.),
    (x: -104., y: 41.),
    (x: -104., y: 45.),
];

assert_eq!(
    poly.exterior()[1],
    geo_types::coord! { x: -111., y: 41. },
);

Creating a Polygon, supplying x/y values:

use geo_types::polygon;

let poly = polygon!(
    exterior: [
        (x: -111., y: 45.),
        (x: -111., y: 41.),
        (x: -104., y: 41.),
        (x: -104., y: 45.),
    ],
    interiors: [
        [
            (x: -110., y: 44.),
            (x: -110., y: 42.),
            (x: -105., y: 42.),
            (x: -105., y: 44.),
        ],
    ],
);

assert_eq!(
    poly.exterior()[1],
    geo_types::coord! { x: -111., y: 41. },
);