0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / math / math_DirectPolynomialRoots.hxx
1 // Created on: 1991-05-13
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _math_DirectPolynomialRoots_HeaderFile
18 #define _math_DirectPolynomialRoots_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Boolean.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Real.hxx>
27 #include <Standard_OStream.hxx>
28 class Standard_RangeError;
29 class StdFail_InfiniteSolutions;
30
31
32
33 //! This class implements the calculation of all the real roots of a real
34 //! polynomial of degree <= 4 using a direct method. Once found,
35 //! the roots are polished using the Newton method.
36 class math_DirectPolynomialRoots 
37 {
38 public:
39
40   DEFINE_STANDARD_ALLOC
41
42   
43
44   //! computes all the real roots of the polynomial
45   //! Ax4 + Bx3 + Cx2 + Dx + E using a direct method.
46   Standard_EXPORT math_DirectPolynomialRoots(const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D, const Standard_Real E);
47   
48
49   //! computes all the real roots of the polynomial
50   //! Ax3 + Bx2 + Cx + D using a direct method.
51   Standard_EXPORT math_DirectPolynomialRoots(const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D);
52   
53
54   //! computes all the real roots of the polynomial
55   //! Ax2 + Bx + C using a direct method.
56   Standard_EXPORT math_DirectPolynomialRoots(const Standard_Real A, const Standard_Real B, const Standard_Real C);
57   
58
59   //! computes the real root of the polynomial Ax + B.
60   Standard_EXPORT math_DirectPolynomialRoots(const Standard_Real A, const Standard_Real B);
61   
62   //! Returns true if the computations are successful, otherwise returns false.
63     Standard_Boolean IsDone() const;
64   
65   //! Returns true if there is an infinity of roots, otherwise returns false.
66     Standard_Boolean InfiniteRoots() const;
67   
68   //! returns the number of solutions.
69   //! An exception is raised if there are an infinity of roots.
70     Standard_Integer NbSolutions() const;
71   
72   //! returns the value of the Nieme root.
73   //! An exception is raised if there are an infinity of roots.
74   //! Exception RangeError is raised if Nieme is < 1
75   //! or Nieme > NbSolutions.
76     Standard_Real Value (const Standard_Integer Nieme) const;
77   
78   //! Prints on the stream o information on the current state
79   //! of the object.
80   //! Is used to redefine the operator <<.
81   Standard_EXPORT void Dump (Standard_OStream& o) const;
82
83
84
85
86 protected:
87
88   
89   Standard_EXPORT void Solve (const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D, const Standard_Real E);
90   
91   Standard_EXPORT void Solve (const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D);
92   
93   Standard_EXPORT void Solve (const Standard_Real A, const Standard_Real B, const Standard_Real C);
94   
95   Standard_EXPORT void Solve (const Standard_Real A, const Standard_Real B);
96
97
98
99
100 private:
101
102
103
104   Standard_Boolean Done;
105   Standard_Boolean InfiniteStatus;
106   Standard_Integer NbSol;
107   Standard_Real TheRoots[4];
108
109
110 };
111
112
113 #include <math_DirectPolynomialRoots.lxx>
114
115
116
117
118
119 #endif // _math_DirectPolynomialRoots_HeaderFile