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_DistFunction2d.hxx> |
15 | #include <gp_Pnt2d.hxx> |
16 | |
17 | |
18 | //======================================================================= |
19 | //function : GCPnts_DistFunction2d |
20 | //purpose : |
21 | //======================================================================= |
22 | GCPnts_DistFunction2d::GCPnts_DistFunction2d(const Adaptor2d_Curve2d& theCurve, |
23 | const Standard_Real U1, const Standard_Real U2) |
24 | : myCurve(theCurve), |
25 | myU1(U1), myU2(U2) |
26 | { |
27 | gp_Pnt2d P2d1 = theCurve.Value(U1), P2d2 = theCurve.Value(U2); |
5fdf69c9 |
28 | if (P2d1.SquareDistance(P2d2) > gp::Resolution()) |
29 | { |
30 | myLin = gp_Lin2d(P2d1, P2d2.XY() - P2d1.XY()); |
31 | } |
32 | else |
33 | { |
34 | //For #28812 |
35 | theCurve.D0(U1 + .01*(U2 - U1), P2d2); |
36 | myLin = gp_Lin2d(P2d1, P2d2.XY() - P2d1.XY()); |
37 | } |
38 | |
9c1519c4 |
39 | } |
40 | |
41 | //======================================================================= |
42 | //function : Value |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | Standard_Boolean GCPnts_DistFunction2d::Value (const Standard_Real X, |
47 | Standard_Real& F) |
48 | { |
49 | if (X < myU1 || X > myU2) |
50 | return Standard_False; |
51 | // |
52 | gp_Pnt2d aP2d = myCurve.Value(X); |
53 | F = -myLin.SquareDistance(aP2d); |
54 | return Standard_True; |
55 | } |
56 | // |
57 | //======================================================================= |
58 | //function : GCPnts_DistFunction2dMV |
59 | //purpose : |
60 | //======================================================================= |
61 | GCPnts_DistFunction2dMV::GCPnts_DistFunction2dMV(GCPnts_DistFunction2d& theCurvLinDist) |
62 | : myMaxCurvLinDist(theCurvLinDist) |
63 | { |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : Value |
68 | //purpose : |
69 | //======================================================================= |
70 | Standard_Boolean GCPnts_DistFunction2dMV::Value (const math_Vector& X, |
71 | Standard_Real& F) |
72 | { |
73 | Standard_Boolean Ok = myMaxCurvLinDist.Value(X(1), F); |
74 | return Ok; |
75 | } |
76 | |
77 | |
78 | //======================================================================= |
79 | //function : NbVariables |
80 | //purpose : |
81 | //======================================================================= |
82 | Standard_Integer GCPnts_DistFunction2dMV::NbVariables() const |
83 | { |
84 | return 1; |
85 | } |
86 | |