Skip to content

box::extend: upper bound in all directions - #25

Open
mority wants to merge 1 commit into
motis-project:masterfrom
mority:box_rounding
Open

mority wants to merge 1 commit into
motis-project:masterfrom
mority:box_rounding

Conversation

@mority

@mority mority commented Sep 30, 2026

Copy link
Copy Markdown
Member
A box is bounded by two parallels and two meridians. A distance in metres
covers more degrees of longitude the farther the edge is from the equator, so
the true edge of "everything within dist_in_m of the box" is slanted in
degree space while the box edges stay vertical.

Drawn in degree space, northern hemisphere, strongly exaggerated.


Before: one longitude offset per side, each computed at a different edge
-------------------------------------------------------------------------

                 north: a degree of longitude is short

        \░░░░░░░┌───────────────────────────────────────┐
         \░░░░░░│                                      /│
          \░░░░░│       ┌─────────────────────┐       / │
           \░░░░│       │        box          │      /  │
            \░░░│       │                     │     /   │
             \░░│       └─────────────────────┘    /    │
              \░│                                 /     │
                └───────────────────────────────────────┘

                 south: a degree of longitude is long

  outer box   what extend() produced: the west offset was computed at the
              southern edge, the east offset at the northern edge
  \ and /     where dist_in_m actually ends on each side
  ░           within dist_in_m but outside the box: missed
  right of /  outside dist_in_m but inside the box: surplus, harmless

In the southern hemisphere the picture is mirrored: the east side was short
at its southern end.


After: the larger offset on both sides
--------------------------------------

        ┌───────────────────────────────────────────────┐
        │\                                             /│
        │ \             ┌─────────────────────┐       / │
        │  \            │        box          │      /  │
        │   \           │                     │     /   │
        │    \          └─────────────────────┘    /    │
        │     \                                   /     │
        └───────────────────────────────────────────────┘

The offset is computed at the edge farther from the equator,
max(|min_lat|, |max_lat|), and applied to both sides. The box now covers
dist_in_m everywhere, at the cost of a little surplus in the two
equator-facing corners.

Real proportions: at 47° N with a 5 km offset, the missed wedge was about
30 m wide at the top of a box 30 km tall.

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