0024275: Cppcheck warnings on uninitialized class members
[occt.git] / src / ChFi2d / ChFi2d_ChamferAPI.cxx
CommitLineData
8b7c5e47 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
18#include <ChFi2d_ChamferAPI.hxx>
19
20#include <Precision.hxx>
21#include <gp_Pnt.hxx>
22#include <GC_MakeLine.hxx>
23#include <BRep_Tool.hxx>
24#include <BRepBuilderAPI_MakeEdge.hxx>
25#include <TopoDS_Iterator.hxx>
26#include <TopoDS.hxx>
27
28// An empty constructor.
29ChFi2d_ChamferAPI::ChFi2d_ChamferAPI()
30{
31
32}
33
34// A constructor accepting a wire consisting of two linear edges.
c24d4017 35ChFi2d_ChamferAPI::ChFi2d_ChamferAPI(const TopoDS_Wire& theWire) :
36 myStart1(0.),
37 myEnd1(0.),
38 myStart2(0.),
39 myEnd2(0.),
40 myCommonStart1(Standard_False),
41 myCommonStart2(Standard_False)
8b7c5e47 42{
43 Init(theWire);
44}
45
46// A constructor accepting two linear edges.
c24d4017 47ChFi2d_ChamferAPI::ChFi2d_ChamferAPI(const TopoDS_Edge& theEdge1, const TopoDS_Edge& theEdge2) :
48 myStart1(0.),
49 myEnd1(0.),
50 myStart2(0.),
51 myEnd2(0.),
52 myCommonStart1(Standard_False),
53 myCommonStart2(Standard_False)
8b7c5e47 54{
55 Init(theEdge1, theEdge2);
56}
57
58// Initializes the class by a wire consisting of two libear edges.
59void ChFi2d_ChamferAPI::Init(const TopoDS_Wire& theWire)
60{
61 TopoDS_Edge E1, E2;
62 TopoDS_Iterator itr(theWire);
63 for (; itr.More(); itr.Next())
64 {
65 if (E1.IsNull())
66 E1 = TopoDS::Edge(itr.Value());
67 else if (E2.IsNull())
68 E2 = TopoDS::Edge(itr.Value());
69 else
70 break;
71 }
72 Init(E1, E2);
73}
74
75// Initializes the class by two linear edges.
76void ChFi2d_ChamferAPI::Init(const TopoDS_Edge& theEdge1, const TopoDS_Edge& theEdge2)
77{
78 myEdge1 = theEdge1;
79 myEdge2 = theEdge2;
80}
81
82// Constructs a chamfer edge.
83// Returns true if the edge is constructed.
84Standard_Boolean ChFi2d_ChamferAPI::Perform()
85{
86 myCurve1 = BRep_Tool::Curve(myEdge1, myStart1, myEnd1);
87 myCurve2 = BRep_Tool::Curve(myEdge2, myStart2, myEnd2);
88 // searching for common points
89 if (myCurve1->Value(myStart1).IsEqual(myCurve2->Value(myEnd2), Precision::Confusion()))
90 {
91 myCommonStart1 = true;
92 myCommonStart2 = false;
93 }
94 else
95 {
96 if (myCurve1->Value(myEnd1).IsEqual(myCurve2->Value(myStart2), Precision::Confusion()))
97 {
98 myCommonStart1 = false;
99 myCommonStart2 = true;
100 }
101 else
102 {
103 if (myCurve1->Value(myEnd1).IsEqual(myCurve2->Value(myEnd2), Precision::Confusion()))
104 {
105 myCommonStart1 = false;
106 myCommonStart2 = false;
107 }
108 else
109 {
110 myCommonStart1 = true;
111 myCommonStart2 = true;
112 }
113 }
114 }
115 return Standard_True;
116}
117
118// Returns the result (chamfer edge, modified edge1, modified edge2).
119TopoDS_Edge ChFi2d_ChamferAPI::Result(TopoDS_Edge& theEdge1, TopoDS_Edge& theEdge2,
120 const Standard_Real theLength1, const Standard_Real theLength2)
121{
122 TopoDS_Edge aResult;
123 if (Abs(myEnd1 - myStart1) < theLength1)
124 return aResult;
125 if (Abs(myEnd2 - myStart2) < theLength2)
126 return aResult;
127
128 Standard_Real aCommon1 = (myCommonStart1?myStart1:myEnd1) + (((myStart1 > myEnd1)^myCommonStart1)?theLength1:-theLength1);
129 Standard_Real aCommon2 = (myCommonStart2?myStart2:myEnd2) + (((myStart2 > myEnd2)^myCommonStart2)?theLength2:-theLength2);
130
131 // make chamfer edge
132 GC_MakeLine aML(myCurve1->Value(aCommon1), myCurve2->Value(aCommon2));
133 BRepBuilderAPI_MakeEdge aBuilder(aML.Value(), myCurve1->Value(aCommon1), myCurve2->Value(aCommon2));
134 aResult = aBuilder.Edge();
135 // divide first edge
136 BRepBuilderAPI_MakeEdge aDivider1(myCurve1, aCommon1, (myCommonStart1?myEnd1:myStart1));
137 theEdge1 = aDivider1.Edge();
138 // divide second edge
139 BRepBuilderAPI_MakeEdge aDivider2(myCurve2, aCommon2, (myCommonStart2?myEnd2:myStart2));
140 theEdge2 = aDivider2.Edge();
141
142 return aResult;
143}