0024624: Lost word in license statement in source files
[occt.git] / src / BRepBlend / BRepBlend_BlendTool.cxx
1 // Created on: 1993-12-06
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1993-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 #include <BRepBlend_BlendTool.ixx>
18
19 #include <BRepClass_FaceClassifier.hxx>
20 #include <Extrema_EPCOfExtPC2d.hxx>
21 #include <Extrema_POnCurv2d.hxx>
22 #include <TopoDS_Vertex.hxx>
23 #include <TopoDS_Edge.hxx>
24 #include <BRep_Tool.hxx>
25 #include <Geom2d_Line.hxx>
26 #include <Geom2dAdaptor_Curve.hxx>
27 #include <gp_Dir2d.hxx>
28 #include <gp_Vec2d.hxx>
29 #include <Geom2dInt_GInter.hxx>
30 #include <IntRes2d_IntersectionPoint.hxx>
31 #include <BRepBlend_HCurve2dTool.hxx>
32
33
34 //=======================================================================
35 //function : Project 
36 //purpose  : Projection orthogonal d'un point sur une courbe
37 // pmn 8/10/98 : On retourne toujours une distance. (BUC60360)
38 //=======================================================================
39 Standard_Boolean BRepBlend_BlendTool::Project(const gp_Pnt2d& P,
40                                               const Handle(Adaptor3d_HSurface)&,
41                                               const Handle(Adaptor2d_HCurve2d)& C,
42                                               Standard_Real& Paramproj,
43                                               Standard_Real& Dist)
44 {
45   Paramproj =  BRepBlend_HCurve2dTool::FirstParameter(C);
46   gp_Pnt2d P2d;
47   BRepBlend_HCurve2dTool::D0(C, Paramproj, P2d);
48   Dist = P2d.Distance(P);
49
50   const Standard_Real t =  BRepBlend_HCurve2dTool::LastParameter(C);
51   BRepBlend_HCurve2dTool::D0(C, t, P2d);
52   if (P2d.Distance(P) < Dist) {
53     Paramproj = t;
54     Dist = P2d.Distance(P);
55   }
56
57   const Standard_Real epsX = 1.e-8;
58   const Standard_Integer Nbu = 20;
59   const Standard_Real Tol = 1.e-5;
60   Extrema_EPCOfExtPC2d extrema(P, C->Curve2d(), Nbu, epsX, Tol);
61   if (!extrema.IsDone())
62     return Standard_True;
63
64   const Standard_Integer Nbext = extrema.NbExt(); 
65   Standard_Real aDist2 = Dist * Dist;
66   for (Standard_Integer i=1; i<=Nbext; i++) {
67     if (extrema.SquareDistance(i) < aDist2) {
68       aDist2 = extrema.SquareDistance(i);
69       Paramproj = extrema.Point(i).Parameter();
70     }
71   }
72   Dist = sqrt (aDist2);
73
74   return Standard_True;
75 }
76
77 //=======================================================================
78 //function : Inters 
79 //purpose  : Intersection d'un segment avec une courbe
80 //=======================================================================
81 Standard_Boolean BRepBlend_BlendTool::Inters(const gp_Pnt2d& P1,
82                                              const gp_Pnt2d& P2,
83                                              const Handle(Adaptor3d_HSurface)&,
84                                              const Handle(Adaptor2d_HCurve2d)& C,
85                                              Standard_Real& Param,
86                                              Standard_Real& Dist)
87 {
88   const Standard_Real Tol = 1.e-8;
89   const gp_Vec2d v(P1,P2);
90   const Standard_Real mag = v.Magnitude();
91   if(mag < Tol) return Standard_False;
92
93   gp_Dir2d d(v);
94   Handle(Geom2d_Line) bid = new Geom2d_Line(P1,d);
95   Geom2dAdaptor_Curve seg(bid,-0.01*mag,1.01*mag);
96
97   Geom2dInt_GInter inter(seg,C->Curve2d(),Tol,Tol);
98   if (!inter.IsDone())
99     return Standard_False;
100
101   const Standard_Integer Nbint = inter.NbPoints();
102   if (Nbint == 0)
103     return Standard_False;
104
105   IntRes2d_IntersectionPoint ip = inter.Point(1);
106   Param = ip.ParamOnSecond();
107   Dist = P1.Distance(ip.Value());
108   return Standard_True;
109 }
110
111 Standard_Integer BRepBlend_BlendTool::NbSamplesV
112   (const Handle(Adaptor3d_HSurface)&,
113    const Standard_Real,
114    const Standard_Real)
115 {
116   return 10;
117 }
118
119 Standard_Integer BRepBlend_BlendTool::NbSamplesU
120   (const Handle(Adaptor3d_HSurface)&,
121    const Standard_Real,
122    const Standard_Real)
123 {
124   return 10;
125 }
126
127 void BRepBlend_BlendTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
128                                  Standard_Real& Ufirst,
129                                  Standard_Real& Ulast)
130 {
131   Ufirst = BRepBlend_HCurve2dTool::FirstParameter(A);
132   Ulast  = BRepBlend_HCurve2dTool::LastParameter(A);
133 }