0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Extrema / Extrema_Curve2dTool.cxx
1 // Created on: 1995-07-18
2 // Created by: Modelistation
3 // Copyright (c) 1995-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 <Extrema_Curve2dTool.hxx>
18 #include <Adaptor2d_Curve2d.hxx>
19 #include <TColStd_HArray1OfReal.hxx>
20 #include <Precision.hxx>
21 #include <GCPnts_TangentialDeflection.hxx>
22
23 //=======================================================================
24 //function : DeflCurvIntervals
25 //purpose  : 
26 //=======================================================================
27 Handle(TColStd_HArray1OfReal) 
28   Extrema_Curve2dTool::DeflCurvIntervals(const Adaptor2d_Curve2d& C)
29 {
30   const Standard_Real epsd = 1.e-3;
31   const Standard_Real maxdefl = 1.e3;
32   const Standard_Real mindefl = 1.e-3;
33   Handle(TColStd_HArray1OfReal) Intervals;
34   Standard_Integer nbpnts = 23, i;
35   Standard_Real L = 0.;
36   Standard_Real tf = C.FirstParameter(), tl = C.LastParameter();
37   gp_Pnt2d aP = C.Value(tf);
38   for (i = 2; i <= nbpnts; ++i)
39   {
40     Standard_Real t = (tf * (nbpnts - i) + (i - 1) * tl) / (nbpnts - 1);
41     gp_Pnt2d aP1 = C.Value(t);
42     L += aP.Distance(aP1);
43   }
44   //
45   Standard_Real dLdt = L / (tl - tf);
46   if (L <= Precision::Confusion() || dLdt < epsd || (tl - tf) > 10000.)
47   {
48     nbpnts = 2;
49     Intervals = new TColStd_HArray1OfReal(1, nbpnts);
50     Intervals->SetValue(1, tf);
51     Intervals->SetValue(nbpnts, tl);
52     return Intervals;
53   }
54   //
55   Standard_Real aDefl = Max(0.01 * L / (2. * M_PI), mindefl);
56   if (aDefl > maxdefl)
57   {
58     nbpnts = 2;
59     Intervals = new TColStd_HArray1OfReal(1, nbpnts);
60     Intervals->SetValue(1, tf);
61     Intervals->SetValue(nbpnts, tl);
62     return Intervals;
63   }
64   Standard_Real aMinLen = Max(.00001*L, Precision::Confusion());
65   Standard_Real aTol = Max(0.00001*(tl - tf), Precision::PConfusion());
66   GCPnts_TangentialDeflection aPntGen(C, M_PI / 6, aDefl, 2, aTol, aMinLen);
67   nbpnts = aPntGen.NbPoints();
68   Intervals = new TColStd_HArray1OfReal(1, nbpnts);
69   for (i = 1; i <= nbpnts; ++i)
70   {
71     Intervals->SetValue(i, aPntGen.Parameter(i));
72   }
73   return Intervals;
74 }