b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | // JCV 30/08/90 Modif passage version C++ 2.0 sur Sun |
16 | |
17 | #include <gp_Lin.hxx> |
18 | |
19 | inline gp_Pln::gp_Pln() |
20 | { } |
21 | |
22 | inline gp_Pln::gp_Pln(const gp_Ax3& A3) : pos(A3) |
23 | { } |
24 | |
25 | inline void gp_Pln::Coefficients (Standard_Real& A, |
26 | Standard_Real& B, |
27 | Standard_Real& C, |
28 | Standard_Real& D) const |
29 | { |
30 | const gp_Dir& dir = pos.Direction(); |
31 | if (pos.Direct()) { |
32 | A = dir.X(); |
33 | B = dir.Y(); |
34 | C = dir.Z(); |
35 | } |
36 | else { |
37 | A = -dir.X(); |
38 | B = -dir.Y(); |
39 | C = -dir.Z(); |
40 | } |
41 | const gp_Pnt& P = pos.Location(); |
42 | D = -(A * P.X() + B * P.Y() + C * P.Z()); |
43 | } |
44 | |
45 | inline void gp_Pln::SetAxis (const gp_Ax1& A1) |
46 | { pos.SetAxis (A1); } |
47 | |
48 | inline void gp_Pln::SetLocation (const gp_Pnt& Loc) |
49 | { pos.SetLocation (Loc); } |
50 | |
51 | inline void gp_Pln::SetPosition (const gp_Ax3& A3) |
52 | { pos = A3; } |
53 | |
54 | inline void gp_Pln::UReverse () |
55 | { pos.XReverse(); } |
56 | |
57 | inline void gp_Pln::VReverse () |
58 | { pos.YReverse(); } |
59 | |
60 | inline Standard_Boolean gp_Pln::Direct()const |
61 | { return pos.Direct(); } |
62 | |
63 | inline const gp_Ax1& gp_Pln::Axis() const |
64 | { return pos.Axis(); } |
65 | |
66 | inline const gp_Pnt& gp_Pln::Location() const |
67 | { return pos.Location(); } |
68 | |
69 | inline const gp_Ax3& gp_Pln::Position() const |
70 | { return pos; } |
71 | |
72 | inline Standard_Real gp_Pln::Distance(const gp_Pnt& P) const |
73 | { |
74 | const gp_Pnt& loc = pos.Location (); |
75 | const gp_Dir& dir = pos.Direction(); |
76 | Standard_Real D = (dir.X() * (P.X() - loc.X()) + |
77 | dir.Y() * (P.Y() - loc.Y()) + |
78 | dir.Z() * (P.Z() - loc.Z())); |
79 | if (D < 0) D = - D; |
80 | return D; |
81 | } |
82 | |
83 | inline Standard_Real gp_Pln::Distance (const gp_Lin& L) const |
84 | { |
85 | Standard_Real D = 0.0; |
86 | if ((pos.Direction()).IsNormal (L.Direction(), gp::Resolution())) { |
87 | const gp_Pnt& P = L .Location (); |
88 | const gp_Pnt& loc = pos.Location (); |
89 | const gp_Dir& dir = pos.Direction(); |
90 | D = (dir.X() * (P.X() - loc.X()) + |
91 | dir.Y() * (P.Y() - loc.Y()) + |
92 | dir.Z() * (P.Z() - loc.Z())); |
93 | if (D < 0) D = - D; |
94 | } |
95 | return D; |
96 | } |
97 | |
98 | inline Standard_Real gp_Pln::Distance(const gp_Pln& Other) const |
99 | { |
100 | Standard_Real D = 0.0; |
101 | if ((pos.Direction()).IsParallel(Other.pos.Direction(), gp::Resolution())){ |
102 | const gp_Pnt& P = Other.pos.Location(); |
103 | const gp_Pnt& loc = pos.Location (); |
104 | const gp_Dir& dir = pos.Direction(); |
105 | D = (dir.X() * (P.X() - loc.X()) + |
106 | dir.Y() * (P.Y() - loc.Y()) + |
107 | dir.Z() * (P.Z() - loc.Z())); |
108 | if (D < 0) D = - D; |
109 | } |
110 | return D; |
111 | } |
112 | |
113 | inline Standard_Real gp_Pln::SquareDistance (const gp_Pnt& P) const |
114 | { Standard_Real D = Distance(P); return D * D; } |
115 | |
116 | inline Standard_Real gp_Pln::SquareDistance (const gp_Lin& L) const |
117 | { Standard_Real D = Distance(L); return D * D; } |
118 | |
119 | inline Standard_Real gp_Pln::SquareDistance (const gp_Pln& Other) const |
120 | { Standard_Real D = Distance(Other); return D * D; } |
121 | |
122 | inline gp_Ax1 gp_Pln::XAxis () const |
123 | { return gp_Ax1 (pos.Location(), pos.XDirection()); } |
124 | |
125 | inline gp_Ax1 gp_Pln::YAxis () const |
126 | { return gp_Ax1 (pos.Location(), pos.YDirection()); } |
127 | |
128 | inline Standard_Boolean gp_Pln::Contains |
129 | (const gp_Pnt& P, |
130 | const Standard_Real LinearTolerance) const |
131 | { return Distance(P) <= LinearTolerance; } |
132 | |
133 | inline Standard_Boolean gp_Pln::Contains |
134 | (const gp_Lin& L, |
135 | const Standard_Real LinearTolerance, |
136 | const Standard_Real AngularTolerance) const |
137 | { return Contains(L.Location(), LinearTolerance) && |
138 | pos.Direction().IsNormal(L.Direction(), AngularTolerance); |
139 | } |
140 | |
141 | inline void gp_Pln::Rotate (const gp_Ax1& A1, const Standard_Real Ang) |
142 | { pos.Rotate(A1, Ang); } |
143 | |
144 | inline gp_Pln gp_Pln::Rotated (const gp_Ax1& A1, |
145 | const Standard_Real Ang) const |
146 | { |
147 | gp_Pln Pl = *this; |
148 | Pl.pos.Rotate(A1, Ang); |
149 | return Pl; |
150 | } |
151 | |
152 | inline void gp_Pln::Scale (const gp_Pnt& P, const Standard_Real S) |
153 | { pos.Scale(P, S); } |
154 | |
155 | inline gp_Pln gp_Pln::Scaled (const gp_Pnt& P, |
156 | const Standard_Real S) const |
157 | { |
158 | gp_Pln Pl = *this; |
159 | Pl.pos.Scale(P, S); |
160 | return Pl; |
161 | } |
162 | |
163 | inline void gp_Pln::Transform (const gp_Trsf& T) |
164 | { pos.Transform(T); } |
165 | |
166 | inline gp_Pln gp_Pln::Transformed (const gp_Trsf& T) const |
167 | { |
168 | gp_Pln Pl = *this; |
169 | Pl.pos.Transform(T); |
170 | return Pl; |
171 | } |
172 | |
173 | inline void gp_Pln::Translate (const gp_Vec& V) |
174 | { pos.Translate(V); } |
175 | |
176 | inline gp_Pln gp_Pln::Translated (const gp_Vec& V) const |
177 | { |
178 | gp_Pln Pl = *this; |
179 | Pl.pos.Translate(V); |
180 | return Pl; |
181 | } |
182 | |
183 | inline void gp_Pln::Translate (const gp_Pnt& P1, const gp_Pnt& P2) |
184 | { pos.Translate(P1,P2); } |
185 | |
186 | inline gp_Pln gp_Pln::Translated (const gp_Pnt& P1, |
187 | const gp_Pnt& P2) const |
188 | { |
189 | gp_Pln Pl = *this; |
190 | Pl.pos.Translate(P1, P2); |
191 | return Pl; |
192 | } |
193 | |