# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1550775853 -3600
#      Thu Feb 21 20:04:13 2019 +0100
# Node ID aee65d0f37c06c2d6447b2403567b3d13e0dbd67
# Parent  c97a65af7c4bac33f6fb58fdb713a823f7573836
Fix slowdown of scatter3 (bug #55751).

* graphics.cc: Don't check co-planarity if facecolor and edgecolor are none.
  Use faster driver for svd.
* __scatter__.m: Set facecolor and edgecolor of patches before any other
  properties.

diff -r c97a65af7c4b -r aee65d0f37c0 libinterp/corefcn/graphics.cc
--- a/libinterp/corefcn/graphics.cc	Thu Feb 21 15:08:27 2019 +0100
+++ b/libinterp/corefcn/graphics.cc	Thu Feb 21 20:04:13 2019 +0100
@@ -9474,7 +9474,8 @@
 
   // check coplanarity for 3D-faces with more than 3 corners
   int fcmax = idx.rows ();
-  if (fcmax > 3 && vert.columns () > 2)
+  if (fcmax > 3 && vert.columns () > 2 && 
+      ! (facecolor_is ("none") && edgecolor_is ("none")))
     {
       for (octave_idx_type jj = 0; jj < idx.columns (); jj++)
         {
@@ -9500,11 +9501,15 @@
                           fc(j,i) = vert(idx(j + i_start,jj)-1,i)
                                     - vert(idx(0,jj)-1,i);
 
+                      // FIXME: Using  svd's to check for co-planarity is slow
+                      // for faces with many vertices. Is there a better way to
+                      // check this?
+
                       // calculate rank of matrix
                       octave::math::svd<Matrix> result
                         (fc,
                          octave::math::svd<Matrix>::Type::sigma_only,
-                         octave::math::svd<Matrix>::Driver::GESVD);
+                         octave::math::svd<Matrix>::Driver::GESDD);
                       DiagMatrix sigma = result.singular_values ();
                       double tol = nc * sigma(0,0)
                                    * std::numeric_limits<double>::epsilon ();
diff -r c97a65af7c4b -r aee65d0f37c0 scripts/plot/draw/private/__scatter__.m
--- a/scripts/plot/draw/private/__scatter__.m	Thu Feb 21 15:08:27 2019 +0100
+++ b/scripts/plot/draw/private/__scatter__.m	Thu Feb 21 20:04:13 2019 +0100
@@ -201,16 +201,16 @@
     if (one_explicit_color)
       for i = 1 : numel (x)
         if (filled)
-          __go_patch__ (hg, "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
+          __go_patch__ (hg, "facecolor", "none", "edgecolor", "none",
+                        "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
                         "faces", 1, "vertices", [x(i), y(i), z(i,:)],
-                        "facecolor", "none", "edgecolor", "none",
                         "marker", marker,  "markersize", s(i),
                         "markeredgecolor", c, "markerfacecolor", c,
                         "linestyle", "none");
         else
-          __go_patch__ (hg, "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
+          __go_patch__ (hg, "facecolor", "none", "edgecolor", "none",
+                        "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
                         "faces", 1, "vertices", [x(i), y(i), z(i,:)],
-                        "facecolor", "none", "edgecolor", "none",
                         "marker", marker,  "markersize", s(i),
                         "markeredgecolor", c, "markerfacecolor", "none",
                         "linestyle", "none");
@@ -222,18 +222,18 @@
       endif
       for i = 1 : numel (x)
         if (filled)
-          __go_patch__ (hg, "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
+          __go_patch__ (hg, "facecolor", "none", "edgecolor", "none",
+                        "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
                         "faces", 1, "vertices", [x(i), y(i), z(i,:)],
-                        "facecolor", "none", "edgecolor", "none",
                         "marker", marker, "markersize", s(i),
                         "markeredgecolor", "none",
                         "markerfacecolor", "flat",
                         "cdata", c(i,:), "facevertexcdata", c(i,:),
                         "linestyle", "none");
         else
-          __go_patch__ (hg, "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
+          __go_patch__ (hg, "facecolor", "none", "edgecolor", "none",
+                        "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
                         "faces", 1, "vertices", [x(i), y(i), z(i,:)],
-                        "facecolor", "none", "edgecolor", "none",
                         "marker", marker, "markersize", s(i),
                         "markeredgecolor", "flat",
                         "markerfacecolor", "none",
@@ -330,17 +330,17 @@
                     && strcmp (toolkit, "gnuplot"));
     if (ischar (c) || ! isflat || gnuplot_hack)
       if (filled)
-        __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
+        __go_patch__ (hg, "facecolor", "none", "edgecolor", "none",
+                          "xdata", x, "ydata", y, "zdata", z,
                           "faces", 1:numel (x), "vertices", vert,
-                          "facecolor", "none", "edgecolor", "none",
                           "marker", marker,
                           "markeredgecolor", "none",
                           "markerfacecolor", c(1,:),
                           "markersize", s, "linestyle", "none");
       else
-        __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
+        __go_patch__ (hg, "facecolor", "none", "edgecolor", "none",
+                          "xdata", x, "ydata", y, "zdata", z,
                           "faces", 1:numel (x), "vertices", vert,
-                          "facecolor", "none", "edgecolor", "none",
                           "marker", marker,
                           "markeredgecolor", c(1,:),
                           "markerfacecolor", "none",
@@ -348,18 +348,18 @@
       endif
     else
       if (filled)
-        __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
+        __go_patch__ (hg, "facecolor", "none", "edgecolor", "none",
+                          "xdata", x, "ydata", y, "zdata", z,
                           "faces", 1:numel (x), "vertices", vert,
-                          "facecolor", "none", "edgecolor", "none",
                           "marker", marker, "markersize", s,
                           "markeredgecolor", "none",
                           "markerfacecolor", "flat",
                           "cdata", c, "facevertexcdata", c,
                           "linestyle", "none");
       else
-        __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
+        __go_patch__ (hg, "facecolor", "none", "edgecolor", "none",
+                          "xdata", x, "ydata", y, "zdata", z,
                           "faces", 1:numel (x), "vertices", vert,
-                          "facecolor", "none", "edgecolor", "none",
                           "marker", marker, "markersize", s,
                           "markeredgecolor", "flat",
                           "markerfacecolor", "none",
