Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/clip/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export default function() {
var lines = [],
line;
return {
point: function(x, y) {
line.push([x, y]);
point: function(x, y, m) {
line.push([x, y, m]);
},
lineStart: function() {
lines.push(line = []);
Expand Down
13 changes: 4 additions & 9 deletions src/clip/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@ export default function(radius) {
? v ? 0 : code(lambda, phi)
: v ? code(lambda + (lambda < 0 ? pi : -pi), phi) : 0;
if (!point0 && (v00 = v0 = v)) stream.lineStart();
// Handle degeneracies.
// TODO ignore if not clipping polygons.
if (v !== v0) {
point2 = intersect(point0, point1);
if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
point1[0] += epsilon;
point1[1] += epsilon;
v = visible(point1[0], point1[1]);
}
if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))
point1[2] = 1;
}
if (v !== v0) {
clean = 0;
Expand All @@ -61,7 +56,7 @@ export default function(radius) {
} else {
// inside going out
point2 = intersect(point0, point1);
stream.point(point2[0], point2[1]);
stream.point(point2[0], point2[1], 2);
stream.lineEnd();
}
point0 = point2;
Expand All @@ -80,7 +75,7 @@ export default function(radius) {
stream.point(t[1][0], t[1][1]);
stream.lineEnd();
stream.lineStart();
stream.point(t[0][0], t[0][1]);
stream.point(t[0][0], t[0][1], 3);
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/clip/rejoin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pointEqual from "../pointEqual.js";
import {epsilon} from "../math.js";

function Intersection(point, points, other, entry) {
this.x = point;
Expand All @@ -22,14 +23,15 @@ export default function(segments, compareIntersection, startInside, interpolate,
if ((n = segment.length - 1) <= 0) return;
var n, p0 = segment[0], p1 = segment[n], x;

// If the first and last points of a segment are coincident, then treat as a
// closed ring. TODO if all rings are closed, then the winding order of the
// exterior ring should be checked.
if (pointEqual(p0, p1)) {
stream.lineStart();
for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
stream.lineEnd();
return;
if (!p0[2] && !p1[2]) {
stream.lineStart();
for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
stream.lineEnd();
return;
}
// handle degenerate cases by moving the point
p1[0] += 2 * epsilon;
}

subject.push(x = new Intersection(p0, segment, null, true));
Expand Down
16 changes: 16 additions & 0 deletions test/projection/clipcircle-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var tape = require("tape"),
d3 = require("../../");

tape("projection.clipAngle() deals with degenerate polygons", function(test) {
// https://observablehq.com/d/495020ca139c39bd
var polygon = {
type: "Polygon",
coordinates: [ [[-120, -30],[0, -30],[0, -90],[0, -30],[120, -30],[-120, -30]] ]
};
var projection = d3.geoAzimuthalEqualArea()
.translate([0.5, 0.5])
.rotate([0, -90, 0])
.clipAngle(170);
test.equal(d3.geoPath(projection)(polygon).replace(/\.\d+/g,""), 'M0,249L0,238L0,216L21,219L45,219L71,215L98,207L127,193L141,184L155,173L168,161L181,148L192,133L202,117L211,100L218,83L224,65L228,48L230,30L231,13L229,-17L222,-45L212,-70L200,-90L187,-107L179,-127L167,-147L151,-168L130,-188L104,-206L89,-213L73,-220L55,-225L37,-229L19,-232L0,-233L-18,-232L-36,-229L-54,-225L-72,-220L-88,-213L-103,-206L-129,-188L-150,-168L-166,-147L-178,-127L-186,-107L-186,-107L-199,-90L-211,-70L-221,-45L-228,-17L-230,13L-229,30L-227,48L-223,65L-217,83L-210,100L-201,117L-191,133L-180,148L-167,161L-154,173L-140,184L-126,193L-97,207L-70,215L-44,219L-20,219L0,216L0,238L0,249L0,249L-25,247L-51,243L-76,236L-100,227L-123,215L-145,201L-165,185L-184,166L-200,146L-214,124L-226,101L-235,77L-242,52L-246,26L-248,0L-246,-25L-242,-51L-235,-76L-226,-100L-214,-123L-200,-145L-184,-165L-165,-184L-145,-200L-123,-214L-100,-226L-76,-235L-51,-242L-25,-246L0,-248L26,-246L52,-242L77,-235L101,-226L124,-214L146,-200L166,-184L185,-165L201,-145L215,-123L227,-100L236,-76L243,-51L247,-25L249,0L247,26L243,52L236,77L227,101L215,124L201,146L185,166L166,185L146,201L124,215L101,227L77,236L52,243L26,247Z');
test.end();
});