basegfx/source/polygon/b2dpolypolygoncutter.cxx |   21 +++++----------------
 include/basegfx/point/b2dpoint.hxx              |   15 +++++++++++++++
 2 files changed, 20 insertions(+), 16 deletions(-)

New commits:
commit 41ab6a5dfa0bbc67c726ba872e9ef85fde67a394
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Fri Oct 25 08:20:19 2024 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Mon Dec 9 15:13:46 2024 +0100

    struct SN needs a strict weak ordering operator <
    
    ...so it can be used with std::sort in impSolve() (further down in
    basegfx/source/polygon/b2dpolypolygoncutter.cxx).  At least on macOS with a
    LLVM 20 trunk libc++ in hardened mode, JunitTest_sfx2_complex failed with
    
    > 
~/llvm/inst/bin/../include/c++/v1/__debug_utils/strict_weak_ordering_check.h:59:
 assertion __comp(*(__first + __a), *(__first + __b)) failed: Your comparator 
is not a valid strict-weak ordering
    
    To simplify the new implementation of struct SN operator <, add a B2DPoint
    operator <=> (but whose implementation would cause
    
    > In file included from 
/home/tdf/lode/jenkins/workspace/android_arm/basegfx/source/curve/b2dbeziertools.cxx:21:
    > In file included from 
/home/tdf/lode/jenkins/workspace/android_arm/include/basegfx/curve/b2dcubicbezier.hxx:22:
    > 
/home/tdf/lode/jenkins/workspace/android_arm/include/basegfx/point/b2dpoint.hxx:129:41:
 error: invalid operands to binary expression ('tuple<const double &, const 
double &>' and 'tuple<const double &, const double &>')
    >         { return std::tie(a.mnX, a.mnY) <=> std::tie(b.mnX, b.mnY); }
    >                  ~~~~~~~~~~~~~~~~~~~~~~ ^   ~~~~~~~~~~~~~~~~~~~~~~
    
    etc. on Android with NDK 23.2, see
    <https://ci.libreoffice.org/job/gerrit_android_arm/43174/>, so work around 
that
    in the implementation for now).
    
    Change-Id: I9f46d39dc9e9024fe9ac59413c44e49642282c8b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175622
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/basegfx/source/polygon/b2dpolypolygoncutter.cxx 
b/basegfx/source/polygon/b2dpolypolygoncutter.cxx
index 1cf414c1cc56..6feeb1685bfc 100644
--- a/basegfx/source/polygon/b2dpolypolygoncutter.cxx
+++ b/basegfx/source/polygon/b2dpolypolygoncutter.cxx
@@ -17,7 +17,6 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <basegfx/numeric/ftools.hxx>
 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
 #include <basegfx/point/b2dpoint.hxx>
 #include <basegfx/vector/b2dvector.hxx>
@@ -32,6 +31,7 @@
 #include <vector>
 #include <algorithm>
 #include <numeric>
+#include <tuple>
 
 namespace basegfx
 {
@@ -72,23 +72,12 @@ namespace basegfx
         public:
             PN*                     mpPN;
 
+            // For this to be a strict weak ordering, the assumption is that 
none of the involved
+            // maPoint coordinates are NaN:
             bool operator<(const SN& rComp) const
             {
-                if(fTools::equal(mpPN->maPoint.getX(), 
rComp.mpPN->maPoint.getX()))
-                {
-                    if(fTools::equal(mpPN->maPoint.getY(), 
rComp.mpPN->maPoint.getY()))
-                    {
-                        return (mpPN->mnI < rComp.mpPN->mnI);
-                    }
-                    else
-                    {
-                        return fTools::less(mpPN->maPoint.getY(), 
rComp.mpPN->maPoint.getY());
-                    }
-                }
-                else
-                {
-                    return fTools::less(mpPN->maPoint.getX(), 
rComp.mpPN->maPoint.getX());
-                }
+                return std::tie(mpPN->maPoint, mpPN->mnI)
+                    < std::tie(rComp.mpPN->maPoint, rComp.mpPN->mnI);
             }
         };
 
diff --git a/include/basegfx/point/b2dpoint.hxx 
b/include/basegfx/point/b2dpoint.hxx
index ce16965de042..94140aa6f5e1 100644
--- a/include/basegfx/point/b2dpoint.hxx
+++ b/include/basegfx/point/b2dpoint.hxx
@@ -19,7 +19,9 @@
 
 #pragma once
 
+#include <compare>
 #include <ostream>
+#include <tuple>
 
 #include <basegfx/tuple/b2dtuple.hxx>
 #include <basegfx/point/b2ipoint.hxx>
@@ -122,6 +124,19 @@ namespace basegfx
         {
             return static_cast<const B2DPoint&>( 
::basegfx::B2DTuple::getEmptyTuple() );
         }
+
+        friend auto operator <=>(B2DPoint const & a, B2DPoint const & b)
+        {
+            // Avoid compilation failure with Android NDK 23.2, where 
std::tuple operator <=> isn't
+            // yet implemented (and where __cpp_lib_three_way_comparison 
happens to not be defined
+            // in <compare>, so discriminate on that):
+#if defined __cpp_lib_three_way_comparison
+            return std::tie(a.mnX, a.mnY) <=> std::tie(b.mnX, b.mnY);
+#else
+            auto const comp = a.mnX <=> b.mnX;
+            return comp == 0 ? a.mnY <=> b.mnY : comp;
+#endif
+        }
     };
 
     // external operators

Reply via email to