0022939: Make B-Spline internal cache thread-safe to be used in multy-threaded mode
[occt.git] / src / Geom2d / Geom2d_TrimmedCurve.cxx
CommitLineData
b311480e 1// Created on: 1993-03-24
2// Created by: JCV
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
7fd59977 22
23#include <Geom2d_TrimmedCurve.ixx>
24#include <gp.hxx>
25#include <Geom2d_Geometry.hxx>
26#include <Geom2d_BSplineCurve.hxx>
27#include <Geom2d_BezierCurve.hxx>
28#include <Geom2d_OffsetCurve.hxx>
29#include <Geom2d_Line.hxx>
30#include <Geom2d_Circle.hxx>
31#include <Geom2d_Ellipse.hxx>
32#include <Geom2d_Hyperbola.hxx>
33#include <Geom2d_Parabola.hxx>
34#include <Standard_ConstructionError.hxx>
35#include <Standard_RangeError.hxx>
36#include <ElCLib.hxx>
37#include <Precision.hxx>
38
39
40typedef Handle(Geom2d_TrimmedCurve) Handle(TrimmedCurve);
41typedef Geom2d_TrimmedCurve TrimmedCurve;
42typedef Handle(Geom2d_Curve) Handle(Curve);
43typedef Handle(Geom2d_Geometry) Handle(Geometry);
44typedef gp_Ax2d Ax2d;
45typedef gp_Pnt2d Pnt2d;
46typedef gp_Trsf2d Trsf2d;
47typedef gp_Vec2d Vec2d;
48
49
50
51
52
53//=======================================================================
54//function : Copy
55//purpose :
56//=======================================================================
57
58Handle(Geom2d_Geometry) Geom2d_TrimmedCurve::Copy () const
59{
60 Handle(TrimmedCurve) Tc;
61 Tc = new TrimmedCurve (basisCurve, uTrim1, uTrim2);
62 return Tc;
63}
64
65//=======================================================================
66//function : Geom2d_TrimmedCurve
67//purpose :
68//=======================================================================
69
70Geom2d_TrimmedCurve::Geom2d_TrimmedCurve (const Handle(Geom2d_Curve)& C,
71 const Standard_Real U1,
72 const Standard_Real U2,
73 const Standard_Boolean Sense) :
74 uTrim1 (U1),
75 uTrim2 (U2)
76{
77 if(C.IsNull()) Standard_ConstructionError::Raise("Geom2d_TrimmedCurve:: C is null");
78 // kill trimmed basis curves
79 Handle(Geom2d_TrimmedCurve) T = Handle(Geom2d_TrimmedCurve)::DownCast(C);
80 if (!T.IsNull())
81 basisCurve = Handle(Curve)::DownCast(T->BasisCurve()->Copy());
82 else
83 basisCurve = Handle(Curve)::DownCast(C->Copy());
84
85 SetTrim(U1,U2,Sense);
86}
87
88//=======================================================================
89//function : Reverse
90//purpose :
91//=======================================================================
92
93void Geom2d_TrimmedCurve::Reverse ()
94{
95 Standard_Real U1 = basisCurve->ReversedParameter(uTrim2);
96 Standard_Real U2 = basisCurve->ReversedParameter(uTrim1);
97 basisCurve->Reverse();
98 SetTrim(U1,U2);
99}
100
101//=======================================================================
102//function : ReversedParamater
103//purpose :
104//=======================================================================
105
106Standard_Real Geom2d_TrimmedCurve::ReversedParameter( const Standard_Real U) const
107{
108 return basisCurve->ReversedParameter(U);
109}
110
111//=======================================================================
112//function : SetTrim
113//purpose :
114//=======================================================================
115
116void Geom2d_TrimmedCurve::SetTrim (const Standard_Real U1,
117 const Standard_Real U2,
118 const Standard_Boolean Sense)
119{
120 Standard_Boolean sameSense = Standard_True;
121 if (U1 == U2)
122 Standard_ConstructionError::Raise("Geom2d_TrimmedCurve::U1 == U2");
123
124 Standard_Real Udeb = basisCurve->FirstParameter();
125 Standard_Real Ufin = basisCurve->LastParameter();
126
127 if (basisCurve->IsPeriodic()) {
128 sameSense = Sense;
129
130 // set uTrim1 in the range Udeb , Ufin
131 // set uTrim2 in the range uTrim1 , uTrim1 + Period()
132 uTrim1 = U1;
133 uTrim2 = U2;
134 ElCLib::AdjustPeriodic(Udeb, Ufin,
135 Min(Abs(uTrim2-uTrim1)/2,Precision::PConfusion()),
136 uTrim1, uTrim2);
137 }
138 else {
139 if (U1 < U2) {
140 sameSense = Sense;
141 uTrim1 = U1;
142 uTrim2 = U2;
143 }
144 else {
145 sameSense = !Sense;
146 uTrim1 = U2;
147 uTrim2 = U1;
148 }
149
150 if ((Udeb - uTrim1 > Precision::PConfusion()) ||
151 (uTrim2 - Ufin > Precision::PConfusion())) {
152 Standard_ConstructionError::Raise
153 ("Geom_TrimmedCurve::parameters out of range");
154 }
155 }
156
157 if (!sameSense)
158 Reverse();
159}
160
161//=======================================================================
162//function : BasisCurve
163//purpose :
164//=======================================================================
165
166Handle(Curve) Geom2d_TrimmedCurve::BasisCurve () const
167{
168 return basisCurve;
169}
170
171//=======================================================================
172//function : Continuity
173//purpose :
174//=======================================================================
175
176GeomAbs_Shape Geom2d_TrimmedCurve::Continuity () const
177{
178 return basisCurve->Continuity();
179}
180
181//=======================================================================
182//function : IsCN
183//purpose :
184//=======================================================================
185
186Standard_Boolean Geom2d_TrimmedCurve::IsCN (const Standard_Integer N) const
187{
188 Standard_RangeError_Raise_if (N < 0, " ");
189 return basisCurve->IsCN (N);
190}
191
192//=======================================================================
193//function : EndPoint
194//purpose :
195//=======================================================================
196
197Pnt2d Geom2d_TrimmedCurve::EndPoint () const
198{
199 return basisCurve->Value(uTrim2);
200}
201
202//=======================================================================
203//function : FirstParameter
204//purpose :
205//=======================================================================
206
207Standard_Real Geom2d_TrimmedCurve::FirstParameter () const { return uTrim1; }
208
209//=======================================================================
210//function : IsClosed
211//purpose :
212//=======================================================================
213
214Standard_Boolean Geom2d_TrimmedCurve::IsClosed () const
215{
216 Standard_Real Dist =
217 Value(FirstParameter()).Distance(Value(LastParameter()));
218 return ( Dist <= gp::Resolution());
219}
220
221//=======================================================================
222//function : IsPeriodic
223//purpose :
224//=======================================================================
225
226Standard_Boolean Geom2d_TrimmedCurve::IsPeriodic () const
227{
228 //return basisCurve->IsPeriodic();
229 return Standard_False;
230}
231
232//=======================================================================
233//function : Period
234//purpose :
235//=======================================================================
236
237Standard_Real Geom2d_TrimmedCurve::Period () const
238{
239 return basisCurve->Period();
240}
241
242//=======================================================================
243//function : LastParameter
244//purpose :
245//=======================================================================
246
247Standard_Real Geom2d_TrimmedCurve::LastParameter () const { return uTrim2; }
248
249//=======================================================================
250//function : StartPoint
251//purpose :
252//=======================================================================
253
254Pnt2d Geom2d_TrimmedCurve::StartPoint () const
255{
256 gp_Pnt2d P;
257 P = basisCurve->Value(uTrim1);
258 return P;
259}
260
261//=======================================================================
262//function : D0
263//purpose :
264//=======================================================================
265
266void Geom2d_TrimmedCurve::D0 (const Standard_Real U,
267 Pnt2d& P ) const {
268 basisCurve->D0(U, P);
269}
270
271//=======================================================================
272//function : D1
273//purpose :
274//=======================================================================
275
276void Geom2d_TrimmedCurve::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const
277{
278 basisCurve->D1 (U, P, V1);
279}
280
281//=======================================================================
282//function : D2
283//purpose :
284//=======================================================================
285
286void Geom2d_TrimmedCurve::D2 (const Standard_Real U,
287 Pnt2d& P,
288 Vec2d& V1, Vec2d& V2) const
289{
290 basisCurve->D2 (U, P, V1, V2);
291}
292
293//=======================================================================
294//function : D3
295//purpose :
296//=======================================================================
297
298void Geom2d_TrimmedCurve::D3 (const Standard_Real U,
299 Pnt2d& P,
300 Vec2d& V1, Vec2d& V2, Vec2d& V3) const
301{
302 basisCurve->D3 (U, P, V1, V2, V3);
303}
304
305//=======================================================================
306//function : DN
307//purpose :
308//=======================================================================
309
310Vec2d Geom2d_TrimmedCurve::DN (const Standard_Real U, const Standard_Integer N) const
311{
312 return basisCurve->DN(U, N);
313}
314
315//=======================================================================
316//function : Transform
317//purpose :
318//=======================================================================
319
320void Geom2d_TrimmedCurve::Transform (const Trsf2d& T)
321{
322 basisCurve->Transform (T);
323 Standard_Real U1 = basisCurve->TransformedParameter(uTrim1,T);
324 Standard_Real U2 = basisCurve->TransformedParameter(uTrim2,T);
325 SetTrim(U1,U2);
326}
327
328//=======================================================================
329//function : TransformedParameter
330//purpose :
331//=======================================================================
332
333Standard_Real Geom2d_TrimmedCurve::TransformedParameter(const Standard_Real U,
334 const gp_Trsf2d& T) const
335{
336 return basisCurve->TransformedParameter(U,T);
337}
338
339//=======================================================================
340//function : ParametricTransformation
341//purpose :
342//=======================================================================
343
344Standard_Real Geom2d_TrimmedCurve::ParametricTransformation(const gp_Trsf2d& T) const
345{
346 return basisCurve->ParametricTransformation(T);
347}
348