Skip to content

Commit c5a27ec

Browse files
committed
Fix d3_geo_type; expose d3.geo.rotation.
Not sure we want to expose d3.geo.rotation, since it's functionality that's also provided by d3.geo.projection.
1 parent 13c2d0c commit c5a27ec

4 files changed

Lines changed: 62 additions & 30 deletions

File tree

d3.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5586,51 +5586,51 @@
55865586
var d3_geo_typeDefaults = {
55875587
Feature: function(o) {
55885588
var g = this.geometry(o.geometry);
5589-
return g && (o = Object.create(o), o.geometry = g);
5589+
return g && (o = Object.create(o), o.geometry = g, o);
55905590
},
55915591
FeatureCollection: function foo(o) {
55925592
var a, f, features = o.features, i = -1, n = features.length;
55935593
while (++i < n) if (f = this.Feature(features[i])) a ? a.push(f) : a = [ f ];
5594-
return a && (o = Object.create(o), o.features = a);
5594+
return a && (o = Object.create(o), o.features = a, o);
55955595
},
55965596
GeometryCollection: function(o) {
55975597
var a, g, geometries = o.geometries, i = -1, n = geometries.length;
55985598
while (++i < n) if (g = this.geometry(geometries[i])) a ? a.push(g) : a = [ g ];
5599-
return a && (o = Object.create(o), o.geometries = a);
5599+
return a && (o = Object.create(o), o.geometries = a, o);
56005600
},
56015601
LineString: function(o) {
56025602
var c = this.line(o.coordinates);
5603-
return c && (o = Object.create(o), o.coordinates = c);
5603+
return c && (o = Object.create(o), o.coordinates = c, o);
56045604
},
56055605
MultiLineString: function(o) {
56065606
var a, c, coordinates = o.coordinates, i = -1, n = coordinates.length;
56075607
while (++i < n) if (c = this.line(coordinates[i])) a ? a.push(c) : a = [ c ];
5608-
return a && (o = Object.create(o), o.coordinates = a);
5608+
return a && (o = Object.create(o), o.coordinates = a, o);
56095609
},
56105610
MultiPoint: function(o) {
56115611
var a, c, coordinates = o.coordinates, i = -1, n = coordinates.length;
56125612
while (++i < n) if (c = this.point(coordinates[i])) a ? a.push(c) : a = [ c ];
5613-
return a && (o = Object.create(o), o.coordinates = a);
5613+
return a && (o = Object.create(o), o.coordinates = a, o);
56145614
},
56155615
MultiPolygon: function(o) {
56165616
var a, c, coordinates = o.coordinates, i = -1, n = coordinates.length;
56175617
while (++i < n) if (c = this.polygon(coordinates[i])) a ? a.push(c) : a = [ c ];
5618-
return a && (o = Object.create(o), o.coordinates = a);
5618+
return a && (o = Object.create(o), o.coordinates = a, o);
56195619
},
56205620
Point: function(o) {
56215621
var c = this.point(o.coordinates);
5622-
return c && (o = Object.create(o), o.coordinates = c);
5622+
return c && (o = Object.create(o), o.coordinates = c, o);
56235623
},
56245624
Polygon: function(o) {
56255625
var c = this.polygon(o.coordinates);
5626-
return c && (o = Object.create(o), o.coordinates = c);
5626+
return c && (o = Object.create(o), o.coordinates = c, o);
56275627
},
56285628
Sphere: d3_noop,
5629-
object: function(object) {
5630-
return d3_geo_typeObjects.hasOwnProperty(object.type) ? this[object.type](object) : this.geometry(object);
5629+
object: function(o) {
5630+
return d3_geo_typeObjects.hasOwnProperty(o.type) ? this[o.type](o) : this.geometry(o);
56315631
},
5632-
geometry: function(geometry) {
5633-
return d3_geo_typeGeometries.hasOwnProperty(geometry.type) ? this[geometry.type](geometry) : null;
5632+
geometry: function(o) {
5633+
return d3_geo_typeGeometries.hasOwnProperty(o.type) ? this[o.type](o) : null;
56345634
},
56355635
point: d3_noop,
56365636
line: function(coordinates) {
@@ -6478,6 +6478,19 @@
64786478
return reset();
64796479
};
64806480
}
6481+
d3.geo.rotation = function(δλ, δφ, δγ) {
6482+
var rotate = d3_geo_rotation(δλ * d3_radians, δφ * d3_radians, δγ * d3_radians);
6483+
var type = d3_geo_type({
6484+
point: function(coordinates) {
6485+
coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
6486+
coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees;
6487+
return coordinates;
6488+
}
6489+
});
6490+
return function(o) {
6491+
return type.object(o);
6492+
};
6493+
};
64816494
function d3_geo_rotation(δλ, δφ, δγ) {
64826495
return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
64836496
}

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/rotation.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
d3.geo.rotation = function(δλ, δφ, δγ) {
2+
var rotate = d3_geo_rotation(δλ * d3_radians, δφ * d3_radians, δγ * d3_radians);
3+
4+
var type = d3_geo_type({
5+
point: function(coordinates) {
6+
coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
7+
coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees;
8+
return coordinates;
9+
}
10+
});
11+
12+
return function(o) {
13+
return type.object(o);
14+
};
15+
};
16+
117
// Note: |δλ| and |δφ| must be < 2π
218
function d3_geo_rotation(δλ, δφ, δγ) {
319
return δλ ? (δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ))

src/geo/type.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TODO optimized path when no object creation is desired?
2+
// TODO return bound object function, rather than a map of types?
3+
14
function d3_geo_type(types) {
25
for (var type in d3_geo_typeDefaults) {
36
if (!(type in types)) {
@@ -11,65 +14,65 @@ var d3_geo_typeDefaults = {
1114

1215
Feature: function(o) {
1316
var g = this.geometry(o.geometry);
14-
return g && (o = Object.create(o), o.geometry = g);
17+
return g && (o = Object.create(o), o.geometry = g, o);
1518
},
1619

1720
FeatureCollection: function foo(o) {
1821
var a, f, features = o.features, i = -1, n = features.length;
1922
while (++i < n) if (f = this.Feature(features[i])) a ? a.push(f) : a = [f];
20-
return a && (o = Object.create(o), o.features = a);
23+
return a && (o = Object.create(o), o.features = a, o);
2124
},
2225

2326
GeometryCollection: function(o) {
2427
var a, g, geometries = o.geometries, i = -1, n = geometries.length;
2528
while (++i < n) if (g = this.geometry(geometries[i])) a ? a.push(g) : a = [g];
26-
return a && (o = Object.create(o), o.geometries = a);
29+
return a && (o = Object.create(o), o.geometries = a, o);
2730
},
2831

2932
LineString: function(o) {
3033
var c = this.line(o.coordinates);
31-
return c && (o = Object.create(o), o.coordinates = c);
34+
return c && (o = Object.create(o), o.coordinates = c, o);
3235
},
3336

3437
MultiLineString: function(o) {
3538
var a, c, coordinates = o.coordinates, i = -1, n = coordinates.length;
3639
while (++i < n) if (c = this.line(coordinates[i])) a ? a.push(c) : a = [c];
37-
return a && (o = Object.create(o), o.coordinates = a);
40+
return a && (o = Object.create(o), o.coordinates = a, o);
3841
},
3942

4043
MultiPoint: function(o) {
4144
var a, c, coordinates = o.coordinates, i = -1, n = coordinates.length;
4245
while (++i < n) if (c = this.point(coordinates[i])) a ? a.push(c) : a = [c];
43-
return a && (o = Object.create(o), o.coordinates = a);
46+
return a && (o = Object.create(o), o.coordinates = a, o);
4447
},
4548

4649
MultiPolygon: function(o) {
4750
var a, c, coordinates = o.coordinates, i = -1, n = coordinates.length;
4851
while (++i < n) if (c = this.polygon(coordinates[i])) a ? a.push(c) : a = [c];
49-
return a && (o = Object.create(o), o.coordinates = a);
52+
return a && (o = Object.create(o), o.coordinates = a, o);
5053
},
5154

5255
Point: function(o) {
5356
var c = this.point(o.coordinates);
54-
return c && (o = Object.create(o), o.coordinates = c);
57+
return c && (o = Object.create(o), o.coordinates = c, o);
5558
},
5659

5760
Polygon: function(o) {
5861
var c = this.polygon(o.coordinates);
59-
return c && (o = Object.create(o), o.coordinates = c);
62+
return c && (o = Object.create(o), o.coordinates = c, o);
6063
},
6164

6265
Sphere: d3_noop,
6366

64-
object: function(object) {
65-
return d3_geo_typeObjects.hasOwnProperty(object.type)
66-
? this[object.type](object)
67-
: this.geometry(object);
67+
object: function(o) {
68+
return d3_geo_typeObjects.hasOwnProperty(o.type)
69+
? this[o.type](o)
70+
: this.geometry(o);
6871
},
6972

70-
geometry: function(geometry) {
71-
return d3_geo_typeGeometries.hasOwnProperty(geometry.type)
72-
? this[geometry.type](geometry)
73+
geometry: function(o) {
74+
return d3_geo_typeGeometries.hasOwnProperty(o.type)
75+
? this[o.type](o)
7376
: null;
7477
},
7578

0 commit comments

Comments
 (0)