Test for 0022778: Bug in BRepMesh
[occt.git] / src / gp / gp_Lin2d.lxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20
21 inline gp_Lin2d::gp_Lin2d ()
22 { }
23
24 inline gp_Lin2d::gp_Lin2d (const gp_Ax2d& A) : pos(A)
25 { }
26
27 inline gp_Lin2d::gp_Lin2d (const gp_Pnt2d& P,
28                            const gp_Dir2d& V) : pos(P, V)
29 { }
30
31 inline void gp_Lin2d::Reverse()
32 { pos.Reverse(); }
33
34 inline gp_Lin2d gp_Lin2d::Reversed() const
35
36   gp_Lin2d L = *this;
37   L.pos.Reverse ();
38   return L;
39 }
40
41 inline void gp_Lin2d::SetDirection (const gp_Dir2d& V)
42 { pos.SetDirection (V); }
43
44 inline void gp_Lin2d::SetLocation (const gp_Pnt2d& P)
45 { pos.SetLocation (P); }
46
47 inline void gp_Lin2d::SetPosition (const gp_Ax2d& A)
48 { pos = A; }
49
50 inline void gp_Lin2d::Coefficients (Standard_Real& A,
51                                     Standard_Real& B,
52                                     Standard_Real& C) const
53 {
54   A =   pos.Direction().Y();
55   B = - pos.Direction().X();
56   C = -(A * pos.Location().X() + B * pos.Location().Y());
57 }
58
59 inline const gp_Dir2d& gp_Lin2d::Direction() const
60 { return pos.Direction(); }
61
62 inline const gp_Pnt2d& gp_Lin2d::Location() const
63 { return pos.Location(); }
64
65 inline    const gp_Ax2d& gp_Lin2d::Position() const
66 { return pos; }
67
68 inline Standard_Real gp_Lin2d::Angle (const gp_Lin2d& Other) const
69 { return pos.Direction().Angle (Other.pos.Direction()); }
70
71 inline Standard_Boolean gp_Lin2d::Contains
72 (const gp_Pnt2d& P,
73  const Standard_Real LinearTolerance) const
74 { return Distance(P) <= LinearTolerance; }
75
76 inline Standard_Real gp_Lin2d::Distance (const gp_Pnt2d& P) const
77 {
78   gp_XY Coord = P.XY();
79   Coord.Subtract ((pos.Location()).XY());
80   Standard_Real val = Coord.Crossed (pos.Direction().XY());
81   if (val < 0) val = - val;
82   return val;
83 }
84
85 inline Standard_Real gp_Lin2d::Distance (const gp_Lin2d& Other) const
86 {
87   Standard_Real D = 0.0;
88   if (pos.IsParallel (Other.pos, gp::Resolution())) 
89     D = Other.Distance(pos.Location());
90   return D;
91 }
92
93 inline Standard_Real gp_Lin2d::SquareDistance (const gp_Pnt2d& P) const
94 {
95   gp_XY Coord = P.XY();
96   Coord.Subtract ((pos.Location()).XY());
97   Standard_Real D = Coord.Crossed (pos.Direction().XY());
98   return D * D;
99 }
100
101 inline Standard_Real gp_Lin2d::SquareDistance (const gp_Lin2d& Other) const
102 {
103   Standard_Real D = 0.0;
104   if (pos.IsParallel (Other.pos, gp::Resolution())) { 
105     D = Other.Distance(pos.Location());
106     D *= D;return D * D;
107   }
108   return D;
109 }
110
111 inline gp_Lin2d gp_Lin2d::Normal (const gp_Pnt2d& P) const
112 {            
113   return gp_Lin2d
114     (gp_Ax2d
115      (P,gp_Dir2d
116       (-(pos.Direction().Y()), pos.Direction().X())));
117 }
118
119 inline void gp_Lin2d::Rotate (const gp_Pnt2d& P, const Standard_Real Ang)
120 { pos.Rotate (P, Ang); }
121
122 inline gp_Lin2d gp_Lin2d::Rotated (const gp_Pnt2d& P,
123                                    const Standard_Real Ang) const
124 {
125   gp_Lin2d L = *this;
126   L.pos.Rotate (P, Ang);
127   return L;
128 }
129
130 inline void gp_Lin2d::Scale (const gp_Pnt2d& P, const Standard_Real S)
131 { pos.Scale(P, S);  }
132
133 inline gp_Lin2d gp_Lin2d::Scaled (const gp_Pnt2d& P,
134                                   const Standard_Real S) const
135 {
136   gp_Lin2d L = *this;
137   L.pos.Scale(P, S);
138   return L;
139 }
140
141 inline void gp_Lin2d::Transform (const gp_Trsf2d& T)
142 { pos.Transform(T); }
143
144 inline gp_Lin2d gp_Lin2d::Transformed (const gp_Trsf2d& T) const
145 {
146   gp_Lin2d L = *this;
147   L.pos.Transform(T);
148   return L;
149 }
150
151 inline void gp_Lin2d::Translate (const gp_Vec2d& V)
152 { pos.Translate(V); }
153
154 inline gp_Lin2d gp_Lin2d::Translated (const gp_Vec2d& V) const
155 {
156   gp_Lin2d L = *this;
157   L.pos.Translate(V); 
158   return L;
159 }
160
161 inline void gp_Lin2d::Translate (const gp_Pnt2d& P1,
162                                  const gp_Pnt2d& P2)
163 { pos.Translate(P1, P2); }                 
164
165 inline gp_Lin2d gp_Lin2d::Translated (const gp_Pnt2d& P1,
166                                       const gp_Pnt2d& P2) const
167 {
168   gp_Lin2d L = *this;
169   L.pos.Translate (gp_Vec2d(P1, P2));
170   return L;
171 }
172