summaryrefslogtreecommitdiff
path: root/src/Geom/Geom_TrimmedCurve.cxx
blob: fef559f4df8148b43f0f0134ab0891ec9d6d7bbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// File:	Geom_TrimmedCurve.cxx
// Created:	Wed Mar 10 11:01:02 1993
// Author:	JCV
//		<fid@phylox>
// Copyright:	Matra Datavision 1993

//File Geom_TrimmedCurve.cxx, JCV 17/01/91

#include <Geom_TrimmedCurve.ixx>

#include <gp.hxx>
#include <Geom_Geometry.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_OffsetCurve.hxx>
#include <Geom_Line.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_Hyperbola.hxx>
#include <Geom_Parabola.hxx>
#include <Standard_ConstructionError.hxx>
#include <Standard_RangeError.hxx>
#include <Precision.hxx>
#include <ElCLib.hxx>


typedef Handle(Geom_TrimmedCurve) Handle(TrimmedCurve);
typedef Geom_TrimmedCurve         TrimmedCurve;
typedef Handle(Geom_Curve)        Handle(Curve);
typedef Handle(Geom_Geometry)     Handle(Geometry);
typedef gp_Ax1  Ax1;
typedef gp_Ax2  Ax2;
typedef gp_Pnt  Pnt;
typedef gp_Trsf Trsf;
typedef gp_Vec  Vec;

//=======================================================================
//function : Copy
//purpose  : 
//=======================================================================

Handle(Geom_Geometry) Geom_TrimmedCurve::Copy () const {
 
  Handle(TrimmedCurve) Tc = new TrimmedCurve (basisCurve, uTrim1, uTrim2);
  return Tc;
}


//=======================================================================
//function : Geom_TrimmedCurve
//purpose  : 
//=======================================================================

Geom_TrimmedCurve::Geom_TrimmedCurve (const Handle(Geom_Curve)& C, 
				      const Standard_Real U1, 
				      const Standard_Real U2,
				      const Standard_Boolean Sense) :
       uTrim1 (U1),
       uTrim2 (U2) 
{
  // kill trimmed basis curves
  Handle(Geom_TrimmedCurve) T = Handle(Geom_TrimmedCurve)::DownCast(C);
  if (!T.IsNull())
    basisCurve = Handle(Curve)::DownCast(T->BasisCurve()->Copy());
  else
    basisCurve = Handle(Curve)::DownCast(C->Copy());

  SetTrim(U1,U2,Sense);
}

//=======================================================================
//function : Reverse
//purpose  : 
//=======================================================================

void Geom_TrimmedCurve::Reverse () 
{
  Standard_Real U1 = basisCurve->ReversedParameter(uTrim2);
  Standard_Real U2 = basisCurve->ReversedParameter(uTrim1);
  basisCurve->Reverse();
  SetTrim(U1,U2);
}


//=======================================================================
//function : ReversedParameter
//purpose  : 
//=======================================================================

Standard_Real Geom_TrimmedCurve::ReversedParameter
  (const Standard_Real U) const 
{
  return basisCurve->ReversedParameter(U);
}


//=======================================================================
//function : SetTrim
//purpose  : 
//=======================================================================

void Geom_TrimmedCurve::SetTrim (const Standard_Real U1, 
				 const Standard_Real U2, 
				 const Standard_Boolean Sense) 
{
   Standard_Boolean sameSense = Standard_True;
   if (U1 == U2) 
     Standard_ConstructionError::Raise("Geom_TrimmedCurve::U1 == U2");

   Standard_Real Udeb = basisCurve->FirstParameter();
   Standard_Real Ufin = basisCurve->LastParameter();

   if (basisCurve->IsPeriodic())  {
     sameSense = Sense;
      
     // set uTrim1 in the range Udeb , Ufin
     // set uTrim2 in the range uTrim1 , uTrim1 + Period()
     uTrim1 = U1;
     uTrim2 = U2;
     ElCLib::AdjustPeriodic(Udeb, Ufin, 
			    Min(Abs(uTrim2-uTrim1)/2,Precision::PConfusion()), 
			    uTrim1, uTrim2);
   }

   else {
     if (U1 < U2) {
       sameSense = Sense;
       uTrim1 = U1;
       uTrim2 = U2;
     }
     else {
       sameSense = !Sense;
       uTrim1 = U2;
       uTrim2 = U1;
     }

     if ((Udeb - uTrim1 > Precision::PConfusion()) ||
	 (uTrim2 - Ufin > Precision::PConfusion()))
      Standard_ConstructionError::Raise
	("Geom_TrimmedCurve::parameters out of range");
       

   }
   if (!sameSense) {
     Reverse();
   }
}


