Test for 0022778: Bug in BRepMesh
[occt.git] / src / gp / gp_Pln.cxx
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 // JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
20 // JCV 1/10/90 Changement de nom du package vgeom -> gp
21 // JCV 12/12/90 Modif suite a la premiere revue de projet
22 // LPA, JCV  07/92 passage sur C1.
23 // JCV 07/92 Introduction de la method Dump 
24 // LBO 08/93 Passage aux Ax3
25
26 #include <gp_Pln.ixx>
27 #include <gp.hxx>
28
29 gp_Pln::gp_Pln (const gp_Pnt& P,
30                 const gp_Dir& V)
31 {
32   Standard_Real A = V.X();
33   Standard_Real B = V.Y();
34   Standard_Real C = V.Z();
35   Standard_Real Aabs = A;
36   if (Aabs < 0) Aabs = - Aabs;
37   Standard_Real Babs = B;
38   if (Babs < 0) Babs = - Babs;
39   Standard_Real Cabs = C;
40   if (Cabs < 0) Cabs = - Cabs;
41
42   //  pour determiner l'axe X :
43   //  on dit que le produit scalaire Vx.V = 0. 
44   //  et on recherche le max(A,B,C) pour faire la division.
45   //  l'une des coordonnees du vecteur est nulle. 
46
47   if( Babs <= Aabs && Babs <= Cabs) {
48     if (Aabs > Cabs)  pos = gp_Ax3 (P, V, gp_Dir (-C,0., A));
49     else              pos = gp_Ax3 (P, V, gp_Dir ( C,0.,-A));
50   }
51   else if( Aabs <= Babs && Aabs <= Cabs) {
52     if (Babs > Cabs)  pos = gp_Ax3 (P, V, gp_Dir (0.,-C, B));
53     else              pos = gp_Ax3 (P, V, gp_Dir (0., C,-B));
54   }
55   else {
56     if (Aabs > Babs)  pos = gp_Ax3 (P, V, gp_Dir (-B, A,0.));
57     else              pos = gp_Ax3 (P, V, gp_Dir ( B,-A,0.));
58   }
59 }
60
61 gp_Pln::gp_Pln (const Standard_Real A,
62                 const Standard_Real B,
63                 const Standard_Real C,
64                 const Standard_Real D)
65 {
66   Standard_Real Aabs = A;
67   if (Aabs < 0) Aabs = - Aabs;
68   Standard_Real Babs = B;
69   if (Babs < 0) Babs = - Babs;
70   Standard_Real Cabs = C;
71   if (Cabs < 0) Cabs = - Cabs;
72   if (Babs <= Aabs && Babs <= Cabs) {
73     if (Aabs > Cabs) pos = gp_Ax3(gp_Pnt(-D/A,  0.,  0.),
74                                   gp_Dir(A,B,C),
75                                   gp_Dir(-C,0., A));
76     else             pos = gp_Ax3(gp_Pnt(  0.,  0.,-D/C),
77                                   gp_Dir(A,B,C),
78                                   gp_Dir( C,0.,-A));
79   }
80   else if (Aabs <= Babs && Aabs <= Cabs) {
81     if (Babs > Cabs) pos = gp_Ax3(gp_Pnt(  0.,-D/B,  0.),
82                                   gp_Dir(A,B,C),
83                                   gp_Dir(0.,-C, B));
84     else             pos = gp_Ax3(gp_Pnt(  0.,  0.,-D/C),
85                                   gp_Dir(A,B,C),
86                                   gp_Dir(0., C,-B));
87   }
88   else {
89     if (Aabs > Babs) pos = gp_Ax3(gp_Pnt(-D/A,  0.,  0.),
90                                   gp_Dir(A,B,C),
91                                   gp_Dir(-B, A, 0.));
92     else             pos = gp_Ax3(gp_Pnt(  0.,-D/B,  0.),
93                                   gp_Dir(A,B,C),
94                                   gp_Dir( B,-A, 0.));
95   }
96
97
98 void gp_Pln::Mirror (const gp_Pnt& P)
99 { pos.Mirror(P);  }
100
101 gp_Pln gp_Pln::Mirrored (const gp_Pnt& P) const
102 {
103   gp_Pln Pl = *this;
104   Pl.pos.Mirror(P);
105   return Pl;
106 }
107
108 void gp_Pln::Mirror (const gp_Ax1& A1)
109 { pos.Mirror(A1); }
110
111 gp_Pln gp_Pln::Mirrored (const gp_Ax1& A1) const
112 {
113   gp_Pln Pl = *this;
114   Pl.pos.Mirror(A1);
115   return Pl;
116 }
117
118 void gp_Pln::Mirror (const gp_Ax2& A2)
119 { pos.Mirror(A2); }
120
121 gp_Pln gp_Pln::Mirrored (const gp_Ax2& A2) const
122 {
123   gp_Pln Pl = *this;
124   Pl.pos.Mirror(A2);
125   return Pl;
126 }
127