polylabel 0.1.11

A Rust implementation of the Polylabel algorithm
Documentation

Build Status Build status Coverage Status

Polylabel-rs

A Rust implementation of the Polylabel algorithm

Visualised: The orange dot is the polygon centroid. The teal dot is the ideal label position. GIF

How to Use

extern crate polylabel;
use polylabel::polylabel;

extern crate geo;
use geo::{Point, LineString, Polygon};

let coords = vec![
    (0.0, 0.0),
    (4.0, 0.0),
    (4.0, 1.0),
    (1.0, 1.0),
    (1.0, 4.0),
    (0.0, 4.0),
    (0.0, 0.0)
];
let ls = LineString(coords.iter().map(|e| Point::new(e.0, e.1)).collect());
let poly = Polygon::new(ls, vec![]);
let label_pos = polylabel(&poly, &0.10);
// Point(0.5625, 0.5625)

Documentation

https://docs.rs/polylabel

FFI

Call polylabel_ffi with the following three mandatory arguments:

  • Array (a void pointer to an array of two-element c_doubles, the exterior Polygon ring)
  • WrapperArray (a void pointer to an array of Arrays, the interior Polygon rings, empty if there are none)
  • tolerance, a c_float

The function returns a struct with two c_double fields:

  • x_pos
  • y_pos

A Python example is available in ffi.py

Binaries

Binary libs for:

  • x86_64 *nix (built using manylinux1, thus easy to include in Python 2.7 / 3.5 / 3.6 wheels) and OS X
  • i686 and x86_64 Windows

are available in releases.

License

MIT