0030582: Coding - avoid defining references to properties of NULL objects
[occt.git] / src / Geom2d / Geom2d_Line.cxx
CommitLineData
b311480e 1// Created on: 1993-03-24
2// Created by: JCV
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
7fd59977 18#include <ElCLib.hxx>
42cf5bc1 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>
7fd59977 27#include <gp_XY.hxx>
42cf5bc1 28#include <Precision.hxx>
7fd59977 29#include <Standard_RangeError.hxx>
42cf5bc1 30#include <Standard_Type.hxx>
7fd59977 31
92efcf78 32IMPLEMENT_STANDARD_RTTIEXT(Geom2d_Line,Geom2d_Curve)
33
7fd59977 34typedef Geom2d_Line Line;
7fd59977 35typedef gp_Ax2d Ax2d;
36typedef gp_Dir2d Dir2d;
37typedef gp_Pnt2d Pnt2d;
38typedef gp_Vec2d Vec2d;
39typedef gp_Trsf2d Trsf2d;
40typedef gp_XY XY;
41
7fd59977 42//=======================================================================
43//function : Copy
44//purpose :
45//=======================================================================
46
47Handle(Geom2d_Geometry) Geom2d_Line::Copy() const
48{
c04c30b3 49 Handle(Geom2d_Line) L;
7fd59977 50 L = new Line (pos);
51 return L;
52}
53
54
55//=======================================================================
56//function : Geom2d_Line
57//purpose :
58//=======================================================================
59
60Geom2d_Line::Geom2d_Line (const Ax2d& A) : pos (A) { }
61
62//=======================================================================
63//function : Geom2d_Line
64//purpose :
65//=======================================================================
66
67Geom2d_Line::Geom2d_Line (const gp_Lin2d& L) : pos (L.Position()) { }
68
69//=======================================================================
70//function : Geom2d_Line
71//purpose :
72//=======================================================================
73
74Geom2d_Line::Geom2d_Line (const Pnt2d& P, const Dir2d& V) : pos (P, V) { }
75
76//=======================================================================
77//function : SetDirection
78//purpose :
79//=======================================================================
80
81void Geom2d_Line::SetDirection (const Dir2d& V) { pos.SetDirection (V); }
82
83//=======================================================================
84//function : Direction
85//purpose :
86//=======================================================================
87
88const gp_Dir2d& Geom2d_Line::Direction () const { return pos.Direction (); }
89
90//=======================================================================
91//function : SetLin2d
92//purpose :
93//=======================================================================
94
95void Geom2d_Line::SetLin2d (const gp_Lin2d& L) { pos = L.Position(); }
96
97//=======================================================================
98//function : SetLocation
99//purpose :
100//=======================================================================
101
102void Geom2d_Line::SetLocation (const Pnt2d& P) { pos.SetLocation (P); }
103
104//=======================================================================
105//function : Location
106//purpose :
107//=======================================================================
108
109const gp_Pnt2d& Geom2d_Line::Location () const { return pos.Location (); }
110
111//=======================================================================
112//function : SetPosition
113//purpose :
114//=======================================================================
115
116void Geom2d_Line::SetPosition (const Ax2d& A) { pos = A; }
117
118//=======================================================================
119//function : Position
120//purpose :
121//=======================================================================
122
123const gp_Ax2d& Geom2d_Line::Position () const { return pos; }
124
125//=======================================================================
126//function : Lin2d
127//purpose :
128//=======================================================================
129
130gp_Lin2d Geom2d_Line::Lin2d () const { return gp_Lin2d (pos); }
131
132//=======================================================================
133//function : Reverse
134//purpose :
135//=======================================================================
136
137void Geom2d_Line::Reverse () { pos.Reverse(); }
138
139//=======================================================================
140//function : ReversedParameter
141//purpose :
142//=======================================================================
143
144Standard_Real Geom2d_Line::ReversedParameter( const Standard_Real U) const { return (-U); }
145
146//=======================================================================
147//function : FirstParameter
148//purpose :
149//=======================================================================
150
151Standard_Real Geom2d_Line::FirstParameter () const
152{ return -Precision::Infinite(); }
153
154//=======================================================================
155//function : LastParameter
156//purpose :
157//=======================================================================
158
159Standard_Real Geom2d_Line::LastParameter () const
160{ return Precision::Infinite(); }
161
162//=======================================================================
163//function : IsClosed
164//purpose :
165//=======================================================================
166
167Standard_Boolean Geom2d_Line::IsClosed () const { return Standard_False; }
168
169//=======================================================================
170//function : IsPeriodic
171//purpose :
172//=======================================================================
173
174Standard_Boolean Geom2d_Line::IsPeriodic () const { return Standard_False; }
175
176//=======================================================================
177//function : Continuity
178//purpose :
179//=======================================================================
180
181GeomAbs_Shape Geom2d_Line::Continuity () const { return GeomAbs_CN; }
182
183//=======================================================================
184//function : IsCN
185//purpose :
186//=======================================================================
187
188Standard_Boolean Geom2d_Line::IsCN (const Standard_Integer ) const { return Standard_True; }
189
190//=======================================================================
191//function : D0
192//purpose :
193//=======================================================================
194
195void 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
205void 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
215void 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
228void 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
243Vec2d 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
260void Geom2d_Line::Transform (const Trsf2d& T) { pos.Transform (T); }
261
262//=======================================================================
263//function : TransformedParameter
264//purpose :
265//=======================================================================
266
267Standard_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
279Standard_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
290Standard_Real Geom2d_Line::Distance (const gp_Pnt2d& P) const {
291
292 gp_Lin2d L (pos);
293 return L.Distance (P);
294}
295