0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Geom2d / Geom2d_BezierCurve.cxx
1 // Created on: 1993-03-25
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // Passage en classe persistante - 23/01/91
18 // Modif suite a la deuxieme revue de projet toolkit Geometry -23/01/91
19 // Infos :
20 // Actuellement pour les champs de la courbe le tableau des poles est 
21 // declare de 1 a NbPoles et le tableau des poids est declare de 1 a NbPoles
22
23
24 // Revised RLE  Aug 19 1993
25 // Suppressed Swaps, added Init, removed typedefs
26
27 #define No_Standard_OutOfRange
28 #define No_Standard_DimensionError
29
30
31 #include <Geom2d_BezierCurve.hxx>
32 #include <Geom2d_Geometry.hxx>
33 #include <gp.hxx>
34 #include <gp_Pnt2d.hxx>
35 #include <gp_Trsf2d.hxx>
36 #include <gp_Vec2d.hxx>
37 #include <PLib.hxx>
38 #include <Standard_ConstructionError.hxx>
39 #include <Standard_DimensionError.hxx>
40 #include <Standard_OutOfRange.hxx>
41 #include <Standard_RangeError.hxx>
42 #include <Standard_Type.hxx>
43 #include <TColStd_Array1OfInteger.hxx>
44 #include <TColStd_Array1OfReal.hxx>
45
46 IMPLEMENT_STANDARD_RTTIEXT(Geom2d_BezierCurve,Geom2d_BoundedCurve)
47
48 //=======================================================================
49 //function : Rational
50 //purpose  : check rationality of an array of weights
51 //=======================================================================
52 static Standard_Boolean Rational(const TColStd_Array1OfReal& W)
53 {
54   Standard_Integer i, n = W.Length();
55   Standard_Boolean rat = Standard_False;
56   for (i = 1; i < n; i++) {
57     rat =  Abs(W(i) - W(i+1)) > gp::Resolution();
58     if (rat) break;
59   }
60   return rat;
61 }
62
63
64 //=======================================================================
65 //function : Geom2d_BezierCurve
66 //purpose  : 
67 //=======================================================================
68
69 Geom2d_BezierCurve::Geom2d_BezierCurve
70  (const TColgp_Array1OfPnt2d& Poles)
71 {
72   //  copy the poles
73   
74   Handle(TColgp_HArray1OfPnt2d) npoles =
75     new TColgp_HArray1OfPnt2d(1,Poles.Length());
76   
77   npoles->ChangeArray1() = Poles;
78   
79   // Init non rational
80   Init(npoles,
81        Handle(TColStd_HArray1OfReal)());
82 }
83
84
85 //=======================================================================
86 //function : Geom2d_BezierCurve
87 //purpose  : 
88 //=======================================================================
89
90 Geom2d_BezierCurve::Geom2d_BezierCurve
91 (const TColgp_Array1OfPnt2d&  Poles,
92  const TColStd_Array1OfReal& Weights)
93
94 {
95   // copy the poles
96   
97   Handle(TColgp_HArray1OfPnt2d) npoles =
98     new TColgp_HArray1OfPnt2d(1,Poles.Length());
99   
100   npoles->ChangeArray1()   = Poles;
101   
102   
103   // check  the weights
104   
105   Standard_Integer nbpoles = Poles.Length();
106   
107   if (Weights.Length() != nbpoles)
108     throw Standard_ConstructionError();
109   
110   Standard_Integer i;
111   for (i = 1; i <= nbpoles; i++) {
112     if (Weights(i) <= gp::Resolution()) {
113       throw Standard_ConstructionError();
114     }
115   }
116   
117   // check really rational
118   Standard_Boolean rat = Rational(Weights);
119   
120   // copy the weights
121   Handle(TColStd_HArray1OfReal) nweights;
122   if (rat) {
123     nweights = new TColStd_HArray1OfReal(1,nbpoles);
124     nweights->ChangeArray1() = Weights;
125   }
126   
127   // Init
128   Init(npoles,nweights);
129 }
130
131
132 //=======================================================================
133 //function : Increase
134 //purpose  : increase degree
135 //=======================================================================
136
137 void Geom2d_BezierCurve::Increase (const Standard_Integer Deg)
138 {
139   if (Deg == Degree()) return;
140   
141   Standard_ConstructionError_Raise_if
142     (Deg < Degree() ||
143      Deg > Geom2d_BezierCurve::MaxDegree(), "Geom2d_BezierCurve::Increase");
144   
145   Handle(TColgp_HArray1OfPnt2d) npoles =
146     new TColgp_HArray1OfPnt2d(1,Deg+1);
147   
148   Handle(TColStd_HArray1OfReal) nweights;
149   
150   TColStd_Array1OfReal bidknots(1,2); bidknots(1) = 0.; bidknots(2) = 1.;
151   TColStd_Array1OfInteger bidmults(1,2); bidmults.Init(Degree() + 1);
152   
153   if (IsRational()) {
154     nweights = new TColStd_HArray1OfReal(1,Deg+1);
155     BSplCLib::IncreaseDegree(Degree(), Deg, 0,
156                              poles->Array1(),&weights->Array1(),
157                              bidknots, bidmults,
158                              npoles->ChangeArray1(),&nweights->ChangeArray1(),
159                              bidknots, bidmults);
160   }
161   else {
162     BSplCLib::IncreaseDegree(Degree(), Deg, 0,
163                              poles->Array1(),
164                              BSplCLib::NoWeights(),
165                              bidknots, bidmults,
166                              npoles->ChangeArray1(),
167                              BSplCLib::NoWeights(),
168                              bidknots, bidmults);
169   }
170   
171   Init(npoles,nweights);
172 }
173
174
175 //=======================================================================
176 //function : MaxDegree
177 //purpose  : 
178 //=======================================================================
179
180 Standard_Integer Geom2d_BezierCurve::MaxDegree () 
181
182   return BSplCLib::MaxDegree(); 
183 }
184
185
186 //=======================================================================
187 //function : InsertPoleAfter
188 //purpose  : 
189 //=======================================================================
190
191 void Geom2d_BezierCurve::InsertPoleAfter
192 (const Standard_Integer Index,
193  const gp_Pnt2d& P,
194  const Standard_Real Weight)
195 {
196   Standard_Integer nbpoles = NbPoles();
197   
198   Standard_ConstructionError_Raise_if
199     (nbpoles >= Geom2d_BezierCurve::MaxDegree() ||
200      Weight <= gp::Resolution(), 
201      "Geom2d_BezierCurve::InsertPoleAfter" );
202   
203   Standard_OutOfRange_Raise_if
204     (Index < 0 || Index > nbpoles,
205      "Geom2d_BezierCurve::InsertPoleAfter");
206   
207   Standard_Integer i;
208   
209   // Insert the pole
210   Handle(TColgp_HArray1OfPnt2d) npoles =
211     new TColgp_HArray1OfPnt2d(1,nbpoles+1);
212   
213   TColgp_Array1OfPnt2d&        newpoles = npoles->ChangeArray1();
214   const TColgp_Array1OfPnt2d& oldpoles  = poles->Array1();
215   
216   for (i = 1; i <= Index; i++)
217     newpoles(i) = oldpoles(i);
218   
219   newpoles(Index+1) = P;
220   
221   for (i = Index+1; i <= nbpoles; i++)
222     newpoles(i+1) = oldpoles(i);
223   
224   
225   // Insert the weight
226   Handle(TColStd_HArray1OfReal) nweights;
227   Standard_Boolean rat = IsRational() || Abs(Weight-1.) > gp::Resolution();
228   
229   if (rat) {
230     nweights = new TColStd_HArray1OfReal(1,nbpoles+1);
231     TColStd_Array1OfReal& newweights = nweights->ChangeArray1();
232     
233     for (i = 1; i <= Index; i++)
234       if (IsRational())
235         newweights(i) = weights->Value(i);
236       else
237         newweights(i) = 1.;
238     
239     newweights(Index+1) = Weight;
240     
241     for (i = Index+1; i <= nbpoles; i++)
242       if (IsRational())
243         newweights(i+1) = weights->Value(i);
244       else
245         newweights(i+1) = 1.;
246   }
247   
248   
249   Init(npoles,nweights);
250 }
251
252
253 //=======================================================================
254 //function : InsertPoleBefore
255 //purpose  : 
256 //=======================================================================
257
258 void Geom2d_BezierCurve::InsertPoleBefore
259 (const Standard_Integer Index,
260  const gp_Pnt2d& P,
261  const Standard_Real Weight)
262 {
263   InsertPoleAfter(Index-1,P,Weight);
264 }
265
266
267 //=======================================================================
268 //function : RemovePole
269 //purpose  : 
270 //=======================================================================
271
272 void Geom2d_BezierCurve::RemovePole
273 (const Standard_Integer Index)
274 {
275   Standard_Integer nbpoles = NbPoles();
276   
277   Standard_ConstructionError_Raise_if
278     (nbpoles <= 2 , "Geom2d_BezierCurve::RemovePole" );
279   
280   Standard_OutOfRange_Raise_if
281     (Index < 1 || Index > nbpoles,
282      "Geom2d_BezierCurve::RemovePole");
283   
284   Standard_Integer i;
285   
286   // Remove the pole
287   Handle(TColgp_HArray1OfPnt2d) npoles =
288     new TColgp_HArray1OfPnt2d(1,nbpoles-1);
289   
290   TColgp_Array1OfPnt2d&        newpoles = npoles->ChangeArray1();
291   const TColgp_Array1OfPnt2d& oldpoles  = poles->Array1();
292   
293   for (i = 1; i < Index; i++)
294     newpoles(i) = oldpoles(i);
295   
296   for (i = Index+1; i <= nbpoles; i++)
297     newpoles(i-1) = oldpoles(i);
298   
299   
300   // Remove the weight
301   Handle(TColStd_HArray1OfReal) nweights;
302   
303   if (IsRational()) {
304     nweights = new TColStd_HArray1OfReal(1,nbpoles-1);
305     TColStd_Array1OfReal&       newweights = nweights->ChangeArray1();
306     const TColStd_Array1OfReal& oldweights = weights->Array1();
307     
308     for (i = 1; i < Index; i++)
309       newweights(i) = oldweights(i);
310     
311     for (i = Index+1; i <= nbpoles; i++)
312       newweights(i-1) = oldweights(i);
313   }
314   
315   Init(npoles,nweights);
316 }
317
318
319 //=======================================================================
320 //function : Reverse
321 //purpose  : 
322 //=======================================================================
323
324 void Geom2d_BezierCurve::Reverse ()
325 {
326   gp_Pnt2d P;
327   Standard_Integer i, nbpoles = NbPoles();
328   TColgp_Array1OfPnt2d & cpoles = poles->ChangeArray1();
329   
330   // reverse poles
331   for (i = 1; i <= nbpoles / 2; i++) {
332     P = cpoles(i);
333     cpoles(i) = cpoles(nbpoles-i+1);
334     cpoles(nbpoles-i+1) = P;
335   }
336   
337   // reverse weights
338   if (IsRational()) {
339     TColStd_Array1OfReal & cweights = weights->ChangeArray1();
340     Standard_Real w;
341     for (i = 1; i <= nbpoles / 2; i++) {
342       w = cweights(i);
343       cweights(i) = cweights(nbpoles-i+1);
344       cweights(nbpoles-i+1) = w;
345     }
346   }
347 }
348
349
350 //=======================================================================
351 //function : ReversedParameter
352 //purpose  : 
353 //=======================================================================
354
355 Standard_Real Geom2d_BezierCurve::ReversedParameter
356 ( const Standard_Real U) const 
357 {
358   return ( 1. - U);
359 }
360
361
362 //=======================================================================
363 //function : Segment
364 //purpose  : 
365 //=======================================================================
366
367 void Geom2d_BezierCurve::Segment
368 (const Standard_Real U1, const Standard_Real U2)
369 {
370   closed =  (Abs(Value(U1).Distance (Value(U2))) <= gp::Resolution());
371 //
372 //   WARNING : when calling trimming be careful that the cache
373 //   is computed regarding 0.0e0 and not 1.0e0 
374 //
375   TColStd_Array1OfReal bidflatknots(BSplCLib::FlatBezierKnots(Degree()), 1, 2 * (Degree() + 1));
376   TColgp_Array1OfPnt2d coeffs(1, poles->Size());
377   if (IsRational()) {
378     TColStd_Array1OfReal wcoeffs(1, poles->Size());
379     BSplCLib::BuildCache(0.0, 1.0, 0, Degree(), bidflatknots,
380         poles->Array1(), &weights->Array1(), coeffs, &wcoeffs);
381     PLib::Trimming(U1, U2, coeffs, &wcoeffs);
382     PLib::CoefficientsPoles(coeffs, &wcoeffs, poles->ChangeArray1(), &weights->ChangeArray1());
383   }
384   else {
385     BSplCLib::BuildCache(0.0, 1.0, 0, Degree(), bidflatknots,
386         poles->Array1(), BSplCLib::NoWeights(), coeffs, BSplCLib::NoWeights());
387     PLib::Trimming(U1, U2, coeffs, PLib::NoWeights());
388     PLib::CoefficientsPoles(coeffs, PLib::NoWeights(), poles->ChangeArray1(), PLib::NoWeights());
389   }
390 }
391
392
393 //=======================================================================
394 //function : SetPole
395 //purpose  : 
396 //=======================================================================
397
398 void Geom2d_BezierCurve::SetPole
399 (const Standard_Integer Index,
400  const gp_Pnt2d& P)
401 {
402   Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPoles(),
403                                 "Geom2d_BezierCurve::SetPole");
404   
405   TColgp_Array1OfPnt2d& cpoles = poles->ChangeArray1();
406   cpoles(Index) = P;
407   
408   if (Index == 1 || Index == cpoles.Length()) {
409     closed = (cpoles(1).Distance(cpoles(NbPoles())) <= gp::Resolution());
410   }
411 }
412
413
414 //=======================================================================
415 //function : SetPole
416 //purpose  : 
417 //=======================================================================
418
419 void Geom2d_BezierCurve::SetPole
420 (const Standard_Integer Index,
421  const gp_Pnt2d& P,
422  const Standard_Real Weight)
423 {
424   SetPole(Index,P);
425   SetWeight(Index,Weight);
426 }
427
428
429 //=======================================================================
430 //function : SetWeight
431 //purpose  : 
432 //=======================================================================
433
434 void Geom2d_BezierCurve::SetWeight
435 (const Standard_Integer Index,
436  const Standard_Real Weight)
437 {
438   Standard_Integer nbpoles = NbPoles();
439   
440   Standard_OutOfRange_Raise_if
441     (Index < 1 || Index > nbpoles,
442      "Geom2d_BezierCurve::SetWeight");
443   Standard_ConstructionError_Raise_if
444     (Weight <= gp::Resolution (),
445      "Geom2d_BezierCurve::SetWeight");
446   
447   
448   // compute new rationality
449   Standard_Boolean wasrat = IsRational();
450   if (!wasrat) {
451     // a weight of 1. does not turn to rational
452     if (Abs(Weight - 1.) <= gp::Resolution()) return;
453     
454     // set weights of 1.
455     weights = new TColStd_HArray1OfReal(1,nbpoles);
456     weights->Init(1.);
457   }
458   
459   TColStd_Array1OfReal & cweights = weights->ChangeArray1();
460   cweights(Index) = Weight;
461   
462   // is it turning into non rational
463   if (wasrat && !Rational(cweights))
464     weights.Nullify();
465 }
466
467
468 //=======================================================================
469 //function : IsClosed
470 //purpose  : 
471 //=======================================================================
472
473 Standard_Boolean Geom2d_BezierCurve::IsClosed () const 
474 {
475   return closed; 
476 }
477
478
479 //=======================================================================
480 //function : IsCN
481 //purpose  : 
482 //=======================================================================
483
484 Standard_Boolean Geom2d_BezierCurve::IsCN (const Standard_Integer ) const 
485 {
486   return Standard_True; 
487 }
488
489
490 //=======================================================================
491 //function : IsPeriodic
492 //purpose  : 
493 //=======================================================================
494
495 Standard_Boolean Geom2d_BezierCurve::IsPeriodic () const 
496 {
497   return Standard_False; 
498 }
499
500
501 //=======================================================================
502 //function : IsRational
503 //purpose  : 
504 //=======================================================================
505
506 Standard_Boolean Geom2d_BezierCurve::IsRational () const 
507 {  
508   return !weights.IsNull(); 
509 }
510
511
512 //=======================================================================
513 //function : Continuity
514 //purpose  : 
515 //=======================================================================
516
517 GeomAbs_Shape Geom2d_BezierCurve::Continuity () const 
518
519   return GeomAbs_CN; 
520 }
521
522
523 //=======================================================================
524 //function : Degree
525 //purpose  : 
526 //=======================================================================
527
528 Standard_Integer Geom2d_BezierCurve::Degree () const 
529 {
530   return poles->Length()-1;
531 }
532
533
534 //=======================================================================
535 //function : D0
536 //purpose  : 
537 //=======================================================================
538
539 void Geom2d_BezierCurve::D0 (const Standard_Real U, gp_Pnt2d& P ) const
540 {
541   BSplCLib::D0(U, Poles(), Weights(), P);
542 }
543
544 //=======================================================================
545 //function : D1
546 //purpose  : 
547 //=======================================================================
548
549 void Geom2d_BezierCurve::D1(const Standard_Real U, 
550                             gp_Pnt2d& P, 
551                             gp_Vec2d& V1) const
552 {
553   BSplCLib::D1(U, Poles(), Weights(), P, V1);
554 }
555
556 //=======================================================================
557 //function : D2
558 //purpose  : 
559 //=======================================================================
560
561 void Geom2d_BezierCurve::D2 (const Standard_Real U,
562                              gp_Pnt2d& P,
563                              gp_Vec2d& V1,
564                              gp_Vec2d& V2) const
565 {
566   BSplCLib::D2(U, Poles(), Weights(), P, V1, V2);
567 }
568
569 //=======================================================================
570 //function : D3
571 //purpose  : 
572 //=======================================================================
573
574 void Geom2d_BezierCurve::D3 (const Standard_Real U,
575                              gp_Pnt2d& P,
576                              gp_Vec2d& V1,
577                              gp_Vec2d& V2,
578                              gp_Vec2d& V3) const
579 {
580   BSplCLib::D3(U, Poles(), Weights(), P, V1, V2, V3);
581 }
582
583 //=======================================================================
584 //function : DN
585 //purpose  : 
586 //=======================================================================
587
588 gp_Vec2d Geom2d_BezierCurve::DN (const Standard_Real U,
589                                  const Standard_Integer N) const
590 {
591   Standard_RangeError_Raise_if (N < 1, "Geom2d_BezierCurve::DN");
592   gp_Vec2d V;
593   
594   TColStd_Array1OfReal bidknots(1,2); bidknots(1) = 0.; bidknots(2) = 1.;
595   TColStd_Array1OfInteger bidmults(1,2); bidmults.Init(Degree() + 1);
596   
597   if (IsRational())
598     BSplCLib::DN(U,N,0,Degree(),Standard_False,
599                  poles->Array1(),&weights->Array1(),
600                  bidknots,&bidmults,V);
601   else 
602     BSplCLib::DN(U,N,0,Degree(),Standard_False,
603                  poles->Array1(),
604                  BSplCLib::NoWeights(),
605                  bidknots,&bidmults,V);
606   return V;
607 }
608
609 //=======================================================================
610 //function : EndPoint
611 //purpose  : 
612 //=======================================================================
613
614 gp_Pnt2d Geom2d_BezierCurve::EndPoint () const
615 {
616   return poles->Value (poles->Upper());
617 }
618
619
620 //=======================================================================
621 //function : FirstParameter
622 //purpose  : 
623 //=======================================================================
624
625 Standard_Real Geom2d_BezierCurve::FirstParameter () const 
626 {
627   return 0.0; 
628 }
629
630
631 //=======================================================================
632 //function : LastParameter
633 //purpose  : 
634 //=======================================================================
635
636 Standard_Real Geom2d_BezierCurve::LastParameter () const 
637 {
638   return 1.0; 
639 }
640
641
642 //=======================================================================
643 //function : NbPoles
644 //purpose  : 
645 //=======================================================================
646
647 Standard_Integer Geom2d_BezierCurve::NbPoles () const 
648 {
649   return poles->Length(); 
650 }
651
652
653 //=======================================================================
654 //function : Pole
655 //purpose  : 
656 //=======================================================================
657
658 const gp_Pnt2d& Geom2d_BezierCurve::Pole (const Standard_Integer Index) const
659 {
660   Standard_OutOfRange_Raise_if (Index < 1 || Index > poles->Length(),
661                                 "Geom2d_BezierCurve::Pole");
662   return poles->Value(Index);
663 }
664
665
666 //=======================================================================
667 //function : Poles
668 //purpose  : 
669 //=======================================================================
670
671 void Geom2d_BezierCurve::Poles (TColgp_Array1OfPnt2d& P) const
672 {
673   Standard_DimensionError_Raise_if (P.Length() != poles->Length(),
674                                     "Geom2d_BezierCurve::Poles");
675   P = poles->Array1();
676 }
677
678
679 //=======================================================================
680 //function : StartPoint
681 //purpose  : 
682 //=======================================================================
683
684 gp_Pnt2d Geom2d_BezierCurve::StartPoint () const
685 {
686   return poles->Value(1);
687 }
688
689
690 //=======================================================================
691 //function : Weight
692 //purpose  : 
693 //=======================================================================
694
695 Standard_Real Geom2d_BezierCurve::Weight
696 (const Standard_Integer Index) const
697 {
698   Standard_OutOfRange_Raise_if (Index < 1 || Index > weights->Length(),
699                                 "Geom2d_BezierCurve::Weight");
700   if (IsRational())
701     return weights->Value(Index);
702   else
703     return 1.;
704 }
705
706
707 //=======================================================================
708 //function : Weights
709 //purpose  : 
710 //=======================================================================
711
712 void Geom2d_BezierCurve::Weights
713 (TColStd_Array1OfReal& W) const
714 {
715   
716   Standard_Integer nbpoles = NbPoles();
717   Standard_DimensionError_Raise_if (W.Length() != nbpoles,
718                                     "Geom2d_BezierCurve::Weights");
719   if (IsRational())
720     W = weights->Array1();
721   else {
722     Standard_Integer i;
723     for (i = 1; i <= nbpoles; i++)
724       W(i) = 1.;
725   }
726 }
727
728
729 //=======================================================================
730 //function : Transform
731 //purpose  : 
732 //=======================================================================
733
734 void Geom2d_BezierCurve::Transform (const gp_Trsf2d& T)
735 {
736   Standard_Integer nbpoles = NbPoles();
737   TColgp_Array1OfPnt2d & cpoles = poles->ChangeArray1();
738   
739   for (Standard_Integer i = 1; i <= nbpoles; i++) 
740     cpoles (i).Transform(T);
741 }
742
743
744 //=======================================================================
745 //function : Resolution
746 //purpose  : 
747 //=======================================================================
748
749 void Geom2d_BezierCurve::Resolution(const Standard_Real ToleranceUV,
750                                     Standard_Real &     UTolerance)
751 {
752   if(!maxderivinvok){
753     TColStd_Array1OfReal bidflatknots(1, 2*(Degree()+1));
754     for(Standard_Integer i = 1; i <= Degree()+1; i++){
755       bidflatknots(i) = 0.;
756       bidflatknots(i + Degree() +1) = 1.;
757     }
758     
759     if (IsRational()) {  
760       BSplCLib::Resolution(poles->Array1(),
761                            &weights->Array1(),
762                            poles->Length(),
763                            bidflatknots,
764                            Degree(),
765                            1.,
766                            maxderivinv) ;
767     }
768     else {
769       BSplCLib::Resolution(poles->Array1(),
770                            BSplCLib::NoWeights(),
771                            poles->Length(),
772                            bidflatknots,
773                            Degree(),
774                            1.,
775                            maxderivinv) ;
776     }
777     maxderivinvok = 1;
778   }
779   UTolerance = ToleranceUV * maxderivinv;
780 }
781
782
783 //=======================================================================
784 //function : Copy
785 //purpose  : 
786 //=======================================================================
787
788 Handle(Geom2d_Geometry) Geom2d_BezierCurve::Copy() const {
789   
790   Handle(Geom2d_BezierCurve) C;
791   if (IsRational())
792     C = new Geom2d_BezierCurve (poles->Array1(),weights->Array1());
793   else
794     C = new Geom2d_BezierCurve (poles->Array1());
795   return C;
796 }
797
798
799 //=======================================================================
800 //function : Init
801 //purpose  : 
802 //=======================================================================
803
804 void Geom2d_BezierCurve::Init
805 (const Handle(TColgp_HArray1OfPnt2d)&   Poles, 
806  const Handle(TColStd_HArray1OfReal)& Weights)
807 {
808   Standard_Integer nbpoles = Poles->Length();
809   // closed ?
810   const TColgp_Array1OfPnt2d&   cpoles   = Poles->Array1();
811   closed = cpoles(1).Distance(cpoles(nbpoles)) <= gp::Resolution(); 
812   
813   // rational
814   rational = !Weights.IsNull();
815   
816   // set fields
817   poles = Poles;
818   if (rational)
819     weights = Weights;
820   else
821     weights.Nullify();
822 }
823
824 //=======================================================================
825 //function : DumpJson
826 //purpose  : 
827 //=======================================================================
828 void Geom2d_BezierCurve::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
829 {
830   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
831
832   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom2d_BoundedCurve)
833
834   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, rational)
835   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, closed)
836   if (!poles.IsNull())
837     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, poles->Size())
838   if (!weights.IsNull())
839     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, weights->Size())
840
841   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, maxderivinv)
842   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, maxderivinvok)
843 }