1 // Created on: 1994-03-24
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Geom2dAPI_InterCurveCurve.ixx>
19 #include <Geom2dAdaptor_Curve.hxx>
20 #include <Geom2d_TrimmedCurve.hxx>
21 #include <IntRes2d_IntersectionPoint.hxx>
22 #include <IntRes2d_IntersectionSegment.hxx>
24 #include <Standard_NotImplemented.hxx>
25 #include <Geom2d_Curve.hxx>
27 //=======================================================================
28 //function : Geom2dAPI_InterCurveCurve
30 //=======================================================================
32 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve()
34 myIsDone = Standard_False;
38 //=======================================================================
39 //function : Geom2dAPI_InterCurveCurve
41 //=======================================================================
43 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
44 (const Handle(Geom2d_Curve)& C1,
45 const Handle(Geom2d_Curve)& C2,
46 const Standard_Real Tol)
52 //=======================================================================
53 //function : Geom2dAPI_InterCurveCurve
55 //=======================================================================
57 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
58 (const Handle(Geom2d_Curve)& C1,
59 const Standard_Real Tol)
65 //=======================================================================
68 //=======================================================================
70 void Geom2dAPI_InterCurveCurve::Init
71 (const Handle(Geom2d_Curve)& C1,
72 const Handle(Geom2d_Curve)& C2,
73 const Standard_Real Tol)
75 myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
76 myCurve2 = Handle(Geom2d_Curve)::DownCast(C2->Copy());
78 Geom2dAdaptor_Curve AC1(C1);
79 Geom2dAdaptor_Curve AC2(C2);
80 myIntersector = Geom2dInt_GInter( AC1, AC2, Tol, Tol);
81 myIsDone = myIntersector.IsDone();
86 //=======================================================================
89 //=======================================================================
91 void Geom2dAPI_InterCurveCurve::Init
92 (const Handle(Geom2d_Curve)& C1,
93 const Standard_Real Tol)
95 myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
98 Geom2dAdaptor_Curve AC1(C1);
99 myIntersector = Geom2dInt_GInter( AC1, Tol, Tol);
100 myIsDone = myIntersector.IsDone();
105 //=======================================================================
106 //function : NbPoints
108 //=======================================================================
110 Standard_Integer Geom2dAPI_InterCurveCurve::NbPoints() const
113 return myIntersector.NbPoints();
119 //=======================================================================
122 //=======================================================================
124 gp_Pnt2d Geom2dAPI_InterCurveCurve::Point
125 (const Standard_Integer Index) const
127 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbPoints(),
128 "Geom2dAPI_InterCurveCurve::Points");
130 return (myIntersector.Point(Index)).Value();
134 //=======================================================================
135 //function : NbSegments
137 //=======================================================================
139 Standard_Integer Geom2dAPI_InterCurveCurve::NbSegments() const
142 return myIntersector.NbSegments();
148 //=======================================================================
151 // If aSeg.IsOpposite() == TRUE
154 // Curve 1: *------------>*
157 // Curve 2: *<------------*
159 // Segment: FirstPoint--->LastPoint
162 // If aSeg.IsOpposite() == FALSE
165 // Curve 1: *------------>*
168 // Curve 2: *------------>*
170 // Segment: FirstPoint--->LastPoint
171 //=======================================================================
173 void Geom2dAPI_InterCurveCurve::Segment
174 (const Standard_Integer theIndex,
175 Handle(Geom2d_Curve)& theCurve1,
176 Handle(Geom2d_Curve)& theCurve2) const
178 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > NbSegments(),
179 "Geom2dAPI_InterCurveCurve::Segment");
181 Standard_NullObject_Raise_if(myCurve1.IsNull() || myCurve2.IsNull(),
182 "Geom2dAPI_InterCurveCurve::Segment");
184 Standard_Real aU1 = myCurve1->FirstParameter(),
185 aU2 = myCurve1->LastParameter(),
186 aV1 = myCurve2->FirstParameter(),
187 aV2 = myCurve2->LastParameter();
189 const IntRes2d_IntersectionSegment& aSeg = myIntersector.Segment(theIndex);
190 const Standard_Boolean isOpposite = aSeg.IsOpposite();
192 if(aSeg.HasFirstPoint())
194 const IntRes2d_IntersectionPoint& anIPF = aSeg.FirstPoint();
195 aU1 = anIPF.ParamOnFirst();
198 aV2 = anIPF.ParamOnSecond();
200 aV1 = anIPF.ParamOnSecond();
203 if(aSeg.HasLastPoint())
205 const IntRes2d_IntersectionPoint& anIPL = aSeg.LastPoint();
206 aU2 = anIPL.ParamOnFirst();
209 aV1 = anIPL.ParamOnSecond();
211 aV2 = anIPL.ParamOnSecond();
214 theCurve1 = new Geom2d_TrimmedCurve(myCurve1, aU1, aU2);
215 theCurve2 = new Geom2d_TrimmedCurve(myCurve2, aV1, aV2);
218 //=======================================================================
221 //=======================================================================
223 void Geom2dAPI_InterCurveCurve::Segment (const Standard_Integer Index,
224 Handle(Geom2d_Curve)&) const
226 Standard_NotImplemented::Raise(" ");
227 (void)Index; // avoid compiler warning in Release mode
228 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbSegments(),
229 "Geom2dAPI_InterCurveCurve::Segment");