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 typedef Geom2d_Line Line;
34 typedef gp_Dir2d Dir2d;
35 typedef gp_Pnt2d Pnt2d;
36 typedef gp_Vec2d Vec2d;
37 typedef gp_Trsf2d Trsf2d;
40 //=======================================================================
43 //=======================================================================
45 Handle(Geom2d_Geometry) Geom2d_Line::Copy() const
47 Handle(Geom2d_Line) L;
53 //=======================================================================
54 //function : Geom2d_Line
56 //=======================================================================
58 Geom2d_Line::Geom2d_Line (const Ax2d& A) : pos (A) { }
60 //=======================================================================
61 //function : Geom2d_Line
63 //=======================================================================
65 Geom2d_Line::Geom2d_Line (const gp_Lin2d& L) : pos (L.Position()) { }
67 //=======================================================================
68 //function : Geom2d_Line
70 //=======================================================================
72 Geom2d_Line::Geom2d_Line (const Pnt2d& P, const Dir2d& V) : pos (P, V) { }
74 //=======================================================================
75 //function : SetDirection
77 //=======================================================================
79 void Geom2d_Line::SetDirection (const Dir2d& V) { pos.SetDirection (V); }
81 //=======================================================================
82 //function : Direction
84 //=======================================================================
86 const gp_Dir2d& Geom2d_Line::Direction () const { return pos.Direction (); }
88 //=======================================================================
91 //=======================================================================
93 void Geom2d_Line::SetLin2d (const gp_Lin2d& L) { pos = L.Position(); }
95 //=======================================================================
96 //function : SetLocation
98 //=======================================================================
100 void Geom2d_Line::SetLocation (const Pnt2d& P) { pos.SetLocation (P); }
102 //=======================================================================
103 //function : Location
105 //=======================================================================
107 const gp_Pnt2d& Geom2d_Line::Location () const { return pos.Location (); }
109 //=======================================================================
110 //function : SetPosition
112 //=======================================================================
114 void Geom2d_Line::SetPosition (const Ax2d& A) { pos = A; }
116 //=======================================================================
117 //function : Position
119 //=======================================================================
121 const gp_Ax2d& Geom2d_Line::Position () const { return pos; }
123 //=======================================================================
126 //=======================================================================
128 gp_Lin2d Geom2d_Line::Lin2d () const { return gp_Lin2d (pos); }
130 //=======================================================================
133 //=======================================================================
135 void Geom2d_Line::Reverse () { pos.Reverse(); }
137 //=======================================================================
138 //function : ReversedParameter
140 //=======================================================================
142 Standard_Real Geom2d_Line::ReversedParameter( const Standard_Real U) const { return (-U); }
144 //=======================================================================
145 //function : FirstParameter
147 //=======================================================================
149 Standard_Real Geom2d_Line::FirstParameter () const
150 { return -Precision::Infinite(); }
152 //=======================================================================
153 //function : LastParameter
155 //=======================================================================
157 Standard_Real Geom2d_Line::LastParameter () const
158 { return Precision::Infinite(); }
160 //=======================================================================
161 //function : IsClosed
163 //=======================================================================
165 Standard_Boolean Geom2d_Line::IsClosed () const { return Standard_False; }
167 //=======================================================================
168 //function : IsPeriodic
170 //=======================================================================
172 Standard_Boolean Geom2d_Line::IsPeriodic () const { return Standard_False; }
174 //=======================================================================
175 //function : Continuity
177 //=======================================================================
179 GeomAbs_Shape Geom2d_Line::Continuity () const { return GeomAbs_CN; }
181 //=======================================================================
184 //=======================================================================
186 Standard_Boolean Geom2d_Line::IsCN (const Standard_Integer ) const { return Standard_True; }
188 //=======================================================================
191 //=======================================================================
193 void Geom2d_Line::D0 (const Standard_Real U, Pnt2d& P) const
195 P = ElCLib::LineValue (U, pos);
198 //=======================================================================
201 //=======================================================================
203 void Geom2d_Line::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const
205 ElCLib::LineD1 (U, pos, P, V1);
208 //=======================================================================
211 //=======================================================================
213 void Geom2d_Line::D2 (const Standard_Real U,
215 Vec2d& V1, Vec2d& V2) const
217 ElCLib::LineD1 (U, pos, P, V1);
218 V2.SetCoord (0.0, 0.0);
221 //=======================================================================
224 //=======================================================================
226 void Geom2d_Line::D3 (const Standard_Real U,
228 Vec2d& V1, Vec2d& V2, Vec2d& V3) const
230 ElCLib::LineD1 (U, pos, P, V1);
231 V2.SetCoord (0.0, 0.0);
232 V3.SetCoord (0.0, 0.0);
236 //=======================================================================
239 //=======================================================================
241 Vec2d Geom2d_Line::DN
242 (const Standard_Real ,
243 const Standard_Integer N ) const
245 Standard_RangeError_Raise_if (N <= 0, " ");
247 return Vec2d (pos.Direction ());
249 return Vec2d (0.0, 0.0);
253 //=======================================================================
254 //function : Transform
256 //=======================================================================
258 void Geom2d_Line::Transform (const Trsf2d& T) { pos.Transform (T); }
260 //=======================================================================
261 //function : TransformedParameter
263 //=======================================================================
265 Standard_Real Geom2d_Line::TransformedParameter(const Standard_Real U,
266 const gp_Trsf2d& T) const
268 if (Precision::IsInfinite(U)) return U;
269 return U * Abs(T.ScaleFactor());
272 //=======================================================================
273 //function : ParametricTransformation
275 //=======================================================================
277 Standard_Real Geom2d_Line::ParametricTransformation(const gp_Trsf2d& T) const
279 return Abs(T.ScaleFactor());
283 //=======================================================================
284 //function : Distance
286 //=======================================================================
288 Standard_Real Geom2d_Line::Distance (const gp_Pnt2d& P) const {
291 return L.Distance (P);