0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / IntTools / IntTools_Curve.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <IntTools_Curve.hxx>
16 #include <Geom2d_Curve.hxx>
17 #include <Geom_BoundedCurve.hxx>
18 #include <Geom_Curve.hxx>
19 #include <GeomAdaptor_Curve.hxx>
20 #include <gp_Pnt.hxx>
21
22 //=======================================================================
23 //function : IntTools_Curve::IntTools_Curve
24 //purpose  : 
25 //=======================================================================
26 IntTools_Curve::IntTools_Curve()
27 :
28   myTolerance(0.0),
29   myTangentialTolerance(0.0)
30 {
31 }
32 //=======================================================================
33 //function : IntTools_Curve::IntTools_Curve
34 //purpose  : 
35 //=======================================================================
36 IntTools_Curve::IntTools_Curve(const Handle(Geom_Curve)& the3dCurve,
37                                const Handle(Geom2d_Curve)& the2dCurve1,
38                                const Handle(Geom2d_Curve)& the2dCurve2,
39                                const Standard_Real theTolerance,
40                                const Standard_Real theTangentialTolerance)
41 :
42   myTolerance(theTolerance),
43   myTangentialTolerance(theTangentialTolerance)
44 {
45   SetCurves(the3dCurve, the2dCurve1, the2dCurve2);
46 }
47 //=======================================================================
48 //function : HasBounds
49 //purpose  : 
50 //=======================================================================
51   Standard_Boolean IntTools_Curve::HasBounds() const 
52 {
53   Handle(Geom_BoundedCurve) aC3DBounded =
54     Handle(Geom_BoundedCurve)::DownCast(my3dCurve);
55   Standard_Boolean bIsBounded = !aC3DBounded.IsNull();
56   return bIsBounded;
57 }
58
59 //=======================================================================
60 //function : Bounds
61 //purpose  : 
62 //=======================================================================
63 Standard_Boolean IntTools_Curve::Bounds(Standard_Real& theFirst,
64                                         Standard_Real& theLast,
65                                         gp_Pnt& theFirstPnt,
66                                         gp_Pnt& theLastPnt) const
67 {
68   Standard_Boolean bIsBounded = HasBounds();
69   if (bIsBounded) {
70     theFirst = my3dCurve->FirstParameter();
71     theLast  = my3dCurve->LastParameter();
72     my3dCurve->D0(theFirst, theFirstPnt);
73     my3dCurve->D0(theLast,  theLastPnt);
74   }
75   return bIsBounded;
76 }
77
78 //=======================================================================
79 //function : D0
80 //purpose  : 
81 //=======================================================================
82 Standard_Boolean IntTools_Curve::D0(const Standard_Real& thePar,
83                                     gp_Pnt& thePnt) const
84 {
85   Standard_Boolean bInside = !(thePar < my3dCurve->FirstParameter() &&
86                                thePar > my3dCurve->LastParameter());
87   if (bInside) {
88     my3dCurve->D0(thePar, thePnt);
89   }
90   return bInside;
91 }
92
93 //=======================================================================
94 //function : Type
95 //purpose  : 
96 //=======================================================================
97 GeomAbs_CurveType IntTools_Curve::Type() const
98 {
99   GeomAdaptor_Curve aGAC(my3dCurve);
100   GeomAbs_CurveType aType = aGAC.GetType();
101   return aType;
102 }