From 04952f01e9cf04364124c0a0a43ab808425d1108 Mon Sep 17 00:00:00 2001
From: Nicolas Vuaille <nicolas.vuaille@kitware.com>
Date: Tue, 28 Jan 2025 11:25:44 +0100
Subject: [PATCH] Restore vtkGeometryFilter behavior for degenerated cells

`Initialize` is expected to put lowest point id first.
This was not the case with a face that have duplicated point.

This is a regression starting from commit 4a46c5dd (MR !10025)

Try with the degenerated tri `1 0 0`.
As `0` is not strictly lower than the second `0`,
the algo keeps `1` (first id of the list) as the lowest.
Using `<=` correct this behavior.

Without this change, vtkGeometryFilter misses some external faces.
See #19600 for more discussion.
---
 Filters/Geometry/vtkGeometryFilter.cxx | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Filters/Geometry/vtkGeometryFilter.cxx b/Filters/Geometry/vtkGeometryFilter.cxx
index 678369e1cf6..42f39fd86d8 100644
--- a/Filters/Geometry/vtkGeometryFilter.cxx
+++ b/Filters/Geometry/vtkGeometryFilter.cxx
@@ -411,13 +411,13 @@ public:
   typename std::enable_if<(Size == 3), void>::type Initialize(const vtkIdType* pointIds)
   {
     // Reorder to get smallest id in first.
-    if (pointIds[1] < pointIds[0] && pointIds[1] < pointIds[2])
+    if (pointIds[1] <= pointIds[0] && pointIds[1] <= pointIds[2])
     {
       this->PointIds[0] = static_cast<TInputIdType>(pointIds[1]);
       this->PointIds[1] = static_cast<TInputIdType>(pointIds[2]);
       this->PointIds[2] = static_cast<TInputIdType>(pointIds[0]);
     }
-    else if (pointIds[2] < pointIds[0] && pointIds[2] < pointIds[1])
+    else if (pointIds[2] <= pointIds[0] && pointIds[2] <= pointIds[1])
     {
       this->PointIds[0] = static_cast<TInputIdType>(pointIds[2]);
       this->PointIds[1] = static_cast<TInputIdType>(pointIds[0]);
@@ -435,21 +435,21 @@ public:
   typename std::enable_if<(Size == 4), void>::type Initialize(const vtkIdType* pointIds)
   {
     // Reorder to get smallest id in first.
-    if (pointIds[1] < pointIds[0] && pointIds[1] < pointIds[2] && pointIds[1] < pointIds[3])
+    if (pointIds[1] <= pointIds[0] && pointIds[1] <= pointIds[2] && pointIds[1] <= pointIds[3])
     {
       this->PointIds[0] = static_cast<TInputIdType>(pointIds[1]);
       this->PointIds[1] = static_cast<TInputIdType>(pointIds[2]);
       this->PointIds[2] = static_cast<TInputIdType>(pointIds[3]);
       this->PointIds[3] = static_cast<TInputIdType>(pointIds[0]);
     }
-    else if (pointIds[2] < pointIds[0] && pointIds[2] < pointIds[1] && pointIds[2] < pointIds[3])
+    else if (pointIds[2] <= pointIds[0] && pointIds[2] <= pointIds[1] && pointIds[2] <= pointIds[3])
     {
       this->PointIds[0] = static_cast<TInputIdType>(pointIds[2]);
       this->PointIds[1] = static_cast<TInputIdType>(pointIds[3]);
       this->PointIds[2] = static_cast<TInputIdType>(pointIds[0]);
       this->PointIds[3] = static_cast<TInputIdType>(pointIds[1]);
     }
-    else if (pointIds[3] < pointIds[0] && pointIds[3] < pointIds[1] && pointIds[3] < pointIds[2])
+    else if (pointIds[3] <= pointIds[0] && pointIds[3] <= pointIds[1] && pointIds[3] <= pointIds[2])
     {
       this->PointIds[0] = static_cast<TInputIdType>(pointIds[3]);
       this->PointIds[1] = static_cast<TInputIdType>(pointIds[0]);
-- 
GitLab