Skip to content

[Bug]: Buffer outlines sit up to 10 % of the distance off: long sides come back from the plane straight, and arcs have 32 edges #1159

Closed

Description

@Mavrick-F

What happened

A 2 km buffer of a 96 km east–west line (r1 in the analysis reference corpus, at 46.25° N) has 33 vertices. Every vertex is exactly 2,000 m from the line, but between vertices the outline is wrong: midway along the long sides it is 190 m from where it should be, inside on one side and outside on the other. Places 1.85 km from the line fall outside its 2 km buffer, and places 2.15 km away fall inside.

Two causes, both in crates/analysis/src/geodesic.rs:

  1. Long edges come back straight. The buffer is drawn in an azimuthal equidistant plane, where a straight side is the right curve, and Plane::back converts only its vertices back to lon/lat. The side between two vertices becomes a straight line in lon/lat (and Web Mercator), which is not that curve. The error grows with the square of the side's length:

    Line (2 km buffer) Length Worst offset
    r3, diagonal 17 km 11 m
    r4, east–west 38 km 30 m
    r7, east–west 67 km 93 m
    r1, east–west 96 km 190 m
  2. Arcs have 32 edges. A point's buffer is a 32-sided polygon inside the circle: its edges cut up to d(1 − cos(π/32)), 0.48 % of the distance, inside it (4.8 m at 1 km). Its area is 0.64 % short at any distance.

The module's header says the projection error is under 0.01 %. That holds at the vertices; the outline between them is 50 to 1,000 times further off.

How to reproduce

The analysis reference corpus gets six Buffer cases in a pull request that links here (points at 1 and 120 km, lines at 2 km, a 1,200 km line at 5 km, polygons at 1 and −2 km). Their answers are worked out from the definition of a buffer: GeographicLib discs along each edge's geodesic, checked by measuring from the outline back to the feature. They're marked as known failures pointing here, so cargo test -p rustgis-analysis --test reference -- --nocapture lists the differences without failing:

buffer lines: still differs:
    r1: area 832127436.2 m² vs 832367265.3 m²; 51208321.2 m² (6.15e-2 of it) not shared
buffer points: still differs:
    a: area 6496360.6 m² vs 6537959.7 m²; 41600.1 m² (6.36e-3 of it) not shared

What I'd expect

The outline within the stated 0.01 % of the distance everywhere along it, not only at its vertices. Probably:

  • densify the buffer's rings in the plane (each edge split so its midpoint stays within, say, 1e-4 of the distance) before converting them back;
  • draw arcs with enough edges for the same bound (about 1.5° per edge, roughly 230 per circle, rather than 32).

Both add vertices, so the output grows; the bound could set how many. When it's fixed, the reference cases flip to passing and the test asks for their known mark to be removed.

RustGIS version

main at 6b2556a

Activity

  1. added
    bug
    on Oct 30, 2026
  2. self-assigned this
    on Oct 31, 2026
  3. added a commit that references this issue on Oct 31, 2026
    020bba1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions