39006dc3f169ca9b3907605067f8bfa4616757f9
[occt.git] / src / gp / gp_Circ.lxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <Standard_ConstructionError.hxx>
16 #include <gp_Pnt.hxx>
17 #include <gp_Ax1.hxx>
18 #include <gp_Ax2.hxx>
19
20 inline gp_Circ::gp_Circ () : radius(RealLast())
21 {  }
22
23 inline gp_Circ::gp_Circ (const gp_Ax2& A2,
24                          const Standard_Real R) : pos(A2), radius(R)
25 {
26   Standard_ConstructionError_Raise_if (R < 0.0, "gp_Circ() - radius should be positive number");
27 }
28
29 inline void gp_Circ::SetAxis (const gp_Ax1& A1)
30 { pos.SetAxis (A1); }
31
32 inline void gp_Circ::SetLocation (const gp_Pnt& P)
33 { pos.SetLocation (P); }
34
35 inline void gp_Circ::SetPosition (const gp_Ax2& A2)
36 { pos = A2; }
37
38 inline void gp_Circ::SetRadius (const Standard_Real R)
39
40   Standard_ConstructionError_Raise_if (R < 0.0, "gp_Circ::SetRadius() - radius should be positive number");
41   radius = R;
42 }
43
44 inline   Standard_Real gp_Circ::Area() const
45 { return M_PI * radius * radius; }
46
47 inline const gp_Ax1& gp_Circ::Axis () const
48 { return pos.Axis(); }
49
50 inline   Standard_Real gp_Circ::Length() const
51 { return 2. * M_PI * radius; }
52
53 inline const gp_Pnt& gp_Circ::Location () const
54 { return pos.Location(); }
55
56 inline   const gp_Ax2& gp_Circ::Position() const
57 { return pos; }
58
59 inline   Standard_Real gp_Circ::Radius() const
60 { return radius; }
61
62 inline gp_Ax1 gp_Circ::XAxis () const
63 {return gp_Ax1(pos.Location(), pos.XDirection());}
64
65 inline gp_Ax1 gp_Circ::YAxis () const
66 {return gp_Ax1(pos.Location(), pos.YDirection());}
67
68 inline Standard_Real gp_Circ::Distance (const gp_Pnt& P) const
69 { return sqrt(SquareDistance(P)); }
70
71 inline Standard_Real gp_Circ::SquareDistance (const gp_Pnt& P) const
72 {
73   gp_Vec V(Location(),P);
74   Standard_Real x = V.Dot(pos.XDirection());
75   Standard_Real y = V.Dot(pos.YDirection());
76   Standard_Real z = V.Dot(pos.Direction ());
77   Standard_Real t = sqrt( x*x + y*y) - radius;
78   return (t*t + z*z);
79 }
80
81 inline Standard_Boolean gp_Circ::Contains
82 (const gp_Pnt& P,
83  const Standard_Real LinearTolerance) const
84 { return Distance(P) <= LinearTolerance; }
85
86 inline void gp_Circ::Rotate (const gp_Ax1& A1,
87                              const Standard_Real Ang)
88 { pos.Rotate(A1, Ang); }
89
90 inline gp_Circ gp_Circ::Rotated (const gp_Ax1& A1,
91                                  const Standard_Real Ang) const
92 {
93   gp_Circ C = *this;
94   C.pos.Rotate(A1, Ang);
95   return C; 
96 }
97
98 inline void gp_Circ::Scale (const gp_Pnt& P,
99                             const Standard_Real S)
100 {
101   radius *= S;
102   if (radius < 0) radius = - radius;
103   pos.Scale(P, S);
104 }
105
106 inline gp_Circ gp_Circ::Scaled (const gp_Pnt& P,
107                                 const Standard_Real S) const 
108 {
109   gp_Circ C = *this;
110   C.radius *= S;
111   if (C.radius < 0) C.radius = - C.radius;
112   C.pos.Scale(P, S);
113   return C; 
114 }
115
116 inline void gp_Circ::Transform (const gp_Trsf& T)
117 {
118   radius *= T.ScaleFactor();
119   if (radius < 0) radius = - radius;
120   pos.Transform(T);
121 }
122
123 inline gp_Circ gp_Circ::Transformed (const gp_Trsf& T) const
124 {
125   gp_Circ C = *this;
126   C.radius *= T.ScaleFactor();
127   if (C.radius < 0) C.radius = - C.radius;
128   C.pos.Transform(T);
129   return C;
130 }
131
132 inline void gp_Circ::Translate (const gp_Vec& V)
133 { pos.Translate(V); }
134
135 inline gp_Circ gp_Circ::Translated (const gp_Vec& V) const 
136 {
137   gp_Circ C = *this;
138   C.pos.Translate(V);
139   return C; 
140 }
141
142 inline void gp_Circ::Translate (const gp_Pnt& P1,
143                                 const gp_Pnt& P2)
144 {pos.Translate(P1,P2);}
145
146 inline gp_Circ gp_Circ::Translated (const gp_Pnt& P1,
147                                     const gp_Pnt& P2) const
148 {
149   gp_Circ C = *this;
150   C.pos.Translate(P1, P2);
151   return C; 
152 }
153