0024255: Regressions in test cases on OCCT vc9 win64 Release
[occt.git] / src / Bisector / Bisector_PolyBis.cxx
1 // Created on: 1994-01-10
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1994-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 <Bisector_PolyBis.ixx>
18 #include <Bisector_PointOnBis.hxx>
19 #include <Geom2d_Curve.hxx>
20 #include <ElCLib.hxx>
21 #include <gp.hxx>
22
23 #include <Standard_ConstructionError.hxx>
24
25 //=============================================================================
26 //function : Bisector_PolyBis
27 // purpose :
28 //=============================================================================
29 Bisector_PolyBis::Bisector_PolyBis()
30 {
31   nbPoints = 0;
32 }
33
34 //=============================================================================
35 //function : Append
36 // purpose :
37 //=============================================================================
38 void Bisector_PolyBis::Append (const Bisector_PointOnBis& P)
39 {
40   nbPoints++;
41   thePoints [nbPoints] = P;
42 }
43
44 //=============================================================================
45 //function : Length
46 // purpose :
47 //=============================================================================
48 Standard_Integer Bisector_PolyBis::Length() const
49 {
50   return nbPoints;
51 }
52
53 //=============================================================================
54 //function : IsEmpty
55 // purpose :
56 //=============================================================================
57 Standard_Boolean Bisector_PolyBis::IsEmpty() const
58 {
59   return (nbPoints == 0);
60 }
61
62 //=============================================================================
63 //function : Value
64 // purpose :
65 //=============================================================================
66 const Bisector_PointOnBis& Bisector_PolyBis::Value
67   (const Standard_Integer Index)
68 const
69 {
70   return thePoints [Index];
71 }
72
73 //=============================================================================
74 //function : First
75 // purpose :
76 //=============================================================================
77 const Bisector_PointOnBis& Bisector_PolyBis::First() const
78 {
79   return thePoints[1];
80 }
81
82 //=============================================================================
83 //function : Last
84 // purpose :
85 //=============================================================================
86 const Bisector_PointOnBis& Bisector_PolyBis::Last() const
87 {
88   return thePoints[nbPoints];
89 }
90
91 //=============================================================================
92 //function : Points
93 // purpose :
94 //=============================================================================
95 //const PointOnBis& Bisector_PolyBis::Points()
96 //{
97 //  return thePoints;
98 //}
99
100 //=============================================================================
101 //function : Interval
102 // purpose :
103 //=============================================================================
104 Standard_Integer Bisector_PolyBis::Interval (const Standard_Real U) const
105 {
106   if ( Last().ParamOnBis() - U < gp::Resolution()) {
107     return nbPoints - 1;
108   }
109   Standard_Real    dU   = (Last().ParamOnBis() - First().ParamOnBis())/(nbPoints - 1);
110   if (dU <= gp::Resolution()) return 1;
111
112   Standard_Integer IntU = Standard_Integer(Abs(U - First().ParamOnBis())/dU) ;
113   IntU++;
114
115   if (thePoints[IntU].ParamOnBis() >= U) {
116     for (Standard_Integer i = IntU; i >= 1; i--) {
117       if (thePoints[i].ParamOnBis() <= U) {
118         IntU = i;
119         break;
120       }
121     }
122   }
123   else {
124     for (Standard_Integer i = IntU; i <= nbPoints - 1; i++) {
125       if (thePoints[i].ParamOnBis() >= U) {
126         IntU = i - 1;
127         break;
128       }
129     }
130   }
131   return IntU;
132 }
133
134
135 //=======================================================================
136 //function : Transform
137 //purpose  : 
138 //=======================================================================
139
140 void Bisector_PolyBis::Transform(const gp_Trsf2d& T)
141 {
142   for (Standard_Integer i = 1; i <= nbPoints; i ++) {
143     gp_Pnt2d P = thePoints[i].Point();
144     P.Transform(T) ;
145     thePoints[i].Point(P);
146   }
147 }