0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / GccAna / GccAna_CircLin2dBisec.cxx
CommitLineData
b311480e 1// Created on: 1991-10-11
2// Created by: Remi GILET
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17//=========================================================================
0d969553 18// CREATION of the BISSECTICE between a CIRCLE and a STRAIGHT LINE. +
7fd59977 19//=========================================================================
20
42cf5bc1 21#include <GccAna_CircLin2dBisec.hxx>
22#include <GccInt_Bisec.hxx>
7fd59977 23#include <GccInt_BLine.hxx>
42cf5bc1 24#include <GccInt_BParab.hxx>
25#include <gp.hxx>
26#include <gp_Ax2d.hxx>
27#include <gp_Circ2d.hxx>
28#include <gp_Dir2d.hxx>
29#include <gp_Lin2d.hxx>
30#include <gp_XY.hxx>
7fd59977 31#include <Standard_OutOfRange.hxx>
32#include <StdFail_NotDone.hxx>
7fd59977 33
34//=========================================================================
7fd59977 35GccAna_CircLin2dBisec::
36 GccAna_CircLin2dBisec (const gp_Circ2d& Circle ,
37 const gp_Lin2d& Line ):
38
39 circle(Circle),
40 line(Line)
41{
42
43//=========================================================================
0d969553
Y
44// Initialization of fields : +
45// - circle +
46// - line (straight line.) +
47// - NbrSol (number of solution.) +
48// - WellDone (Booleen showing success or failure of algorithm). +
7fd59977 49//=========================================================================
50
51 NbrSol = 2;
52 WellDone = Standard_True;
53 }
54
55//=========================================================================
0d969553
Y
56// Processing. +
57// Return coordinates of origins of the straight line (xloc,yloc) and the +
58// circle (xcencir, ycencir). +
59// Also return the coordinates of the direction of the straight line (xdir, +
60// ydir) and the radius of circle R1. +
61// Check at which side of the straight line is found the center of the circle +
62// to orientate the parabola (sign). +
63// Create axis of each parabola (axeparab1, axeparb2), then +
64// two parabolas (biscirlin1, biscirlin1). +
7fd59977 65//=========================================================================
66
67Handle(GccInt_Bisec) GccAna_CircLin2dBisec::
68 ThisSolution (const Standard_Integer Index) const
69{
70
9775fa61 71 if (!WellDone) throw StdFail_NotDone();
7fd59977 72
9775fa61 73 if ((Index <=0) || (Index > NbrSol)) throw Standard_OutOfRange();
7fd59977 74
75 Handle(GccInt_Bisec) bissol;
76 Standard_Real xdir = line.Direction().X();
77 Standard_Real ydir = line.Direction().Y();
78 Standard_Real xloc = line.Location().X();
79 Standard_Real yloc = line.Location().Y();
80 Standard_Real xcencir = circle.Location().X();
81 Standard_Real ycencir = circle.Location().Y();
82 Standard_Real R1 = circle.Radius();
83 Standard_Real dist = line.Distance(circle.Location());
84 if ((Abs(line.Distance(circle.Location())-circle.Radius())
85 <= gp::Resolution()) && (Index == 1)) {
86 gp_Lin2d biscirlin1(circle.Location(),gp_Dir2d(-ydir,xdir));
87 bissol = new GccInt_BLine(biscirlin1);
88 // ==========================================================
89 }
90 else {
91 Standard_Integer signe;
92 if ((-ydir*(xcencir-xloc)+xdir*(ycencir-yloc)) > 0.0) {
93 signe = 1;
94 }
95 else {
96 signe = -1;
97 }
98 gp_Ax2d axeparab1;
99// gp_Ax2d axeparab2;
100 gp_Parab2d biscirlin;
101 if (dist != R1) {
102 if (Index == 1) {
103 axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist+R1)/2,
104 ycencir-signe*xdir*(dist+R1)/2.)),
105 gp_Dir2d(-signe*ydir,signe*xdir));
106 biscirlin = gp_Parab2d(axeparab1,(dist+R1)/2.0);
107 }
108 else {
109 if (dist < R1) {
110 axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist-R1)/2,
111 ycencir-signe*xdir*(dist-R1)/2.)),
112 gp_Dir2d(signe*ydir,-signe*xdir));
113 }
114 else {
115 axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist-R1)/2,
116 ycencir-signe*xdir*(dist-R1)/2.)),
117 gp_Dir2d(-signe*ydir,signe*xdir));
118 }
119 biscirlin = gp_Parab2d(axeparab1,Abs(dist-R1)/2.0);
120 }
121 bissol = new GccInt_BParab(biscirlin);
122 // ==========================================================
123 }
124 else {
125 axeparab1 = gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist+R1)/2.,
126 ycencir-signe*xdir*(dist+R1)/2.)),
127 gp_Dir2d(signe*(-ydir),signe*xdir));
128 biscirlin = gp_Parab2d(axeparab1,R1);
129 bissol = new GccInt_BParab(biscirlin);
130 // ==========================================================
131 }
132 }
133
134 return bissol;
135}
136
137//=========================================================================
138
139Standard_Boolean GccAna_CircLin2dBisec::
140 IsDone () const { return WellDone; }
141
142Standard_Integer GccAna_CircLin2dBisec::
143 NbSolutions () const { return NbrSol; }
144
145