0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / gp / gp_Ax2d.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 08/01/91 modif introduction des classes XY et Mat dans le package
16 // LPA, JCV  07/92 passage sur C1.
17 // JCV 07/92 Introduction de la method Dump 
18
19 #define No_Standard_OutOfRange
20
21
22 #include <gp_Ax2d.hxx>
23 #include <gp_Dir2d.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <gp_Trsf2d.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <gp_XY.hxx>
28 #include <Standard_Dump.hxx>
29
30 Standard_Boolean gp_Ax2d::IsCoaxial (const gp_Ax2d& Other, 
31                                      const Standard_Real AngularTolerance,
32                                      const Standard_Real LinearTolerance) const
33 {
34   gp_XY XY1 = loc.XY();
35   XY1.Subtract (Other.loc.XY());
36   Standard_Real D1 = XY1.Crossed (Other.vdir.XY());
37   if (D1 < 0) D1 = - D1;
38   gp_XY XY2 = Other.loc.XY();
39   XY2.Subtract (loc.XY());
40   Standard_Real D2 = XY2.Crossed (vdir.XY());
41   if (D2 < 0) D2 = - D2;
42   return (vdir.IsParallel (Other.vdir, AngularTolerance) &&
43           D1 <= LinearTolerance && D2 <= LinearTolerance);
44 }
45
46 void gp_Ax2d::Scale (const gp_Pnt2d& P,
47                      const Standard_Real S)
48 {
49   loc.Scale(P, S);
50   if (S < 0.0)  vdir.Reverse();
51 }
52
53 void gp_Ax2d::Mirror (const gp_Pnt2d& P)
54 {
55   loc.Mirror(P);
56   vdir.Reverse();
57 }
58
59 gp_Ax2d gp_Ax2d::Mirrored (const gp_Pnt2d& P) const
60 {
61   gp_Ax2d A = *this;    
62   A.Mirror (P);
63   return A;
64 }
65
66 void gp_Ax2d::Mirror (const gp_Ax2d& A)
67 {
68   loc.Mirror (A);
69   vdir.Mirror (A.vdir); 
70 }
71
72 gp_Ax2d gp_Ax2d::Mirrored (const gp_Ax2d& A) const
73 {
74   gp_Ax2d AA = *this;
75   AA.Mirror (A);
76   return AA;
77 }
78
79 void gp_Ax2d::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
80 {
81   OCCT_DUMP_CLASS_BEGIN (theOStream, gp_Ax2d)
82
83   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &loc)
84   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &vdir)
85 }