Skip to content

Collapse the renderMetatile overloads into one - #121

Merged
trasch merged 3 commits into
mainfrom
fix/collapse-metatile-overloads
Nov 2, 2026
Merged

trasch merged 3 commits into
mainfrom
fix/collapse-metatile-overloads

Conversation

@trasch

@trasch trasch commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Three renderMetatile overloads with overlapping semantics are now one, and MetatileOptions is gone. The block size has a single source of truth: Metatile.metaSize.

This is a breaking change (see below).

Before

public func renderMetatile(origin: MapTile, metaSize: Int, options: RenderOptions = .tile()) throws -> MetatileRendered?
public func renderMetatile(_ metatile: Metatile, options: RenderOptions = .tile()) throws -> MetatileRendered?
public func renderMetatile(_ metatile: Metatile, options: MetatileOptions) throws -> MetatileRendered?

MetatileOptions bundled metaSize and RenderOptions, so a call that already had a Metatile carried the block size twice — and the two could disagree. The RenderOptions overload silently used metatile.metaSize; the MetatileOptions overload silently used options.metaSize and threw on a mismatch.

After

public func renderMetatile(_ metatile: Metatile, options: RenderOptions = .tile()) throws -> MetatileRendered?
let block = try Metatile(origin: MapTile(x: 1080, y: 712, z: 11), metaSize: 4)
let metatile = try map.renderMetatile(block, options: .tile(format: .png()))
  • The block size comes from Metatile.metaSize; RenderOptions only controls per-tile rendering.
  • The mismatched-metaSize guard is gone — the situation can no longer arise.
  • MetatileOptions' pixel-dimension helpers moved to Metatile.pixelSize(for:), which returns nil instead of trapping when the dimensions do not fit in an Int.

A trap I fixed on the way

The first version of pixelSize(for:) used a plain Int(...) conversion and crashed the test suite:

Fatal error: Double value cannot be converted to Int because the result would be greater than Int.max

That is the same class of bug as #17. It now returns nil, and renderMetatile reports it:

metatile pixel size for 1000000×1000000 at scale 100000000000000.0 is out of range

Testing

  • New test: the rendered block size comes from the Metatile, not the options.
  • New test: an out-of-range pixel size is reported, not trapped.
  • pixelSize(for:) is asserted for square and non-square options, plus the nil case.
  • 193 tests pass, swiftformat --lint clean, DocC builds with --warnings-as-errors.

Breaking changes

  • MetatileOptions is removed.
  • renderMetatile(origin:metaSize:options:) is removed — construct a Metatile instead.
  • renderMetatile(_:options:) no longer accepts MetatileOptions.
  • MetatileOptions.metatileWidth/metatileHeight/metatileSize are replaced by Metatile.pixelSize(for:).

Migration:

// before
try map.renderMetatile(origin: tile, metaSize: 4, options: .tile())
try map.renderMetatile(block, options: MetatileOptions(metaSize: 4, render: .tile()))

// after
try map.renderMetatile(try Metatile(origin: tile, metaSize: 4), options: .tile())
try map.renderMetatile(block, options: .tile())

Closes #86

- The clamping range is public as WorkQueue.concurrencyRange, so callers can
  validate their own input instead of discovering the clamp after the fact.
- The property and the initializer share one clamp helper instead of
  duplicating `max(1, min(256, ...))`.
- maxConcurrency's documentation now states the clamping and documents the
  previously undocumented mid-run behaviour: raising the limit takes effect
  on the next refill, lowering it does not interrupt running processWork
  calls, so concurrency can briefly exceed the new limit.
- setMaxConcurrency stays, but its documentation explains why it exists
  rather than reading as a redundant duplicate: Swift only permits mutating
  actor state from inside the actor, so it is the supported way to change
  the limit from outside.

Tests
- Clamping is asserted against concurrencyRange instead of hard-coded
  numbers.
- New test that raising the limit mid-run actually increases observed
  parallelism, which is the behaviour the docs now promise.

Fixes #99
There were three overloads with overlapping semantics: one took
(origin, metaSize), one took a Metatile plus RenderOptions, and one took a
Metatile plus MetatileOptions. The last two were easy to confuse, and
MetatileOptions duplicated the block size that Metatile already carries.

Now there is a single entry point:

    renderMetatile(_ metatile: Metatile, options: RenderOptions = .tile())

The block size comes from Metatile.metaSize, so there is one source of truth
and no way to pass a metaSize that disagrees with the block. RenderOptions
only controls per-tile rendering (size, scale, format, buffer).

- MetatileOptions is removed. Its pixel-dimension helpers move to
  Metatile.pixelSize(for:), which returns nil instead of trapping when the
  dimensions do not fit in an Int.
- The mismatched-metaSize guard is gone: the situation can no longer arise.
- renderMetatile validates the block against the tile grid and rejects a
  block whose pixel buffer would not fit, both as MapnikError.invalidInput.

This is a breaking change: callers using renderMetatile(origin:metaSize:),
renderMetatile(_:options:) with MetatileOptions, or MetatileOptions itself
need to construct a Metatile and pass RenderOptions.

Tests and docs updated; a new test asserts the block size comes from the
Metatile, and that an out-of-range pixel size is reported rather than
trapping.

Fixes #86
@trasch trasch self-assigned this Nov 2, 2026
@trasch trasch added the enhancement New feature or request label Nov 2, 2026
@trasch
trasch merged commit 1d2b3ee into main Nov 2, 2026
5 checks passed
@trasch
trasch deleted the fix/collapse-metatile-overloads branch November 2, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The three renderMetatile overloads have overlapping, confusing semantics

1 participant