0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / GeomLib / GeomLib_Check2dBSplineCurve.cxx
CommitLineData
b311480e 1// Created on: 1997-05-28
2// Created by: Xavier BENVENISTE
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <GeomLib_Check2dBSplineCurve.ixx>
18#include <Geom_BSplineCurve.hxx>
19#include <gp_Pnt2d.hxx>
20#include <gp_Vec2d.hxx>
ec357c5c 21#include <Geom2d_BSplineCurve.hxx>
7fd59977 22//=======================================================================
23//function : GeomLib_Check2dBSplineCurve
24//purpose :
25//=======================================================================
26
27GeomLib_Check2dBSplineCurve::GeomLib_Check2dBSplineCurve(const Handle(Geom2d_BSplineCurve)& Curve,
28 const Standard_Real Tolerance,
29 const Standard_Real AngularTolerance)
30:myCurve(Curve),
31myDone(Standard_False),
32myFixFirstTangent(Standard_False),
33myFixLastTangent(Standard_False),
34myAngularTolerance(Abs(AngularTolerance)),
35myTolerance(Abs(Tolerance)),
36myFirstPole(1.0,0.0e0),
37myLastPole(1.0e0,0.0e0)
38{
39
40
41 Standard_Integer ii,
42 num_poles ;
43 Standard_Real tangent_magnitude,
44 value,
45 angular_value,
46 factor,
47 vector_magnitude ;
48 num_poles = Curve->NbPoles() ;
49 if (( ! myCurve->IsPeriodic() )&& num_poles >= 4) {
50
51 gp_Vec2d tangent,
52 diff,
53 a_vector;
54 for (ii = 1 ; ii <= 2 ; ii++) {
55 tangent.SetCoord(ii,myCurve->Pole(2).Coord(ii) - myCurve->Pole(1).Coord(ii)) ;
56 a_vector.SetCoord(ii, myCurve->Pole(3).Coord(ii) - myCurve->Pole(1).Coord(ii)) ;
57 }
58 tangent_magnitude = tangent.Magnitude() ;
59 vector_magnitude = a_vector.Magnitude() ;
60 if (tangent_magnitude > myTolerance &&
61 vector_magnitude > myTolerance)
62 {
63 value = tangent.Dot(a_vector) ;
64 if ( value < 0.0e0) {
65 for (ii = 1 ; ii <= 2 ; ii++) {
66 diff.SetCoord(ii, (tangent.Coord(ii) / tangent_magnitude) + (a_vector.Coord(ii) / vector_magnitude)) ;
67 }
68 angular_value =
69 diff.Magnitude() ;
70 if (angular_value < myAngularTolerance) {
71 myFixFirstTangent = Standard_True ;
72 factor = 1.0e0 ;
73 if (tangent_magnitude > 0.5e0 * vector_magnitude) {
74 factor = 0.5e0 * vector_magnitude / tangent_magnitude ;
75 }
76 for (ii = 1 ; ii <= 2 ; ii++) {
77 myFirstPole.SetCoord(ii, myCurve->Pole(1).Coord(ii) - factor * tangent.Coord(ii)) ;
78 }
79 }
80
81 }
82 }
83 for (ii = 1 ; ii <= 2 ; ii++) {
84 tangent.SetCoord(ii,myCurve->Pole(num_poles-1).Coord(ii) - myCurve->Pole(num_poles).Coord(ii)) ;
85 a_vector.SetCoord(ii, myCurve->Pole(num_poles-2).Coord(ii) - myCurve->Pole(num_poles).Coord(ii)) ;
86 }
87 tangent_magnitude = tangent.Magnitude() ;
88 vector_magnitude = a_vector.Magnitude() ;
89
90 if (tangent_magnitude > myTolerance &&
91 vector_magnitude > myTolerance)
92 {
93 value = tangent.Dot(a_vector) ;
94 if (value < 0.0e0) {
95 for (ii = 1 ; ii <= 2 ; ii++) {
96 diff.SetCoord(ii, (tangent.Coord(ii) / tangent_magnitude) + (a_vector.Coord(ii) / vector_magnitude)) ;
97 }
98 angular_value =
99 diff.Magnitude() ;
100 if ( angular_value < myAngularTolerance) {
101 myFixLastTangent = Standard_True ;
102 factor = 1.0e0 ;
103 if (tangent_magnitude > 0.5e0 * vector_magnitude) {
104 factor = 0.5e0 * vector_magnitude / tangent_magnitude ;
105 }
106 for (ii = 1 ; ii <= 2 ; ii++) {
107 myLastPole.SetCoord(ii, myCurve->Pole(num_poles).Coord(ii) - factor * tangent.Coord(ii)) ;
108 }
109 }
110
111 }
112 }
113
114 }
115 else {
116 myDone = Standard_True ;
117 }
118}
119
120//=======================================================================
121//function : NeedTangentFix
122//purpose :
123//=======================================================================
124
125void GeomLib_Check2dBSplineCurve::NeedTangentFix(Standard_Boolean & FirstFlag,
126 Standard_Boolean & LastFlag) const
127{
128 FirstFlag = myFixFirstTangent ;
129 LastFlag = myFixLastTangent ;
130}
131//=======================================================================
132//function : FixTangent
133//purpose :
134//=======================================================================
135
136Handle(Geom2d_BSplineCurve) GeomLib_Check2dBSplineCurve::FixedTangent(const Standard_Boolean FirstFlag,
137 const Standard_Boolean LastFlag)
138{
139 Handle(Geom2d_BSplineCurve) new_curve ;
140 if ((myFixFirstTangent && FirstFlag) ||(myFixLastTangent && LastFlag)) {
141 new_curve =
142 Handle(Geom2d_BSplineCurve)::DownCast(myCurve->Copy()) ;
143
144 }
145 if (myFixFirstTangent && FirstFlag) {
146 new_curve->SetPole(2,
147 myFirstPole) ;
148 }
149 if (myFixLastTangent && LastFlag) {
150 Standard_Integer num_poles = myCurve->NbPoles() ;
151 new_curve->SetPole(num_poles-1,
152 myLastPole) ;
153 }
154
155 myDone = Standard_True ;
156 return new_curve ;
157}
158//=======================================================================
159//function : FixTangent
160//purpose :
161//=======================================================================
162
163void GeomLib_Check2dBSplineCurve::FixTangent(const Standard_Boolean FirstFlag,
164 const Standard_Boolean LastFlag)
165{
166
167 if (myFixFirstTangent && FirstFlag) {
168 myCurve->SetPole(2,
169 myFirstPole) ;
170 }
171 if (myFixLastTangent && LastFlag) {
172 Standard_Integer num_poles = myCurve->NbPoles() ;
173 myCurve->SetPole(num_poles-1,
174 myLastPole) ;
175 }
176
177 myDone = Standard_True ;
178}