0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / GccAna / GccAna_Lin2dBisec.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 //=========================================================================
16 //   CREATION of the BISSECTICE between two STRAIGHT LINES.                        +
17 //=========================================================================
18
19 #include <ElCLib.hxx>
20 #include <GccAna_Lin2dBisec.hxx>
21 #include <GccEnt_BadQualifier.hxx>
22 #include <gp.hxx>
23 #include <gp_Dir2d.hxx>
24 #include <gp_Lin2d.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <gp_XY.hxx>
28 #include <IntAna2d_AnaIntersection.hxx>
29 #include <IntAna2d_IntPoint.hxx>
30 #include <Standard_OutOfRange.hxx>
31 #include <StdFail_NotDone.hxx>
32
33 //=========================================================================
34 //   The first calculated bissectrice is the interior bisectrice, the     +
35 //   second is the exterior bissectrice.                                  +
36 //   the direction of the first bissectrice is such that its scalar product +
37 //   with direction of Lin1 is always positive.             +
38 //   The second bissectrice is turned in the positive direction.             +
39 //=========================================================================
40 GccAna_Lin2dBisec::
41    GccAna_Lin2dBisec (const gp_Lin2d& Lin1,
42                       const gp_Lin2d& Lin2):
43    linsol(1,2)    ,
44    pntint1sol(1,2),
45    pntint2sol(1,2),
46    par1sol(1,2),
47    par2sol(1,2),
48    pararg1(1,2),
49    pararg2(1,2) {
50
51    WellDone = Standard_False;
52    NbrSol = 0;
53
54    IntAna2d_AnaIntersection Intp(Lin1,Lin2);
55    if (Intp.IsDone()) {
56      
57      if (Intp.ParallelElements()) {
58        if (Intp.IdenticalElements()) {
59          NbrSol = 1;
60          WellDone = Standard_True;
61          linsol(NbrSol) = gp_Lin2d(Lin1);
62        }
63        else {
64          // Attention : do not use dist = Lin1.Distance(Lin2);
65          // as straight lines can be concurrent for gp_Lin2d
66          // so dist = 0.0 (test of the angle too strict ?)
67          Standard_Real dist = Lin1.Distance(Lin2.Location())/2.0;
68          Standard_Real cross = 
69            gp_Vec2d ( -Lin2.Direction().Y() , Lin2.Direction().X() )
70            .Dot ( gp_Vec2d ( Lin2.Location() , Lin1.Location() ) );
71          if (cross < 0) dist = -dist;
72          NbrSol++;
73          WellDone = Standard_True;
74          linsol(NbrSol) = gp_Lin2d(gp_Pnt2d(Lin2.Location().XY()+
75 //       ========================================================
76                  gp_XY(-Lin2.Direction().Y()*dist,Lin2.Direction().X()*dist)),
77 //               =============================================================
78                  Lin2.Direction());
79 //               =================
80        }
81      }
82      
83      else {
84        if (!Intp.IsEmpty()) {
85          for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
86            NbrSol++;
87            linsol(NbrSol) = gp_Lin2d(Intp.Point(i).Value(),
88 //         ================================================
89                        gp_Dir2d(Lin1.Direction().XY()+Lin2.Direction().XY()));
90 //                     ======================================================
91            NbrSol++;
92            linsol(NbrSol) = gp_Lin2d(Intp.Point(i).Value(),
93 //         ===============================================
94                        gp_Dir2d(Lin1.Direction().XY()-Lin2.Direction().XY()));
95 //                     ======================================================
96            if (Lin1.Angle(Lin2) >= 0.) { linsol(NbrSol).Reverse(); }
97            WellDone = Standard_True;
98          }
99        }
100      }
101    }
102
103    for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
104      pntint1sol(i) = linsol(i).Location();
105      pntint2sol(i) = pntint1sol(i);
106      par1sol(i)=ElCLib::Parameter(linsol(i),pntint1sol(i));
107      par2sol(i)=ElCLib::Parameter(linsol(i),pntint2sol(i));
108      pararg1(i)=ElCLib::Parameter(Lin1,pntint1sol(i));
109      pararg2(i)=ElCLib::Parameter(Lin2,pntint2sol(i));
110    }
111
112  }
113
114 //=========================================================================
115
116 Standard_Boolean GccAna_Lin2dBisec::
117    IsDone () const { return WellDone; }
118
119
120 Standard_Integer GccAna_Lin2dBisec::
121    NbSolutions () const 
122 {
123   if (!WellDone) 
124     throw StdFail_NotDone();
125   return NbrSol;
126 }
127
128 gp_Lin2d GccAna_Lin2dBisec::
129    ThisSolution (const Standard_Integer Index) const 
130 {
131   if (!WellDone) 
132     throw StdFail_NotDone();
133   if (Index <= 0 || Index > NbrSol) 
134     throw Standard_OutOfRange();
135   return linsol(Index);
136 }
137
138 void GccAna_Lin2dBisec::
139    Intersection1 (const Standard_Integer Index,
140                   Standard_Real& ParSol,
141                   Standard_Real& ParArg,
142                   gp_Pnt2d& PntSol) const{
143    if (!WellDone) { throw StdFail_NotDone(); }
144    else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
145    else {
146      ParSol = par1sol(Index);
147      ParArg = pararg1(Index);
148      PntSol = gp_Pnt2d(pntint1sol(Index));
149    }
150  }
151
152
153 void GccAna_Lin2dBisec::
154    Intersection2 (const Standard_Integer Index,
155                   Standard_Real& ParSol,
156                   Standard_Real& ParArg,
157                   gp_Pnt2d& PntSol) const{
158    if (!WellDone) { throw StdFail_NotDone(); }
159    else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
160    else {
161      ParSol = par2sol(Index);
162      ParArg = pararg2(Index);
163      PntSol = gp_Pnt2d(pntint2sol(Index));
164    }
165  }
166