4d14751d50343267d10f64b80afbcb28244c0a89
[occt.git] / src / gp / gp_Pln.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 // JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
16 // JCV 1/10/90 Changement de nom du package vgeom -> gp
17 // JCV 12/12/90 Modif suite a la premiere revue de projet
18 // LPA, JCV  07/92 passage sur C1.
19 // JCV 07/92 Introduction de la method Dump 
20 // LBO 08/93 Passage aux Ax3
21
22 #include <gp.hxx>
23 #include <gp_Ax1.hxx>
24 #include <gp_Ax2.hxx>
25 #include <gp_Ax3.hxx>
26 #include <gp_Dir.hxx>
27 #include <gp_Lin.hxx>
28 #include <gp_Pln.hxx>
29 #include <gp_Pnt.hxx>
30 #include <gp_Trsf.hxx>
31 #include <gp_Vec.hxx>
32 #include <Standard_ConstructionError.hxx>
33 #include <Standard_Dump.hxx>
34
35 gp_Pln::gp_Pln (const gp_Pnt& P,
36                 const gp_Dir& V)
37 {
38   Standard_Real A = V.X();
39   Standard_Real B = V.Y();
40   Standard_Real C = V.Z();
41   Standard_Real Aabs = A;
42   if (Aabs < 0) Aabs = - Aabs;
43   Standard_Real Babs = B;
44   if (Babs < 0) Babs = - Babs;
45   Standard_Real Cabs = C;
46   if (Cabs < 0) Cabs = - Cabs;
47
48   //  pour determiner l'axe X :
49   //  on dit que le produit scalaire Vx.V = 0. 
50   //  et on recherche le max(A,B,C) pour faire la division.
51   //  l'une des coordonnees du vecteur est nulle. 
52
53   if( Babs <= Aabs && Babs <= Cabs) {
54     if (Aabs > Cabs)  pos = gp_Ax3 (P, V, gp_Dir (-C,0., A));
55     else              pos = gp_Ax3 (P, V, gp_Dir ( C,0.,-A));
56   }
57   else if( Aabs <= Babs && Aabs <= Cabs) {
58     if (Babs > Cabs)  pos = gp_Ax3 (P, V, gp_Dir (0.,-C, B));
59     else              pos = gp_Ax3 (P, V, gp_Dir (0., C,-B));
60   }
61   else {
62     if (Aabs > Babs)  pos = gp_Ax3 (P, V, gp_Dir (-B, A,0.));
63     else              pos = gp_Ax3 (P, V, gp_Dir ( B,-A,0.));
64   }
65 }
66
67 gp_Pln::gp_Pln (const Standard_Real A,
68                 const Standard_Real B,
69                 const Standard_Real C,
70                 const Standard_Real D)
71 {
72   Standard_Real Aabs = A;
73   if (Aabs < 0) Aabs = - Aabs;
74   Standard_Real Babs = B;
75   if (Babs < 0) Babs = - Babs;
76   Standard_Real Cabs = C;
77   if (Cabs < 0) Cabs = - Cabs;
78   if (Babs <= Aabs && Babs <= Cabs) {
79     if (Aabs > Cabs) pos = gp_Ax3(gp_Pnt(-D/A,  0.,  0.),
80                                   gp_Dir(A,B,C),
81                                   gp_Dir(-C,0., A));
82     else             pos = gp_Ax3(gp_Pnt(  0.,  0.,-D/C),
83                                   gp_Dir(A,B,C),
84                                   gp_Dir( C,0.,-A));
85   }
86   else if (Aabs <= Babs && Aabs <= Cabs) {
87     if (Babs > Cabs) pos = gp_Ax3(gp_Pnt(  0.,-D/B,  0.),
88                                   gp_Dir(A,B,C),
89                                   gp_Dir(0.,-C, B));
90     else             pos = gp_Ax3(gp_Pnt(  0.,  0.,-D/C),
91                                   gp_Dir(A,B,C),
92                                   gp_Dir(0., C,-B));
93   }
94   else {
95     if (Aabs > Babs) pos = gp_Ax3(gp_Pnt(-D/A,  0.,  0.),
96                                   gp_Dir(A,B,C),
97                                   gp_Dir(-B, A, 0.));
98     else             pos = gp_Ax3(gp_Pnt(  0.,-D/B,  0.),
99                                   gp_Dir(A,B,C),
100                                   gp_Dir( B,-A, 0.));
101   }
102
103
104 void gp_Pln::Mirror (const gp_Pnt& P)
105 { pos.Mirror(P);  }
106
107 gp_Pln gp_Pln::Mirrored (const gp_Pnt& P) const
108 {
109   gp_Pln Pl = *this;
110   Pl.pos.Mirror(P);
111   return Pl;
112 }
113
114 void gp_Pln::Mirror (const gp_Ax1& A1)
115 { pos.Mirror(A1); }
116
117 gp_Pln gp_Pln::Mirrored (const gp_Ax1& A1) const
118 {
119   gp_Pln Pl = *this;
120   Pl.pos.Mirror(A1);
121   return Pl;
122 }
123
124 void gp_Pln::Mirror (const gp_Ax2& A2)
125 { pos.Mirror(A2); }
126
127 gp_Pln gp_Pln::Mirrored (const gp_Ax2& A2) const
128 {
129   gp_Pln Pl = *this;
130   Pl.pos.Mirror(A2);
131   return Pl;
132 }
133
134 void gp_Pln::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
135 {
136   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &pos)
137 }