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