0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- manual
[occt.git] / src / Geom2d / Geom2d_OffsetCurve.cxx
CommitLineData
b311480e 1// Created on: 1991-06-25
2// Created by: JCV
3// Copyright (c) 1991-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// modified by Edward AGAPOV (eap) Jan 28 2002 --- DN(), occ143(BUC60654)
18
42cf5bc1 19#include <Geom2d_BezierCurve.hxx>
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>
7fd59977 29#include <Geom2d_TrimmedCurve.hxx>
42cf5bc1 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>
7fd59977 36#include <gp_XY.hxx>
3d58dc49 37#include <Precision.hxx>
42cf5bc1 38#include <Standard_ConstructionError.hxx>
39#include <Standard_NoSuchObject.hxx>
40#include <Standard_NotImplemented.hxx>
41#include <Standard_RangeError.hxx>
42#include <Standard_Type.hxx>
7fd59977 43
f5f4ebd0 44IMPLEMENT_STANDARD_RTTIEXT(Geom2d_OffsetCurve,Geom2d_Curve)
7fd59977 45
3d58dc49 46static const Standard_Real MyAngularToleranceForG1 = Precision::Angular();
7fd59977 47
94f71cad 48
7fd59977 49//=======================================================================
50//function : Copy
51//purpose :
52//=======================================================================
53
54Handle(Geom2d_Geometry) Geom2d_OffsetCurve::Copy () const
55{
c04c30b3 56 Handle(Geom2d_OffsetCurve) C;
d660a72a 57 C = new Geom2d_OffsetCurve (basisCurve, offsetValue);
7fd59977 58 return C;
59}
60
61
62//=======================================================================
63//function : Geom2d_OffsetCurve
3d58dc49 64//purpose : Basis curve cannot be an Offset curve or trimmed from
65// offset curve.
7fd59977 66//=======================================================================
67
3d58dc49 68Geom2d_OffsetCurve::Geom2d_OffsetCurve (const Handle(Geom2d_Curve)& theCurve,
69 const Standard_Real theOffset,
70 const Standard_Boolean isTheNotCheckC0)
71: offsetValue (theOffset)
7fd59977 72{
3d58dc49 73 SetBasisCurve (theCurve, isTheNotCheckC0);
7fd59977 74}
75
76//=======================================================================
77//function : Reverse
78//purpose :
79//=======================================================================
80
81void Geom2d_OffsetCurve::Reverse ()
82{
83 basisCurve->Reverse();
84 offsetValue = -offsetValue;
85}
86
87//=======================================================================
88//function : ReversedParameter
89//purpose :
90//=======================================================================
91
92Standard_Real Geom2d_OffsetCurve::ReversedParameter( const Standard_Real U) const
93{
94 return basisCurve->ReversedParameter( U);
95}
96
97//=======================================================================
98//function : SetBasisCurve
99//purpose :
100//=======================================================================
101
c04c30b3 102void Geom2d_OffsetCurve::SetBasisCurve (const Handle(Geom2d_Curve)& C,
3d58dc49 103 const Standard_Boolean isNotCheckC0)
7fd59977 104{
3d58dc49 105 const Standard_Real aUf = C->FirstParameter(),
106 aUl = C->LastParameter();
107 Handle(Geom2d_Curve) aCheckingCurve = C;
108 Standard_Boolean isTrimmed = Standard_False;
109
110 while(aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)) ||
111 aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve)))
112 {
113 if (aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
114 {
115 Handle(Geom2d_TrimmedCurve) aTrimC =
116 Handle(Geom2d_TrimmedCurve)::DownCast(aCheckingCurve);
117 aCheckingCurve = aTrimC->BasisCurve();
118 isTrimmed = Standard_True;
119 }
120
121 if (aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve)))
122 {
123 Handle(Geom2d_OffsetCurve) aOC =
124 Handle(Geom2d_OffsetCurve)::DownCast(aCheckingCurve);
125 aCheckingCurve = aOC->BasisCurve();
126 offsetValue += aOC->Offset();
127 }
128 }
129
130 myBasisCurveContinuity = aCheckingCurve->Continuity();
131
132 Standard_Boolean isC0 = !isNotCheckC0 &&
133 (myBasisCurveContinuity == GeomAbs_C0);
06be28a4
RL
134
135 // Basis curve must be at least C1
3d58dc49 136 if (isC0 && aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve)))
06be28a4 137 {
3d58dc49 138 Handle(Geom2d_BSplineCurve) aBC = Handle(Geom2d_BSplineCurve)::DownCast(aCheckingCurve);
139 if(aBC->IsG1(aUf, aUl, MyAngularToleranceForG1))
06be28a4 140 {
3d58dc49 141 //Checking if basis curve has more smooth (C1, G2 and above) is not done.
142 //It can be done in case of need.
143 myBasisCurveContinuity = GeomAbs_G1;
144 isC0 = Standard_False;
06be28a4
RL
145 }
146
147 // Raise exception if still C0
3d58dc49 148 if (isC0)
06be28a4
RL
149 Standard_ConstructionError::Raise("Offset on C0 curve");
150 }
3d58dc49 151 //
152 if(isTrimmed)
153 {
154 basisCurve = new Geom2d_TrimmedCurve(aCheckingCurve, aUf, aUl);
155 }
156 else
157 {
158 basisCurve = aCheckingCurve;
159 }
06be28a4 160
d660a72a 161 myEvaluator = new Geom2dEvaluator_OffsetCurve(basisCurve, offsetValue);
7fd59977 162}
163
164//=======================================================================
165//function : SetOffsetValue
166//purpose :
167//=======================================================================
168
d660a72a 169void Geom2d_OffsetCurve::SetOffsetValue (const Standard_Real D)
170{
171 offsetValue = D;
172 myEvaluator->SetOffsetValue(offsetValue);
173}
7fd59977 174
175//=======================================================================
176//function : BasisCurve
177//purpose :
178//=======================================================================
179
c04c30b3 180Handle(Geom2d_Curve) Geom2d_OffsetCurve::BasisCurve () const
7fd59977 181{
182 return basisCurve;
183}
184
185//=======================================================================
186//function : Continuity
187//purpose :
188//=======================================================================
189
190GeomAbs_Shape Geom2d_OffsetCurve::Continuity () const
191{
192 GeomAbs_Shape OffsetShape=GeomAbs_C0;
3d58dc49 193 switch (myBasisCurveContinuity) {
7fd59977 194 case GeomAbs_C0 : OffsetShape = GeomAbs_C0; break;
195 case GeomAbs_C1 : OffsetShape = GeomAbs_C0; break;
196 case GeomAbs_C2 : OffsetShape = GeomAbs_C1; break;
197 case GeomAbs_C3 : OffsetShape = GeomAbs_C2; break;
198 case GeomAbs_CN : OffsetShape = GeomAbs_CN; break;
199 case GeomAbs_G1 : OffsetShape = GeomAbs_G1; break;
200 case GeomAbs_G2 : OffsetShape = GeomAbs_G2; break;
201 }
3d58dc49 202
7fd59977 203 return OffsetShape;
204}
205
206//=======================================================================
207//function : D0
208//purpose :
209//=======================================================================
210
94f71cad 211void Geom2d_OffsetCurve::D0 (const Standard_Real theU,
d660a72a 212 gp_Pnt2d& theP) const
213{
214 myEvaluator->D0(theU, theP);
94f71cad 215}
7fd59977 216
217//=======================================================================
218//function : D1
219//purpose :
220//=======================================================================
d660a72a 221void Geom2d_OffsetCurve::D1 (const Standard_Real theU, gp_Pnt2d& theP, gp_Vec2d& theV1) const
94f71cad 222{
d660a72a 223 myEvaluator->D1(theU, theP, theV1);
7fd59977 224}
225
226//=======================================================================
227//function : D2
228//purpose :
229//=======================================================================
230
32ca7a51 231void Geom2d_OffsetCurve::D2 (const Standard_Real theU,
d660a72a 232 gp_Pnt2d& theP,
233 gp_Vec2d& theV1, gp_Vec2d& theV2) const
7fd59977 234{
d660a72a 235 myEvaluator->D2(theU, theP, theV1, theV2);
7fd59977 236}
237
238
239//=======================================================================
240//function : D3
241//purpose :
242//=======================================================================
243
32ca7a51 244void Geom2d_OffsetCurve::D3 (const Standard_Real theU,
d660a72a 245 gp_Pnt2d& theP,
246 gp_Vec2d& theV1, gp_Vec2d& theV2, gp_Vec2d& theV3) const
94f71cad 247{
d660a72a 248 myEvaluator->D3(theU, theP, theV1, theV2, theV3);
94f71cad 249}
7fd59977 250
251//=======================================================================
252//function : DN
253//purpose :
254//=======================================================================
255
d660a72a 256gp_Vec2d Geom2d_OffsetCurve::DN (const Standard_Real U,
257 const Standard_Integer N) const
7fd59977 258{
d660a72a 259 Standard_RangeError_Raise_if (N < 1, "Exception: Geom2d_OffsetCurve::DN(). N<1.");
7fd59977 260
261 gp_Vec2d VN, VBidon;
262 gp_Pnt2d PBidon;
263 switch (N) {
264 case 1: D1( U, PBidon, VN); break;
265 case 2: D2( U, PBidon, VBidon, VN); break;
266 case 3: D3( U, PBidon, VBidon, VBidon, VN); break;
267 default:
32ca7a51 268 Standard_NotImplemented::Raise("Exception: Derivative order is greater than 3. "
269 "Cannot compute of derivative.");
7fd59977 270 }
271
272 return VN;
273}
274
7fd59977 275//=======================================================================
276//function : FirstParameter
277//purpose :
278//=======================================================================
279
280Standard_Real Geom2d_OffsetCurve::FirstParameter () const
281{
282 return basisCurve->FirstParameter();
283}
284
285//=======================================================================
286//function : LastParameter
287//purpose :
288//=======================================================================
289
290Standard_Real Geom2d_OffsetCurve::LastParameter () const
291{
292 return basisCurve->LastParameter();
293}
294
295
296//=======================================================================
297//function : Offset
298//purpose :
299//=======================================================================
300
d660a72a 301Standard_Real Geom2d_OffsetCurve::Offset () const
302{ return offsetValue; }
7fd59977 303
304//=======================================================================
305//function : IsClosed
306//purpose :
307//=======================================================================
308
309Standard_Boolean Geom2d_OffsetCurve::IsClosed () const
310{
311 gp_Pnt2d PF, PL;
312 D0(FirstParameter(),PF);
313 D0(LastParameter(),PL);
314 return ( PF.Distance(PL) <= gp::Resolution());
315}
316
317//=======================================================================
318//function : IsCN
319//purpose :
320//=======================================================================
321
322Standard_Boolean Geom2d_OffsetCurve::IsCN (const Standard_Integer N) const
323{
324 Standard_RangeError_Raise_if (N < 0, " " );
325 return basisCurve->IsCN (N + 1);
326}
327
328//=======================================================================
329//function : IsPeriodic
330//purpose :
331//=======================================================================
332
333Standard_Boolean Geom2d_OffsetCurve::IsPeriodic () const
334{
335 return basisCurve->IsPeriodic();
336}
337
338//=======================================================================
339//function : Period
340//purpose :
341//=======================================================================
342
343Standard_Real Geom2d_OffsetCurve::Period() const
344{
345 return basisCurve->Period();
346}
347
348//=======================================================================
349//function : Transform
350//purpose :
351//=======================================================================
352
d660a72a 353void Geom2d_OffsetCurve::Transform (const gp_Trsf2d& T)
7fd59977 354{
355 basisCurve->Transform (T);
356 offsetValue *= Abs(T.ScaleFactor());
d660a72a 357
358 myEvaluator->SetOffsetValue(offsetValue);
7fd59977 359}
360
361
362//=======================================================================
363//function : TransformedParameter
364//purpose :
365//=======================================================================
366
367Standard_Real Geom2d_OffsetCurve::TransformedParameter(const Standard_Real U,
368 const gp_Trsf2d& T) const
369{
370 return basisCurve->TransformedParameter(U,T);
371}
372
373//=======================================================================
374//function : ParametricTransformation
375//purpose :
376//=======================================================================
377
378Standard_Real Geom2d_OffsetCurve::ParametricTransformation(const gp_Trsf2d& T) const
379{
380 return basisCurve->ParametricTransformation(T);
381}
3d58dc49 382
383//=======================================================================
384//function : GetBasisCurveContinuity
385//purpose :
386//=======================================================================
387GeomAbs_Shape Geom2d_OffsetCurve::GetBasisCurveContinuity() const
388{
389 return myBasisCurveContinuity;
390}