0031939: Coding - correction of spelling errors in comments [part 3]
[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
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
42cf5bc1 17
18#include <ElCLib.hxx>
7fd59977 19#include <Geom2d_BezierCurve.hxx>
42cf5bc1 20#include <Geom2d_BSplineCurve.hxx>
7fd59977 21#include <Geom2d_Circle.hxx>
42cf5bc1 22#include <Geom2d_Curve.hxx>
7fd59977 23#include <Geom2d_Ellipse.hxx>
42cf5bc1 24#include <Geom2d_Geometry.hxx>
7fd59977 25#include <Geom2d_Hyperbola.hxx>
42cf5bc1 26#include <Geom2d_Line.hxx>
27#include <Geom2d_OffsetCurve.hxx>
7fd59977 28#include <Geom2d_Parabola.hxx>
42cf5bc1 29#include <Geom2d_TrimmedCurve.hxx>
30#include <Geom2d_UndefinedDerivative.hxx>
31#include <Geom2d_UndefinedValue.hxx>
32#include <gp.hxx>
33#include <gp_Pnt2d.hxx>
34#include <gp_Trsf2d.hxx>
35#include <gp_Vec2d.hxx>
36#include <Precision.hxx>
7fd59977 37#include <Standard_ConstructionError.hxx>
42cf5bc1 38#include <Standard_NoSuchObject.hxx>
7fd59977 39#include <Standard_RangeError.hxx>
42cf5bc1 40#include <Standard_Type.hxx>
7fd59977 41
92efcf78 42IMPLEMENT_STANDARD_RTTIEXT(Geom2d_TrimmedCurve,Geom2d_BoundedCurve)
43
7fd59977 44typedef Geom2d_TrimmedCurve TrimmedCurve;
7fd59977 45typedef gp_Ax2d Ax2d;
46typedef gp_Pnt2d Pnt2d;
47typedef gp_Trsf2d Trsf2d;
48typedef gp_Vec2d Vec2d;
49
7fd59977 50//=======================================================================
51//function : Copy
52//purpose :
53//=======================================================================
54
55Handle(Geom2d_Geometry) Geom2d_TrimmedCurve::Copy () const
56{
c04c30b3 57 Handle(Geom2d_TrimmedCurve) Tc;
7fd59977 58 Tc = new TrimmedCurve (basisCurve, uTrim1, uTrim2);
59 return Tc;
60}
61
62//=======================================================================
63//function : Geom2d_TrimmedCurve
64//purpose :
65//=======================================================================
66
67Geom2d_TrimmedCurve::Geom2d_TrimmedCurve (const Handle(Geom2d_Curve)& C,
8ac0cf52 68 const Standard_Real U1,
69 const Standard_Real U2,
70 const Standard_Boolean Sense,
71 const Standard_Boolean theAdjustPeriodic) :
7fd59977 72 uTrim1 (U1),
73 uTrim2 (U2)
74{
9775fa61 75 if(C.IsNull()) throw Standard_ConstructionError("Geom2d_TrimmedCurve:: C is null");
7fd59977 76 // kill trimmed basis curves
77 Handle(Geom2d_TrimmedCurve) T = Handle(Geom2d_TrimmedCurve)::DownCast(C);
78 if (!T.IsNull())
c04c30b3 79 basisCurve = Handle(Geom2d_Curve)::DownCast(T->BasisCurve()->Copy());
7fd59977 80 else
c04c30b3 81 basisCurve = Handle(Geom2d_Curve)::DownCast(C->Copy());
7fd59977 82
8ac0cf52 83 SetTrim(U1, U2, Sense, theAdjustPeriodic);
7fd59977 84}
85
86//=======================================================================
87//function : Reverse
88//purpose :
89//=======================================================================
90
91void Geom2d_TrimmedCurve::Reverse ()
92{
93 Standard_Real U1 = basisCurve->ReversedParameter(uTrim2);
94 Standard_Real U2 = basisCurve->ReversedParameter(uTrim1);
95 basisCurve->Reverse();
8ac0cf52 96 SetTrim(U1, U2, Standard_True, Standard_False);
7fd59977 97}
98
99//=======================================================================
a25d5aaa 100//function : ReversedParameter
7fd59977 101//purpose :
102//=======================================================================
103
104Standard_Real Geom2d_TrimmedCurve::ReversedParameter( const Standard_Real U) const
105{
106 return basisCurve->ReversedParameter(U);
107}
108
109//=======================================================================
110//function : SetTrim
111//purpose :
112//=======================================================================
113
8ac0cf52 114void Geom2d_TrimmedCurve::SetTrim (const Standard_Real U1,
115 const Standard_Real U2,
116 const Standard_Boolean Sense,
117 const Standard_Boolean theAdjustPeriodic)
7fd59977 118{
119 Standard_Boolean sameSense = Standard_True;
120 if (U1 == U2)
9775fa61 121 throw Standard_ConstructionError("Geom2d_TrimmedCurve::U1 == U2");
7fd59977 122
123 Standard_Real Udeb = basisCurve->FirstParameter();
124 Standard_Real Ufin = basisCurve->LastParameter();
125
126 if (basisCurve->IsPeriodic()) {
127 sameSense = Sense;
128
129 // set uTrim1 in the range Udeb , Ufin
130 // set uTrim2 in the range uTrim1 , uTrim1 + Period()
131 uTrim1 = U1;
8ac0cf52 132 uTrim2 = U2;
133 if (theAdjustPeriodic)
134 ElCLib::AdjustPeriodic(Udeb, Ufin,
135 Min(Abs(uTrim2-uTrim1)/2,Precision::PConfusion()),
136 uTrim1, uTrim2);
7fd59977 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())) {
9775fa61 152 throw Standard_ConstructionError("Geom_TrimmedCurve::parameters out of range");
7fd59977 153 }
154 }
155
156 if (!sameSense)
157 Reverse();
158}
159
160//=======================================================================
161//function : BasisCurve
162//purpose :
163//=======================================================================
164
c04c30b3 165Handle(Geom2d_Curve) Geom2d_TrimmedCurve::BasisCurve () const
7fd59977 166{
167 return basisCurve;
168}
169
170//=======================================================================
171//function : Continuity
172//purpose :
173//=======================================================================
174
175GeomAbs_Shape Geom2d_TrimmedCurve::Continuity () const
176{
177 return basisCurve->Continuity();
178}
179
180//=======================================================================
181//function : IsCN
182//purpose :
183//=======================================================================
184
185Standard_Boolean Geom2d_TrimmedCurve::IsCN (const Standard_Integer N) const
186{
187 Standard_RangeError_Raise_if (N < 0, " ");
188 return basisCurve->IsCN (N);
189}
190
191//=======================================================================
192//function : EndPoint
193//purpose :
194//=======================================================================
195
196Pnt2d Geom2d_TrimmedCurve::EndPoint () const
197{
198 return basisCurve->Value(uTrim2);
199}
200
201//=======================================================================
202//function : FirstParameter
203//purpose :
204//=======================================================================
205
206Standard_Real Geom2d_TrimmedCurve::FirstParameter () const { return uTrim1; }
207
208//=======================================================================
209//function : IsClosed
210//purpose :
211//=======================================================================
212
213Standard_Boolean Geom2d_TrimmedCurve::IsClosed () const
214{
215 Standard_Real Dist =
216 Value(FirstParameter()).Distance(Value(LastParameter()));
217 return ( Dist <= gp::Resolution());
218}
219
220//=======================================================================
221//function : IsPeriodic
222//purpose :
223//=======================================================================
224
225Standard_Boolean Geom2d_TrimmedCurve::IsPeriodic () const
226{
227 //return basisCurve->IsPeriodic();
228 return Standard_False;
229}
230
231//=======================================================================
232//function : Period
233//purpose :
234//=======================================================================
235
236Standard_Real Geom2d_TrimmedCurve::Period () const
237{
238 return basisCurve->Period();
239}
240
241//=======================================================================
242//function : LastParameter
243//purpose :
244//=======================================================================
245
246Standard_Real Geom2d_TrimmedCurve::LastParameter () const { return uTrim2; }
247
248//=======================================================================
249//function : StartPoint
250//purpose :
251//=======================================================================
252
253Pnt2d Geom2d_TrimmedCurve::StartPoint () const
254{
255 gp_Pnt2d P;
256 P = basisCurve->Value(uTrim1);
257 return P;
258}
259
260//=======================================================================
261//function : D0
262//purpose :
263//=======================================================================
264
265void Geom2d_TrimmedCurve::D0 (const Standard_Real U,
266 Pnt2d& P ) const {
267 basisCurve->D0(U, P);
268}
269
270//=======================================================================
271//function : D1
272//purpose :
273//=======================================================================
274
275void Geom2d_TrimmedCurve::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const
276{
277 basisCurve->D1 (U, P, V1);
278}
279
280//=======================================================================
281//function : D2
282//purpose :
283//=======================================================================
284
285void Geom2d_TrimmedCurve::D2 (const Standard_Real U,
286 Pnt2d& P,
287 Vec2d& V1, Vec2d& V2) const
288{
289 basisCurve->D2 (U, P, V1, V2);
290}
291
292//=======================================================================
293//function : D3
294//purpose :
295//=======================================================================
296
297void Geom2d_TrimmedCurve::D3 (const Standard_Real U,
298 Pnt2d& P,
299 Vec2d& V1, Vec2d& V2, Vec2d& V3) const
300{
301 basisCurve->D3 (U, P, V1, V2, V3);
302}
303
304//=======================================================================
305//function : DN
306//purpose :
307//=======================================================================
308
309Vec2d Geom2d_TrimmedCurve::DN (const Standard_Real U, const Standard_Integer N) const
310{
311 return basisCurve->DN(U, N);
312}
313
314//=======================================================================
315//function : Transform
316//purpose :
317//=======================================================================
318
319void Geom2d_TrimmedCurve::Transform (const Trsf2d& T)
320{
321 basisCurve->Transform (T);
322 Standard_Real U1 = basisCurve->TransformedParameter(uTrim1,T);
323 Standard_Real U2 = basisCurve->TransformedParameter(uTrim2,T);
8ac0cf52 324 SetTrim(U1, U2, Standard_True, Standard_False);
7fd59977 325}
326
327//=======================================================================
328//function : TransformedParameter
329//purpose :
330//=======================================================================
331
332Standard_Real Geom2d_TrimmedCurve::TransformedParameter(const Standard_Real U,
333 const gp_Trsf2d& T) const
334{
335 return basisCurve->TransformedParameter(U,T);
336}
337
338//=======================================================================
339//function : ParametricTransformation
340//purpose :
341//=======================================================================
342
343Standard_Real Geom2d_TrimmedCurve::ParametricTransformation(const gp_Trsf2d& T) const
344{
345 return basisCurve->ParametricTransformation(T);
346}
347
bc73b006 348//=======================================================================
349//function : DumpJson
350//purpose :
351//=======================================================================
352void Geom2d_TrimmedCurve::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
353{
354 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
355
356 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom2d_BoundedCurve)
357
358 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, basisCurve.get())
359 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, uTrim1)
360 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, uTrim2)
361}