Skip to content

Close the remaining API gaps - #118

Merged
trasch merged 3 commits into
mainfrom
fix/remaining-api-gaps
Nov 2, 2026
Merged

trasch merged 3 commits into
mainfrom
fix/remaining-api-gaps

Conversation

@trasch

@trasch trasch commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The last batch of API gaps: a counter that disagreed with its own output, vector renders whose page size depended on earlier calls, and internal-only accessors.

TilelistBuilder

b.add(tile); b.add(tile); b.add(otherTile)
b.tileCount   // was 3, tilelist encoded 2 tiles

tileCount counted additions while tilelist de-duplicated. It now counts unique tiles, so the two agree.

Vector rendering

renderSVG/renderPDF/renderPostScript rendered at whatever size the map happened to have, so the page size depended on the previous call:

let svg1 = try map.renderSVG()          // width="256"
_ = try map.render(width: 800, height: 800, format: .png())
let svg2 = try map.renderSVG()          // width="800"  — stateful

They now take optional width/height, and the map size is restored afterwards:

let svg = try map.renderSVG(width: 400, height: 300)  // width="400" height="300"

ImageFormat

typeString is public, so the documented mapnik-type mapping ("webp:quality=80", …) is observable and testable without @testable import.

Render prologue

render(), renderTile, renderMetatile and renderPNG256 each re-implemented validate → resize → apply buffer → zoom → restore. That duplication is exactly how scale, height and skipFullyTransparent came to be honoured by some paths and ignored by others. A new withRenderState(_:resize:zoomIfUnset:body:) captures the sequence, and render() uses it.

C shim

  • The cairo temporary file honours TMPDIR via std::filesystem::temp_directory_path instead of hard-coding /tmp, which is not writable in every sandbox.
  • Removed the unused write_buffer_to_file helper and the unused AGG include.

Packaging

Package.resolved is no longer committed. For a library it only pins the repo's own builds while hiding incompatibilities with newer gis-tools releases.

Testing

New tests for tileCount uniqueness, vector page size (including that the map size is restored), the default vector size, and every ImageFormat.typeString. swiftformat --lint is clean.

Breaking changes

  • TilelistBuilder.tileCount now counts unique tiles.
  • renderSVG/renderPDF/renderPostScript gained width:/height: parameters (defaulted, so existing calls compile).

Closes #15
Closes #22
Closes #23
Closes #54
Closes #88
Closes #90
Closes #96

TilelistBuilder
- tileCount counts unique tiles instead of additions, so it agrees with
  tilelist (which de-duplicates).

Vector rendering
- renderSVG/renderPDF/renderPostScript take optional width/height so the
  page size is explicit instead of depending on the map's previous size.
  The map size is restored afterwards.

ImageFormat
- typeString is public, so the documented mapnik type mapping is
  observable (and testable without @testable import).

Render prologue
- New withRenderState(_:resize:zoomIfUnset:body:) captures the
  validate/resize/buffer/zoom/restore sequence. render() uses it, so the
  paths can no longer drift apart the way they did for scale, height and
  skipFullyTransparent.

C shim
- The cairo temp file honours TMPDIR via
  std::filesystem::temp_directory_path instead of hard-coding /tmp.
- Removed the unused write_buffer_to_file helper and the unused AGG
  include.

Packaging
- Package.resolved is no longer committed: for a library it only pins the
  repo's own builds and hides incompatibilities with newer gis-tools
  releases.

Tests
- tileCount uniqueness, vector page size (and that the map size is
  restored), default vector size, and every ImageFormat type string.

Fixes #15
Fixes #22
Fixes #23
Fixes #54
Fixes #88
Fixes #90
Fixes #96
@trasch trasch self-assigned this Nov 2, 2026
@trasch trasch added the enhancement New feature or request label Nov 2, 2026
Rebased onto main after #117 landed. Conflicts were resolved by keeping
main's newer render pipeline (withRenderState, the cairo resize helper) and
re-applying this PR's additions on top.

TilelistBuilder
- tileCount counts unique tiles instead of additions, so it agrees with
  tilelist (which de-duplicates).

Vector rendering
- renderSVG/renderPDF/renderPostScript take optional width/height so the
  page size is explicit instead of depending on the map's previous size.
  The map size is restored afterwards.

ImageFormat
- typeString is public, so the documented mapnik type mapping is
  observable (and testable without @testable import).

C shim
- The cairo temp file honours TMPDIR via
  std::filesystem::temp_directory_path instead of hard-coding /tmp.
- Removed the unused AGG include.

Packaging
- Package.resolved is no longer committed: for a library it only pins the
  repo's own builds and hides incompatibilities with newer gis-tools
  releases.

Tests
- tileCount uniqueness, vector page size (and that the map size is
  restored), default vector size, and every ImageFormat type string.
The docs job builds with --warnings-as-errors, which requires every
parameter of a documented function to be described.
@trasch
trasch merged commit 7ca8f13 into main Nov 2, 2026
5 checks passed
@trasch
trasch deleted the fix/remaining-api-gaps branch November 2, 2026 21:28
trasch added a commit that referenced this pull request Nov 2, 2026
Rebased onto main after #118 landed. Conflicts were resolved by combining
both sides: main's newer code (dropped-feature counting, non-square metatile
dimensions) plus this PR's hardening on top.

Thread safety
- mapnik_datasource_destroy takes the lifecycle mutex like
  mapnik_datasource_create, so a datasource cannot be torn down while
  another thread is loading a stylesheet.
- MapnikDatasource.init passes the pointer arrays directly instead of
  reinterpreting their storage through UnsafeRawPointer +
  assumingMemoryBound (undefined behaviour, and it force-unwrapped
  baseAddress).
- Documented that MapnikDatasource is safe for one concurrent query at a
  time, and that Mapnik.deinit may block on the lifecycle lock.

Feature queries
- Boolean detection compares against Foundation's shared boolean instances
  instead of sniffing NSNumber.objCType[0] == 'c', which is an
  implementation detail and also matches small integers on some versions.
  Verified: {"flag": true, "small": 1} decodes as Bool and Int.

Docs
- renderTile warns that a non-Web-Mercator map interprets the tile box in
  its own SRS (an epsg:4326 map renders empty) instead of claiming it is
  "valid".
- ImageFormat.svg documents that it is not usable with the raster entry
  points.
- inspect's fieldFilter documents that it is a membership filter and does
  not control output order.
- The counting-datasource header matches the implementation: the layer
  keeps a shared_ptr, so the handle may be destroyed early.
- MetatileOptions.validated() validates at construction for callers that
  want the error early, without making the default argument throwing.

Tests
- Concurrent datasource create/inspect/query/destroy, and that a map stays
  usable after its counting datasource handle is destroyed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment