pub fn polyfill(polygon: &[Vec<GeoCoord>], resolution: Resolution) -> Vec<H3Index> {
    let real_polygon = polygon
        .iter()
        .map(|p| p.iter().map(libh3_sys::GeoCoord::from).collect())
        .collect::<Vec<Vec<libh3_sys::GeoCoord>>>();

    unsafe {
        let fence = libh3_sys::Geofence {
            numVerts: real_polygon[0].len() as i32,
            verts: real_polygon[0].as_ptr(),
        };

        let holes = real_polygon
            .iter()
            .skip(1)
            .map(|p| libh3_sys::Geofence {
                numVerts: p.len() as i32,
                verts: p.as_ptr(),
            })
            .collect::<Vec<libh3_sys::Geofence>>();

        let p = libh3_sys::GeoPolygon {
            geofence: fence,
            numHoles: (real_polygon.len() - 1) as i32,
            holes: holes.as_ptr(),
        };

        let max = libh3_sys::maxPolyfillSize(&p, resolution as i32);
        let mut r = Vec::<H3Index>::with_capacity(max as usize);
        libh3_sys::polyfill(&p, resolution as i32, r.as_mut_ptr());
        r.set_len(max as usize);
        r.retain(|&v| v != 0);
        r
    }
}
/// Get all hexagons with centers contained in a given polygon. The polygon
/// is specified with GeoJson semantics as an array of loops. The first loop
/// is the perimeter of the polygon, and subsequent loops are
/// expected to be holes.
///
/// # Arguments
///
/// * `polygon` - The vector of polygons.
/// * `resolution` - The resolution of the generated hexagons
///
/// ```
/// use libh3::{polyfill, GeoCoord, degs_to_rads};
/// /// Some vertexes around San Francisco
/// let sf_verts = vec![
///   (0.659966917655, -2.1364398519396),
///   (0.6595011102219, -2.1359434279405),
///   (0.6583348114025, -2.1354884206045),
///   (0.6581220034068, -2.1382437718946),
///   (0.6594479998527, -2.1384597563896),
///   (0.6599990002976, -2.1376771158464),
/// ]
/// .iter()
/// .map(|v| GeoCoord::new(v.0, v.1))
/// .collect();
///
/// let h = polyfill(&vec![sf_verts], 9);
/// assert_eq!(h.len(), 1253);
///
///
/// /// Fill a polygon around Wellington, NZ
/// /// Coordinates are in GeoJSON lon, lat order.
///
/// let wellington_verts: Vec<GeoCoord> = vec![
///    (174.800937866947, -41.22501356278325),
///    (174.8079721211159, -41.226732341115365),
///    (174.82262997231396, -41.231639803277986),
///    (174.83561105648377, -41.23873115217201),
///    (174.84634815587896, -41.24769587535717),
///    (174.85069634833735, -41.252194466801384),
///    (174.8587207192276, -41.26264015566857),
///    (174.8636809159909, -41.27410982273725),
///    (174.86536017144866, -41.28610182569948),
///    (174.8653611411562, -41.29165993179072),
///    (174.8636858034186, -41.30364998147521),
///    (174.85872883206798, -41.31511423541933),
///    (174.8507068877321, -41.32555201329627),
///    (174.846359294586, -41.33004662498431),
///    (174.8356222320399, -41.33900220579377),
///    (174.82263983163466, -41.346084796073406),
///    (174.807979604528, -41.35098543989819),
///    (174.80094378133927, -41.35270175860709),
///    (174.78524618901284, -41.35520670405109),
///    (174.76919781098724, -41.35520670405109),
///    (174.75350021866086, -41.35270175860712),
///    (174.7464643954721, -41.35098543989822),
///    (174.7318041683653, -41.346084796073406),
///    (174.71882176795995, -41.33900220579369),
///    (174.7080847054138, -41.330046624984135),
///    (174.70373711226773, -41.32555201329609),
///    (174.69571516793187, -41.31511423541913),
///    (174.69075819658127, -41.303649981474955),
///    (174.68908285884382, -41.29165993179046),
///    (174.68908382855136, -41.2861018256992),
///    (174.69076308400918, -41.274109822737074),
///    (174.69572328077246, -41.26264015566849),
///    (174.70374765166264, -41.252194466801384),
///    (174.70809584412103, -41.24769587535717),
///    (174.71883294351622, -41.23873115217201),
///    (174.731814027686, -41.231639803278014),
///    (174.746471878884, -41.22673234111539),
///    (174.75350613305287, -41.22501356278328),
///    (174.7691998725514, -41.222504896122565),
///    (174.78524412744844, -41.222504896122565),
///    (174.800937866947, -41.22501356278325),
/// ].iter().map(|v| GeoCoord::new(degs_to_rads(v.1), degs_to_rads(v.0))).collect();
///
/// let mut h = polyfill(&vec![wellington_verts], 6);
/// assert_eq!(h.len(), 5);
/// h.sort_unstable();
/// assert_eq!(h, vec![606774924341673983, 606774925281198079, 606774925549633535, 606774929307729919, 606774929441947647]);
/// ```
Get all hexagons with centers contained in a given polygon. The polygon
is specified with GeoJson semantics as an array of loops. The first loop
is the perimeter of the polygon, and subsequent loops are
expected to be holes.
Get all hexagons with centers contained in a given polygon . The polygon is specified with GeoJson semantics as an array of loops . The first loop is the perimeter of the polygon and subsequent loops are expected to be holes .
pub fn polyfill(polygon: &[Vec<GeoCoord>], resolution: Resolution) -> Vec<H3Index> {
    let real_polygon = polygon
        .iter()
        .map(|p| p.iter().map(libh3_sys::GeoCoord::from).collect())
        .collect::<Vec<Vec<libh3_sys::GeoCoord>>>();
    unsafe {
        let fence = libh3_sys::Geofence {
            numVerts: real_polygon[0].len() as i32,
            verts: real_polygon[0].as_ptr(),
        };
        let holes = real_polygon
            .iter()
            .skip(1)
            .map(|p| libh3_sys::Geofence {
                numVerts: p.len() as i32,
                verts: p.as_ptr(),
            })
            .collect::<Vec<libh3_sys::Geofence>>();
        let p = libh3_sys::GeoPolygon {
            geofence: fence,
            numHoles: (real_polygon.len() - 1) as i32,
            holes: holes.as_ptr(),
        };
        let max = libh3_sys::maxPolyfillSize(&p, resolution as i32);
        let mut r = Vec::<H3Index>::with_capacity(max as usize);
        libh3_sys::polyfill(&p, resolution as i32, r.as_mut_ptr());
        r.set_len(max as usize);
        r.retain(|&v| v != 0);
        r
    }
}
pub fn polyfill ( polygon : & [ Vec < GeoCoord > ] , resolution : Resolution ) -> Vec < H3Index > { let real_polygon = polygon . iter ( ) . map ( | p | p . iter ( ) . map ( libh3_sys :: GeoCoord :: from ) . collect ( ) ) . collect :: < Vec < Vec < libh3_sys :: GeoCoord > > > ( ) ; unsafe { let fence = libh3_sys :: Geofence { numVerts : real_polygon [ 0 ] . len ( ) as i32 , verts : real_polygon [ 0 ] . as_ptr ( ) , } ; let holes = real_polygon . iter ( ) . skip ( 1 ) . map ( | p | libh3_sys :: Geofence { numVerts : p . len ( ) as i32 , verts : p . as_ptr ( ) , } ) . collect :: < Vec < libh3_sys :: Geofence > > ( ) ; let p = libh3_sys :: GeoPolygon { geofence : fence , numHoles : ( real_polygon . len ( ) - 1 ) as i32 , holes : holes . as_ptr ( ) , } ; let max = libh3_sys :: maxPolyfillSize ( & p , resolution as i32 ) ; let mut r = Vec :: < H3Index > :: with_capacity ( max as usize ) ; libh3_sys :: polyfill ( & p , resolution as i32 , r . as_mut_ptr ( ) ) ; r . set_len ( max as usize ) ; r . retain ( | & v | v != 0 ) ; r } }
Get all hexagons with centers contained in a given polygon.
Get all hexagons with centers contained in a given polygon .
polygon
&[Vec<GeoCoord>]
resolution
Resolution
polygon
&[Vec<GeoCoord>]
resolution
Resolution