0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / gp / gp_Circ.lxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #include <Standard_ConstructionError.hxx>
21 #include <gp_Pnt.hxx>
22 #include <gp_Ax1.hxx>
23 #include <gp_Ax2.hxx>
24
25 inline gp_Circ::gp_Circ () : radius(RealLast())
26 {  }
27
28 inline gp_Circ::gp_Circ (const gp_Ax2& A2,
29                          const Standard_Real R) : pos(A2), radius(R)
30 {
31   Standard_ConstructionError_Raise_if (R < 0.0, "");
32 }
33
34 inline void gp_Circ::SetAxis (const gp_Ax1& A1)
35 { pos.SetAxis (A1); }
36
37 inline void gp_Circ::SetLocation (const gp_Pnt& P)
38 { pos.SetLocation (P); }
39
40 inline void gp_Circ::SetPosition (const gp_Ax2& A2)
41 { pos = A2; }
42
43 inline void gp_Circ::SetRadius (const Standard_Real R)
44
45   Standard_ConstructionError_Raise_if (R < 0.0, "");
46   radius = R;
47 }
48
49 inline   Standard_Real gp_Circ::Area() const
50 { return M_PI * radius * radius; }
51
52 inline const gp_Ax1& gp_Circ::Axis () const
53 { return pos.Axis(); }
54
55 inline   Standard_Real gp_Circ::Length() const
56 { return 2. * M_PI * radius; }
57
58 inline const gp_Pnt& gp_Circ::Location () const
59 { return pos.Location(); }
60
61 inline   const gp_Ax2& gp_Circ::Position() const
62 { return pos; }
63
64 inline   Standard_Real gp_Circ::Radius() const
65 { return radius; }
66
67 inline gp_Ax1 gp_Circ::XAxis () const
68 {return gp_Ax1(pos.Location(), pos.XDirection());}
69
70 inline gp_Ax1 gp_Circ::YAxis () const
71 {return gp_Ax1(pos.Location(), pos.YDirection());}
72
73 inline Standard_Real gp_Circ::Distance (const gp_Pnt& P) const
74 { return sqrt(SquareDistance(P)); }
75
76 inline Standard_Real gp_Circ::SquareDistance (const gp_Pnt& P) const
77 {
78   gp_Vec V(Location(),P);
79   Standard_Real x = V.Dot(pos.XDirection());
80   Standard_Real y = V.Dot(pos.YDirection());
81   Standard_Real z = V.Dot(pos.Direction ());
82   Standard_Real t = sqrt( x*x + y*y) - radius;
83   return (t*t + z*z);
84 }
85
86 inline Standard_Boolean gp_Circ::Contains
87 (const gp_Pnt& P,
88  const Standard_Real LinearTolerance) const
89 { return Distance(P) <= LinearTolerance; }
90
91 inline void gp_Circ::Rotate (const gp_Ax1& A1,
92                              const Standard_Real Ang)
93 { pos.Rotate(A1, Ang); }
94
95 inline gp_Circ gp_Circ::Rotated (const gp_Ax1& A1,
96                                  const Standard_Real Ang) const
97 {
98   gp_Circ C = *this;
99   C.pos.Rotate(A1, Ang);
100   return C; 
101 }
102
103 inline void gp_Circ::Scale (const gp_Pnt& P,
104                             const Standard_Real S)
105 {
106   radius *= S;
107   if (radius < 0) radius = - radius;
108   pos.Scale(P, S);
109 }
110
111 inline gp_Circ gp_Circ::Scaled (const gp_Pnt& P,
112                                 const Standard_Real S) const 
113 {
114   gp_Circ C = *this;
115   C.radius *= S;
116   if (C.radius < 0) C.radius = - C.radius;
117   C.pos.Scale(P, S);
118   return C; 
119 }
120
121 inline void gp_Circ::Transform (const gp_Trsf& T)
122 {
123   radius *= T.ScaleFactor();
124   if (radius < 0) radius = - radius;
125   pos.Transform(T);
126 }
127
128 inline gp_Circ gp_Circ::Transformed (const gp_Trsf& T) const
129 {
130   gp_Circ C = *this;
131   C.radius *= T.ScaleFactor();
132   if (C.radius < 0) C.radius = - C.radius;
133   C.pos.Transform(T);
134   return C;
135 }
136
137 inline void gp_Circ::Translate (const gp_Vec& V)
138 { pos.Translate(V); }
139
140 inline gp_Circ gp_Circ::Translated (const gp_Vec& V) const 
141 {
142   gp_Circ C = *this;
143   C.pos.Translate(V);
144   return C; 
145 }
146
147 inline void gp_Circ::Translate (const gp_Pnt& P1,
148                                 const gp_Pnt& P2)
149 {pos.Translate(P1,P2);}
150
151 inline gp_Circ gp_Circ::Translated (const gp_Pnt& P1,
152                                     const gp_Pnt& P2) const
153 {
154   gp_Circ C = *this;
155   C.pos.Translate(P1, P2);
156   return C; 
157 }
158