Sha256: 791b5b7a554e7a081afe423fe2766177ea944bfefb0adec92ba603f1a3a6c658

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 KB

Contents

import "projection";

function quincuncialProjection(projectHemisphere) {
  var dx = projectHemisphere(π / 2, 0)[0] - projectHemisphere(-π / 2, 0)[0];

  function projection() {
    var quincuncial = false,
        m = projectionMutator(projectAt),
        p = m(quincuncial);

    p.quincuncial = function(_) {
      if (!arguments.length) return quincuncial;
      return m(quincuncial = !!_);
    };

    return p;
  }

  function projectAt(quincuncial) {
    var forward = quincuncial ? function(λ, φ) {
      var t = Math.abs(λ) < π / 2,
          p = projectHemisphere(t ? λ : λ > 0 ? λ - π : λ + π, φ);

      var x = (p[0] - p[1]) * Math.SQRT1_2,
          y = (p[0] + p[1]) * Math.SQRT1_2;

      if (t) return [x, y];

      var d = dx * Math.SQRT1_2,
          s = x > 0 ^ y > 0 ? -1 : 1;

      return [s * x - sgn(y) * d, s * y - sgn(x) * d];
    } : function(λ, φ) {
      var s = λ > 0 ? -.5 : .5,
          point = projectHemisphere(λ + s * π, φ);
      point[0] -= s * dx;
      return point;
    };

    if (projectHemisphere.invert) forward.invert = quincuncial ? function(x0, y0) {
      var x = (x0 + y0) * Math.SQRT1_2,
          y = (y0 - x0) * Math.SQRT1_2,
          t = Math.abs(x) < .5 * dx && Math.abs(y) < .5 * dx;

      if (!t) {
        var d = dx * Math.SQRT1_2,
            s = x > 0 ^ y > 0 ? -1 : 1,
            x1 = -s * (x0 + (y > 0 ? 1 : -1) * d),
            y1 = -s * (y0 + (x > 0 ? 1 : -1) * d);
        x = (-x1 - y1) * Math.SQRT1_2;
        y = (x1 - y1) * Math.SQRT1_2;
      }

      var p = projectHemisphere.invert(x, y);
      if (!t) p[0] += x > 0 ? π : -π;
      return p;
    } : function(x, y) {
      var s = x > 0 ? -.5 : .5,
          location = projectHemisphere.invert(x + s * dx, y),
          λ = location[0] - s * π;
      if (λ < -π) λ += 2 * π;
      else if (λ > π) λ -= 2 * π;
      location[0] = λ;
      return location;
    };

    return forward;
  }

  projection.raw = projectAt;

  return projection;
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
d3js-plugins-rails-0.0.8 vendor/assets/javascripts/d3/plugins/geo/projection/quincuncial.js
d3js-plugins-rails-0.0.7 vendor/assets/javascripts/d3/plugins/geo/projection/quincuncial.js
d3js-plugins-rails-0.0.6 vendor/assets/javascripts/d3/plugins/geo/projection/quincuncial.js
d3js-plugins-rails-0.0.5 vendor/assets/javascripts/d3/plugins/geo/projection/quincuncial.js