Skip to content

Commit e5ebc4b

Browse files
committed
clamp small deltax and deltay to avoid slopes to blow
1 parent 23476d9 commit e5ebc4b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/plots/polar/polar.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ proto.updateMainDrag = function(fullLayout, polarLayout) {
654654

655655
var xy0 = ra2xy(r, va0);
656656
var xy1 = ra2xy(r, va1);
657-
var x = (xy0[0] + xy1[0]) / 2;
658-
var y = (xy0[1] + xy1[1]) / 2;
657+
var x = clampTiny((xy0[0] + xy1[0]) / 2);
658+
var y = clampTiny((xy0[1] + xy1[1]) / 2);
659659
var innerPts, outerPts;
660660

661661
if(x && y) {
@@ -665,10 +665,20 @@ proto.updateMainDrag = function(fullLayout, polarLayout) {
665665
innerPts = findXYatLength(chl, mperp, midPts[0][0], midPts[0][1]);
666666
outerPts = findXYatLength(chl, mperp, midPts[1][0], midPts[1][1]);
667667
} else {
668-
// horizontal / vertical
669-
innerPts = [[x - chl, y - chw], [x + chl, y - chw]];
670-
outerPts = [[x - chl, y + chw], [x + chl, y + chw]];
668+
var dx, dy;
669+
if(y) {
670+
// horizontal handles
671+
dx = chl;
672+
dy = chw;
673+
} else {
674+
// vertical handles
675+
dx = chw;
676+
dy = chl;
677+
}
678+
innerPts = [[x - dx, y - dy], [x + dx, y - dy]];
679+
outerPts = [[x - dx, y + dy], [x + dx, y + dy]];
671680
}
681+
672682
return 'M' + innerPts.join('L') +
673683
'L' + outerPts.reverse().join('L') + 'Z';
674684
}
@@ -1314,8 +1324,8 @@ function findIntersectionXY(v0, v1, a, xpyp) {
13141324

13151325
var xp = xpyp[0];
13161326
var yp = xpyp[1];
1317-
var dsin = Math.sin(v1) - Math.sin(v0);
1318-
var dcos = Math.cos(v1) - Math.cos(v0);
1327+
var dsin = clampTiny(Math.sin(v1) - Math.sin(v0));
1328+
var dcos = clampTiny(Math.cos(v1) - Math.cos(v0));
13191329

13201330
if(dsin && dcos) {
13211331
// given
@@ -1532,6 +1542,10 @@ function strRotate(angle) {
15321542
return 'rotate(' + angle + ')';
15331543
}
15341544

1545+
function clampTiny(v) {
1546+
return Math.abs(v) > 1e-10 ? v : 0;
1547+
}
1548+
15351549
// because Math.sign(Math.cos(Math.PI / 2)) === 1
15361550
// oh javascript ;)
15371551
function sign(v) {

0 commit comments

Comments
 (0)