Skip to content

MapWinGIS6 — Map Model and Basic Navigation - #35

Merged
pmeems merged 1 commit into
developmentfrom
phase-2-viewport-and-coordinate-transformations
Oct 31, 2026
Merged

pmeems merged 1 commit into
developmentfrom
phase-2-viewport-and-coordinate-transformations

Conversation

@pmeems

@pmeems pmeems commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Phase 2 of the Map Model and Basic Navigation plan. Stacked on #34.

Motivation

Multi-layer rendering (Phase 3) and navigation (Phases 4 and 5) need one reusable map-to-screen transformation in Core. Today the only transformation is activex::ViewTransform, which lives in the OCX and is rebuilt from the dataset extent on every draw.

What changes

  • mwg::Viewport (mapwingis/map/Viewport.h) holds a pixel size plus a view (center and map units per pixel). It provides MapToScreen, ScreenToMap, VisibleExtent, FitExtent(extent, padding), SetView, and SetSize.
  • MapPoint, ScreenPoint, PixelPoint and ToPixel, the only place where screen coordinates are rounded.
  • ViewportTests.cpp with 36 tests. No window and no ActiveX.
  • A "Viewport" section in docs/ARCHITECTURE.md.

Key design decisions

  • State is center + resolution, not an extent. One resolution applies to both axes, so the view never distorts geometry. Resizing keeps the center and scale, which Phase 3 resizing and Phase 4 zoom/pan need.
  • Continuous screen coordinates. Pixel (i, j) covers [i, i+1) x [j, j+1), and Y points down. FitExtent maps the extent edges to the centers of the outermost pixels, so rounding never pushes boundary geometry out of the viewport.
  • Invalid input: API misuse (negative size, non-finite view, negative padding) throws InvalidArgument. Non-finite points or overflowing results return std::nullopt. Invalid extents and zero-sized viewports make FitExtent return false without changing the view. A zero-sized viewport keeps its view.
  • Limits: the center is clamped to ±1e12, resolution to [1e-10 × max(1, |center|), 1e9], and size to 65536 px. Because the minimum resolution scales with the center, a pixel always spans many representable doubles.
  • Value type, not PImpl. Like Extent, Viewport is small and copyable, so renderers and navigation code can take snapshots of it.
  • The viewport does not reference a Map. Callers fit it to Map::GetExtent().

Dependencies / follow-up

Build: Debug|x64, 0 warnings. Tests: 226 passed, 3 skipped (opt-in suites).

@pmeems
pmeems added this pull request to stack #36 October 31, 2026 08:43
Base automatically changed from phase-1-map-model-and-layer-collection to development October 31, 2026 11:52
Introduce mwg::Viewport: a pixel size plus a center/resolution view that converts between map and screen coordinates, fits extents with padding while preserving aspect ratio, and clamps to documented limits. Add ToPixel for the single rounding step, viewport tests, and architecture docs.

Co-authored-by: Junie <junie@jetbrains.com>
@pmeems
pmeems force-pushed the phase-2-viewport-and-coordinate-transformations branch from e8ee36b to 54a55c9 Compare October 31, 2026 11:52
@pmeems
pmeems merged commit f387957 into development Oct 31, 2026
1 check passed
@pmeems
pmeems deleted the phase-2-viewport-and-coordinate-transformations branch October 31, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant