Bug 13033 fixed: Could not use -1 in nax argument in plot2d 56/13056/5
Calixte DENIZET [Thu, 31 Oct 2013 14:32:51 +0000 (15:32 +0100)]
Change-Id: I2034f9e3a3c5a4297d0aa052f26b690199df2040

scilab/CHANGES_5.5.X
scilab/modules/graphics/src/c/Plo2dn.c
scilab/modules/graphics/tests/nonreg_tests/bug_13033.dia.ref [new file with mode: 0644]
scilab/modules/graphics/tests/nonreg_tests/bug_13033.tst [new file with mode: 0644]
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/ruler/RulerDrawer.java

index a8e8fc3..ffaac28 100644 (file)
@@ -105,6 +105,8 @@ Scilab Bug Fixes
 
 * Bug #13032 fixed - Fixed CMATVIEW help example and created one for CMAT3D.
 
+* Bug #13033 fixed - -1 could not be used as nax argument in plot2d.
+
 * Bug #13036 fixed - Help page associated to history browser was wrong.
 
 * Bug #13042 fixed - Texts in graphics were not correctly centered.
index 9345b93..6fca16d 100644 (file)
@@ -257,104 +257,133 @@ int plot2dn(int ptype, char *logflags, double *x, double *y, int *n1, int *n2, i
             int i = 0;
             int iSize = 0;
             double dblFabs = 0;
-            double* dXGrads = (double*) malloc(aaint[1] * sizeof(double));
-            double* dYGrads = (double*) malloc(aaint[3] * sizeof(double));
             char** stringVector = NULL;
 
-            // set auto ticks to off
-            setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
-            setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
-
-            // Compute X grads
-            dXGrads[0] = drect[0];
-            if (aaint[1] > 1)
+            if (aaint[1] == -1)
             {
-                double pas = (drect[1] - drect[0]) / (aaint[1] - 1);
-                for (i = 0; i < aaint[1]; i++)
-                {
-                    dXGrads[i] = drect[0] + pas * i;
-                }
+                autoTicks = 1;
+                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
             }
-
-            setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, dXGrads, jni_double_vector, aaint[1]);
-
-            // Compute Y grads
-            dYGrads[0] = drect[2];
-            if (aaint[3] > 1)
+            else if (aaint[1] == 0)
             {
-                double pas = (drect[3] - drect[2]) / (aaint[3] - 1);
-                for (i = 0; i < aaint[3]; i++)
-                {
-                    dYGrads[i] = drect[2] + pas * i;
-                }
+                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, NULL, jni_double_vector, 0);
+                autoTicks = 0;
+                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
             }
+            else
+            {
+                double* dXGrads = (double*) MALLOC(aaint[1] * sizeof(double));
 
-            setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, dYGrads, jni_double_vector, aaint[3]);
+                // Compute X grads
+                dXGrads[0] = drect[0];
+                if (aaint[1] > 1)
+                {
+                    double pas = (drect[1] - drect[0]) / (aaint[1] - 1);
+                    for (i = 0; i < aaint[1]; i++)
+                    {
+                        dXGrads[i] = drect[0] + pas * i;
+                    }
+                }
 
-            // Create X Labels
-            stringVector = (char **) malloc(aaint[1] * sizeof(char*));
-            for (i = 0; i < aaint[1]; i++)
-            {
-                iSize = 6;
-                if (dXGrads[i] < 0)
+                autoTicks = 0;
+                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
+                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, dXGrads, jni_double_vector, aaint[1]);
+                // Create X Labels
+                stringVector = (char **) MALLOC(aaint[1] * sizeof(char*));
+                for (i = 0; i < aaint[1]; i++)
                 {
-                    iSize += 2;
+                    iSize = 6;
+                    if (dXGrads[i] < 0)
+                    {
+                        iSize += 2;
+                    }
+                    dblFabs = fabs(dXGrads[i]);
+                    if (dblFabs >= 10)
+                    {
+                        iSize = iSize + (int)floor(log10(dblFabs));
+                    }
+
+                    stringVector[i] = (char*) MALLOC(iSize * sizeof(char));
+                    sprintf(stringVector[i], "%.3f", dXGrads[i]);
+                    stringVector[i][iSize - 1] = '\0';
                 }
-                dblFabs = fabs(dXGrads[i]);
-                if (dblFabs >= 10)
+
+                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[1]);
+
+                for (i = 0; i < aaint[1]; i++)
                 {
-                    iSize = iSize + (int)floor(log10(dblFabs));
+                    FREE(stringVector[i]);
                 }
 
-                stringVector[i] = (char*) malloc(iSize * sizeof(char));
-                sprintf(stringVector[i], "%.3f", dXGrads[i]);
-                stringVector[i][iSize - 1] = '\0';
+                FREE(stringVector);
+                FREE(dXGrads);
+                stringVector = NULL;
             }
 
