From a6c58f89e0f2aeadf370a1b037d6ccabac29fe39 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 24 Nov 2010 15:09:18 +0000 Subject: [PATCH] avoid division by zero --- src/VTKViewer/VTKViewer_ArcBuilder.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/VTKViewer/VTKViewer_ArcBuilder.cxx b/src/VTKViewer/VTKViewer_ArcBuilder.cxx index c453a1589..6879c1e29 100644 --- a/src/VTKViewer/VTKViewer_ArcBuilder.cxx +++ b/src/VTKViewer/VTKViewer_ArcBuilder.cxx @@ -24,6 +24,7 @@ #include "VTKViewer_ArcBuilder.h" #include +#include //VTK includes #include @@ -425,19 +426,23 @@ vtkUnstructuredGrid* VTKViewer_ArcBuilder::BuildArc(std::vector& theScal theScalarValues.clear(); - double K1; - double K2; - K1 = (y2 - y1)/(x2 - x1); - K2 = (y3 - y2)/(x3 - x2); + double K1 = 0; + double K2 = 0; + bool okK1 = false, okK2 = false; + if ( fabs(x2 - x1) > DBL_MIN ) + K1 = (y2 - y1)/(x2 - x1), okK1 = true; + if ( fabs(x3 - x2) > DBL_MIN ) + K2 = (y3 - y2)/(x3 - x2), okK2 = true; + #ifdef _MY_DEBUG_ std::cout<<"K1 : "<< K1 < infinity + if( !okK2 ) //K2 --> infinity xCenter = (K1*(y1-y3) + (x1+x2))/2.0; - else if(x2 == x1) //K1 --> infinity + else if( !okK1 ) //K1 --> infinity xCenter = (K2*(y1-y3) - (x2+x3))/(-2.0); else -- 2.39.2