sc/source/core/tool/interpr1.cxx |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

New commits:
commit 9501315fc7baa9b7b32834252375afc39379305b
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Fri May 13 01:30:20 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon May 16 10:30:23 2022 +0200

    Use interpreter stack to determine JumpMatrix context, tdf#148863 follow-up
    
    pJumpMatrix may or may not be set; actually may need some rework,
    but get this straight here.
    
    Change-Id: I0948e6aeb6637e7a5009a17f63f01d0733c0205c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134252
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134277

diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 87bc8e5fe8d6..42d6dde67df2 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1744,10 +1744,10 @@ void ScInterpreter::ScRandomImpl( const 
std::function<double( double fFirst, dou
         // In JumpMatrix context use its dimensions for the return matrix; the
         // formula cell range selected may differ, for example if the result is
         // to be transposed.
-        if (pJumpMatrix)
+        if (GetStackType(1) == svJumpMatrix)
         {
             SCSIZE nC, nR;
-            pJumpMatrix->GetDimensions( nC, nR);
+            pStack[sp-1]->GetJumpMatrix()->GetDimensions( nC, nR);
             nCols = std::max<SCCOL>(0, static_cast<SCCOL>(nC));
             nRows = std::max<SCROW>(0, static_cast<SCROW>(nR));
         }
commit c6cdfd364963ada3fc12aa35ecc8c641eff0276c
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Thu May 12 19:23:14 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon May 16 10:30:10 2022 +0200

    Resolves: tdf#148863 In JumpMatrix context use its dimensions for results
    
    Problem was, that in array mode the result matrix of random values
    was created according to the dimensions of the formula cell range
    selected/resulting, which if transposed and displayed obeys the general 
rules of
    a repeating vector if not a 2D matrix.
    
    For example, entering the array formula
    =TRANSPOSE(IF({1,1,1};RAND()))
    (with , comma array column separator) is supposed to create a row
    vector of 3 columns transposed to a column vector of 3 rows. The
    selection created for the automatically determined result is 3
    rows in one column, for which the RAND() was calculated, resulting
    in a column vector
    
    {
    1
    2
    3
    }
    
    which transposed gave a row vector { 1, 2, 3 } and displayed for
    one column such row vector is repeated as
    
    {
    { 1, 2, 3 }
    { 1, 2, 3 }
    { 1, 2, 3 }
    }
    
    of which the first column displayed is the repeating first value 1.
    
    With this change the dimensions of the JumpMatrix created by
    IF({1,1,1};...) is used to generate the RAND() matrix, resulting
    in a { 1, 2, 3 } row vector that then is transposed and displayed
    as expected.
    
    Change-Id: I267ff5d336a86372ee456fd929249e5f0444f843
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134247
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134276

diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index d40e93608d6e..87bc8e5fe8d6 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1741,7 +1741,17 @@ void ScInterpreter::ScRandomImpl( const 
std::function<double( double fFirst, dou
     {
         SCCOL nCols = 0;
         SCROW nRows = 0;
-        if (pMyFormulaCell)
+        // In JumpMatrix context use its dimensions for the return matrix; the
+        // formula cell range selected may differ, for example if the result is
+        // to be transposed.
+        if (pJumpMatrix)
+        {
+            SCSIZE nC, nR;
+            pJumpMatrix->GetDimensions( nC, nR);
+            nCols = std::max<SCCOL>(0, static_cast<SCCOL>(nC));
+            nRows = std::max<SCROW>(0, static_cast<SCROW>(nR));
+        }
+        else if (pMyFormulaCell)
             pMyFormulaCell->GetMatColsRows( nCols, nRows);
 
         if (nCols == 1 && nRows == 1)

Reply via email to