1 // File : Extrema_CurveCache.gxx
2 // Created : Sun Dec 28 2008
3 // Author : Roman Lygin
4 // roman.lygin@gmail.com
5 // Copyright: Roman Lygin, Open CASCADE 2008
7 #include <Precision.hxx>
9 //=======================================================================
10 //function : Extrema_CurveCache
12 //=======================================================================
14 Extrema_CurveCache::Extrema_CurveCache(const Curve& theC,
15 const Standard_Real theUFirst,
16 const Standard_Real theULast,
17 const Standard_Integer theNbSamples,
18 const Standard_Boolean theToCalculate) :
19 myC (0), myNbSamples (-1), myIsArrayValid (Standard_False)
21 SetCurve (theC, theUFirst, theULast, theNbSamples, theToCalculate);
24 //=======================================================================
25 //function : Extrema_CurveCache
27 //=======================================================================
29 Extrema_CurveCache::Extrema_CurveCache() : myC (0), myNbSamples (-1),
30 myIsArrayValid (Standard_False)
34 //=======================================================================
37 //=======================================================================
39 void Extrema_CurveCache::SetCurve (const Curve& theC,
40 const Standard_Integer theNbSamples,
41 const Standard_Boolean theToCalculate)
43 myC = (Standard_Address)&theC;
44 myNbSamples = theNbSamples;
45 myIsArrayValid = Standard_False;
52 //=======================================================================
55 //=======================================================================
57 void Extrema_CurveCache::SetCurve (const Curve& theC,
58 const Standard_Real theUFirst,
59 const Standard_Real theULast,
60 const Standard_Integer theNbSamples,
61 const Standard_Boolean theToCalculate)
63 SetCurve (theC, theNbSamples, Standard_False); //no calculation
64 SetRange (theUFirst, theULast, theToCalculate);
67 //=======================================================================
70 //=======================================================================
72 void Extrema_CurveCache::SetRange (const Standard_Real theUFirst,
73 const Standard_Real theULast,
74 const Standard_Boolean theToCalculate)
76 //myTrimFirst and myTrimLast are used to compute values on unlimited curves
77 myTrimFirst = myFirst = theUFirst;
78 if (Precision::IsInfinite(myTrimFirst)){
79 myTrimFirst = -1.0e+10;
81 myTrimLast = myLast = theULast;
82 if (Precision::IsInfinite(myTrimLast)){
86 myIsArrayValid = Standard_False;
93 //=======================================================================
94 //function : CalculatePoints
96 //=======================================================================
98 void Extrema_CurveCache::CalculatePoints()
100 if (myIsArrayValid) return; //no need to recalculate if nothing has changed
101 const Curve& aCurve = *((Curve*)myC);
103 // compute myNbSamples point along the [myTrimFirst, myTrimLast] range
105 Standard_Real aDelta = myTrimLast - myTrimFirst;
106 Standard_Real aPar0 = aDelta / myNbSamples / 100.;
107 aDelta = (aDelta - aPar0) / (myNbSamples - 1);
108 aPar0 = myTrimFirst + (aPar0/2.);
112 myPntArray = new ArrayOfPnt (1, myNbSamples);
116 for (i = 1, aPar = aPar0; i <= myNbSamples; i++, aPar += aDelta) {
117 myPntArray->SetValue (i, aCurve.Value (aPar));
120 myIsArrayValid = Standard_True; //cache is available now