Skip to content

Commit 210085d

Browse files
jasondaviesmbostock
authored andcommitted
Fix antemeridian degeneracy handling.
1 parent 7069125 commit 210085d

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

d3.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6264,16 +6264,16 @@
62646264
context.lineTo(sλ0, φ0);
62656265
context.moveTo(sλ1, φ0);
62666266
context.lineTo(λ1, φ0);
6267-
context.lineTo(λ0 = λ1, φ0 = φ1);
62686267
keepWinding = false;
62696268
} else if (sλ0 !== sλ1 && >= π) {
6269+
if (Math.abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
6270+
if (Math.abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
62706271
φ0 = d3_geo_projectionIntersectAntemeridian(λ0, φ0, λ1, φ1);
6271-
if (Math.abs(λ0 - sλ0) > ε) context.lineTo(sλ0, φ0);
6272-
if (Math.abs(λ1 - sλ1) > ε) context.moveTo(sλ1, φ0), context.lineTo(λ0 = λ1, φ0 = φ1); else context.moveTo(λ0 = λ1, φ0 = φ1);
6272+
context.lineTo(sλ0, φ0);
6273+
context.moveTo(sλ1, φ0);
62736274
keepWinding = false;
6274-
} else {
6275-
context.lineTo(λ0 = λ1, φ0 = φ1);
62766275
}
6276+
context.lineTo(λ0 = λ1, φ0 = φ1);
62776277
sλ0 = sλ1;
62786278
}
62796279
if (winding != null) context.closePath();

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geo/projection.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,17 @@ function d3_geo_projectionCutAntemeridian(rotatePoint) {
221221
context.lineTo(sλ0, φ0);
222222
context.moveTo(sλ1, φ0);
223223
context.lineTo(λ1, φ0);
224-
context.lineTo(λ0 = λ1, φ0 = φ1);
225224
keepWinding = false;
226225
} else if (sλ0 !== sλ1 && >= π) { // line crosses antemeridian
226+
// handle degeneracies
227+
if (Math.abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
228+
if (Math.abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
227229
φ0 = d3_geo_projectionIntersectAntemeridian(λ0, φ0, λ1, φ1);
228-
if (Math.abs(λ0 - sλ0) > ε) context.lineTo(sλ0, φ0);
229-
if (Math.abs(λ1 - sλ1) > ε) context.moveTo(sλ1, φ0), context.lineTo(λ0 = λ1, φ0 = φ1);
230-
else context.moveTo(λ0 = λ1, φ0 = φ1);
230+
context.lineTo(sλ0, φ0);
231+
context.moveTo(sλ1, φ0);
231232
keepWinding = false;
232-
} else {
233-
context.lineTo(λ0 = λ1, φ0 = φ1);
234233
}
234+
context.lineTo(λ0 = λ1, φ0 = φ1);
235235
sλ0 = sλ1;
236236
}
237237
if (winding != null) context.closePath();

test/geo/path-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,23 @@ suite.addBatch({
348348
}
349349
},
350350

351+
"antemeridian cutting": {
352+
"rotate([330, 232])": {
353+
topic: function() {
354+
return d3.geo.path()
355+
.context(testContext)
356+
.projection(d3.geo.equirectangular()
357+
.rotate([330, 232])
358+
.scale(900 / Math.PI)
359+
.precision(0));
360+
},
361+
"degenerate points": function(path) {
362+
path(d3.geo.circle().angle(30)());
363+
assert.equal(testContext.buffer().filter(function(d) { return d.type === "moveTo"; }).length, 2);
364+
}
365+
}
366+
},
367+
351368
"stereographic.precision(1)": {
352369
topic: function() {
353370
return d3.geo.path()

0 commit comments

Comments
 (0)