-            setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[1]);
-
-            for (i = 0; i < aaint[1]; i++)
+            if (aaint[3] == -1)
             {
-                free(stringVector[i]);
+                autoTicks = 1;
+                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
             }
-
-            free(stringVector);
-            stringVector = NULL;
-
-            // Create Y Labels
-            stringVector = (char**) malloc(aaint[3] * sizeof(char*));
-            for (i = 0; i < aaint[3]; i++)
+            else if (aaint[3] == 0)
             {
-                iSize = 6;
-                if (dYGrads[i] < 0)
+                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, NULL, jni_double_vector, 0);
+                autoTicks = 0;
+                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
+            }
+            else
+            {
+                double* dYGrads = (double*) MALLOC(aaint[3] * sizeof(double));
+
+                // Compute Y grads
+                dYGrads[0] = drect[2];
+                if (aaint[3] > 1)
                 {
-                    iSize += 2;
+                    double pas = (drect[3] - drect[2]) / (aaint[3] - 1);
+                    for (i = 0; i < aaint[3]; i++)
+                    {
+                        dYGrads[i] = drect[2] + pas * i;
+                    }
                 }
-                dblFabs = fabs(dYGrads[i]);
-                if (dblFabs >= 10)
+
+                autoTicks = 0;
+                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
+                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, dYGrads, jni_double_vector, aaint[3]);
+
+                // Create Y Labels
+                stringVector = (char**) MALLOC(aaint[3] * sizeof(char*));
+                for (i = 0; i < aaint[3]; i++)
                 {
-                    iSize = iSize + (int)floor(log10(dblFabs));
+                    iSize = 6;
+                    if (dYGrads[i] < 0)
+                    {
+                        iSize += 2;
+                    }
+                    dblFabs = fabs(dYGrads[i]);
+                    if (dblFabs >= 10)
+                    {
+                        iSize = iSize + (int)floor(log10(dblFabs));
+                    }
+                    stringVector[i] = (char*) MALLOC(iSize * sizeof(char));
+                    sprintf(stringVector[i], "%.3f", dYGrads[i]);
+                    stringVector[i][iSize - 1] = '\0';
                 }
-                stringVector[i] = (char*) malloc(iSize * sizeof(char));
-                sprintf(stringVector[i], "%.3f", dYGrads[i]);
-                stringVector[i][iSize - 1] = '\0';
-            }
 
-            setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[3]);
+                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[3]);
 
-            for (i = 0; i < aaint[3]; i++)
-            {
-                free(stringVector[i]);
-            }
+                for (i = 0; i < aaint[3]; i++)
+                {
+                    FREE(stringVector[i]);
+                }
 
-            free(stringVector);
-            free(dXGrads);
-            free(dYGrads);
+                FREE(stringVector);
+                FREE(dYGrads);
+                stringVector = NULL;
+            }
 
             // X and Y subticks
             setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_SUBTICKS__, aaint, jni_int, 1);
             setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_SUBTICKS__, &aaint[2], jni_int, 1);
-
         }
         else
         {
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_13033.dia.ref b/scilab/modules/graphics/tests/nonreg_tests/bug_13033.dia.ref
new file mode 100644 (file)
index 0000000..bca9470
--- /dev/null
@@ -0,0 +1,18 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Vincent COUVERT
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- TEST WITH GRAPHIC -->
+// <-- Non-regression test for bug 13033 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/13033
+//
+// <-- Short Description -->
+// -1 can be used as major number of ticks in plot2d
+clf;
+x=0:0.1:5;
+// Following line produced a critical error before this bug fix.
+plot2d(x,sin(x),nax=[2,-1,2,-1]);
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_13033.tst b/scilab/modules/graphics/tests/nonreg_tests/bug_13033.tst
new file mode 100644 (file)
index 0000000..eed556d
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Vincent COUVERT
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- TEST WITH GRAPHIC -->
+
+// <-- Non-regression test for bug 13033 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/13033
+//
+// <-- Short Description -->
+// -1 can be used as major number of ticks in plot2d
+
+clf;
+x=0:0.1:5;
+// Following line produced a critical error before this bug fix.
+plot2d(x,sin(x),nax=[2,-1,2,-1]);
\ No newline at end of file
index 33d91de..743868f 100644 (file)
@@ -279,6 +279,10 @@ public class RulerDrawer {
          * @param drawingTools {@link DrawingTools} used to perform the ruler drawing.
          */
         private synchronized void draw(DrawingTools drawingTools) {
+            if (rulerModel == null) {
+                return;
+            }
+
             BuffersManager bufferManager = drawingTools.getCanvas().getBuffersManager();
             ElementsBuffer vertices = bufferManager.createElementsBuffer();
             fillVertices(vertices, rulerModel, ticksValue, subTicksValue, canvasProjection);