b311480e |
1 | // Created on: 1996-11-14 |
2 | // Created by: Philippe MANGIN |
3 | // Copyright (c) 1996-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 <AdvApprox_PrefAndRec.hxx> |
7fd59977 |
19 | #include <Precision.hxx> |
20 | #include <Standard_DomainError.hxx> |
21 | |
7fd59977 |
22 | AdvApprox_PrefAndRec::AdvApprox_PrefAndRec(const TColStd_Array1OfReal& RecCut, |
23 | const TColStd_Array1OfReal& PrefCut, |
24 | const Standard_Real Weight): |
25 | myRecCutting(1, RecCut.Length()), |
26 | myPrefCutting(1, PrefCut.Length()), |
27 | myWeight(Weight) |
28 | { |
29 | myRecCutting = RecCut; |
30 | myPrefCutting = PrefCut; |
9775fa61 |
31 | if (myWeight <= 1) { throw Standard_DomainError("PrefAndRec : Weight is too small");} |
7fd59977 |
32 | } |
33 | |
34 | Standard_Boolean AdvApprox_PrefAndRec::Value(const Standard_Real a, |
35 | const Standard_Real b, |
36 | Standard_Real& cuttingvalue) const |
37 | { |
38 | // longueur minimum d'un intervalle parametrique : 10*PConfusion() |
39 | Standard_Real lgmin = 10 * Precision::PConfusion(); |
40 | Standard_Integer i; |
41 | Standard_Real cut, mil=(a+b)/2, dist; |
42 | |
43 | cut = mil; |
44 | |
45 | // Recheche d'une decoupe preferentiel |
46 | dist = Abs( (a*myWeight+b)/(1+myWeight) - mil ) ; |
47 | for ( i=1; i<=myPrefCutting.Length(); i++) { |
48 | if ( dist > Abs(mil-myPrefCutting.Value(i))) { |
49 | cut = myPrefCutting.Value(i); |
50 | dist = Abs(mil-cut); |
51 | } |
52 | } |
53 | |
54 | // Recheche d'une decoupe recommende |
55 | dist = Abs((a-b)/2); |
56 | for ( i=1; i<=myRecCutting.Length(); i++) { |
57 | if ((dist-lgmin) > Abs(mil-myRecCutting.Value(i))) { |
58 | cut = myRecCutting.Value(i); |
59 | dist = Abs(mil-cut); |
60 | } |
61 | } |
62 | |
63 | // Resultat |
64 | cuttingvalue = cut; |
65 | return (Abs(cut-a)>=lgmin && Abs(b-cut)>=lgmin); |
66 | } |