Integration of OCCT 6.5.0 from SVN
[occt.git] / src / AdvApprox / AdvApprox_PrefAndRec.cxx
... / ...
CommitLineData
1// File: AdvApprox_PrefAndRec.cxx
2// Created: Thu Nov 14 13:29:18 1996
3// Author: Philippe MANGIN
4// <pmn@sgi29>
5
6
7#include <AdvApprox_PrefAndRec.ixx>
8
9#include <Precision.hxx>
10#include <Standard_DomainError.hxx>
11
12
13AdvApprox_PrefAndRec::AdvApprox_PrefAndRec(const TColStd_Array1OfReal& RecCut,
14 const TColStd_Array1OfReal& PrefCut,
15 const Standard_Real Weight):
16 myRecCutting(1, RecCut.Length()),
17 myPrefCutting(1, PrefCut.Length()),
18 myWeight(Weight)
19{
20 myRecCutting = RecCut;
21 myPrefCutting = PrefCut;
22 if (myWeight <= 1) { Standard_DomainError::Raise("PrefAndRec : Weight is too small");}
23}
24
25Standard_Boolean AdvApprox_PrefAndRec::Value(const Standard_Real a,
26 const Standard_Real b,
27 Standard_Real& cuttingvalue) const
28{
29// longueur minimum d'un intervalle parametrique : 10*PConfusion()
30 Standard_Real lgmin = 10 * Precision::PConfusion();
31 Standard_Integer i;
32 Standard_Real cut, mil=(a+b)/2, dist;
33
34 cut = mil;
35
36// Recheche d'une decoupe preferentiel
37 dist = Abs( (a*myWeight+b)/(1+myWeight) - mil ) ;
38 for ( i=1; i<=myPrefCutting.Length(); i++) {
39 if ( dist > Abs(mil-myPrefCutting.Value(i))) {
40 cut = myPrefCutting.Value(i);
41 dist = Abs(mil-cut);
42 }
43 }
44
45// Recheche d'une decoupe recommende
46 dist = Abs((a-b)/2);
47 for ( i=1; i<=myRecCutting.Length(); i++) {
48 if ((dist-lgmin) > Abs(mil-myRecCutting.Value(i))) {
49 cut = myRecCutting.Value(i);
50 dist = Abs(mil-cut);
51 }
52 }
53
54// Resultat
55 cuttingvalue = cut;
56 return (Abs(cut-a)>=lgmin && Abs(b-cut)>=lgmin);
57}