1 // Created on: 2008-12-28
2 // Created by: Roman Lygin
3 // Copyright (c) 2008-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 // roman.lygin@gmail.com
22 #include <Precision.hxx>
24 //=======================================================================
25 //function : Extrema_CurveCache
27 //=======================================================================
29 Extrema_CurveCache::Extrema_CurveCache(const Curve& theC,
30 const Standard_Real theUFirst,
31 const Standard_Real theULast,
32 const Standard_Integer theNbSamples,
33 const Standard_Boolean theToCalculate) :
34 myC (0), myNbSamples (-1), myIsArrayValid (Standard_False)
36 SetCurve (theC, theUFirst, theULast, theNbSamples, theToCalculate);
39 //=======================================================================
40 //function : Extrema_CurveCache
42 //=======================================================================
44 Extrema_CurveCache::Extrema_CurveCache() : myC (0), myNbSamples (-1),
45 myIsArrayValid (Standard_False)
49 //=======================================================================
52 //=======================================================================
54 void Extrema_CurveCache::SetCurve (const Curve& theC,
55 const Standard_Integer theNbSamples,
56 const Standard_Boolean theToCalculate)
58 myC = (Standard_Address)&theC;
59 myNbSamples = theNbSamples;
60 myIsArrayValid = Standard_False;
67 //=======================================================================
70 //=======================================================================
72 void Extrema_CurveCache::SetCurve (const Curve& theC,
73 const Standard_Real theUFirst,
74 const Standard_Real theULast,
75 const Standard_Integer theNbSamples,
76 const Standard_Boolean theToCalculate)
78 SetCurve (theC, theNbSamples, Standard_False); //no calculation
79 SetRange (theUFirst, theULast, theToCalculate);
82 //=======================================================================
85 //=======================================================================
87 void Extrema_CurveCache::SetRange (const Standard_Real theUFirst,
88 const Standard_Real theULast,
89 const Standard_Boolean theToCalculate)
91 //myTrimFirst and myTrimLast are used to compute values on unlimited curves
92 myTrimFirst = myFirst = theUFirst;
93 if (Precision::IsInfinite(myTrimFirst)){
94 myTrimFirst = -1.0e+10;
96 myTrimLast = myLast = theULast;
97 if (Precision::IsInfinite(myTrimLast)){
101 myIsArrayValid = Standard_False;
102 myPntArray.Nullify();
103 if (theToCalculate) {
108 //=======================================================================
109 //function : CalculatePoints
111 //=======================================================================
113 void Extrema_CurveCache::CalculatePoints()
115 if (myIsArrayValid) return; //no need to recalculate if nothing has changed
116 const Curve& aCurve = *((Curve*)myC);
118 // compute myNbSamples point along the [myTrimFirst, myTrimLast] range
120 Standard_Real aDelta = myTrimLast - myTrimFirst;
121 Standard_Real aPar0 = aDelta / myNbSamples / 100.;
122 aDelta = (aDelta - aPar0) / (myNbSamples - 1);
123 aPar0 = myTrimFirst + (aPar0/2.);
127 myPntArray = new ArrayOfPnt (1, myNbSamples);
131 for (i = 1, aPar = aPar0; i <= myNbSamples; i++, aPar += aDelta) {
132 myPntArray->SetValue (i, aCurve.Value (aPar));
135 myIsArrayValid = Standard_True; //cache is available now