0030731: Modeling Data - B-Spline should have explicit data check error messages
[occt.git] / src / Geom2d / Geom2d_Line.cxx
1 // Created on: 1993-03-24
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 <Geom2d_Geometry.hxx>
20 #include <Geom2d_Line.hxx>
21 #include <gp_Ax2d.hxx>
22 #include <gp_Dir2d.hxx>
23 #include <gp_Lin2d.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <gp_Trsf2d.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <gp_XY.hxx>
28 #include <Precision.hxx>
29 #include <Standard_RangeError.hxx>
30 #include <Standard_Type.hxx>
31
32 IMPLEMENT_STANDARD_RTTIEXT(Geom2d_Line,Geom2d_Curve)
33
34 typedef Geom2d_Line         Line;
35 typedef gp_Ax2d   Ax2d;
36 typedef gp_Dir2d  Dir2d;
37 typedef gp_Pnt2d  Pnt2d;
38 typedef gp_Vec2d  Vec2d;
39 typedef gp_Trsf2d Trsf2d;
40 typedef gp_XY     XY;
41
42 //=======================================================================
43 //function : Copy
44 //purpose  : 
45 //=======================================================================
46
47 Handle(Geom2d_Geometry) Geom2d_Line::Copy() const 
48 {
49   Handle(Geom2d_Line) L;
50   L = new Line (pos);
51   return L;
52 }
53
54
55 //=======================================================================
56 //function : Geom2d_Line
57 //purpose  : 
58 //=======================================================================
59
60 Geom2d_Line::Geom2d_Line (const Ax2d& A)           : pos (A) { }
61
62 //=======================================================================
63 //function : Geom2d_Line
64 //purpose  : 
65 //=======================================================================
66
67 Geom2d_Line::Geom2d_Line (const gp_Lin2d& L)       : pos (L.Position()) { }
68
69 //=======================================================================
70 //function : Geom2d_Line
71 //purpose  : 
72 //=======================================================================
73
74 Geom2d_Line::Geom2d_Line (const Pnt2d& P, const Dir2d& V)  : pos (P, V) { }
75
76 //=======================================================================
77 //function : SetDirection
78 //purpose  : 
79 //=======================================================================
80
81 void Geom2d_Line::SetDirection (const Dir2d& V) { pos.SetDirection (V); }
82
83 //=======================================================================
84 //function : Direction
85 //purpose  : 
86 //=======================================================================
87
88 const gp_Dir2d& Geom2d_Line::Direction () const { return pos.Direction (); }
89
90 //=======================================================================
91 //function : SetLin2d
92 //purpose  : 
93 //=======================================================================
94
95 void Geom2d_Line::SetLin2d (const gp_Lin2d& L)  { pos = L.Position(); }
96
97 //=======================================================================
98 //function : SetLocation
99 //purpose  : 
100 //=======================================================================
101
102 void Geom2d_Line::SetLocation (const Pnt2d& P)  { pos.SetLocation (P); }
103
104 //=======================================================================
105 //function : Location
106 //purpose  : 
107 //=======================================================================
108
109 const gp_Pnt2d& Geom2d_Line::Location () const  { return pos.Location (); }
110
111 //=======================================================================
112 //function : SetPosition
113 //purpose  : 
114 //=======================================================================
115
116 void Geom2d_Line::SetPosition (const Ax2d& A)   { pos = A; }
117
118 //=======================================================================
119 //function : Position
120 //purpose  : 
121 //=======================================================================
122
123 const gp_Ax2d& Geom2d_Line::Position () const   { return pos; }
124
125 //=======================================================================
126 //function : Lin2d
127 //purpose  : 
128 //=======================================================================
129
130 gp_Lin2d Geom2d_Line::Lin2d () const            { return gp_Lin2d (pos); }
131
132 //=======================================================================
133 //function : Reverse
134 //purpose  : 
135 //=======================================================================
136
137 void Geom2d_Line::Reverse ()                    { pos.Reverse(); }
138
139 //=======================================================================
140 //function : ReversedParameter
141 //purpose  : 
142 //=======================================================================
143
144 Standard_Real Geom2d_Line::ReversedParameter( const Standard_Real U) const  { return (-U); }
145
146 //=======================================================================
147 //function : FirstParameter
148 //purpose  : 
149 //=======================================================================
150
151 Standard_Real Geom2d_Line::FirstParameter () const       
152 { return -Precision::Infinite(); }
153
154 //=======================================================================
155 //function : LastParameter
156 //purpose  : 
157 //=======================================================================
158
159 Standard_Real Geom2d_Line::LastParameter () const        
160 { return Precision::Infinite(); }
161
162 //=======================================================================
163 //function : IsClosed
164 //purpose  : 
165 //=======================================================================
166
167 Standard_Boolean Geom2d_Line::IsClosed () const          { return Standard_False; }
168
169 //=======================================================================
170 //function : IsPeriodic
171 //purpose  : 
172 //=======================================================================
173
174 Standard_Boolean Geom2d_Line::IsPeriodic () const        { return Standard_False;  }
175
176 //=======================================================================
177 //function : Continuity
178 //purpose  : 
179 //=======================================================================
180
181 GeomAbs_Shape Geom2d_Line::Continuity () const   { return GeomAbs_CN; }
182
183 //=======================================================================
184 //function : IsCN
185 //purpose  : 
186 //=======================================================================
187
188 Standard_Boolean Geom2d_Line::IsCN (const Standard_Integer ) const      { return Standard_True; }
189
190 //=======================================================================
191 //function : D0
192 //purpose  : 
193 //=======================================================================
194
195 void Geom2d_Line::D0 (const Standard_Real U, Pnt2d& P) const  
196 {
197   P = ElCLib::LineValue (U, pos);
198 }
199
200 //=======================================================================
201 //function : D1
202 //purpose  : 
203 //=======================================================================
204
205 void Geom2d_Line::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const 
206 {
207   ElCLib::LineD1 (U, pos, P, V1);
208 }
209
210 //=======================================================================
211 //function : D2
212 //purpose  : 
213 //=======================================================================
214
215 void Geom2d_Line::D2 (const Standard_Real U, 
216                             Pnt2d& P, 
217                             Vec2d& V1, Vec2d& V2) const 
218 {
219   ElCLib::LineD1 (U, pos, P, V1);
220   V2.SetCoord (0.0, 0.0);
221 }
222
223 //=======================================================================
224 //function : D3
225 //purpose  : 
226 //=======================================================================
227
228 void Geom2d_Line::D3 (const Standard_Real U, 
229                             Pnt2d& P, 
230                             Vec2d& V1, Vec2d& V2, Vec2d& V3) const
231 {
232   ElCLib::LineD1 (U, pos, P, V1);
233   V2.SetCoord (0.0, 0.0);
234   V3.SetCoord (0.0, 0.0);
235 }
236
237
238 //=======================================================================
239 //function : DN
240 //purpose  : 
241 //=======================================================================
242
243 Vec2d Geom2d_Line::DN
244   (const Standard_Real     ,
245    const Standard_Integer N ) const
246 {
247   Standard_RangeError_Raise_if (N <= 0, " ");
248   if (N == 1) 
249     return Vec2d (pos.Direction ());
250   else        
251     return Vec2d (0.0, 0.0);
252 }
253
254
255 //=======================================================================
256 //function : Transform
257 //purpose  : 
258 //=======================================================================
259
260 void Geom2d_Line::Transform (const Trsf2d& T)          { pos.Transform (T); }
261
262 //=======================================================================
263 //function : TransformedParameter
264 //purpose  : 
265 //=======================================================================
266
267 Standard_Real Geom2d_Line::TransformedParameter(const Standard_Real U,
268                                                 const gp_Trsf2d& T) const
269 {
270   if (Precision::IsInfinite(U)) return U;
271   return U * Abs(T.ScaleFactor());
272 }
273
274 //=======================================================================
275 //function : ParametricTransformation
276 //purpose  : 
277 //=======================================================================
278
279 Standard_Real Geom2d_Line::ParametricTransformation(const gp_Trsf2d& T) const
280 {
281   return Abs(T.ScaleFactor());
282 }
283
284
285 //=======================================================================
286 //function : Distance
287 //purpose  : 
288 //=======================================================================
289
290 Standard_Real Geom2d_Line::Distance (const gp_Pnt2d& P) const {
291
292   gp_Lin2d L (pos);   
293   return L.Distance (P);
294 }
295