Minor optimization to d3.geo.circle.

This commit is contained in:
Mike Bostock 2012-12-15 12:48:22 -08:00
Родитель 75be0ab272
Коммит 4782853182
4 изменённых файлов: 34 добавлений и 45 удалений

26
d3.js поставляемый
Просмотреть файл

@ -5671,17 +5671,13 @@
d3_geo_centroid.point = d3_geo_centroidPoint; d3_geo_centroid.point = d3_geo_centroidPoint;
} }
d3.geo.circle = function() { d3.geo.circle = function() {
var origin = [ 0, 0 ], angle, precision = 6, rotate, interpolate; var origin = [ 0, 0 ], angle, precision = 6, interpolate;
function circle() { function circle() {
var o = typeof origin === "function" ? origin.apply(this, arguments) : origin; var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(center[0] * d3_radians, center[1] * d3_radians, 0), ring = [];
rotate = d3_geo_rotation(-o[0] * d3_radians, -o[1] * d3_radians, 0);
var ring = [];
interpolate(null, null, 1, { interpolate(null, null, 1, {
point: function(λ, φ) { point: function(x, y) {
var point = rotate.invert(λ, φ); ring.push(x = rotate(x, y));
point[0] *= d3_degrees; x[0] *= d3_degrees, x[1] *= d3_degrees;
point[1] *= d3_degrees;
ring.push(point);
} }
}); });
return { return {
@ -6522,13 +6518,13 @@
x = project(x, y); x = project(x, y);
return [ x[0] * k + δx, δy - x[1] * k ]; return [ x[0] * k + δx, δy - x[1] * k ];
}), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, clip = d3_geo_clipAntimeridian, clipAngle = null; }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, clip = d3_geo_clipAntimeridian, clipAngle = null;
function projection(coordinates) { function projection(point) {
coordinates = projectRotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians); point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
return [ coordinates[0] * k + δx, δy - coordinates[1] * k ]; return [ point[0] * k + δx, δy - point[1] * k ];
} }
function invert(coordinates) { function invert(point) {
coordinates = projectRotate.invert((coordinates[0] - δx) / k, (δy - coordinates[1]) / k); point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
return [ coordinates[0] * d3_degrees, coordinates[1] * d3_degrees ]; return [ point[0] * d3_degrees, point[1] * d3_degrees ];
} }
projection.stream = function(stream) { projection.stream = function(stream) {
return d3_geo_projectionRadiansRotate(rotate, clip(projectResample(stream))); return d3_geo_projectionRadiansRotate(rotate, clip(projectResample(stream)));

2
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -2,23 +2,21 @@ d3.geo.circle = function() {
var origin = [0, 0], var origin = [0, 0],
angle, angle,
precision = 6, precision = 6,
rotate,
interpolate; interpolate;
function circle() { function circle() {
var o = typeof origin === "function" ? origin.apply(this, arguments) : origin; var center = typeof origin === "function" ? origin.apply(this, arguments) : origin,
rotate = d3_geo_rotation(-o[0] * d3_radians, -o[1] * d3_radians, 0); rotate = d3_geo_rotation(center[0] * d3_radians, center[1] * d3_radians, 0),
var ring = []; ring = [];
interpolate(null, null, 1, {point: function(λ, φ) {
var point = rotate.invert(λ, φ); interpolate(null, null, 1, {
point[0] *= d3_degrees; point: function(x, y) {
point[1] *= d3_degrees; ring.push(x = rotate(x, y));
ring.push(point); x[0] *= d3_degrees, x[1] *= d3_degrees;
}}); }
return { });
type: "Polygon",
coordinates: [ring] return {type: "Polygon", coordinates: [ring]};
};
} }
circle.origin = function(x) { circle.origin = function(x) {

Просмотреть файл

@ -11,26 +11,21 @@ function d3_geo_projectionMutator(projectAt) {
projectRotate, projectRotate,
projectResample = d3_geo_resample(function(x, y) { x = project(x, y); return [x[0] * k + δx, δy - x[1] * k]; }), projectResample = d3_geo_resample(function(x, y) { x = project(x, y); return [x[0] * k + δx, δy - x[1] * k]; }),
k = 150, // scale k = 150, // scale
x = 480, // translate x = 480, y = 250, // translate
y = 250, λ = 0, φ = 0, // center
λ = 0, // center δλ = 0, δφ = 0, δγ = 0, // rotate
φ = 0, δx, δy, // center
δλ = 0, // rotate
δφ = 0,
δγ = 0,
δx, // center
δy,
clip = d3_geo_clipAntimeridian, clip = d3_geo_clipAntimeridian,
clipAngle = null; clipAngle = null;
function projection(coordinates) { function projection(point) {
coordinates = projectRotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians); point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
return [coordinates[0] * k + δx, δy - coordinates[1] * k]; return [point[0] * k + δx, δy - point[1] * k];
} }
function invert(coordinates) { function invert(point) {
coordinates = projectRotate.invert((coordinates[0] - δx) / k, (δy - coordinates[1]) / k); point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
return [coordinates[0] * d3_degrees, coordinates[1] * d3_degrees]; return [point[0] * d3_degrees, point[1] * d3_degrees];
} }
projection.stream = function(stream) { projection.stream = function(stream) {