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