Skip to content

Commit

Permalink
default geoCircle precision to 2 degrees (#281)
Browse files Browse the repository at this point in the history
* default geoCircle precision to 2 degrees

Results in 180 control points instead of 60 (⨉3). The error is quadratic with the precision, with the worst case (for a parallel) being at latitude 45°. Under this new setting, the maximum error is now ~484m, vs. 4.365km with precision 6°.
https://observablehq.com/@d3/geocircle-error

* document
  • Loading branch information
Fil authored Mar 12, 2024
1 parent 719819b commit dcca6b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function circleRadius(cosRadius, point) {
export default function() {
var center = constant([0, 0]),
radius = constant(90),
precision = constant(6),
precision = constant(2),
ring,
rotate,
stream = {point: point};
Expand Down
4 changes: 2 additions & 2 deletions test/circle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {assertInDelta} from "./asserts.js";
it("circle generates a Polygon", () => {
const o = geoCircle()();
assert.strictEqual(o.type, "Polygon");
assertInDelta(o.coordinates, [[[-78.69007,-90],[-90,-84],[-90,-78],[-90,-72],[-90,-66],[-90,-60],[-90,-54],[-90,-48],[-90,-42],[-90,-36],[-90,-30],[-90,-24],[-90,-18],[-90,-12],[-90,-6],[-90,0],[-90,6],[-90,12],[-90,18],[-90,24],[-90,30],[-90,36],[-90,42],[-90,48],[-90,54],[-90,60],[-90,66],[-90,72],[-90,78],[-90,84],[-89.59666,90],[90,84],[90,78],[90,72],[90,66],[90,60],[90,54],[90,48],[90,42],[90,36],[90,30],[90,24],[90,18],[90,12],[90,6],[90,0],[90,-6],[90,-12],[90,-18],[90,-24],[90,-30],[90,-36],[90,-42],[90,-48],[90,-54],[90,-60],[90,-66],[90,-72],[90,-78],[90,-84],[89.56977,-90]]], 1e-5);
assertInDelta(o.coordinates, [[[-78.69007,-90],[-90,-88],[-90,-86],[-90,-84],[-90,-82],[-90,-80],[-90,-78],[-90,-76],[-90,-74],[-90,-72],[-90,-70],[-90,-68],[-90,-66],[-90,-64],[-90,-62],[-90,-60],[-90,-58],[-90,-56],[-90,-54],[-90,-52],[-90,-50],[-90,-48],[-90,-46],[-90,-44],[-90,-42],[-90,-40],[-90,-38],[-90,-36],[-90,-34],[-90,-32],[-90,-30],[-90,-28],[-90,-26],[-90,-24],[-90,-22],[-90,-20],[-90,-18],[-90,-16],[-90,-14],[-90,-12],[-90,-10],[-90,-8],[-90,-6],[-90,-4],[-90,-2],[-90,0],[-90,2],[-90,4],[-90,6],[-90,8],[-90,10],[-90,12],[-90,14],[-90,16],[-90,18],[-90,20],[-90,22],[-90,24],[-90,26],[-90,28],[-90,30],[-90,32],[-90,34],[-90,36],[-90,38],[-90,40],[-90,42],[-90,44],[-90,46],[-90,48],[-90,50],[-90,52],[-90,54],[-90,56],[-90,58],[-90,60],[-90,62],[-90,64],[-90,66],[-90,68],[-90,70],[-90,72],[-90,74],[-90,76],[-90,78],[-90,80],[-90,82],[-90,84],[-90,86],[-90,88],[-89.900735,90],[90,88],[90,86],[90,84],[90,82],[90,80],[90,78],[90,76],[90,74],[90,72],[90,70],[90,68],[90,66],[90,64],[90,62],[90,60],[90,58],[90,56],[90,54],[90,52],[90,50],[90,48],[90,46],[90,44],[90,42],[90,40],[90,38],[90,36],[90,34],[90,32],[90,30],[90,28],[90,26],[90,24],[90,22],[90,20],[90,18],[90,16],[90,14],[90,12],[90,10],[90,8],[90,6],[90,4],[90,2],[90,0],[90,-2],[90,-4],[90,-6],[90,-8],[90,-10],[90,-12],[90,-14],[90,-16],[90,-18],[90,-20],[90,-22],[90,-24],[90,-26],[90,-28],[90,-30],[90,-32],[90,-34],[90,-36],[90,-38],[90,-40],[90,-42],[90,-44],[90,-46],[90,-48],[90,-50],[90,-52],[90,-54],[90,-56],[90,-58],[90,-60],[90,-62],[90,-64],[90,-66],[90,-68],[90,-70],[90,-72],[90,-74],[90,-76],[90,-78],[90,-80],[90,-82],[90,-84],[90,-86],[90,-88],[89.91209,-90]]], 1e-5);
});

it("circle.center([0, 90])", () => {
const o = geoCircle().center([0, 90])();
assert.strictEqual(o.type, "Polygon");
assertInDelta(o.coordinates, [range(360, -1, -6).map(function(x) { return [x >= 180 ? x - 360 : x, 0]; })], 1e-6);
assertInDelta(o.coordinates, [range(360, -1, -2).map(function(x) { return [x >= 180 ? x - 360 : x, 0]; })], 1e-6);
});

it("circle.center([45, 45])", () => {
Expand Down

0 comments on commit dcca6b2

Please sign in to comment.