From 611f24778cee1ee0c9acf29c01d40bf58ba667da Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 16 Apr 2006 03:27:30 +0000
Subject: [PATCH] generalize previous fix

---
 Geo/GeoUtils.cpp                    | 51 +++++++++++++++++------------
 benchmarks/1d/1d_discrete.geo       |  2 +-
 benchmarks/1d/1d_with_points.msh    |  4 +--
 benchmarks/1d/1d_without_points.msh |  4 +--
 4 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/Geo/GeoUtils.cpp b/Geo/GeoUtils.cpp
index 3b2fd680a7..671bd2ffe9 100644
--- a/Geo/GeoUtils.cpp
+++ b/Geo/GeoUtils.cpp
@@ -1,4 +1,4 @@
-// $Id: GeoUtils.cpp,v 1.11 2006-04-16 02:42:23 geuzaine Exp $
+// $Id: GeoUtils.cpp,v 1.12 2006-04-16 03:27:30 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -43,27 +43,36 @@ void sortEdgesInLoop(int num, List_T *edges)
     List_Read(edges, i, &j);
     if((c = FindCurve(j, THEM))){
       List_Add(temp, &c);
-      // FIXME: if the loop is composed of a single curve and if the
-      // curve is already discretized, we check if the first vertex
-      // and the last vertex are the same. If not, we assume that they
-      // should, and we add the missing end vertex. (This situation
-      // can arise due to a limitation in Read_Mesh, where we do a
-      // List_Insert() to add the vertices in discrete curves--so that
-      // we never get the last vertex for single, closed curves.)
-      if(c->Typ == MSH_SEGM_DISCRETE && nbEdges == 1 && List_Nbr(c->Vertices)){
-	Vertex *first = *(Vertex**)List_Pointer(c->Vertices, 0);
-	Vertex *last = *(Vertex**)List_Pointer(c->Vertices, List_Nbr(c->Vertices) - 1);
-	if(first != last){
-	  Msg(INFO, "Adding last vertex in closed discrete curve %d", c->Num);
-	  List_Add(c->Vertices, &first);
+      if(c->Typ == MSH_SEGM_DISCRETE){
+	// fill-in vertices in reverse discrete curves
+	if(c->Num < 0 && !List_Nbr(c->Vertices)){
+	  Curve *rc = FindCurve(-c->Num, THEM);
+	  if(rc)
+	    for(int k = List_Nbr(rc->Vertices) - 1; k >= 0; k--)
+	      List_Add(c->Vertices, List_Pointer(rc->Vertices, k));
+	}
+	// if the loop is composed of a single discrete curve we check
+	// if the first vertex and the last vertex are the same. If
+	// not, we assume that they should, and we add the missing end
+	// vertex. (This situation can arise due to a limitation in
+	// Read_Mesh, where we do a List_Insert() to add the vertices
+	// in discrete curves--so that we never get the last vertex
+	// for single, closed curves.)
+	if(nbEdges == 1 && List_Nbr(c->Vertices)){
+	  Vertex *first = *(Vertex**)List_Pointer(c->Vertices, 0);
+	  Vertex *last = *(Vertex**)List_Pointer(c->Vertices, List_Nbr(c->Vertices) - 1);
+	  if(first != last){
+	    Msg(INFO, "Adding last vertex in closed discrete curve %d", c->Num);
+	    List_Add(c->Vertices, &first);
+	  }
+	}
+	// setting end points for discrete curves
+	if(!c->beg && !c->end && List_Nbr(c->Vertices)){
+	  Vertex *first = *(Vertex**)List_Pointer(c->Vertices, 0);
+	  Vertex *last = *(Vertex**)List_Pointer(c->Vertices, List_Nbr(c->Vertices) - 1);
+	  c->beg = FindPoint(first->Num, THEM);
+	  c->end = FindPoint(last->Num, THEM);
 	}
-      }
-      // setting end points for discrete curves
-      if(c->Typ == MSH_SEGM_DISCRETE && !c->beg && !c->end && List_Nbr(c->Vertices)){
-	Vertex *first = *(Vertex**)List_Pointer(c->Vertices, 0);
-	Vertex *last = *(Vertex**)List_Pointer(c->Vertices, List_Nbr(c->Vertices) - 1);
-	c->beg = FindPoint(first->Num, THEM);
-	c->end = FindPoint(last->Num, THEM);
       }
     }
     else
diff --git a/benchmarks/1d/1d_discrete.geo b/benchmarks/1d/1d_discrete.geo
index bfd4f859b4..2a91348e3d 100644
--- a/benchmarks/1d/1d_discrete.geo
+++ b/benchmarks/1d/1d_discrete.geo
@@ -16,5 +16,5 @@ Line(1)={1,2};
 Line(2)={2,3};
 Line(3)={3,4};
 
-Line Loop(1) = {1,2,3,4};
+Line Loop(1) = {1,2,3,-4};
 Plane Surface(1) = {1};
diff --git a/benchmarks/1d/1d_with_points.msh b/benchmarks/1d/1d_with_points.msh
index 4c46d793eb..3cd9d55183 100644
--- a/benchmarks/1d/1d_with_points.msh
+++ b/benchmarks/1d/1d_with_points.msh
@@ -8,6 +8,6 @@ $ELM
 4
 1 15 1 1 1 1
 4 15 4 4 1 4
-10 1 4 4 2 4 5
-11 1 4 4 2 5 1
+10 1 4 4 2 1 5
+11 1 4 4 2 5 4
 $ENDELM
diff --git a/benchmarks/1d/1d_without_points.msh b/benchmarks/1d/1d_without_points.msh
index ae51b9ef8d..d2e1ab67d0 100644
--- a/benchmarks/1d/1d_without_points.msh
+++ b/benchmarks/1d/1d_without_points.msh
@@ -6,6 +6,6 @@ $NOD
 $ENDNOD
 $ELM
 2
-10 1 4 4 2 4 5
-11 1 4 4 2 5 1
+10 1 4 4 2 1 5
+11 1 4 4 2 5 4
 $ENDELM
-- 
GitLab