0024428: Implementation of LGPL license
[occt.git] / src / BRepLProp / BRepLProp.cxx
1 // Created on: 1994-02-24
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1994-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
9 // under the terms of the GNU Lesser General Public 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 #include <BRepLProp.ixx>
18 #include <Precision.hxx>
19 #include <BRepLProp_CLProps.hxx>
20 #include <gp_Dir.hxx>
21 #include <gp_Vec.hxx>
22 #include <TopoDS_Edge.hxx>
23 #include <TopAbs_Orientation.hxx>
24
25 //=======================================================================
26 //function : Continuity
27 //purpose  : 
28 //=======================================================================
29
30 GeomAbs_Shape BRepLProp::Continuity(const BRepAdaptor_Curve& C1, 
31                                     const BRepAdaptor_Curve& C2, 
32                                     const Standard_Real u1, 
33                                     const Standard_Real u2, 
34                                     const Standard_Real tl, 
35                                     const Standard_Real ta)
36 {
37   GeomAbs_Shape cont = GeomAbs_C0;
38   Standard_Boolean fini = Standard_False;
39   gp_Vec d1,d2;
40   gp_Dir dir1,dir2;
41   GeomAbs_Shape cont1 = C1.Continuity(), cont2 = C2.Continuity();
42   Standard_Integer n1 = 0, n2 = 0;
43   if (cont1 >= 5) n1 = 3;
44   else if(cont1 == 4) n1 = 2;
45   else if(cont1 == 2) n1 = 1;
46   if (cont2 >= 5) n2 = 3;
47   else if(cont2 == 4) n2 = 2;
48   else if(cont2 == 2) n2 = 1;
49   BRepLProp_CLProps clp1(C1,u1,n1,tl);
50   BRepLProp_CLProps clp2(C2,u2,n2,tl);
51   if(!(clp1.Value().IsEqual(clp2.Value(),tl))) {
52     Standard_Failure::Raise("Courbes non jointives");
53   }
54   Standard_Integer min = Min(n1,n2);
55   if ( min >= 1 ) {
56     d1 = clp1.D1();
57     d2 = clp2.D1();
58     if(C1.Edge().Orientation() == TopAbs_REVERSED) d1.Reverse();
59     if(C2.Edge().Orientation() == TopAbs_REVERSED) d2.Reverse();
60     if(d1.IsEqual(d2,tl,ta)) { 
61       cont = GeomAbs_C1; 
62     }
63     else if(clp1.IsTangentDefined() && clp2.IsTangentDefined()){
64       clp1.Tangent(dir1);
65       clp2.Tangent(dir2);
66       if(C1.Edge().Orientation() == TopAbs_REVERSED) dir1.Reverse();
67       if(C2.Edge().Orientation() == TopAbs_REVERSED) dir2.Reverse();
68       if(dir1.IsEqual(dir2,ta)){ 
69         cont = GeomAbs_G1; 
70       }
71       fini = Standard_True;
72     }
73     else {fini = Standard_True; }
74   }
75   if ( min >= 2 && !fini ) {
76     d1 = clp1.D2();
77     d2 = clp2.D2();
78     if(d1.IsEqual(d2,tl,ta)){
79       cont = GeomAbs_C2;
80     }
81   }
82   const TopoDS_Edge& E1 = C1.Edge();
83   const TopoDS_Edge& E2 = C2.Edge();
84   if (E1.IsSame(E2) && C1.IsPeriodic() && cont >= GeomAbs_G1)
85     cont = GeomAbs_CN;
86   return cont;
87 }
88
89
90 //=======================================================================
91 //function : Continuity
92 //purpose  : 
93 //=======================================================================
94
95 GeomAbs_Shape BRepLProp::Continuity(const BRepAdaptor_Curve& C1, 
96                                     const BRepAdaptor_Curve& C2, 
97                                     const Standard_Real u1, 
98                                     const Standard_Real u2)
99 {
100   return Continuity(C1,C2,u1,u2,Precision::Confusion(),Precision::Angular());
101 }
102
103