A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/urschrei/polylabel-rs below:

urschrei/polylabel-rs: A Rust implementation of the Polylabel algorithm, with FFI.

A Rust implementation of the Polylabel algorithm

The orange dot is the polygon centroid. The teal dot is the ideal label position. Red boxes show the search space.

You can generate this visualisation yourself by cloning this repo, switching to the visualise branch, and opening the visualise.ipynb Jupyter notebook, then stepping through the cells. You can also easily visualise a Polygon of your own using the notebook.

extern crate polylabel;
use polylabel::polylabel;

extern crate geo;
use geo::{Point, 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 poly = Polygon::new(coords.into(), vec![]);
let label_pos = polylabel(&poly, &0.10);
// Point(0.5625, 0.5625)

A command-line tool is available: cargo install polylabel_cmd. This enables the polylabel command, which takes a GeoJSON file as input, as well as an optional (-t / --tolerance) tolerance value. See more at crates.io.

https://docs.rs/polylabel

Enable the Cargo ffi and headers features to enable this functionality

Call polylabel_ffi with the following three mandatory arguments:

The function returns a struct with two c_double fields:

Headers are provided in the include directory. A Python example is available in ffi.py

An auto-generated header file is available at include/header.h

Using a 4-core 2.3 GHz Intel Core i5, finding a label position on a ~9k-vertex polygon (representing the Norwegian mainland) using a tolerance of 1.0 takes around 9 ms. Depending upon the dimensions of your polygon(s), you may require a higher tolerance (i.e. a smaller number). See here for some guidance on the accuracy provided by each decimal place.

Build using the target-cpu=native RUSTFLAG for a ~10 % perf improvement

are available in releases.

MIT


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4