Skip to content

Commit db39176

Browse files
committed
Optimise.
1 parent 9b8792c commit db39176

5 files changed

Lines changed: 17 additions & 31 deletions

File tree

d3.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,9 +2708,9 @@ d3 = function() {
27082708
a.next = b = array[0];
27092709
b.prev = a;
27102710
}
2711-
function d3_geo_clip(pointVisible, clipLine, interpolate, polygonContains) {
2711+
function d3_geo_clip(pointVisible, clipLine, interpolate, clipPoint) {
27122712
return function(rotate, listener) {
2713-
var line = clipLine(listener);
2713+
var line = clipLine(listener), rotatedClipPoint = rotate.invert(clipPoint[0], clipPoint[1]);
27142714
var clip = {
27152715
point: point,
27162716
lineStart: lineStart,
@@ -2730,7 +2730,7 @@ d3 = function() {
27302730
segments = d3.merge(segments);
27312731
if (segments.length) {
27322732
d3_geo_clipPolygon(segments, d3_geo_clipSort, null, interpolate, listener);
2733-
} else if (polygonContains(rotate.invert, polygon)) {
2733+
} else if (d3_geo_pointInPolygon(rotatedClipPoint, polygon)) {
27342734
listener.lineStart();
27352735
interpolate(null, null, 1, listener);
27362736
listener.lineEnd();
@@ -2851,7 +2851,7 @@ d3 = function() {
28512851
}
28522852
return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
28532853
}
2854-
var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, d3_geo_clipAntimeridianPolygonContains);
2854+
var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, 0 ]);
28552855
function d3_geo_clipAntimeridianLine(listener) {
28562856
var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
28572857
return {
@@ -2918,12 +2918,9 @@ d3 = function() {
29182918
listener.point(to[0], to[1]);
29192919
}
29202920
}
2921-
function d3_geo_clipAntimeridianPolygonContains(rotate, polygon) {
2922-
return d3_geo_pointInPolygon(rotate(-π, 0), polygon);
2923-
}
29242921
function d3_geo_clipCircle(radius) {
2925-
var cr = Math.cos(radius), smallRadius = cr > 0, point = [ radius, 0 ], notHemisphere = Math.abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
2926-
return d3_geo_clip(visible, clipLine, interpolate, polygonContains);
2922+
var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = Math.abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
2923+
return d3_geo_clip(visible, clipLine, interpolate, [ radius, 0 ]);
29272924
function visible(λ, φ) {
29282925
return Math.cos(λ) * Math.cos(φ) > cr;
29292926
}
@@ -3016,9 +3013,6 @@ d3 = function() {
30163013
if (φ < -r) code |= 4; else if (φ > r) code |= 8;
30173014
return code;
30183015
}
3019-
function polygonContains(rotate, polygon) {
3020-
return d3_geo_pointInPolygon(rotate(point[0], point[1]), polygon);
3021-
}
30223016
}
30233017
var d3_geo_clipExtentMAX = 1e9;
30243018
d3.geo.clipExtent = function() {

d3.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geo/clip-antimeridian.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var d3_geo_clipAntimeridian = d3_geo_clip(
77
d3_true,
88
d3_geo_clipAntimeridianLine,
99
d3_geo_clipAntimeridianInterpolate,
10-
d3_geo_clipAntimeridianPolygonContains);
10+
[-π, 0]);
1111

1212
// Takes a line and cuts into visible segments. Return values:
1313
// 0: there were intersections or the line was empty.
@@ -93,7 +93,3 @@ function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
9393
listener.point(to[0], to[1]);
9494
}
9595
}
96-
97-
function d3_geo_clipAntimeridianPolygonContains(rotate, polygon) {
98-
return d3_geo_pointInPolygon(rotate(-π, 0), polygon);
99-
}

src/geo/clip-circle.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import "point-in-polygon";
99
function d3_geo_clipCircle(radius) {
1010
var cr = Math.cos(radius),
1111
smallRadius = cr > 0,
12-
point = [radius, 0],
1312
notHemisphere = Math.abs(cr) > ε, // TODO optimise for this common case
1413
interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
1514

16-
return d3_geo_clip(visible, clipLine, interpolate, polygonContains);
15+
return d3_geo_clip(visible, clipLine, interpolate, [radius, 0]);
1716

1817
function visible(λ, φ) {
1918
return Math.cos(λ) * Math.cos(φ) > cr;
@@ -175,8 +174,4 @@ function d3_geo_clipCircle(radius) {
175174
else if (φ > r) code |= 8; // above
176175
return code;
177176
}
178-
179-
function polygonContains(rotate, polygon) {
180-
return d3_geo_pointInPolygon(rotate(point[0], point[1]), polygon);
181-
}
182177
}

src/geo/clip.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import "../core/noop";
33
import "../math/trigonometry";
44
import "clip-polygon";
55

6-
function d3_geo_clip(pointVisible, clipLine, interpolate, polygonContains) {
6+
function d3_geo_clip(pointVisible, clipLine, interpolate, clipPoint) {
77
return function(rotate, listener) {
8-
var line = clipLine(listener);
8+
var line = clipLine(listener),
9+
rotatedClipPoint = rotate.invert(clipPoint[0], clipPoint[1]);
910

1011
var clip = {
1112
point: point,
@@ -27,7 +28,7 @@ function d3_geo_clip(pointVisible, clipLine, interpolate, polygonContains) {
2728
segments = d3.merge(segments);
2829
if (segments.length) {
2930
d3_geo_clipPolygon(segments, d3_geo_clipSort, null, interpolate, listener);
30-
} else if (polygonContains(rotate.invert, polygon)) {
31+
} else if (d3_geo_pointInPolygon(rotatedClipPoint, polygon)) {
3132
listener.lineStart();
3233
interpolate(null, null, 1, listener);
3334
listener.lineEnd();

0 commit comments

Comments
 (0)