Skip to content

Commit 6a44fa5

Browse files
authored
sharper translate (#1147)
1 parent 0e4cfe3 commit 6a44fa5

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/projection.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ export function Projection(
7575
// is specified, fit the projection to the frame. Otherwise, translate.
7676
if (domain) {
7777
const [[x0, y0], [x1, y1]] = geoPath(projection).bounds(domain);
78-
const kx = dx / (x1 - x0);
79-
const ky = dy / (y1 - y0);
80-
const k = Math.min(kx, ky);
78+
const k = Math.min(dx / (x1 - x0), dy / (y1 - y0));
8179
if (k > 0) {
82-
tx -= k === kx ? x0 * k : ((x0 + x1) * k - dx) / 2;
83-
ty -= k === ky ? y0 * k : ((y0 + y1) * k - dy) / 2;
80+
tx -= (k * (x0 + x1) - dx) / 2;
81+
ty -= (k * (y0 + y1) - dy) / 2;
8482
const {stream: affine} = geoTransform({
8583
point(x, y) {
8684
this.stream.point(x * k + tx, y * k + ty);

0 commit comments

Comments
 (0)