Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/michaelowendyer/polylabel-java
- Owner: MichaelOwenDyer
- License: other
- Created: 2020-09-26T06:30:01.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-06-16T19:04:04.000Z (over 3 years ago)
- Last Synced: 2023-07-20T20:51:04.654Z (over 1 year ago)
- Language: Java
- Size: 62.5 KB
- Stars: 14
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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}
```