From 2a863903f32404edad4c2e6e255941f530f162c6 Mon Sep 17 00:00:00 2001 From: Samuel GOUGEON Date: Tue, 27 Oct 2020 01:16:21 +0100 Subject: [PATCH] * Bug 16573 fixed: mfile2sci: sci_axis is now reliable http://bugzilla.scilab.org/16573 test_run m2sci AXIS enable_lt Requires merging https://codereview.scilab.org/21614 (uses "Colon" defined in m2sci()). Change-Id: I423387a6c92bafdc42e7108b0920586d77073fc0 --- scilab/CHANGES.md | 1 + scilab/modules/m2sci/macros/sci_files/sci_axis.sci | 221 ++++++++++++-------- .../m2sci/tests/unit_tests/conversion/AXIS.dia.ref | 82 +++----- .../m2sci/tests/unit_tests/mfilesnoexec/AXIS.m | 10 +- 4 files changed, 177 insertions(+), 137 deletions(-) diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index fe7944d..afbe737 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -410,6 +410,7 @@ Bug Fixes * [#16565](https://bugzilla.scilab.org/16565): `edit(user_defined_function)` corrupted the original code. * [#16567](https://bugzilla.scilab.org/16567): `mfile2sci` did not support Matlab block-comments %{ ..%}. * [#16571](https://bugzilla.scilab.org/16571): `mfile2sci` had several issues when converting the NOT ~ operator: 1) `~(1-1)` was converted into `~1-1` instead of `~(1-1)` 2) ~ applied to an integer expression yielded an error from `convert2double` 3) `~i` was converted into `~%i` instead of `~abs(%i)`. +* [#16573](https://bugzilla.scilab.org/16573): `mfile2sci`: Some `axis` conversions were wrong or not reliable. * [#16586](https://bugzilla.scilab.org/16586): `mfile2sci`: The `prettyprintoutput` flag badly managed appended comments. * [#16596](https://bugzilla.scilab.org/16596): Concatenating encoded integers with sparse numeric data was not possible. * [#16608](https://bugzilla.scilab.org/16608): `union` did not support input boolean, sparse boolean, nor sparse numerical matrices. The result of `union(complexA, complexB)` was wrongly conjugate. diff --git a/scilab/modules/m2sci/macros/sci_files/sci_axis.sci b/scilab/modules/m2sci/macros/sci_files/sci_axis.sci index f1f1052..c3071f5 100644 --- a/scilab/modules/m2sci/macros/sci_files/sci_axis.sci +++ b/scilab/modules/m2sci/macros/sci_files/sci_axis.sci @@ -1,7 +1,7 @@ // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab // Copyright (C) 2002-2004 - INRIA - Vincent COUVERT -// // Copyright (C) 2012 - 2016 - Scilab Enterprises +// Copyright (C) 2020 - Samuel GOUGEON // // This file is hereby licensed under the terms of the GNU GPL v2.0, // pursuant to article 5.3.4 of the CeCILL v.2.1. @@ -10,120 +10,167 @@ // For more information, see the COPYING file which you should have received // along with this program. -function tree=sci_axis(tree) +function tree = sci_axis(tree) // M2SCI function // Conversion function for Matlab axis() // Input: tree = Matlab funcall tree // Ouput: tree = Scilab equivalent for tree - // Insert %v0=gca() - a=Funcall("gca",1,list(),list()) - - if rhs>0 then - for krhs=1:rhs - if tree.rhs(krhs).vtype==Double then - - // axis([xmin xmax ymin ymax]) - // axis([xmin xmax ymin ymax zmin zmax]) - if or(tree.rhs(krhs).dims(2)==[4,6]) then - mat=Funcall("matrix",1,list(tree.rhs(krhs),Cste(2),Cste(-1)),list()) - tree=Funcall("set",1,Rhs_tlist(a,"data_bounds",mat),tree.lhs) - - // axis([xmin xmax ymin ymax zmin zmax cmin cmax]) - elseif tree.rhs(krhs).dims(2)==8 then - no_equiv(expression2code(tree)) - - // Unknown column number for tree.rhs(krhs) - else - tree.name="mtlb_axis" - end - elseif tree.rhs(krhs).vtype==String then + ax = Funcall("gca",1,list(),list()) - // Option is a character string - if typeof(tree.rhs(krhs))=="cste" then + i = 1 + if rhs > 0 then + if tree.rhs(1).vtype==Handle // The first argin is the target + ax = tree.rhs(1) + if typeof(ax) <> "variable" + ax = gettempvar() + m2sci_insert(Equal(list(ax), tree.rhs(1))) + end + i = 2 + end + end + if rhs==(i-1) then + // v = axis + tree = Funcall("get",1,Rhs_tlist(ax,"data_bounds"),tree.lhs) + tree.lhs(1).dims = list(2,Unknown) + tree.lhs(1).type = Type(Double,Real) + return + end - // axis auto - if tree.rhs(krhs).value=="auto" then - tree=Funcall("set",1,Rhs_tlist(a,"auto_scale","on"),tree.lhs) + keepInputSyntax = %f + for krhs = i:rhs + if tree.rhs(krhs).vtype==Double then - // axis manual - elseif tree.rhs(krhs).value=="manual" then - tree=Funcall("set",1,Rhs_tlist(a,"auto_scale","off"),tree.lhs) + // axis([xmin xmax ymin ymax]) + // axis([xmin xmax ymin ymax zmin zmax]) + if or(tree.rhs(krhs).dims(2)==[4,6]) then + mat = Funcall("matrix",1,list(tree.rhs(krhs),Cste(2),Cste(-1)),list()) + LHS = Operation("ins", list(ax,Cste("data_bounds")), list()) + m2sci_insert(Equal(list(LHS), tree.rhs(krhs))) - // axis tight - elseif tree.rhs(krhs).value=="tight" then - tree=Funcall("set",1,Rhs_tlist(a,"tight_limits","on"),tree.lhs) + // axis([xmin xmax ymin ymax zmin zmax cmin cmax]) + elseif tree.rhs(krhs).dims(2)==8 then + no_equiv(expression2code(tree)) + keepInputSyntax = %t - // axis fill - elseif tree.rhs(krhs).value=="fill" then - no_equiv(expression2code(tree)) + // Unknown column number for tree.rhs(krhs) + else + tree.name = "mtlb_axis" + keepInputSyntax = %t + end + elseif tree.rhs(krhs).vtype==String then - // axis ij - elseif tree.rhs(krhs).value=="ij" then - mat=Operation("cc",list(Cste(180),Cste(270)),list()) - tree=Funcall("set",1,Rhs_tlist(a,"rotation_angles",mat),tree.lhs) + // Option is a character string + if typeof(tree.rhs(krhs))=="cste" then - // axis xy - elseif tree.rhs(krhs).value=="xy" then - mat=Operation("cc",list(Cste(0),Cste(270)),list()) - tree=Funcall("set",1,Rhs_tlist(a,"rotation_angles",mat),tree.lhs) + // axis auto + if tree.rhs(krhs).value=="auto" then + LHS = Operation("ins", list(ax,Cste("auto_scale")), list()) + m2sci_insert(Equal(list(LHS), Cste("on"))) - // axis equal - elseif tree.rhs(krhs).value=="equal" then - tree=Funcall("set",1,Rhs_tlist(a,"isoview","on"),tree.lhs) + // axis manual + elseif tree.rhs(krhs).value=="manual" then + LHS = Operation("ins", list(ax,Cste("auto_scale")), list()) + m2sci_insert(Equal(list(LHS), Cste("off"))) - // axis image - elseif tree.rhs(krhs).value=="image" then - no_equiv(expression2code(tree)) + // axis tight + elseif tree.rhs(krhs).value=="tight" then + LHS = Operation("ins", list(ax,Cste("tight_limits")), list()) + m2sci_insert(Equal(list(LHS), Cste("on"))) - // axis square - elseif tree.rhs(krhs).value=="square" then - set_infos(gettext("cube_scaling only used in 3d mode."),2); - tree=Funcall("set",1,Rhs_tlist(a,"cube_scaling","on"),tree.lhs) + // axis fill + elseif tree.rhs(krhs).value=="fill" then + no_equiv(expression2code(tree)) + keepInputSyntax = %t - // axis vis3d - elseif tree.rhs(krhs).value=="vis3d" then - tree=Funcall("set",1,Rhs_tlist(a,"view","3d"),tree.lhs) + // axis ij + elseif tree.rhs(krhs).value=="ij" then + axis_ij_xy(ax, Cste("on")) // sets .axes_reverse(2)="on" - // axis normal - elseif tree.rhs(krhs).value=="normal" then - no_equiv(expression2code(tree)) + // axis xy + elseif tree.rhs(krhs).value=="xy" then + axis_ij_xy(ax, Cste("off")) // sets .axes_reverse(2)="off" - // axis on - elseif tree.rhs(krhs).value=="on" then - tree=Funcall("set",1,Rhs_tlist(a,"axes_visible","on"),tree.lhs) + // axis equal + elseif tree.rhs(krhs).value=="equal" then + LHS = Operation("ins", list(ax,Cste("isoview")), list()) + m2sci_insert(Equal(list(LHS), Cste("on"))) - // axis off - elseif tree.rhs(krhs).value=="off" then - tree=Funcall("set",1,Rhs_tlist(a,"axes_visible","off"),tree.lhs) + // axis image + elseif tree.rhs(krhs).value=="image" then + no_equiv(expression2code(tree)) + keepInputSyntax = %t - // [mode,visibility,direction] = axis('state') - elseif tree.rhs(krhs).value=="state" then - tree.name="mtlb_axis" + // axis square + elseif tree.rhs(krhs).value=="square" then + set_infos(gettext("cube_scaling only used in 3d mode."),2); + LHS = Operation("ins", list(ax,Cste("cube_scaling")), list()) + m2sci_insert(Equal(list(LHS), Cste("on"))) - // Unknown character string - else - tree.name="mtlb_axis" - end + // axis vis3d + elseif tree.rhs(krhs).value=="vis3d" then + LHS = Operation("ins", list(ax,Cste("view")), list()) + m2sci_insert(Equal(list(LHS), Cste("3d"))) - // Option is a variable + // axis normal + elseif tree.rhs(krhs).value=="normal" then + no_equiv(expression2code(tree)) + keepInputSyntax = %t + + // axis on + elseif tree.rhs(krhs).value=="on" then + LHS = Operation("ins", list(ax,Cste("axes_visible")), list()) + m2sci_insert(Equal(list(LHS), Cste("on"))) + + // axis off + elseif tree.rhs(krhs).value=="off" then + LHS = Operation("ins", list(ax,Cste("axes_visible")), list()) + m2sci_insert(Equal(list(LHS), Cste("off"))) + + // [mode,visibility,direction] = axis('state') + elseif tree.rhs(krhs).value=="state" then + tree.name = "mtlb_axis" + keepInputSyntax = %t + // Unknown character string else - tree.name="mtlb_axis" + tree.name = "mtlb_axis" + keepInputSyntax = %t end - // axis(axes_handles,...) - elseif tree.rhs(krhs).vtype==Handle then - no_equiv(expression2code(tree)) - - // Unknown type for tree.rhs(krhs) + // Option is a variable else - tree.name="mtlb_axis" + tree.name = "mtlb_axis" + keepInputSyntax = %t end + + // axis(axes_handles,...) + elseif tree.rhs(krhs).vtype==Handle then + no_equiv(expression2code(tree)) + keepInputSyntax = %t + + // Unknown type for tree.rhs(krhs) + else + tree.name = "mtlb_axis" + keepInputSyntax = %t end - // v = axis + end + if ~keepInputSyntax then + tree = list() + end +endfunction + +function axis_ij_xy(ax, value) + if typeof(ax) <> "variable" | is_a_scalar(ax) // gca() + LHS = Operation("ins", list(ax,Cste("axes_reverse")), list()) + LHS = Operation("ins", list(LHS,Cste(2)), list()) + m2sci_insert(Equal(list(LHS), value)) else - tree=Funcall("set",1,Rhs_tlist(a,"data_bounds"),tree.lhs) - tree.lhs(1).dims=list(2,Unknown) - tree.lhs(1).type=Type(Double,Real) + // handles(:) : (because .axes_reverse is a row) + LHS = Operation("ins", list(ax,Colon), list()) + // handles(:).axes_reverse : + LHS = Operation("ins", list(LHS,Cste("axes_reverse")), list()) + // handles(:).axes_reverse(:,2) : + LHS = Operation("ins", list(LHS,Colon,Cste(2)), list()) + m2sci_insert(Equal(list(LHS), value)) end endfunction diff --git a/scilab/modules/m2sci/tests/unit_tests/conversion/AXIS.dia.ref b/scilab/modules/m2sci/tests/unit_tests/conversion/AXIS.dia.ref index 3134377..ba0b7a9 100644 --- a/scilab/modules/m2sci/tests/unit_tests/conversion/AXIS.dia.ref +++ b/scilab/modules/m2sci/tests/unit_tests/conversion/AXIS.dia.ref @@ -23,40 +23,23 @@ mprintf("%s\n", m2sciTestConversionNoExe("AXIS")); Syntax modification: Done Macro to tree conversion... Conversion of M-tree... - !! L.11: No Scilab equivalent for: axis([xmin,xmax,ymin,ymax,zmin,zmax,cmin,cmax]) - L.12: Unknown variable axis is a M-file. - L.14: Unknown variable axis is a M-file. - L.15: Unknown variable axis is a M-file. - L.16: Unknown variable axis is a M-file. - L.17: Unknown variable axis is a M-file. - !! L.17: No Scilab equivalent for: axis("fill") - L.19: Unknown variable axis is a M-file. - L.20: Unknown variable axis is a M-file. - L.22: Unknown variable axis is a M-file. - L.23: Unknown variable axis is a M-file. - !! L.23: No Scilab equivalent for: axis("image") - L.24: Unknown variable axis is a M-file. - !! L.24: cube_scaling only used in 3d mode. - L.25: Unknown variable axis is a M-file. - L.26: Unknown variable axis is a M-file. - !! L.26: No Scilab equivalent for: axis("normal") - L.28: Unknown variable axis is a M-file. - L.29: Unknown variable axis is a M-file. - L.34: Unknown variable axis is a M-file. - !! L.34: No Scilab equivalent for: axis([h1,h2],"auto") - L.35: Unknown variable axis is a M-file. - L.37: Unknown variable axis is a M-file. + !! L.12: No Scilab equivalent for: axis([xmin,xmax,ymin,ymax,zmin,zmax,cmin,cmax]) + L.13: Unknown variable axis is a M-file. + !! L.18: No Scilab equivalent for: axis("fill") + !! L.24: No Scilab equivalent for: axis("image") + !! L.25: cube_scaling only used in 3d mode. + !! L.27: No Scilab equivalent for: axis("normal") + !! L.42: cube_scaling only used in 3d mode. Conversion of M-tree: Done TESTING M2SCI: creating varslist file... Macro to tree conversion: Done Translation may be wrong (see the //!! comments). ****** End of mfile2sci() session ****** - // Test file for function axis() // Copyright INRIA // Matlab version: 6.5.1.199709 (R13) Service Pack 1 // V.C. - +// Copyright 2020 - Samuel GOUGEON xmin = 1; ymin = 1; zmin = 1; @@ -65,31 +48,34 @@ xmax = 10; ymax = 10; zmax = 10; cmax = 10; - -set(gca(),"data_bounds",matrix([xmin,xmax,ymin,ymax],2,-1)) -set(gca(),"data_bounds",matrix([xmin,xmax,ymin,ymax,zmin,zmax],2,-1)) +gca().data_bounds = [xmin,xmax,ymin,ymax]; +gca().data_bounds = [xmin,xmax,ymin,ymax,zmin,zmax]; axis([xmin,xmax,ymin,ymax,zmin,zmax,cmin,cmax]) -v = set(gca(),"data_bounds") - -set(gca(),"auto_scale","on") -set(gca(),"auto_scale","off") -set(gca(),"tight_limits","on") +v = get(gca(),"data_bounds"); +gca().auto_scale = "on"; +gca().auto_scale = "off"; +gca().tight_limits = "on"; axis("fill") - -set(gca(),"rotation_angles",[180;270]) -set(gca(),"rotation_angles",[0;270]) - -set(gca(),"isoview","on") +gca().axes_reverse(2) = "on"; +gca().axes_reverse(2) = "off"; +gca().isoview = "on"; axis("image") -set(gca(),"cube_scaling","on") -set(gca(),"view","3d") +gca().cube_scaling = "on"; +gca().view = "3d"; axis("normal") - -set(gca(),"axes_visible","off") -set(gca(),"axes_visible","on") - - -set(gca(),"auto_scale","on") +gca().axes_visible = "off"; +gca().axes_visible = "on"; +h1.isoview = "on"; +h1.axes_reverse(2) = "on"; +h1.axes_reverse(2) = "off"; +%v0 = [h1,h2]; +%v0.auto_scale = "on"; +%v0 = [h1,h2]; +%v0(:).axes_reverse(:,2) = "on"; +%v0(:).axes_reverse(:,2) = "off"; [mode,visibility,direction] = mtlb_axis("state") - -set(gca(),"axes_visible","on") +gca().auto_scale = "on"; +gca().cube_scaling = "on"; +gca().tight_limits = "on"; +h2.auto_scale = "off"; +h2.data_bounds = [xmin,xmax,ymin,ymax]; diff --git a/scilab/modules/m2sci/tests/unit_tests/mfilesnoexec/AXIS.m b/scilab/modules/m2sci/tests/unit_tests/mfilesnoexec/AXIS.m index 4e53bb6..9f41c8b 100644 --- a/scilab/modules/m2sci/tests/unit_tests/mfilesnoexec/AXIS.m +++ b/scilab/modules/m2sci/tests/unit_tests/mfilesnoexec/AXIS.m @@ -2,6 +2,7 @@ % Copyright INRIA % Matlab version: 6.5.1.199709 (R13) Service Pack 1 % V.C. +% Copyright 2020 - Samuel GOUGEON xmin=1;ymin=1;zmin=1;cmin=1; xmax=10;ymax=10;zmax=10;cmax=10; @@ -9,7 +10,7 @@ xmax=10;ymax=10;zmax=10;cmax=10; axis([xmin xmax ymin ymax]) axis([xmin xmax ymin ymax zmin zmax]) axis([xmin xmax ymin ymax zmin zmax cmin cmax]) -v = axis +v = axis; axis auto axis manual @@ -31,7 +32,12 @@ axis on %m2scideclare h1|1 1|Handle %m2scideclare h2|1 1|Handle +axis(h1,'equal') +axis(h1,'ij') +axis(h1,'xy') axis([h1 h2],'auto') +axis([h1 h2],'ij','xy') [mode,visibility,direction] = axis('state') -axis auto manual tight \ No newline at end of file +axis auto square tight +axis(h2,'manual',[xmin xmax ymin ymax]) -- 1.7.9.5