0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / Geom / Geom_Circle.cxx
1 // Created on: 1993-03-10
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
18 #include <ElCLib.hxx>
19 #include <Geom_Circle.hxx>
20 #include <Geom_Geometry.hxx>
21 #include <gp_Ax2.hxx>
22 #include <gp_Circ.hxx>
23 #include <gp_Pnt.hxx>
24 #include <gp_Trsf.hxx>
25 #include <gp_Vec.hxx>
26 #include <gp_XYZ.hxx>
27 #include <Standard_ConstructionError.hxx>
28 #include <Standard_RangeError.hxx>
29 #include <Standard_Type.hxx>
30
31 IMPLEMENT_STANDARD_RTTIEXT(Geom_Circle,Geom_Conic)
32
33 typedef Geom_Circle         Circle;
34 typedef gp_Ax2  Ax2;
35 typedef gp_Pnt  Pnt;
36 typedef gp_Trsf Trsf;
37 typedef gp_Vec  Vec;
38 typedef gp_XYZ  XYZ;
39
40
41
42
43 //=======================================================================
44 //function : Copy
45 //purpose  : 
46 //=======================================================================
47
48 Handle(Geom_Geometry) Geom_Circle::Copy() const {
49
50   Handle(Geom_Circle) C;
51   C = new Circle (pos, radius);
52   return C;
53 }
54
55
56 //=======================================================================
57 //function : Geom_Circle
58 //purpose  : 
59 //=======================================================================
60
61 Geom_Circle::Geom_Circle (const gp_Circ& C) : radius (C.Radius()) {  
62
63   pos = C.Position(); 
64 }
65
66
67 //=======================================================================
68 //function : Geom_Circle
69 //purpose  : 
70 //=======================================================================
71
72 Geom_Circle::Geom_Circle (const Ax2& A2, const Standard_Real R) : radius (R) {
73
74   if (R < 0.0) throw Standard_ConstructionError();
75   pos = A2;
76 }
77
78
79 //=======================================================================
80 //function : IsClosed
81 //purpose  : 
82 //=======================================================================
83
84 Standard_Boolean Geom_Circle::IsClosed () const        { return Standard_True; }
85
86
87 //=======================================================================
88 //function : IsPeriodic
89 //purpose  : 
90 //=======================================================================
91
92 Standard_Boolean Geom_Circle::IsPeriodic () const      { return Standard_True; }
93
94
95 //=======================================================================
96 //function : ReversedParameter
97 //purpose  : 
98 //=======================================================================
99
100 Standard_Real Geom_Circle::ReversedParameter( const Standard_Real U) const 
101 {
102   return ( 2. * M_PI - U);
103 }
104
105 //=======================================================================
106 //function : Eccentricity
107 //purpose  : 
108 //=======================================================================
109
110 Standard_Real Geom_Circle::Eccentricity () const       { return 0.0; }
111
112
113 //=======================================================================
114 //function : FirstParameter
115 //purpose  : 
116 //=======================================================================
117
118 Standard_Real Geom_Circle::FirstParameter () const     { return 0.0; }
119
120
121 //=======================================================================
122 //function : LastParameter
123 //purpose  : 
124 //=======================================================================
125
126 Standard_Real Geom_Circle::LastParameter () const      { return 2.0 * M_PI; }
127
128
129 //=======================================================================
130 //function : Circ
131 //purpose  : 
132 //=======================================================================
133
134 gp_Circ Geom_Circle::Circ () const  { return gp_Circ (pos, radius); }
135
136
137 //=======================================================================
138 //function : SetCirc
139 //purpose  : 
140 //=======================================================================
141
142 void Geom_Circle::SetCirc (const gp_Circ& C) {
143
144    radius = C.Radius();
145    pos = C.Position();
146 }
147
148
149 //=======================================================================
150 //function : SetRadius
151 //purpose  : 
152 //=======================================================================
153
154 void Geom_Circle::SetRadius (const Standard_Real R) { 
155
156    if (R < 0.0)  throw Standard_ConstructionError();
157    radius = R;
158 }
159
160 //=======================================================================
161 //function : Radius
162 //purpose  : 
163 //=======================================================================
164
165 Standard_Real Geom_Circle::Radius() const
166 {
167   return radius;
168 }
169
170 //=======================================================================
171 //function : D0
172 //purpose  : 
173 //=======================================================================
174
175 void Geom_Circle::D0 (const Standard_Real U, Pnt& P) const {
176
177   P = ElCLib::CircleValue (U, pos, radius);
178 }
179
180
181 //=======================================================================
182 //function : D1
183 //purpose  : 
184 //=======================================================================
185
186 void Geom_Circle::D1 (const Standard_Real U, Pnt& P, Vec& V1) const {
187
188   ElCLib::CircleD1 (U, pos, radius, P, V1);
189 }
190
191
192 //=======================================================================
193 //function : D2
194 //purpose  : 
195 //=======================================================================
196
197 void Geom_Circle::D2 (const Standard_Real U, Pnt& P, Vec& V1, Vec& V2) const {
198
199    ElCLib::CircleD2 (U, pos, radius, P, V1, V2);
200 }
201
202
203 //=======================================================================
204 //function : D3
205 //purpose  : 
206 //=======================================================================
207
208 void Geom_Circle::D3 (
209 const Standard_Real U, Pnt& P, Vec& V1, Vec& V2, Vec& V3) const {
210
211   ElCLib::CircleD3 (U, pos, radius, P, V1, V2, V3);
212 }
213
214
215 //=======================================================================
216 //function : DN
217 //purpose  : 
218 //=======================================================================
219
220 Vec Geom_Circle::DN (const Standard_Real U, const Standard_Integer N) const {
221
222    Standard_RangeError_Raise_if (N < 1, " ");
223    return ElCLib::CircleDN (U, pos, radius, N);
224 }
225
226
227 //=======================================================================
228 //function : Transform
229 //purpose  : 
230 //=======================================================================
231
232 void Geom_Circle::Transform (const Trsf& T) {
233
234    radius = radius * Abs(T.ScaleFactor());
235    pos.Transform (T);
236 }
237
238 //=======================================================================
239 //function : DumpJson
240 //purpose  : 
241 //=======================================================================
242 void Geom_Circle::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
243 {
244   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
245
246   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom_Conic)
247
248   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, radius)
249 }