Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix quincuncial inverse when no inverse is defined.

  • Loading branch information...
commit f8370488964d05043622978b9b5758d80bbc62d5 1 parent 77f0b92
@jasondavies jasondavies authored
Showing with 40 additions and 51 deletions.
  1. +40 −51 geo/projection/quincuncial.js
View
91 geo/projection/quincuncial.js
@@ -15,63 +15,52 @@ function quincuncialProjection(projectHemisphere) {
}
function projectAt(quincuncial) {
- var forward;
+ var forward = quincuncial ? function(λ, φ) {
+ var t = Math.abs(λ) < π / 2,
+ p = projectHemisphere(t ? λ : λ > 0 ? λ - π : λ + π, φ);
- if (quincuncial) {
+ var x = (p[0] - p[1]) * Math.SQRT1_2,
+ y = (p[0] + p[1]) * Math.SQRT1_2;
- forward = function(λ, φ) {
- var t = Math.abs(λ) < π / 2,
- p = projectHemisphere(t ? λ : λ > 0 ? λ - π : λ + π, φ);
+ if (t) return [x, y];
- var x = (p[0] - p[1]) * Math.SQRT1_2,
- y = (p[0] + p[1]) * Math.SQRT1_2;
+ var d = dx * Math.SQRT1_2,
+ s = x > 0 ^ y > 0 ? -1 : 1;
- 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];
- };
-
- forward.invert = 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;
- };
-
- } else {
+ 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;
+ };
- forward = 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;
- forward.invert = 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;
- };
- }
+ 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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.