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
9 // under the terms of the GNU Lesser General Public 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>
26 //=======================================================================
27 //function : Geom2dAPI_InterCurveCurve
29 //=======================================================================
31 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve()
33 myIsDone = Standard_False;
37 //=======================================================================
38 //function : Geom2dAPI_InterCurveCurve
40 //=======================================================================
42 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
43 (const Handle(Geom2d_Curve)& C1,
44 const Handle(Geom2d_Curve)& C2,
45 const Standard_Real Tol)
51 //=======================================================================
52 //function : Geom2dAPI_InterCurveCurve
54 //=======================================================================
56 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
57 (const Handle(Geom2d_Curve)& C1,
58 const Standard_Real Tol)
64 //=======================================================================
67 //=======================================================================
69 void Geom2dAPI_InterCurveCurve::Init
70 (const Handle(Geom2d_Curve)& C1,
71 const Handle(Geom2d_Curve)& C2,
72 const Standard_Real Tol)
74 myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
75 myCurve2 = Handle(Geom2d_Curve)::DownCast(C2->Copy());
77 Geom2dAdaptor_Curve AC1(C1);
78 Geom2dAdaptor_Curve AC2(C2);
79 myIntersector = Geom2dInt_GInter( AC1, AC2, Tol, Tol);
80 myIsDone = myIntersector.IsDone();
85 //=======================================================================
88 //=======================================================================
90 void Geom2dAPI_InterCurveCurve::Init
91 (const Handle(Geom2d_Curve)& C1,
92 const Standard_Real Tol)
94 myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
97 Geom2dAdaptor_Curve AC1(C1);
98 myIntersector = Geom2dInt_GInter( AC1, Tol, Tol);
99 myIsDone = myIntersector.IsDone();
104 //=======================================================================
105 //function : NbPoints
107 //=======================================================================
109 Standard_Integer Geom2dAPI_InterCurveCurve::NbPoints() const
112 return myIntersector.NbPoints();
118 //=======================================================================
121 //=======================================================================
123 gp_Pnt2d Geom2dAPI_InterCurveCurve::Point
124 (const Standard_Integer Index) const
126 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbPoints(),
127 "Geom2dAPI_InterCurveCurve::Points");
129 return (myIntersector.Point(Index)).Value();
133 //=======================================================================
134 //function : NbSegments
136 //=======================================================================
138 Standard_Integer Geom2dAPI_InterCurveCurve::NbSegments() const
141 return myIntersector.NbSegments();
147 //=======================================================================
150 //=======================================================================
152 void Geom2dAPI_InterCurveCurve::Segment
153 (const Standard_Integer Index,
154 Handle(Geom2d_Curve)& Curve1,
155 Handle(Geom2d_Curve)& Curve2) const
157 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbSegments(),
158 "Geom2dAPI_InterCurveCurve::Segment");
160 Standard_NullObject_Raise_if(myCurve2.IsNull(),
161 "Geom2dAPI_InterCurveCurve::Segment");
163 Standard_Real U1, U2, V1, V2;
165 IntRes2d_IntersectionSegment Seg = myIntersector.Segment(Index);
166 if ( Seg.IsOpposite()) {
167 if ( Seg.HasFirstPoint()) {
168 IntRes2d_IntersectionPoint IP1 = Seg.FirstPoint();
169 U1 = IP1.ParamOnFirst();
170 V2 = IP1.ParamOnSecond();
173 U1 = Curve1->FirstParameter();
174 V2 = Curve2->LastParameter();
176 if ( Seg.HasLastPoint()) {
177 IntRes2d_IntersectionPoint IP2 = Seg.LastPoint();
178 U2 = IP2.ParamOnFirst();
179 V1 = IP2.ParamOnSecond();
182 U2 = Curve1->FirstParameter();
183 V1 = Curve2->LastParameter();
187 if ( Seg.HasFirstPoint()) {
188 IntRes2d_IntersectionPoint IP1 = Seg.FirstPoint();
189 U1 = IP1.ParamOnFirst();
190 V1 = IP1.ParamOnSecond();
193 U1 = Curve1->FirstParameter();
194 V1 = Curve2->FirstParameter();
196 if ( Seg.HasLastPoint()) {
197 IntRes2d_IntersectionPoint IP2 = Seg.LastPoint();
198 U2 = IP2.ParamOnFirst();
199 V2 = IP2.ParamOnSecond();
202 U2 = Curve1->FirstParameter();
203 V2 = Curve2->FirstParameter();
207 Curve1 = new Geom2d_TrimmedCurve(myCurve1, U1, U2);
208 Curve2 = new Geom2d_TrimmedCurve(myCurve2, V1, V2);
213 //=======================================================================
216 //=======================================================================
218 void Geom2dAPI_InterCurveCurve::Segment (const Standard_Integer Index,
219 Handle(Geom2d_Curve)&) const
221 Standard_NotImplemented::Raise(" ");
222 (void)Index; // avoid compiler warning in Release mode
223 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbSegments(),
224 "Geom2dAPI_InterCurveCurve::Segment");