From: jfa Date: Mon, 6 Mar 2006 13:18:20 +0000 (+0000) Subject: Fix bug 10020. Now NumberOfSegments hypothesis allow scale distribution with scale... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=269e202f6bbf5e021152425c799deb00edfa49be;p=modules%2Fsmesh.git Fix bug 10020. Now NumberOfSegments hypothesis allow scale distribution with scale factor = 1. --- diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx index c5eef6700..b949d872b 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx @@ -170,8 +170,8 @@ void StdMeshers_NumberOfSegments::SetScaleFactor(double scaleFactor) throw SALOME_Exception(LOCALIZED("not a scale distribution")); if (scaleFactor < PRECISION) throw SALOME_Exception(LOCALIZED("scale factor must be positive")); - if (fabs(scaleFactor - 1.0) < PRECISION) - throw SALOME_Exception(LOCALIZED("scale factor must not be equal to 1")); + //if (fabs(scaleFactor - 1.0) < PRECISION) + // throw SALOME_Exception(LOCALIZED("scale factor must not be equal to 1")); if (fabs(_scaleFactor - scaleFactor) > PRECISION) { diff --git a/src/StdMeshers/StdMeshers_Regular_1D.cxx b/src/StdMeshers/StdMeshers_Regular_1D.cxx index c890c67ee..0c6144988 100644 --- a/src/StdMeshers/StdMeshers_Regular_1D.cxx +++ b/src/StdMeshers/StdMeshers_Regular_1D.cxx @@ -354,17 +354,27 @@ bool StdMeshers_Regular_1D::computeInternalParameters(const TopoDS_Edge& theEdge { case StdMeshers_NumberOfSegments::DT_Scale: { + int NbSegm = _ivalue[ NB_SEGMENTS_IND ]; double scale = _value[ SCALE_FACTOR_IND ]; - if ( theReverse ) - scale = 1. / scale; - double alpha = pow( scale , 1.0 / (_ivalue[ NB_SEGMENTS_IND ] - 1)); - double factor = (l - f) / (1 - pow( alpha,_ivalue[ NB_SEGMENTS_IND ])); - - int i, NbPoints = 1 + _ivalue[ NB_SEGMENTS_IND ]; - for ( i = 2; i < NbPoints; i++ ) - { - double param = f + factor * (1 - pow(alpha, i - 1)); - theParams.push_back( param ); + + if (fabs(scale - 1.0) < Precision::Confusion()) { + // special case to avoid division on zero + for (int i = 1; i < NbSegm; i++) { + double param = f + (l - f) * i / NbSegm; + theParams.push_back( param ); + } + } else { + // general case of scale distribution + if ( theReverse ) + scale = 1.0 / scale; + + double alpha = pow(scale, 1.0 / (NbSegm - 1)); + double factor = (l - f) / (1.0 - pow(alpha, NbSegm)); + + for (int i = 1; i < NbSegm; i++) { + double param = f + factor * (1.0 - pow(alpha, i)); + theParams.push_back( param ); + } } return true; }