//=======================================================================
//function : IsClosed
//purpose  : 
//=======================================================================

Standard_Boolean Geom_TrimmedCurve::IsClosed () const
{
  return ( StartPoint().Distance(EndPoint()) <= gp::Resolution());
}

//=======================================================================
//function : IsPeriodic
//purpose  : 
//=======================================================================

Standard_Boolean Geom_TrimmedCurve::IsPeriodic () const 
{
  //return basisCurve->IsPeriodic();
  return Standard_False;
}


//=======================================================================
//function : Period
//purpose  : 
//=======================================================================

Standard_Real Geom_TrimmedCurve::Period() const
{
  return basisCurve->Period();
}


//=======================================================================
//function : Continuity
//purpose  : 
//=======================================================================

GeomAbs_Shape Geom_TrimmedCurve::Continuity () const { 

  return basisCurve->Continuity ();
}


//=======================================================================
//function : BasisCurve
//purpose  : 
//=======================================================================

Handle(Curve) Geom_TrimmedCurve::BasisCurve () const { 

  return basisCurve;
}


//=======================================================================
//function : D0
//purpose  : 
//=======================================================================

void Geom_TrimmedCurve::D0 (const Standard_Real U, Pnt& P) const {

    basisCurve->D0( U, P);
}


//=======================================================================
//function : D1
//purpose  : 
//=======================================================================

void Geom_TrimmedCurve::D1 (const Standard_Real U, Pnt& P, Vec& V1) const {

    basisCurve->D1 (U, P, V1);
}


//=======================================================================
//function : D2
//purpose  : 
//=======================================================================

void Geom_TrimmedCurve::D2 ( const Standard_Real U, 
			     Pnt& P, 
			     Vec& V1, Vec& V2) const {

  basisCurve->D2 (U, P, V1, V2);
}


//=======================================================================
//function : D3
//purpose  : 
//=======================================================================

void Geom_TrimmedCurve::D3 (const Standard_Real U, 
			    Pnt& P, 
			    Vec& V1, Vec& V2, Vec& V3) const {
 
  basisCurve->D3 (U, P, V1, V2, V3);
}


//=======================================================================
//function : DN
//purpose  : 
//=======================================================================

Vec Geom_TrimmedCurve::DN (const Standard_Real U, 
			   const Standard_Integer N) const 
{
   return basisCurve->DN (U, N);
}


//=======================================================================
//function : EndPoint
//purpose  : 
//=======================================================================

Pnt Geom_TrimmedCurve::EndPoint () const { 
 
  return basisCurve->Value (uTrim2);
}


//=======================================================================
//function : FirstParameter
//purpose  : 
//=======================================================================

Standard_Real Geom_TrimmedCurve::FirstParameter () const { 

  return uTrim1; 
}

//=======================================================================
//function : LastParameter
//purpose  : 
//=======================================================================

Standard_Real Geom_TrimmedCurve::LastParameter () const {

  return uTrim2; 
}

//=======================================================================
//function : StartPoint
//purpose  : 
//=======================================================================

Pnt Geom_TrimmedCurve::StartPoint () const {

  return basisCurve->Value (uTrim1);
}


//=======================================================================
//function : IsCN
//purpose  : 
//=======================================================================

Standard_Boolean Geom_TrimmedCurve::IsCN (const Standard_Integer N) const {
  
  Standard_RangeError_Raise_if (N < 0, " ");
  return basisCurve->IsCN (N);
}

 
//=======================================================================
//function : Transform
//purpose  : 
//=======================================================================

void Geom_TrimmedCurve::Transform (const Trsf& T) 
{
  basisCurve->Transform (T);
  Standard_Real U1 = basisCurve->TransformedParameter(uTrim1,T);
  Standard_Real U2 = basisCurve->TransformedParameter(uTrim2,T);
  SetTrim(U1,U2);
}


//=======================================================================
//function : TransformedParameter
//purpose  : 
//=======================================================================

Standard_Real Geom_TrimmedCurve::TransformedParameter(const Standard_Real U,
						      const gp_Trsf& T) const
{
  return basisCurve->TransformedParameter(U,T);
}

//=======================================================================
//function : ParametricTransformation
//purpose  : 
//=======================================================================

Standard_Real Geom_TrimmedCurve::ParametricTransformation(const gp_Trsf& T) 
const
{
  return basisCurve->ParametricTransformation(T);
}