0022915: crash in iges reader TransferRoots()
[occt.git] / src / IGESGeom / IGESGeom_CircularArc.cxx
1 //--------------------------------------------------------------------
2 //
3 //  File Name : IGESGeom_CircularArc.cxx
4 //  Date      :
5 //  Author    : CKY / Contract Toubro-Larsen
6 //  Copyright : MATRA-DATAVISION 1993
7 //
8 //--------------------------------------------------------------------
9
10 #include <IGESGeom_CircularArc.ixx>
11 #include <gp_Dir2d.hxx>
12 #include <gp_GTrsf.hxx>
13
14
15     IGESGeom_CircularArc::IGESGeom_CircularArc ()    {  }
16
17     void IGESGeom_CircularArc::Init 
18   (const Standard_Real aZT, const gp_XY&  aCenter,
19    const gp_XY& aStart,     const gp_XY&  anEnd) 
20 {
21   theZT     = aZT;
22   theCenter = aCenter;
23   theStart  = aStart;
24   theEnd    = anEnd;
25   InitTypeAndForm(100,0);
26 }
27
28
29     gp_Pnt2d IGESGeom_CircularArc::Center () const
30 {
31   gp_Pnt2d Center(theCenter);
32   return Center;
33 }
34
35     gp_Pnt IGESGeom_CircularArc::TransformedCenter () const
36 {
37   gp_XYZ Center(theCenter.X(), theCenter.Y(), theZT);
38   if (HasTransf()) Location().Transforms(Center);
39   gp_Pnt transCenter(Center);
40   return transCenter;
41 }
42
43     gp_Pnt2d IGESGeom_CircularArc::StartPoint () const
44 {
45   gp_Pnt2d Start(theStart);
46   return Start;
47 }
48
49     gp_Pnt IGESGeom_CircularArc::TransformedStartPoint () const
50 {
51   gp_XYZ Start(theStart.X(), theStart.Y(), theZT);
52   if (HasTransf()) Location().Transforms(Start);
53   gp_Pnt transStart(Start);
54   return transStart;
55 }
56
57     Standard_Real IGESGeom_CircularArc::ZPlane () const
58 {
59   return theZT;
60 }
61
62     gp_Pnt2d IGESGeom_CircularArc::EndPoint () const
63 {
64   gp_Pnt2d End(theEnd);
65   return End;
66 }
67
68     gp_Pnt IGESGeom_CircularArc::TransformedEndPoint () const
69 {
70   gp_XYZ End(theEnd.X(), theEnd.Y(), theZT);
71   if (HasTransf()) Location().Transforms(End);
72   gp_Pnt transEnd(End);
73   return transEnd;
74 }
75
76     Standard_Real IGESGeom_CircularArc::Radius () const
77 {
78   Standard_Real x1, y1, x2, y2;
79   x1 = theStart.X();
80   y1 = theStart.Y();
81   x2 = theCenter.X();
82   y2 = theCenter.Y();
83
84   Standard_Real radius = Sqrt(Square(x2 - x1) + Square(y2 - y1));
85   return radius;
86 }
87
88     Standard_Real IGESGeom_CircularArc::Angle () const
89 {
90   Standard_Real x1, y1, x2, y2, xc, yc;
91   xc = theCenter.X();
92   yc = theCenter.Y();
93   x1 = theStart.X();
94   y1 = theStart.Y();
95   x2 = theEnd.X();
96   y2 = theEnd.Y();
97   gp_Dir2d dir1(x1-xc, y1-yc);   // After shifting the centre of
98   // arc to the origin
99   gp_Dir2d dir2(x2-xc, y2-yc);   // After shifting the centre of
100   // arc to the origin
101   Standard_Real t = dir1.Angle(dir2);
102   return t + (t > 0 ? 0 : 2*M_PI);
103 }
104
105     gp_Dir IGESGeom_CircularArc::Axis () const
106 {
107   gp_Dir axis(0.0 , 0.0, 1.0);
108   return axis;
109 }
110
111     gp_Dir IGESGeom_CircularArc::TransformedAxis () const
112 {
113   gp_XYZ axis(0.0 , 0.0, 1.0);
114   if (!HasTransf()) return gp_Dir(axis);
115   gp_GTrsf loc = Location();
116   loc.SetTranslationPart (gp_XYZ(0.,0.,0.));
117   loc.Transforms(axis);
118   return gp_Dir(axis);
119 }
120
121     Standard_Boolean IGESGeom_CircularArc::IsClosed () const
122 {
123   return (Abs (theStart.X() - theEnd.X()) < Precision::PConfusion() && Abs (theStart.Y() - theEnd.Y()) < Precision::PConfusion());
124 }