0032137: Coding Rules - merge redundant .lxx files into header files within Package gp
[occt.git] / src / gp / gp_Ax2.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 1/10/90 Changement de nom du package vgeom -> gp
16 // JCV 12/12/90 Modif mineur suite a la premiere revue de projet
17 // LPA, JCV  07/92 passage sur C1.
18 // JCV 07/92 Introduction de la method Dump 
19
20 #define No_Standard_OutOfRange
21
22 #include <gp_Ax2.hxx>
23
24 #include <gp.hxx>
25 #include <gp_Ax1.hxx>
26 #include <gp_Dir.hxx>
27 #include <gp_Pnt.hxx>
28 #include <gp_Trsf.hxx>
29 #include <gp_Vec.hxx>
30 #include <Standard_ConstructionError.hxx>
31 #include <Standard_Dump.hxx>
32
33 gp_Ax2::gp_Ax2 (const gp_Pnt& P, const gp_Dir& V) :
34 axis(P,V)
35 {
36   Standard_Real A = V.X();
37   Standard_Real B = V.Y();
38   Standard_Real C = V.Z();
39   Standard_Real Aabs = A;
40   if (Aabs < 0) Aabs = - Aabs;
41   Standard_Real Babs = B;
42   if (Babs < 0) Babs = - Babs;
43   Standard_Real Cabs = C;
44   if (Cabs < 0) Cabs = - Cabs;
45   gp_Dir D;
46   
47   //  pour determiner l axe X :
48   //  on dit que le produit scalaire Vx.V = 0. 
49   //  et on recherche le max(A,B,C) pour faire la division.
50   //  l'une des coordonnees du vecteur est nulle. 
51   
52   if      ( Babs <= Aabs && Babs <= Cabs) {
53     if (Aabs > Cabs) D.SetCoord(-C,0., A);
54     else             D.SetCoord( C,0.,-A);
55   }
56   else if ( Aabs <= Babs && Aabs <= Cabs) {
57     if (Babs > Cabs) D.SetCoord(0.,-C, B);
58     else             D.SetCoord(0., C,-B);
59   }
60   else {
61     if (Aabs > Babs) D.SetCoord(-B, A,0.);
62     else             D.SetCoord( B,-A,0.);
63   }
64   SetXDirection(D);
65 }
66
67 void gp_Ax2::Mirror (const gp_Pnt& P)
68 {
69   gp_Pnt Temp = axis.Location();
70   Temp.Mirror (P);
71   axis.SetLocation (Temp);
72   vxdir.Reverse ();
73   vydir.Reverse ();
74 }
75
76 gp_Ax2 gp_Ax2::Mirrored(const gp_Pnt& P) const
77 {
78   gp_Ax2 Temp = *this;
79   Temp.Mirror (P);
80   return Temp;
81 }
82
83 void gp_Ax2::Mirror (const gp_Ax1& A1)
84 {
85   vydir.Mirror (A1);
86   vxdir.Mirror (A1);
87   gp_Pnt Temp = axis.Location();
88   Temp.Mirror (A1);
89   axis.SetLocation (Temp);
90   axis.SetDirection (vxdir.Crossed (vydir));
91 }
92
93 gp_Ax2 gp_Ax2::Mirrored(const gp_Ax1& A1) const
94 {
95   gp_Ax2 Temp = *this;
96   Temp.Mirror (A1);
97   return Temp;
98 }
99
100 void gp_Ax2::Mirror (const gp_Ax2& A2)
101 {
102   vydir.Mirror (A2);
103   vxdir.Mirror (A2);
104   gp_Pnt Temp = axis.Location();
105   Temp.Mirror (A2);
106   axis.SetLocation (Temp);
107   axis.SetDirection (vxdir.Crossed (vydir));
108 }
109
110 gp_Ax2 gp_Ax2::Mirrored(const gp_Ax2& A2) const 
111 {
112   gp_Ax2 Temp = *this;
113   Temp.Mirror (A2);
114   return Temp;
115 }
116
117 void gp_Ax2::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
118 {
119   OCCT_DUMP_VECTOR_CLASS (theOStream, "Location", 3, axis.Location().X(), axis.Location().Y(), axis.Location().Z())
120   OCCT_DUMP_VECTOR_CLASS (theOStream, "Direction", 3, axis.Direction().X(), axis.Direction().Y(), axis.Direction().Z())
121
122   OCCT_DUMP_VECTOR_CLASS (theOStream, "XDirection", 3, vxdir.X(), vxdir.Y(), vxdir.Z())
123   OCCT_DUMP_VECTOR_CLASS (theOStream, "YDirection", 3, vydir.X(), vydir.Y(), vydir.Z())
124 }
125
126 Standard_Boolean gp_Ax2::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
127 {
128   Standard_Integer aPos = theStreamPos;
129   TCollection_AsciiString aStreamStr = Standard_Dump::Text (theSStream);
130
131   gp_XYZ anXYZLoc;
132   OCCT_INIT_VECTOR_CLASS (aStreamStr, "Location", aPos, 3,
133                           &anXYZLoc.ChangeCoord (1), &anXYZLoc.ChangeCoord (2), &anXYZLoc.ChangeCoord (3))
134   SetLocation (anXYZLoc);
135
136   gp_XYZ aDir;
137   OCCT_INIT_VECTOR_CLASS (aStreamStr, "Direction", aPos, 3,
138                           &aDir.ChangeCoord (1), &aDir.ChangeCoord (2), &aDir.ChangeCoord (3))
139   gp_XYZ aXDir;
140   OCCT_INIT_VECTOR_CLASS (aStreamStr, "XDirection", aPos, 3,
141                           &aXDir.ChangeCoord (1), &aXDir.ChangeCoord (2), &aXDir.ChangeCoord (3))
142   gp_XYZ anYDir;
143   OCCT_INIT_VECTOR_CLASS (aStreamStr, "YDirection", aPos, 3,
144                           &anYDir.ChangeCoord (1), &anYDir.ChangeCoord (2), &anYDir.ChangeCoord (3))
145
146   axis.SetDirection (gp_Dir (aDir));
147   vxdir = gp_Dir (aXDir);
148   vydir = gp_Dir (anYDir);
149
150   if (!Direction().IsEqual (aDir, Precision::Confusion()))
151     return Standard_False;
152
153   theStreamPos = aPos;
154   return Standard_True;
155 }