0023604: Uninitialized variables in debug mode
[occt.git] / src / Extrema / Extrema_CurveCache.gxx
1 // Created on: 2008-12-28
2 // Created by: Roman Lygin
3 // Copyright (c) 2008-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20 //            roman.lygin@gmail.com
21
22 #include <Precision.hxx>
23
24 //=======================================================================
25 //function : Extrema_CurveCache
26 //purpose  : 
27 //=======================================================================
28
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)
35 {
36   SetCurve (theC, theUFirst, theULast, theNbSamples, theToCalculate);
37 }
38
39 //=======================================================================
40 //function : Extrema_CurveCache
41 //purpose  : 
42 //=======================================================================
43
44 Extrema_CurveCache::Extrema_CurveCache() : myC (0), myNbSamples (-1),
45     myIsArrayValid (Standard_False)
46 {
47 }
48
49 //=======================================================================
50 //function : SetCurve
51 //purpose  : 
52 //=======================================================================
53
54 void Extrema_CurveCache::SetCurve (const Curve& theC,
55                                    const Standard_Integer theNbSamples,
56                                    const Standard_Boolean theToCalculate)
57 {
58   myC = (Standard_Address)&theC;
59   myNbSamples = theNbSamples;
60   myIsArrayValid = Standard_False;
61   myPntArray.Nullify();
62   if (theToCalculate) {
63     CalculatePoints();
64   }
65 }
66
67 //=======================================================================
68 //function : SetCurve
69 //purpose  : 
70 //=======================================================================
71
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)
77 {
78   SetCurve (theC, theNbSamples, Standard_False); //no calculation
79   SetRange (theUFirst, theULast, theToCalculate);
80 }
81
82 //=======================================================================
83 //function : SetRange
84 //purpose  : 
85 //=======================================================================
86
87 void Extrema_CurveCache::SetRange (const Standard_Real theUFirst,
88                                    const Standard_Real theULast,
89                                    const Standard_Boolean theToCalculate)
90 {
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;
95   }
96   myTrimLast = myLast = theULast;
97   if (Precision::IsInfinite(myTrimLast)){
98     myTrimLast = 1.0e+10;
99   }
100
101   myIsArrayValid = Standard_False;
102   myPntArray.Nullify();
103   if (theToCalculate) {
104     CalculatePoints();
105   }
106 }
107
108 //=======================================================================
109 //function : CalculatePoints
110 //purpose  : 
111 //=======================================================================
112
113 void Extrema_CurveCache::CalculatePoints()
114 {
115   if (myIsArrayValid) return; //no need to recalculate if nothing has changed
116   const Curve& aCurve = *((Curve*)myC);
117
118   // compute myNbSamples point along the [myTrimFirst, myTrimLast] range
119
120   Standard_Real aDelta = myTrimLast - myTrimFirst;
121   Standard_Real aPar0 = aDelta / myNbSamples / 100.;
122   aDelta = (aDelta - aPar0) / (myNbSamples - 1);
123   aPar0 = myTrimFirst + (aPar0/2.);
124
125   //Cache points
126
127   myPntArray = new ArrayOfPnt (1, myNbSamples);
128
129   Standard_Integer i;
130   Standard_Real aPar;
131   for (i = 1, aPar = aPar0; i <= myNbSamples; i++, aPar += aDelta) {
132     myPntArray->SetValue (i, aCurve.Value (aPar));
133   }
134
135   myIsArrayValid = Standard_True; //cache is available now
136 }