1 // Created on: 1992-10-22
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1992-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 
18 #include <Adaptor2d_Curve2d.hxx>
19 #include <Geom2d_BezierCurve.hxx>
20 #include <Geom2d_BSplineCurve.hxx>
21 #include <Geom2dInt_Geom2dCurveTool.hxx>
22 #include <GeomAbs_CurveType.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <gp_Vec2d.hxx>
25 #include <Precision.hxx>
26 
27 //============================================================
NbSamples(const Adaptor2d_Curve2d & C,const Standard_Real U0,const Standard_Real U1)28 Standard_Integer Geom2dInt_Geom2dCurveTool::NbSamples (const Adaptor2d_Curve2d& C,
29   const Standard_Real U0,
30   const Standard_Real U1)
31 {
32   GeomAbs_CurveType typC = C.GetType();
33   Standard_Integer nbs = C.NbSamples();
34 
35   if(typC == GeomAbs_BSplineCurve)
36   {
37     Standard_Real t=C.LastParameter()-C.FirstParameter();
38     if(t > Precision::PConfusion())
39     {
40       Standard_Real t1 = U1 - U0;
41       if(t1 < 0.0) t1 = -t1;
42       nbs = C.NbKnots();
43       nbs*= C.Degree();
44       Standard_Real anb = t1 / t * nbs;
45       nbs = (Standard_Integer)anb;
46 
47       Standard_Integer aMinPntNb = Max(C.Degree() + 1, 4);
48       if(nbs < aMinPntNb)
49         nbs = aMinPntNb;
50     }
51   }
52   else if (typC == GeomAbs_Circle)
53   {
54     //Try to reach deflection = eps*R, eps = 0.01
55     const Standard_Real minR = 1.; //eps = 0.01
56     Standard_Real R = C.Circle().Radius();
57     if(R > minR)
58     {
59       Standard_Real angl = 0.283079; //2.*ACos(1. - eps);
60       Standard_Integer n = RealToInt(Abs(U1 - U0) / angl);
61       nbs = Max(n, nbs);
62     }
63   }
64 
65   if(nbs>300)
66     nbs = 300;
67   return nbs;
68 
69 }
70 //============================================================
NbSamples(const Adaptor2d_Curve2d & C)71 Standard_Integer Geom2dInt_Geom2dCurveTool::NbSamples (const Adaptor2d_Curve2d& C) {
72   Standard_Integer nbs = C.NbSamples();
73   GeomAbs_CurveType typC = C.GetType();
74   if (typC == GeomAbs_Circle)
75   {
76     //Try to reach deflection = eps*R, eps = 0.01
77     const Standard_Real minR = 1.; //eps = 0.01
78     Standard_Real R = C.Circle().Radius();
79     if(R > minR)
80     {
81       Standard_Real angl = 0.283079; //2.*ACos(1. - eps);
82       Standard_Integer n = RealToInt((C.LastParameter()-C.FirstParameter()) / angl);
83       nbs = Max(n, nbs);
84     }
85   }
86 
87   return nbs;
88  }
89 
90 
91 
92 
93