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