diff --git a/src/Grid/GridLineLimiter.cpp b/src/Grid/GridLineLimiter.cpp index 40fbe999..76c4166e 100644 --- a/src/Grid/GridLineLimiter.cpp +++ b/src/Grid/GridLineLimiter.cpp @@ -59,6 +59,7 @@ void GridLineLimiter::limitForXTheta (const Document &document, if (!needReduction) { if (stepX <= 0) { stepX = 0; + needReduction = true; } else { countX = 1.0 + (stopX - startX) / stepX; needReduction = (countX > modelMainWindow.maximumGridLines()); @@ -85,6 +86,7 @@ void GridLineLimiter::limitForXTheta (const Document &document, if (!needReduction) { if (stepX <= 1) { stepX = 1; + needReduction = true; } else { countX = 1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX); needReduction = (countX > modelMainWindow.maximumGridLines()); @@ -119,6 +121,7 @@ void GridLineLimiter::limitForYRadius (const Document &document, if (!needReduction) { if (stepY <= 0) { stepY = 0; + needReduction = true; } else { countY = 1.0 + (stopY - startY) / stepY; needReduction = (countY > modelMainWindow.maximumGridLines()); @@ -145,6 +148,7 @@ void GridLineLimiter::limitForYRadius (const Document &document, if (!needReduction) { if (stepY <= 1) { stepY = 1; + needReduction = true; } else { countY = 1.0 + (qLn (stopY) - qLn (startY)) / qLn (stepY); needReduction = (countY > modelMainWindow.maximumGridLines()); diff --git a/src/Test/TestGridLineLimiter.cpp b/src/Test/TestGridLineLimiter.cpp index 617a2534..ec6f989a 100644 --- a/src/Test/TestGridLineLimiter.cpp +++ b/src/Test/TestGridLineLimiter.cpp @@ -107,7 +107,7 @@ bool TestGridLineLimiter::testLinearX (double start, MainWindowModel modelMainWindow; DocumentModelGridDisplay modelGrid; Transformation transformation; - double startX, stepX; // Outputs from GridLineLimiter + double startX, stepX, stopX; // Outputs from GridLineLimiter modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR); modelGrid.setStartX (start); @@ -124,16 +124,20 @@ bool TestGridLineLimiter::testLinearX (double start, modelMainWindow, modelGrid, startX, - stepX); + stepX, + stopX); - bool success = (stepX > 0); + bool success = true; - if (success) { + if (stepX > 0) { - bool stopX = modelGrid.stopX (); int gridLineCount = 1 + (stopX - startX) / stepX; success = (gridLineCount <= 20); + } else { + + success = (startX == stopX); + } return success; @@ -153,7 +157,7 @@ bool TestGridLineLimiter::testLinearY (double start, MainWindowModel modelMainWindow; DocumentModelGridDisplay modelGrid; Transformation transformation; - double startY, stepY; // Outputs from GridLineLimiter + double startY, stepY, stopY; // Outputs from GridLineLimiter modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR); modelGrid.setStartY (start); @@ -170,16 +174,20 @@ bool TestGridLineLimiter::testLinearY (double start, modelMainWindow, modelGrid, startY, - stepY); + stepY, + stopY); - bool success = (stepY > 0); + bool success = true; - if (success) { + if (stepY > 0) { - bool stopY = modelGrid.stopY (); int gridLineCount = 1 + (stopY - startY) / stepY; success = (gridLineCount <= 20); + } else { + + success = (startY == stopY); + } return success; @@ -199,7 +207,7 @@ bool TestGridLineLimiter::testLogX (double start, MainWindowModel modelMainWindow; DocumentModelGridDisplay modelGrid; Transformation transformation; - double startX, stepX; // Outputs from GridLineLimiter + double startX, stepX, stopX; // Outputs from GridLineLimiter modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG); modelGrid.setStartX (start); @@ -216,13 +224,13 @@ bool TestGridLineLimiter::testLogX (double start, modelMainWindow, modelGrid, startX, - stepX); + stepX, + stopX); bool success = (startX > 0) && (stepX > 0); if (success) { - bool stopX = modelGrid.stopX (); int gridLineCount = 1 + (qLn (stopX) - qLn (startX)) / qLn (stepX); success = (gridLineCount <= 20); @@ -245,7 +253,7 @@ bool TestGridLineLimiter::testLogY (double start, MainWindowModel modelMainWindow; DocumentModelGridDisplay modelGrid; Transformation transformation; - double startY, stepY; // Outputs from GridLineLimiter + double startY, stepY, stopY; // Outputs from GridLineLimiter modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG); modelGrid.setStartY (start); @@ -262,13 +270,13 @@ bool TestGridLineLimiter::testLogY (double start, modelMainWindow, modelGrid, startY, - stepY); + stepY, + stopY); bool success = (startY > 0) && (stepY > 0); if (success) { - bool stopY = modelGrid.stopY (); int gridLineCount = 1 + (qLn (stopY) - qLn (startY)) / qLn (stepY); success = (gridLineCount <= 20);