Skip to content
pubscout

dart_polylabel2

1.0.0, released a year ago by jaffaketchup.dev

Calculates the pole of inaccessibility for polygons to place labels optimally.

WASM-ready
$ flutter pub add dart_polylabel2
Source repository

What it does

A Dart port of Mapbox's polylabel algorithm that identifies the pole of inaccessibility within a polygon. It determines the most interior point of a polygon along with its distance to the polygon boundary. This enables optimal positioning for text labels or markers on complex shapes.

AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Placing labels or center points visually inside complex polygon geometries on maps
  • Finding the most interior point of a 2D shape without using dart:math Point objects

Skip it when

  • Simple bounding box center or centroid arithmetic is sufficient for regular shapes
  • Working with non-polygon spatial data

Strengths

  • Avoids dart:math Point to reduce generic casting overhead and improve performance
  • Modern Dart API using records for coordinates and return values
  • Supports all Dart and Flutter platforms with no native dependencies

Weaknesses

  • Not backwards compatible with the older polylabel package
  • Limited documentation beyond the basic invocation snippet

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
2
import 'package:dart_polylabel2/dart_polylabel2.dart';

final polygon = [[(x: 0, y: 0), (x: 1, y: 0), (x: 1, y: 1), (x: 0, y: 1), (x: 0, y: 0)]];
final (point: (:x, :y), :distance) = polylabel(polygon);

Works with

Packages commonly used together with dart_polylabel2: ones it builds on, ones built on it, and its own family.