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.
18 #include <Geom2d_Curve.hxx>
19 #include <Geom2d_TrimmedCurve.hxx>
20 #include <Geom2dAdaptor_Curve.hxx>
21 #include <Geom2dAPI_InterCurveCurve.hxx>
22 #include <Geom2dInt_GInter.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <IntRes2d_IntersectionPoint.hxx>
25 #include <IntRes2d_IntersectionSegment.hxx>
26 #include <Standard_NotImplemented.hxx>
27 #include <Standard_NullObject.hxx>
28 #include <Standard_OutOfRange.hxx>
30 //=======================================================================
31 //function : Geom2dAPI_InterCurveCurve
33 //=======================================================================
34 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve()
36 myIsDone = Standard_False;
40 //=======================================================================
41 //function : Geom2dAPI_InterCurveCurve
43 //=======================================================================
45 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
46 (const Handle(Geom2d_Curve)& C1,
47 const Handle(Geom2d_Curve)& C2,
48 const Standard_Real Tol)
54 //=======================================================================
55 //function : Geom2dAPI_InterCurveCurve
57 //=======================================================================
59 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
60 (const Handle(Geom2d_Curve)& C1,
61 const Standard_Real Tol)
67 //=======================================================================
70 //=======================================================================
72 void Geom2dAPI_InterCurveCurve::Init
73 (const Handle(Geom2d_Curve)& C1,
74 const Handle(Geom2d_Curve)& C2,
75 const Standard_Real Tol)
77 myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
78 myCurve2 = Handle(Geom2d_Curve)::DownCast(C2->Copy());
80 Geom2dAdaptor_Curve AC1(C1);
81 Geom2dAdaptor_Curve AC2(C2);
82 myIntersector = Geom2dInt_GInter( AC1, AC2, Tol, Tol);
83 myIsDone = myIntersector.IsDone();
88 //=======================================================================
91 //=======================================================================
93 void Geom2dAPI_InterCurveCurve::Init
94 (const Handle(Geom2d_Curve)& C1,
95 const Standard_Real Tol)
97 myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
100 Geom2dAdaptor_Curve AC1(C1);
101 myIntersector = Geom2dInt_GInter( AC1, Tol, Tol);
102 myIsDone = myIntersector.IsDone();
107 //=======================================================================
108 //function : NbPoints
110 //=======================================================================
112 Standard_Integer Geom2dAPI_InterCurveCurve::NbPoints() const
115 return myIntersector.NbPoints();
121 //=======================================================================
124 //=======================================================================
126 gp_Pnt2d Geom2dAPI_InterCurveCurve::Point
127 (const Standard_Integer Index) const
129 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbPoints(),
130 "Geom2dAPI_InterCurveCurve::Points");
132 return (myIntersector.Point(Index)).Value();
136 //=======================================================================
137 //function : NbSegments
139 //=======================================================================
141 Standard_Integer Geom2dAPI_InterCurveCurve::NbSegments() const
144 return myIntersector.NbSegments();
150 //=======================================================================
153 // If aSeg.IsOpposite() == TRUE
156 // Curve 1: *------------>*
159 // Curve 2: *<------------*
161 // Segment: FirstPoint--->LastPoint
164 // If aSeg.IsOpposite() == FALSE
167 // Curve 1: *------------>*
170 // Curve 2: *------------>*
172 // Segment: FirstPoint--->LastPoint
173 //=======================================================================
175 void Geom2dAPI_InterCurveCurve::Segment
176 (const Standard_Integer theIndex,
177 Handle(Geom2d_Curve)& theCurve1,
178 Handle(Geom2d_Curve)& theCurve2) const
180 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > NbSegments(),
181 "Geom2dAPI_InterCurveCurve::Segment");
183 Standard_NullObject_Raise_if(myCurve1.IsNull(),
184 "Geom2dAPI_InterCurveCurve::Segment");
186 Standard_Real aU1, aU2, aV1, aV2;
187 aU1 = myCurve1->FirstParameter();
188 aU2 = myCurve1->LastParameter();
189 if (myCurve2.IsNull())
196 aV1 = myCurve2->FirstParameter();
197 aV2 = myCurve2->LastParameter();
200 const IntRes2d_IntersectionSegment& aSeg = myIntersector.Segment(theIndex);
201 const Standard_Boolean isOpposite = aSeg.IsOpposite();
203 if(aSeg.HasFirstPoint())
205 const IntRes2d_IntersectionPoint& anIPF = aSeg.FirstPoint();
206 aU1 = anIPF.ParamOnFirst();
209 aV2 = anIPF.ParamOnSecond();
211 aV1 = anIPF.ParamOnSecond();
214 if(aSeg.HasLastPoint())
216 const IntRes2d_IntersectionPoint& anIPL = aSeg.LastPoint();
217 aU2 = anIPL.ParamOnFirst();
220 aV1 = anIPL.ParamOnSecond();
222 aV2 = anIPL.ParamOnSecond();
225 theCurve1 = new Geom2d_TrimmedCurve(myCurve1, aU1, aU2);
226 if (myCurve2.IsNull())
227 theCurve2 = new Geom2d_TrimmedCurve(myCurve1, aV1, aV2);
229 theCurve2 = new Geom2d_TrimmedCurve(myCurve2, aV1, aV2);