Skip to content

Migrate polylabel vendor from mapbox to mapnik fork - #4426

Closed
louwers with Copilot wants to merge 6 commits into
mainfrom
copilot/migrate-to-mapnik-polylabel
Closed

louwers with Copilot wants to merge 6 commits into
mainfrom
copilot/migrate-to-mapnik-polylabel

Conversation

Copilot AI commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

mapbox/polylabel deleted its C++ implementation in mapbox/polylabel#124. mapnik/polylabel is the maintained fork that restores and improves the C++ port (v2.1.0 algorithmic improvements: clamped cell sizes, flattened coordinate buffers, block-based bbox skipping, aggressive queue pruning).

Changes

  • .gitmodules — point submodule URL to https://github.com/mapnik/polylabel.git
  • vendor/polylabel — update submodule ref from 6ed5f1a (mapbox 1.1.0) to 1edc167 (mapnik latest)
  • vendor/polylabel.cmake — update INTERFACE_MAPLIBRE_URL and INTERFACE_MAPLIBRE_AUTHOR to reflect the new fork

No source changes needed — the fork preserves the same include path (<mapbox/polylabel.hpp>), namespace (mapbox::polylabel), and function signature, adding only an optional distance output parameter.

Copilot AI linked an issue Jul 22, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Migrate to mapnik/polylabel fork for updates Migrate polylabel vendor from mapbox to mapnik fork Jul 22, 2026
Copilot AI requested a review from louwers July 22, 2026 22:51
@github-actions github-actions Bot added the build Related to build, configuration or CI/CD label Jul 22, 2026
Comment thread vendor/polylabel.cmake Resolved
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Bloaty Results 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0% +43.7Ki  +0.0% +14.8Ki    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-4426-compared-to-main.txt

Compared to d387090 (legacy)

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +55% +64.2Mi  +475% +28.4Mi    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-4426-compared-to-legacy.txt

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results ⚡

Benchmark                                                          Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------
OVERALL_GEOMEAN                                                 -0.0018         -0.0016             0             0             0             0

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/benchmark-results/pr-4426-compared-to-main.txt

@louwers

louwers commented Aug 4, 2026

Copy link
Copy Markdown
Member

@copilot The test is failing. Debug it.

The mapnik/polylabel fork added an early-out: when min(width,height) <=
precision, it returns envelope.min instead of computing the true pole of
inaccessibility. With the default precision of 1.0 degree, a 1x1 degree
polygon triggered this early-out, returning (100,0) instead of (100.5,0.5).

Fix by passing precision=1e-4 (approximately 10m) in MLNPolygon.mm, which
is appropriate for geographic coordinates.

Also removes the unused <mapbox/polylabel.hpp> include from MLNPolyline.mm.

Co-authored-by: louwers <649392+louwers@users.noreply.github.com>

Copilot AI commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@copilot The test is failing. Debug it.

The failing tests were testPolygon and testMultiPolygon in MLNCodingTests.mm. They check that [polygon coordinate] returns the pole of inaccessibility at the center of a 1×1 degree square (100.5°, 0.5°), but were getting (100°, 0°) instead.

Root cause: the mapnik/polylabel fork added an early-out for "sub-precision polygons" — when min(width, height) <= precision, it returns envelope.min immediately instead of computing the true pole. With the default precision of 1.0 degree, a 1×1 degree polygon (min(1.0, 1.0) == 1.0 == precision) triggered this early-out.

Fix (committed in the latest push):

  • MLNPolygon.mm: pass precision=1e-4 (≈10 m) instead of the default 1.0 for geographic-coordinate polygons
  • MLNPolyline.mm: remove the unused <mapbox/polylabel.hpp> include

Copilot AI requested a review from louwers August 4, 2026 16:23
@github-actions github-actions Bot added the iOS label Aug 4, 2026
@louwers

louwers commented Aug 11, 2026

Copy link
Copy Markdown
Member

@copilot Please fix ios-build CI

…ement

The new mapnik/polylabel correctly computes the pole of inaccessibility for
polygons with holes, placing it in a corner rather than at the centre (which
lies inside the hole). The old test put a polygon-with-hole first in the
MLNMultiPolygon, so MLNMultiPolygon.coordinate was taken from a polygon whose
true pole is NOT the square's centre.

Fix: swap the polygon order so the hole-free innerPolygonSquare is first.
Its pole of inaccessibility is exactly (100.5, 0.5) — the centre of the
0.3×0.3 square — which matches the existing assertion.

Co-authored-by: louwers <649392+louwers@users.noreply.github.com>

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please fix ios-build CI

Fixed. The remaining failure was in testMultiPolygon: it was putting a polygon-with-hole first in the MLNMultiPolygon, so [squares coordinate] returned that polygon's pole of inaccessibility. With the new mapnik implementation correctly handling holes, the pole is placed in a corner (~100.795°, ~0.205°) rather than at the centre which lies inside the hole — so the test expectation of (100.5, 0.5) was wrong.

Fix: swap the polygon order so the hole-free innerPolygonSquare is first. Its true pole-of-inaccessibility is exactly the centre of the 0.3×0.3 square (100.5°, 0.5°), matching the existing assertion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Related to build, configuration or CI/CD iOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate to mapnik/polylabel

2 participants