Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/michaelowendyer/polylabel-java

A Java port of PolyLabel
https://github.com/michaelowendyer/polylabel-java

Last synced: 2 months ago
JSON representation

A Java port of PolyLabel

Awesome Lists containing this project

README

        

# polylabel-java
A Java port of PolyLabel from MapBox.

Official repo: [https://github.com/mapbox/polylabel](https://github.com/mapbox/polylabel)

Article: https://blog.mapbox.com/a-new-algorithm-for-finding-a-visual-center-of-a-polygon-7c77e6492fbc

## Requirements
* [Java 8 or later](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
* [Maven 3](http://maven.apache.org/download.html)
* [Git](https://git-scm.com/downloads)

## Installation

Add polylabel-java to your local .m2 folder with the following commands:
```
git clone https://github.com/FreshLlamanade/polylabel-java
cd polylabel-java
mvn clean install
```

Then add the following dependency to your pom.xml:
```
com.monst
polylabel-java
1.2.1
```

## Usage

Using default precision (1.0), no console messages:
```java
PolyLabel result = PolyLabel.polyLabel(new Integer[][][] {{{0, 0}, {10, 0}, {0, 10}}})
// result.getCoordinates() -> {3.125, 3.125}
```
Using precision of 0.5, no console messages:
```java
PolyLabel result = PolyLabel.polyLabel(new Integer[][][] {{{0, 0}, {10, 0}, {0, 10}}}, 0.5)
// result.getCoordinates() -> {2.8125, 2.8125}
```
Using precision of 0.5, with console messages:
```java
PolyLabel result = PolyLabel.polyLabel(new Integer[][][] {{{0, 0}, {10, 0}, {0, 10}}}, 0.5, true)
// Found best 2.50 after 5 probes
//
// Found best 2.65 after 21 probes
//
// Found best 2.81 after 25 probes
//
// Num probes: 25
// Best distance: 2.812500
//
// result.getCoordinates() -> {2.8125, 2.8125}
```