1 // Created on: 1993-03-24
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
28 #include <Precision.hxx>
29 #include <Standard_RangeError.hxx>
30 #include <Standard_Type.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(Geom2d_Line,Geom2d_Curve)
34 typedef Geom2d_Line Line;
36 typedef gp_Dir2d Dir2d;
37 typedef gp_Pnt2d Pnt2d;
38 typedef gp_Vec2d Vec2d;
39 typedef gp_Trsf2d Trsf2d;
42 //=======================================================================
45 //=======================================================================
47 Handle(Geom2d_Geometry) Geom2d_Line::Copy() const
49 Handle(Geom2d_Line) L;
55 //=======================================================================
56 //function : Geom2d_Line
58 //=======================================================================
60 Geom2d_Line::Geom2d_Line (const Ax2d& A) : pos (A) { }
62 //=======================================================================
63 //function : Geom2d_Line
65 //=======================================================================
67 Geom2d_Line::Geom2d_Line (const gp_Lin2d& L) : pos (L.Position()) { }
69 //=======================================================================
70 //function : Geom2d_Line
72 //=======================================================================
74 Geom2d_Line::Geom2d_Line (const Pnt2d& P, const Dir2d& V) : pos (P, V) { }
76 //=======================================================================
77 //function : SetDirection
79 //=======================================================================
81 void Geom2d_Line::SetDirection (const Dir2d& V) { pos.SetDirection (V); }
83 //=======================================================================
84 //function : Direction
86 //=======================================================================
88 const gp_Dir2d& Geom2d_Line::Direction () const { return pos.Direction (); }
90 //=======================================================================
93 //=======================================================================
95 void Geom2d_Line::SetLin2d (const gp_Lin2d& L) { pos = L.Position(); }
97 //=======================================================================
98 //function : SetLocation
100 //=======================================================================
102 void Geom2d_Line::SetLocation (const Pnt2d& P) { pos.SetLocation (P); }
104 //=======================================================================
105 //function : Location
107 //=======================================================================
109 const gp_Pnt2d& Geom2d_Line::Location () const { return pos.Location (); }
111 //=======================================================================
112 //function : SetPosition
114 //=======================================================================
116 void Geom2d_Line::SetPosition (const Ax2d& A) { pos = A; }
118 //=======================================================================
119 //function : Position
121 //=======================================================================
123 const gp_Ax2d& Geom2d_Line::Position () const { return pos; }
125 //=======================================================================
128 //=======================================================================
130 gp_Lin2d Geom2d_Line::Lin2d () const { return gp_Lin2d (pos); }
132 //=======================================================================
135 //=======================================================================
137 void Geom2d_Line::Reverse () { pos.Reverse(); }
139 //=======================================================================
140 //function : ReversedParameter
142 //=======================================================================
144 Standard_Real Geom2d_Line::ReversedParameter( const Standard_Real U) const { return (-U); }
146 //=======================================================================
147 //function : FirstParameter
149 //=======================================================================
151 Standard_Real Geom2d_Line::FirstParameter () const
152 { return -Precision::Infinite(); }
154 //=======================================================================
155 //function : LastParameter
157 //=======================================================================
159 Standard_Real Geom2d_Line::LastParameter () const
160 { return Precision::Infinite(); }
162 //=======================================================================
163 //function : IsClosed
165 //=======================================================================
167 Standard_Boolean Geom2d_Line::IsClosed () const { return Standard_False; }
169 //=======================================================================
170 //function : IsPeriodic
172 //=======================================================================
174 Standard_Boolean Geom2d_Line::IsPeriodic () const { return Standard_False; }
176 //=======================================================================
177 //function : Continuity
179 //=======================================================================
181 GeomAbs_Shape Geom2d_Line::Continuity () const { return GeomAbs_CN; }
183 //=======================================================================
186 //=======================================================================
188 Standard_Boolean Geom2d_Line::IsCN (const Standard_Integer ) const { return Standard_True; }
190 //=======================================================================
193 //=======================================================================
195 void Geom2d_Line::D0 (const Standard_Real U, Pnt2d& P) const
197 P = ElCLib::LineValue (U, pos);
200 //=======================================================================
203 //=======================================================================
205 void Geom2d_Line::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const
207 ElCLib::LineD1 (U, pos, P, V1);
210 //=======================================================================
213 //=======================================================================
215 void Geom2d_Line::D2 (const Standard_Real U,
217 Vec2d& V1, Vec2d& V2) const
219 ElCLib::LineD1 (U, pos, P, V1);
220 V2.SetCoord (0.0, 0.0);
223 //=======================================================================
226 //=======================================================================
228 void Geom2d_Line::D3 (const Standard_Real U,
230 Vec2d& V1, Vec2d& V2, Vec2d& V3) const
232 ElCLib::LineD1 (U, pos, P, V1);
233 V2.SetCoord (0.0, 0.0);
234 V3.SetCoord (0.0, 0.0);
238 //=======================================================================
241 //=======================================================================
243 Vec2d Geom2d_Line::DN
244 (const Standard_Real ,
245 const Standard_Integer N ) const
247 Standard_RangeError_Raise_if (N <= 0, " ");
249 return Vec2d (pos.Direction ());
251 return Vec2d (0.0, 0.0);
255 //=======================================================================
256 //function : Transform
258 //=======================================================================
260 void Geom2d_Line::Transform (const Trsf2d& T) { pos.Transform (T); }
262 //=======================================================================
263 //function : TransformedParameter
265 //=======================================================================
267 Standard_Real Geom2d_Line::TransformedParameter(const Standard_Real U,
268 const gp_Trsf2d& T) const
270 if (Precision::IsInfinite(U)) return U;
271 return U * Abs(T.ScaleFactor());
274 //=======================================================================
275 //function : ParametricTransformation
277 //=======================================================================
279 Standard_Real Geom2d_Line::ParametricTransformation(const gp_Trsf2d& T) const
281 return Abs(T.ScaleFactor());
285 //=======================================================================
286 //function : Distance
288 //=======================================================================
290 Standard_Real Geom2d_Line::Distance (const gp_Pnt2d& P) const {
293 return L.Distance (P);