1 // Created on: 1991-10-04
2 // Created by: Remi GILET
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 //=========================================================================
18 //   CREATION of the BISSECTRICE between a DROITE and POINTS.             +
19 //=========================================================================
20 
21 #include <GccAna_LinPnt2dBisec.hxx>
22 #include <GccInt_Bisec.hxx>
23 #include <GccInt_BLine.hxx>
24 #include <GccInt_BParab.hxx>
25 #include <gp.hxx>
26 #include <gp_Ax2d.hxx>
27 #include <gp_Dir2d.hxx>
28 #include <gp_Lin2d.hxx>
29 #include <gp_Pnt2d.hxx>
30 #include <gp_XY.hxx>
31 #include <Standard_ConstructionError.hxx>
32 #include <StdFail_NotDone.hxx>
33 
34 //=========================================================================
35 GccAna_LinPnt2dBisec::
GccAna_LinPnt2dBisec(const gp_Lin2d & Line1,const gp_Pnt2d & Point2)36    GccAna_LinPnt2dBisec (const gp_Lin2d& Line1 ,
37 		         const gp_Pnt2d& Point2) {
38 
39    WellDone = Standard_False;
40 
41    Standard_Real xdir = Line1.Direction().X();
42    Standard_Real ydir = Line1.Direction().Y();
43    Standard_Real xloc = Line1.Location().X();
44    Standard_Real yloc = Line1.Location().Y();
45    Standard_Real dist = Line1.Distance(Point2);
46 //   if ( dist > gp::Resolution()) {
47    if ( dist > 1.e-10)
48      {
49        Standard_Real xpoint2 = Point2.X();
50        Standard_Real ypoint2 = Point2.Y();
51        if ((-ydir*(xpoint2-xloc)+xdir*(ypoint2-yloc)) > 0.0)
52 	 {
53 	   gp_Ax2d axeparab(gp_Pnt2d(Point2.XY()-dist/2.*gp_XY(-ydir,xdir)),
54 			    gp_Dir2d(-ydir,xdir));
55 	   gp_Parab2d bislinpnt(axeparab,dist/2.0);
56 	   bissol = new GccInt_BParab(bislinpnt);
57 //         =====================================
58 	 }
59        else
60 	 {
61 	   gp_Ax2d axeparab(gp_Pnt2d(Point2.XY()+dist/2.*gp_XY(-ydir,xdir)),
62 			    gp_Dir2d(ydir,-xdir));
63 	   gp_Parab2d bislinpnt(axeparab,dist/2.0);
64 	   bissol = new GccInt_BParab(bislinpnt);
65 //         =====================================
66 	 }
67        WellDone = Standard_True;
68      }
69    else
70      {
71        gp_Lin2d bislinpnt(Point2,gp_Dir2d(-ydir,xdir));
72        bissol = new GccInt_BLine(bislinpnt);
73 //     ====================================
74        WellDone = Standard_True;
75      }
76  }
77 
78 //=========================================================================
79 
80 Standard_Boolean GccAna_LinPnt2dBisec::
IsDone() const81    IsDone () const { return WellDone; }
82 
Handle(GccInt_Bisec)83 Handle(GccInt_Bisec) GccAna_LinPnt2dBisec::
84    ThisSolution () const
85 {
86   if (!WellDone)
87     throw StdFail_NotDone();
88 
89   return bissol;
90 }
91