0023024: Update headers of OCCT files
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <BRepBlend_BlendTool.ixx>
23
24#include <BRepClass_FaceClassifier.hxx>
25#include <Extrema_EPCOfExtPC2d.hxx>
26#include <Extrema_POnCurv2d.hxx>
27#include <TopoDS_Vertex.hxx>
28#include <TopoDS_Edge.hxx>
29#include <BRep_Tool.hxx>
30#include <Geom2d_Line.hxx>
31#include <Geom2dAdaptor_Curve.hxx>
32#include <gp_Dir2d.hxx>
33#include <gp_Vec2d.hxx>
34#include <Geom2dInt_GInter.hxx>
35#include <IntRes2d_IntersectionPoint.hxx>
36#include <BRepBlend_HCurve2dTool.hxx>
37
38
39//=======================================================================
40//function : Project
41//purpose : Projection orthogonal d'un point sur une courbe
42// pmn 8/10/98 : On retourne toujours une distance. (BUC60360)
43//=======================================================================
44Standard_Boolean BRepBlend_BlendTool::Project(const gp_Pnt2d& P,
45 const Handle(Adaptor3d_HSurface)&,
46 const Handle(Adaptor2d_HCurve2d)& C,
47 Standard_Real& Paramproj,
48 Standard_Real& Dist)
49{
50 Paramproj = BRepBlend_HCurve2dTool::FirstParameter(C);
51 gp_Pnt2d P2d;
52 BRepBlend_HCurve2dTool::D0(C, Paramproj, P2d);
53 Dist = P2d.Distance(P);
54
55 const Standard_Real t = BRepBlend_HCurve2dTool::LastParameter(C);
56 BRepBlend_HCurve2dTool::D0(C, t, P2d);
57 if (P2d.Distance(P) < Dist) {
58 Paramproj = t;
59 Dist = P2d.Distance(P);
60 }
61
62 const Standard_Real epsX = 1.e-8;
63 const Standard_Integer Nbu = 20;
64 const Standard_Real Tol = 1.e-5;
65 Extrema_EPCOfExtPC2d extrema(P, C->Curve2d(), Nbu, epsX, Tol);
66 if (!extrema.IsDone())
67 return Standard_True;
68
69 const Standard_Integer Nbext = extrema.NbExt();
70 Standard_Real aDist2 = Dist * Dist;
71 for (Standard_Integer i=1; i<=Nbext; i++) {
72 if (extrema.SquareDistance(i) < aDist2) {
73 aDist2 = extrema.SquareDistance(i);
74 Paramproj = extrema.Point(i).Parameter();
75 }
76 }
77 Dist = sqrt (aDist2);
78
79 return Standard_True;
80}
81
82//=======================================================================
83//function : Inters
84//purpose : Intersection d'un segment avec une courbe
85//=======================================================================
86Standard_Boolean BRepBlend_BlendTool::Inters(const gp_Pnt2d& P1,
87 const gp_Pnt2d& P2,
88 const Handle(Adaptor3d_HSurface)&,
89 const Handle(Adaptor2d_HCurve2d)& C,
90 Standard_Real& Param,
91 Standard_Real& Dist)
92{
93 const Standard_Real Tol = 1.e-8;
94 const gp_Vec2d v(P1,P2);
95 const Standard_Real mag = v.Magnitude();
96 if(mag < Tol) return Standard_False;
97
98 gp_Dir2d d(v);
99 Handle(Geom2d_Line) bid = new Geom2d_Line(P1,d);
100 Geom2dAdaptor_Curve seg(bid,-0.01*mag,1.01*mag);
101
102 Geom2dInt_GInter inter(seg,C->Curve2d(),Tol,Tol);
103 if (!inter.IsDone())
104 return Standard_False;
105
106 const Standard_Integer Nbint = inter.NbPoints();
107 if (Nbint == 0)
108 return Standard_False;
109
110 IntRes2d_IntersectionPoint ip = inter.Point(1);
111 Param = ip.ParamOnSecond();
112 Dist = P1.Distance(ip.Value());
113 return Standard_True;
114}
115
116Standard_Integer BRepBlend_BlendTool::NbSamplesV
117 (const Handle(Adaptor3d_HSurface)& S,
118 const Standard_Real u1,
119 const Standard_Real u2)
120{
121 return 10;
122}
123
124Standard_Integer BRepBlend_BlendTool::NbSamplesU
125 (const Handle(Adaptor3d_HSurface)& S,
126 const Standard_Real u1,
127 const Standard_Real u2)
128{
129 return 10;
130}
131
132void BRepBlend_BlendTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
133 Standard_Real& Ufirst,
134 Standard_Real& Ulast)
135{
136 Ufirst = BRepBlend_HCurve2dTool::FirstParameter(A);
137 Ulast = BRepBlend_HCurve2dTool::LastParameter(A);
138}