Skip to content

forwardRotationLambda does not normalize angles beyond ±3π #242

@jrus

Description

@jrus

If you try to project angles outside the range [–3π, 3π], it can result in wonky artifacts from resampling:

Screen Shot 2021-06-20 at 9 05 45 PM

Here is the current code for forwardRotationLambda https://github.com/d3/d3-geo/blob/v3.0.1/src/rotation.js#L17-L21

function forwardRotationLambda(deltaLambda) {
  return function(lambda, phi) {
    return lambda += deltaLambda, [lambda > pi ? lambda - tau : lambda < -pi ? lambda + tau : lambda, phi];
  };
}

My proposed alternative is:

function forwardRotationLambda(deltaLambda) {
  return function(lambda, phi) {
    lambda += deltaLambda;
    while (lambda > pi) lambda -= tau;
    while (lambda < -pi) lambda += tau;
    return [lambda, phi];
  };
}

This should run at the same speed, and in my opinion is also a bit more legible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions