double dy1 = curY-oldY;
double dx2 = curX-newX;
double dy2 = curY-newY;
- double maxRadius = 0.5 * Math.min(Math.sqrt(dx1*dx1 + dy1*dy1), Math.sqrt(dx2*dx2 + dy2*dy2));
+ double r1 = Math.sqrt(dx1*dx1 + dy1*dy1);
+ double r2 = Math.sqrt(dx2*dx2 + dy2*dy2);
+ double maxRadius = 0.5 * Math.min(r1, r2);
double radius = Math.min(rounding, maxRadius);
- newPath.lineTo(curX + radius*Math.signum(oldX-curX), curY + radius*Math.signum(oldY-curY));
+ double dx1Normalized = r1 > 0 ? dx1 / r1 : 0;
+ double dy1Normalized = r1 > 0 ? dy1 / r1 : 0;
+ double dx2Normalized = r2 > 0 ? dx2 / r2 : 0;
+ double dy2Normalized = r2 > 0 ? dy2 / r2 : 0;
+ newPath.lineTo(curX - radius*dx1Normalized, curY - radius*dy1Normalized);
newPath.curveTo(curX, curY,
curX, curY,
- curX + radius*Math.signum(newX-curX), curY + radius*Math.signum(newY-curY));
-
- //newPath.lineTo(curX + round*Math.signum(oldX-curX), curY + round*Math.signum(oldY-curY));
- //newPath.lineTo(curX + round*Math.signum(newX-curX), curY + round*Math.signum(newY-curY));
- //newPath.lineTo(curX, curY);
+ curX - radius*dx2Normalized, curY - radius*dy2Normalized);
}
else
++state;