Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix d3.geo.circle.origin. #983

Merged
merged 1 commit into from

2 participants

@jasondavies
Collaborator

3D rotations are not commutative, so we must perform an inverse rotation to move something from origin [0, 0] to [λ, φ]. Normally we are moving origin [λ, φ] to [0, 0].

@jasondavies jasondavies Fix d3.geo.circle.origin.
3D rotations are not commutative, so we must perform an inverse rotation
to move something from origin [0, 0] to [λ, φ].  Normally we are moving
origin [λ, φ] to [0, 0].
f6891ef
@mbostock mbostock merged commit f6891ef into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 29, 2012
  1. @jasondavies

    Fix d3.geo.circle.origin.

    jasondavies authored
    3D rotations are not commutative, so we must perform an inverse rotation
    to move something from origin [0, 0] to [λ, φ].  Normally we are moving
    origin [λ, φ] to [0, 0].
This page is out of date. Refresh to see the latest.
View
2  d3.js
@@ -5671,7 +5671,7 @@
d3.geo.circle = function() {
var origin = [ 0, 0 ], angle, precision = 6, interpolate;
function circle() {
- var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(center[0] * d3_radians, center[1] * d3_radians, 0), ring = [];
+ var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];
interpolate(null, null, 1, {
point: function(x, y) {
ring.push(x = rotate(x, y));
View
2  d3.min.js
1 addition, 1 deletion not shown
View
2  src/geo/circle.js
@@ -6,7 +6,7 @@ d3.geo.circle = function() {
function circle() {
var center = typeof origin === "function" ? origin.apply(this, arguments) : origin,
- rotate = d3_geo_rotation(center[0] * d3_radians, center[1] * d3_radians, 0),
+ rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert,
ring = [];
interpolate(null, null, 1, {
View
5 test/geo/circle-test.js
@@ -17,6 +17,11 @@ suite.addBatch({
var o = circle.origin([0, 90])();
assert.equal(o.type, "Polygon");
assert.inDelta(o.coordinates, [d3.range(360, -1, -6).map(function(x) { return [x >= 180 ? x - 360 : x, 0]; })], 1e-6);
+ },
+ "origin([45, 45])": function(circle) {
+ var o = circle.origin([45, 45]).angle(0)();
+ assert.equal(o.type, "Polygon");
+ assert.inDelta(o.coordinates[0][0], [45, 45], 1e-6);
}
}
});
Something went wrong with that request. Please try again.