892b0349f7add5be8113b1b1afd00b2645f4eddd
[occt.git] / src / gce / gce_MakeLin2d.cxx
1 // Created on: 1992-09-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-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 #include <gce_MakeLin2d.ixx>
18 #include <gp.hxx>
19 #include <StdFail_NotDone.hxx>
20
21 //=========================================================================
22 //   Creation d une ligne 2d de gp a partir d un Ax2d de gp.              +
23 //=========================================================================
24
25 gce_MakeLin2d::gce_MakeLin2d(const gp_Ax2d& A)
26 {
27   TheLin2d = gp_Lin2d(A);
28   TheError = gce_Done;
29 }
30
31 //=========================================================================
32 //   Creation d une ligne 2d de gp a partir de son origine P (Pnt2d de gp)+
33 //   et d une direction V (Dir2d de gp).                                  +
34 //=========================================================================
35
36 gce_MakeLin2d::gce_MakeLin2d(const gp_Pnt2d& P,
37                              const gp_Dir2d& V)
38 {
39   TheLin2d = gp_Lin2d(P,V);
40   TheError = gce_Done;
41 }
42
43 //=========================================================================
44 //   Creation d une ligne 2d de gp a partir des parametres de son         +
45 //    equation.                                                           +
46 //=========================================================================
47
48 gce_MakeLin2d::gce_MakeLin2d(const Standard_Real A,
49                              const Standard_Real B,
50                              const Standard_Real C)
51 {
52   if (A*A + B*B <= gp::Resolution()) {
53     TheError = gce_NullAxis;
54   }
55   else {
56     TheLin2d = gp_Lin2d(A,B,C);
57     TheError = gce_Done;
58   }
59 }
60
61 //=========================================================================
62 //   Creation d une ligne 2d de gp passant par les deux points <P1> et    +
63 //   <P2>.                                                                +
64 //=========================================================================
65
66 gce_MakeLin2d::gce_MakeLin2d(const gp_Pnt2d& P1,
67                              const gp_Pnt2d& P2)
68 {
69   if (P1.Distance(P2) >= gp::Resolution()) {
70     TheLin2d = gp_Lin2d(P1,gp_Dir2d(P2.XY()-P1.XY()));
71     TheError = gce_Done;
72   }
73   else { 
74     TheError = gce_ConfusedPoints;
75   }
76 }
77
78 //=========================================================================
79 //   Creation d une ligne 2d de gp <TheLine> parallele a une autre ligne  +
80 //   <Line1> passant par le point <Point1>.                               +
81 //=========================================================================
82
83 gce_MakeLin2d::gce_MakeLin2d(const gp_Lin2d& Line,
84                              const gp_Pnt2d& Point)
85 {
86   TheLin2d = gp_Lin2d(Point,Line.Direction());
87   TheError = gce_Done;
88 }
89
90 //=========================================================================
91 //   Creation d une ligne 2d de gp <TheLine> parallele a une autre ligne  +
92 //   <Line1> a une distance <Dist1>.                                      +
93 //=========================================================================
94
95 gce_MakeLin2d::gce_MakeLin2d(const gp_Lin2d&     Line,
96                              const Standard_Real Dist)
97 {
98   gp_Pnt2d Point(Line.Location().XY()+
99                  Dist*gp_XY(-Line.Direction().Y(),Line.Direction().X()));
100   TheLin2d = gp_Lin2d(Point,Line.Direction());
101   TheError = gce_Done;
102 }
103
104 gp_Lin2d gce_MakeLin2d::Value() const
105
106   StdFail_NotDone_Raise_if(TheError != gce_Done,"");
107   return TheLin2d;
108 }
109
110 gp_Lin2d gce_MakeLin2d::Operator() const 
111 {
112   return Value();
113 }
114
115 gce_MakeLin2d::operator gp_Lin2d () const
116 {
117   return Value();
118 }
119