Macro geo::polygon[][src]

macro_rules! polygon {
    () => { ... };
    (
        exterior: [
            $((x: $exterior_x:expr, y: $exterior_y:expr)),*
            $(,)?
        ],
        interiors: [
            $([
                $((x: $interior_x:expr, y: $interior_y:expr)),*
                $(,)?
            ]),*
            $(,)?
        ]
        $(,)?
    ) => { ... };
    (
        exterior: [
            $($exterior_coord:expr),*
            $(,)?
        ],
        interiors: [
            $([
                $($interior_coord:expr),*
                $(,)?
            ]),*
            $(,)?
        ]
        $(,)?
    ) => { ... };
    (
        $((x: $x:expr, y: $y:expr)),*
        $(,)?
    ) => { ... };
    (
        $($coord:expr),*
        $(,)?
    ) => { ... };
}

Creates a Polygon containing the given coordinates.

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

// or

polygon!(
    exterior: [Coordinate OR (x: <number>, y: <number>), …],
    interiors: [
        [Coordinate 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::Coordinate { 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::Coordinate { x: -111., y: 41. },
);