From 27b953f980d092d326a532d76278e31a9172a418 Mon Sep 17 00:00:00 2001
From: Tavmjong Bah <tavmjong@free.fr>
Date: Tue, 26 Sep 2023 19:23:27 +0000
Subject: [PATCH 4/4] Up C++ version to C++20.

[ismael@sourcemage.org: Needed to build against poppler >= 24.06.0]
Origin: Upstream
Upstream-Status: Backport [commit 1798e9c13b786f3d077ba0132592c4d5c1d1fb9b]
Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 CMakeLists.txt                     | 4 ++--
 _clang-format                      | 2 +-
 src/ui/knot/knot-holder-entity.cpp | 2 +-
 src/ui/tools/pencil-tool.cpp       | 9 ++++++---
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5c25ebb26bf0..7ced1f6f79d5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,9 +18,9 @@ message("Binary Dir: ${CMAKE_CURRENT_BINARY_DIR}")
 # -----------------------------------------------------------------------------
 # CMake Configuration
 # -----------------------------------------------------------------------------
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
-# set(CMAKE_CXX_EXTENSIONS OFF) # enforces -std=c++17 instead of -std=gnu++17
+# set(CMAKE_CXX_EXTENSIONS OFF) # enforces -std=c++20 instead of -std=gnu++20
                                 # TODO: build currently fails with it as we actually depend on GNU compiler extensions...
 
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeScripts/Modules")
diff --git a/_clang-format b/_clang-format
index 39396fad65a6..48de4d2bd88b 100644
--- a/_clang-format
+++ b/_clang-format
@@ -103,7 +103,7 @@ SpacesInContainerLiterals: false
 SpacesInCStyleCastParentheses: false
 SpacesInParentheses: false
 SpacesInSquareBrackets: false
-Standard:        c++17
+Standard:        c++20
 StatementMacros: []
 TypenameMacros: []
 TabWidth: 4
diff --git a/src/ui/knot/knot-holder-entity.cpp b/src/ui/knot/knot-holder-entity.cpp
index 6672c0fb8b06..58e8368982a5 100644
--- a/src/ui/knot/knot-holder-entity.cpp
+++ b/src/ui/knot/knot-holder-entity.cpp
@@ -329,7 +329,7 @@ PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const &
     double scale_x = std::clamp(new_extent[X] / _cached_diagonal[X], _cached_min_scale, 1e9);
     double scale_y = std::clamp(new_extent[Y] / _cached_diagonal[Y], _cached_min_scale, 1e9);
 
-    Affine new_transform = (state & GDK_CONTROL_MASK) ? Scale(lerp(0.5, scale_x, scale_y))
+    Affine new_transform = (state & GDK_CONTROL_MASK) ? Scale((scale_x + scale_y) * 0.5)
                                                       : Scale(scale_x, scale_y);
 
     // 2. Calculate offset to keep pattern origin aligned
diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp
index 568606db8fc1..0284e4ebb051 100644
--- a/src/ui/tools/pencil-tool.cpp
+++ b/src/ui/tools/pencil-tool.cpp
@@ -17,7 +17,11 @@
  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
  */
 
-#include <numeric> // For std::accumulate
+#include "pencil-tool.h"
+
+#include <cmath>   // std::lerp
+#include <numeric> // std::accumulate
+
 #include <gdk/gdkkeysyms.h>
 #include <glibmm/i18n.h>
 
@@ -26,7 +30,6 @@
 #include <2geom/sbasis-to-bezier.h>
 #include <2geom/svg-path-parser.h>
 
-#include "pencil-tool.h"
 
 #include "context-fns.h"
 #include "desktop.h"
@@ -814,7 +817,7 @@ void PencilTool::_addFreehandPoint(Geom::Point const &p, guint /*state*/, bool l
             min = max;
         }
         double dezoomify_factor = 0.05 * 1000 / _desktop->current_zoom();
-        double const pressure_shrunk = pressure * (max - min) + min; // C++20 -> use std::lerp()
+        double const pressure_shrunk = std::lerp(min, max, pressure);
         double pressure_computed = std::abs(pressure_shrunk * dezoomify_factor);
         double pressure_computed_scaled = std::abs(pressure_computed * _desktop->getDocument()->getDocumentScale().inverse()[Geom::X]);
         if (p != this->p[this->_npoints - 1]) {
-- 
2.44.0

