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

New commits:
commit 9391e9fb99a87e71897e29da79eba084682fdaa5
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Thu May 12 19:23:14 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Thu May 12 21:43:02 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

diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 81b75fe21cd5..5b8e326a3c19 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1743,7 +1743,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