b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #include <Standard_ConstructionError.hxx> |
16 | |
17 | inline gp_Circ2d::gp_Circ2d () : radius(RealLast()) |
18 | { } |
19 | |
20 | inline gp_Circ2d::gp_Circ2d (const gp_Ax2d& XAxis, |
21 | const Standard_Real Radius, |
22 | const Standard_Boolean Sense) : radius(Radius) |
23 | { |
2d2b3d53 |
24 | Standard_ConstructionError_Raise_if (Radius < 0.0, "gp_Circ2d() - radius should be positive number"); |
7fd59977 |
25 | pos = gp_Ax22d(XAxis,Sense); |
26 | } |
27 | |
28 | inline gp_Circ2d::gp_Circ2d (const gp_Ax22d& Axis, |
29 | const Standard_Real Radius) : |
30 | pos(Axis), |
31 | radius(Radius) |
2d2b3d53 |
32 | { |
33 | Standard_ConstructionError_Raise_if (Radius < 0.0, "gp_Circ2d() - radius should be positive number"); |
34 | } |
7fd59977 |
35 | |
36 | inline void gp_Circ2d::SetLocation (const gp_Pnt2d& P) |
37 | { pos.SetLocation (P); } |
38 | |
39 | inline void gp_Circ2d::SetXAxis (const gp_Ax2d& A) |
40 | { pos.SetXAxis(A); } |
41 | |
42 | inline void gp_Circ2d::SetAxis (const gp_Ax22d& A) |
43 | { pos.SetAxis(A);} |
44 | |
45 | inline void gp_Circ2d::SetYAxis (const gp_Ax2d& A) |
46 | { pos.SetYAxis(A); } |
47 | |
48 | inline void gp_Circ2d::SetRadius (const Standard_Real Radius) |
49 | { |
2d2b3d53 |
50 | Standard_ConstructionError_Raise_if (Radius < 0.0, "gp_Circ2d::SetRadius() - radius should be positive number"); |
7fd59977 |
51 | radius = Radius; |
52 | } |
53 | |
54 | inline Standard_Real gp_Circ2d::Area() const |
c6541a0c |
55 | { return M_PI * radius * radius; } |
7fd59977 |
56 | |
57 | inline void gp_Circ2d::Coefficients (Standard_Real& A, |
58 | Standard_Real& B, |
59 | Standard_Real& C, |
60 | Standard_Real& D, |
61 | Standard_Real& E, |
62 | Standard_Real& F) const |
63 | { |
64 | Standard_Real Xc = pos.Location().X(); |
65 | Standard_Real Yc = pos.Location().Y(); |
66 | A = 1.0; |
67 | B = 1.0; |
68 | C = 0.0; |
69 | D = - Xc; |
70 | E = - Yc; |
71 | F = Xc * Xc + Yc * Yc - radius * radius; |
72 | } |
73 | |
74 | inline Standard_Boolean gp_Circ2d::Contains |
75 | (const gp_Pnt2d& P, |
76 | const Standard_Real LinearTolerance) const |
77 | { return Distance(P) <= LinearTolerance; } |
78 | |
79 | inline Standard_Real gp_Circ2d::Distance (const gp_Pnt2d& P) const |
80 | { |
81 | gp_XY Coord = P.XY(); |
82 | Coord.Subtract (pos.Location().XY()); |
83 | Standard_Real D = radius - Coord.Modulus(); |
84 | if (D < 0) D = - D; |
85 | return D; |
86 | } |
87 | |
88 | inline Standard_Real gp_Circ2d::SquareDistance (const gp_Pnt2d& P) const |
89 | { |
90 | gp_XY Coord = P.XY(); |
91 | Coord.Subtract (pos.Location().XY()); |
92 | Standard_Real D = radius - Coord.Modulus(); |
93 | return D * D; |
94 | } |
95 | |
96 | inline Standard_Real gp_Circ2d::Length() const |
c6541a0c |
97 | { return 2. * M_PI * radius; } |
7fd59977 |
98 | |
99 | inline const gp_Pnt2d& gp_Circ2d::Location () const |
100 | {return pos.Location(); } |
101 | |
102 | inline Standard_Real gp_Circ2d::Radius() const |
103 | { return radius; } |
104 | |
105 | inline const gp_Ax22d& gp_Circ2d::Axis () const |
106 | { return pos; } |
107 | |
108 | inline const gp_Ax22d& gp_Circ2d::Position () const |
109 | { return pos; } |
110 | |
111 | inline gp_Ax2d gp_Circ2d::XAxis () const |
112 | { return gp_Ax2d (pos.XAxis()); } |
113 | |
114 | inline gp_Ax2d gp_Circ2d::YAxis () const |
115 | { return gp_Ax2d (pos.YAxis()); } |
116 | |
117 | inline void gp_Circ2d::Reverse() |
118 | { |
119 | gp_Dir2d Temp = pos.YDirection (); |
120 | Temp.Reverse (); |
121 | pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); |
122 | } |
123 | |
124 | inline gp_Circ2d gp_Circ2d::Reversed() const |
125 | { |
126 | gp_Circ2d C = *this; |
127 | gp_Dir2d Temp = pos.YDirection (); |
128 | Temp.Reverse (); |
129 | C.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); |
130 | return C; |
131 | } |
132 | |
133 | inline Standard_Boolean gp_Circ2d::IsDirect() const |
134 | { return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; } |
135 | |
136 | inline void gp_Circ2d::Rotate (const gp_Pnt2d& P, |
137 | const Standard_Real Ang) |
138 | {pos.Rotate (P, Ang);} |
139 | |
140 | inline gp_Circ2d gp_Circ2d::Rotated (const gp_Pnt2d& P, |
141 | const Standard_Real Ang) const |
142 | { |
143 | gp_Circ2d C = *this; |
144 | C.pos.Rotate (P, Ang); |
145 | return C; |
146 | } |
147 | |
148 | inline void gp_Circ2d::Scale (const gp_Pnt2d& P, |
149 | const Standard_Real S) |
150 | { |
151 | radius *= S; |
152 | if (radius < 0) radius = - radius; |
153 | pos.Scale(P, S); |
154 | } |
155 | |
156 | inline gp_Circ2d gp_Circ2d::Scaled (const gp_Pnt2d& P, |
157 | const Standard_Real S) const |
158 | { |
159 | gp_Circ2d C = *this; |
160 | C.radius *= S; |
161 | if (C.radius < 0) C.radius = - C.radius; |
162 | C.pos.Scale(P, S); |
163 | return C; |
164 | } |
165 | |
166 | inline void gp_Circ2d::Transform (const gp_Trsf2d& T) |
167 | { |
168 | radius *= T.ScaleFactor(); |
169 | if (radius < 0) radius = - radius; |
170 | pos.Transform(T); |
171 | } |
172 | |
173 | inline gp_Circ2d gp_Circ2d::Transformed (const gp_Trsf2d& T) const |
174 | { |
175 | gp_Circ2d C = *this; |
176 | C.radius *= T.ScaleFactor(); |
177 | if (C.radius < 0) C.radius = - C.radius; |
178 | C.pos.Transform(T); |
179 | return C; |
180 | } |
181 | |
182 | inline void gp_Circ2d::Translate (const gp_Vec2d& V) |
183 | { pos.Translate(V); } |
184 | |
185 | inline gp_Circ2d gp_Circ2d::Translated (const gp_Vec2d& V) const |
186 | { |
187 | gp_Circ2d C = *this; |
188 | C.pos.Translate(V); |
189 | return C; |
190 | } |
191 | |
192 | inline void gp_Circ2d::Translate (const gp_Pnt2d& P1, |
193 | const gp_Pnt2d& P2) |
194 | { pos.Translate(P1, P2); } |
195 | |
196 | inline gp_Circ2d gp_Circ2d::Translated (const gp_Pnt2d& P1, |
197 | const gp_Pnt2d& P2) const |
198 | { |
199 | gp_Circ2d C = *this; |
200 | C.pos.Translate(P1, P2); |
201 | return C; |
202 | } |
203 | |