9c1519c4 |
1 | // Copyright (c) 2014-2014 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #include <GCPnts_DistFunction.hxx> |
15 | #include <gp_Pnt.hxx> |
16 | |
17 | //======================================================================= |
18 | //function : MaxCurvLinDist |
19 | //purpose : |
20 | //======================================================================= |
21 | GCPnts_DistFunction::GCPnts_DistFunction(const Adaptor3d_Curve& theCurve, |
22 | const Standard_Real U1, const Standard_Real U2) |
23 | : myCurve(theCurve), |
24 | myU1(U1), myU2(U2) |
25 | { |
26 | gp_Pnt P1 = theCurve.Value(U1), P2 = theCurve.Value(U2); |
5fdf69c9 |
27 | if (P1.SquareDistance(P2) > gp::Resolution()) |
28 | { |
29 | myLin = gp_Lin(P1, P2.XYZ() - P1.XYZ()); |
30 | } |
31 | else |
32 | { |
33 | //For #28812 |
34 | theCurve.D0(U1 + .01*(U2-U1), P2); |
35 | myLin = gp_Lin(P1, P2.XYZ() - P1.XYZ()); |
36 | } |
9c1519c4 |
37 | } |
38 | // |
39 | //======================================================================= |
40 | //function : Value |
41 | //purpose : |
42 | //======================================================================= |
43 | Standard_Boolean GCPnts_DistFunction::Value (const Standard_Real X, |
44 | Standard_Real& F) |
45 | { |
46 | if (X < myU1 || X > myU2) |
47 | return Standard_False; |
48 | // |
49 | F = -myLin.SquareDistance(myCurve.Value(X)); |
50 | return Standard_True; |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : MaxCurvLinDistMV |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | GCPnts_DistFunctionMV::GCPnts_DistFunctionMV(GCPnts_DistFunction& theCurvLinDist) |
59 | : myMaxCurvLinDist(theCurvLinDist) |
60 | { |
61 | } |
62 | |
63 | //======================================================================= |
64 | //function : Value |
65 | //purpose : |
66 | //======================================================================= |
67 | Standard_Boolean GCPnts_DistFunctionMV::Value (const math_Vector& X, |
68 | Standard_Real& F) |
69 | { |
70 | Standard_Boolean Ok = myMaxCurvLinDist.Value(X(1), F); |
71 | return Ok; |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : NbVariables |
76 | //purpose : |
77 | //======================================================================= |
78 | Standard_Integer GCPnts_DistFunctionMV::NbVariables() const |
79 | { |
80 | return 1; |
81 | } |
82 | |