From 757039f2b8e2422574958b51a17885fdb7fa72b7 Mon Sep 17 00:00:00 2001
From: cignoni <paolo.cignoni@isti.cnr.it>
Date: Fri, 6 Nov 2015 09:44:40 +0000
Subject: [PATCH] Made the midpoint refine operator order independent

---
 vcg/complex/algorithms/refine.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/vcg/complex/algorithms/refine.h b/vcg/complex/algorithms/refine.h
index cdfb3cf5..93718c7b 100644
--- a/vcg/complex/algorithms/refine.h
+++ b/vcg/complex/algorithms/refine.h
@@ -141,19 +141,23 @@ struct MidPoint : public   std::unary_function<face::Pos<typename MESH_TYPE::Fac
 
     void operator()(VertexType &nv, PosType  ep){
         assert(mp);
-        nv.P()=   (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0;
+        VertexType *V0 = ep.V() ;
+        VertexType *V1 = ep.VFlip() ;
+        if(V0 > V1) std::swap(V1,V0);
+
+        nv.P()=   (V0->P()+V1->P())/2.0;
 
         if( tri::HasPerVertexNormal(*mp))
-            nv.N()= (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N()).normalized();
+            nv.N()= (V0->N()+V1->N()).normalized();
 
         if( tri::HasPerVertexColor(*mp))
-            nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f);
+            nv.C().lerp(V0->C(),V1->C(),.5f);
 
         if( tri::HasPerVertexQuality(*mp))
-            nv.Q() = ((ep.f->V(ep.z)->Q()+ep.f->V1(ep.z)->Q())) / 2.0;
+            nv.Q() = (V0->Q()+V1->Q()) / 2.0;
 
         if( tri::HasPerVertexTexCoord(*mp))
-            nv.T().P() = ((ep.f->V(ep.z)->T().P()+ep.f->V1(ep.z)->T().P())) / 2.0;
+            nv.T().P() = (V0->T().P()+V1->T().P()) / 2.0;
         if(intFunc)
           (*intFunc)(nv,ep);
     }