plotSurface fails for non-monotonic x or y data
Background and Expected Behavior
The gnumeric manual section 10.3.15 documents plotSurface as follows:
The first subtype uses an n by 1 or 1 by n range for the x-values, a second 1 by m or m by 1
range for the y-values and an m by n range for the z values. The plotted points are constructed
from these three ranges in such a way that the z value in the ith column and jth row is combined
with the ith x value and the jth y value. This subtype then uses an m by n grid for the surface.
That is 100% fine as-is. Two satisfactory examples are shown in the attached .gnumeric file:
and the associated screenshot:
On the 'hump' worksheet, in the special case of monotonic increasing x, the example exhibits the desired, expected, conventional, documented behavior, namely the top half of a hoop.
Similarly, in the special case of monotonic decreasing x, the example exhibits the desired, expected, conventional, documented behavior, namely the bottom half of a hoop.
Turning now to the 'hoop' worksheet, the plot shows a complete hoop. This is plotted by carrying out the documented behavior cited above, in the most simple, straightforward, direct way possible.
The x-data is known as a function of column number (i) ... and trivially as a function of (i,j).
The y-data is known as a function of row number (j) ... and trivially as a function of (i,j).
The z-data is known as a function of (i) and (j) ... tabulated explicitly.
Therefore we have [x,y,z] points in a 3D space, known as a function of (i,j).
The 3D [x,y,z] points are rotated and projected onto [u,v] space, i.e. the plane of the screen. The third coordinate in screen-space is available for hidden-surface elimination, but that's not at issue here.
The question of whether x is monotonic as a function of (i) does not arise.
The question of whether y is monotonic as a function of (j) does not arise.
The question of whether z is single-valued or known or even knowable as a function of x and/or y does not arise.
It suffices to know [x,y,z] as a function of column and row (i,j).
Observed Bad Behavior
Returning now to the 'hump' worksheet:
Let's try to plot the complete hoop using plotSurface. So we set the x-step in cell B30 to 20.
Alas plotSurface fails. AFAICT it fails whenever x is non-monotonic. Apparently it replaces the user's x-data with the column number (i). This happens without warning, without explanation. Of course (i) is monotonic, but it's the wrong data. Similar words apply to non-monotonic y-data.
This behavior is undocumented, undesired, unconventional, surprising, and exceedingly confusing.
It must be emphasized that a direct, straightforward implementation of the documented behavior would not exhibit this bug.
The hidden-surface elimination issue is the same whether or not x and/or y is monotonic, so it has no bearing on this discussion.
I do not know of any workarounds that I would consider practical for handling the case of non-monotonic x and/or y.
Circumstances
This is observed with a version compiled from freshly-pulled git sources:
gnumeric version '1.12.56'
datadir := '/usr/src/gnome/install/share/gnumeric/1.12.56'
libdir := '/usr/src/gnome/gnumeric'
69a456bedda13c41c79a98a1128edd9e74d2bb62 (origin/master, origin/HEAD)
Date: Sun Sep 24 13:07:14 2023 -0400
It is also observed with an older distro version:
gnumeric version '1.12.51'
datadir := '/usr/share/gnumeric/1.12.51'
libdir := '/usr/lib/gnumeric/1.12.51'
I suspect it has been unchanged for years.