b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | #include <Standard_OutOfRange.hxx> |
20 | |
21 | |
22 | void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C, |
23 | const Standard_Integer NbU, |
24 | POnC& Papp) { |
25 | |
26 | /*----------------------------------------------------------------------------- |
27 | Fonction: |
28 | Recherche, parmi un echantillon de 'NbU' points de la courbe C, du |
29 | point le plus proche du point P. |
30 | L'echantillonnage est fait a parametre constant sur l'intervalle de |
31 | definition de la courbe. |
32 | -----------------------------------------------------------------------------*/ |
33 | |
34 | if (NbU < 2) { Standard_OutOfRange::Raise(); } |
35 | |
36 | Standard_Real U = Tool1::FirstParameter(C); |
37 | Standard_Real PasU = (Tool1::LastParameter(C) - U)/ (NbU - 1); |
38 | Standard_Real Dist2Min = RealLast(), UMin=0; |
39 | Pnt PntMin; |
40 | Standard_Real Dist2; |
41 | Pnt Pt; |
42 | for ( Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) { |
43 | Pt = Tool1::Value(C, U); |
44 | Dist2 = Pt.SquareDistance(P); |
45 | if (Dist2 < Dist2Min) { |
46 | Dist2Min = Dist2; |
47 | UMin = U; |
48 | PntMin = Pt; |
49 | } |
50 | } |
51 | Papp.SetValues(UMin,PntMin); |
52 | } |
53 | |
54 | |
55 | |
56 | void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C, |
57 | const Standard_Integer NbU, |
58 | const Standard_Real Umin, |
59 | const Standard_Real Usup, |
60 | POnC& Papp) { |
61 | |
62 | /*----------------------------------------------------------------------------- |
63 | Fonction: |
64 | Recherche, parmi un echantillon de 'NbU' points de la courbe C, du |
65 | point le plus proche du point P. |
66 | L'echantillonnage est fait a parametre constant sur l'intervalle de |
67 | definition de la courbe. |
68 | -----------------------------------------------------------------------------*/ |
69 | |
70 | if (NbU < 2) { Standard_OutOfRange::Raise(); } |
71 | Standard_Real U1, U2, U11, U12; |
72 | Standard_Real Uinf = Tool1::FirstParameter(C); |
73 | Standard_Real Ulast = Tool1::LastParameter(C); |
74 | |
75 | |
76 | U1 = Min(Uinf, Ulast); |
77 | U2 = Max(Uinf, Ulast); |
78 | U11 = Min(Umin, Usup); |
79 | U12 = Max(Umin, Usup); |
80 | |
81 | if (U11 < U1 - RealEpsilon()) U11 = U1; |
82 | if (U12 > U2 + RealEpsilon()) U12 = U2; |
83 | |
84 | Standard_Real U = U11; |
85 | Standard_Real PasU = (U12 - U)/ (NbU - 1); |
86 | Standard_Real Dist2Min = RealLast(), UMin=0; |
87 | Pnt PntMin; |
88 | Standard_Real Dist2; |
89 | Pnt Pt; |
90 | for ( Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) { |
91 | Pt = Tool1::Value(C, U); |
92 | Dist2 = Pt.SquareDistance(P); |
93 | if (Dist2 < Dist2Min) { |
94 | Dist2Min = Dist2; |
95 | UMin = U; |
96 | PntMin = Pt; |
97 | } |
98 | } |
99 | Papp.SetValues(UMin, PntMin); |
100 | } |
101 | |
102 | |
103 | |