1 // Created on: 1994-03-24
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <Geom2dAPI_InterCurveCurve.ixx>
25 #include <Geom2dAdaptor_Curve.hxx>
26 #include <Geom2d_TrimmedCurve.hxx>
27 #include <IntRes2d_IntersectionPoint.hxx>
28 #include <IntRes2d_IntersectionSegment.hxx>
30 #include <Standard_NotImplemented.hxx>
32 //=======================================================================
33 //function : Geom2dAPI_InterCurveCurve
35 //=======================================================================
37 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve()
39 myIsDone = Standard_False;
43 //=======================================================================
44 //function : Geom2dAPI_InterCurveCurve
46 //=======================================================================
48 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
49 (const Handle(Geom2d_Curve)& C1,
50 const Handle(Geom2d_Curve)& C2,
51 const Standard_Real Tol)
57 //=======================================================================
58 //function : Geom2dAPI_InterCurveCurve
60 //=======================================================================
62 Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
63 (const Handle(Geom2d_Curve)& C1,
64 const Standard_Real Tol)
70 //=======================================================================
73 //=======================================================================
75 void Geom2dAPI_InterCurveCurve::Init
76 (const Handle(Geom2d_Curve)& C1,
77 const Handle(Geom2d_Curve)& C2,
78 const Standard_Real Tol)
80 myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
81 myCurve2 = Handle(Geom2d_Curve)::DownCast(C2->Copy());
83 Geom2dAdaptor_Curve AC1(C1);
84 Geom2dAdaptor_Curve AC2(C2);
85 myIntersector = Geom2dInt_GInter( AC1, AC2, Tol, Tol);
86 myIsDone = myIntersector.IsDone();
91 //=======================================================================
94 //=======================================================================
96 void Geom2dAPI_InterCurveCurve::Init
97 (const Handle(Geom2d_Curve)& C1,
98 const Standard_Real Tol)
100 myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
103 Geom2dAdaptor_Curve AC1(C1);
104 myIntersector = Geom2dInt_GInter( AC1, Tol, Tol);
105 myIsDone = myIntersector.IsDone();
110 //=======================================================================
111 //function : NbPoints
113 //=======================================================================
115 Standard_Integer Geom2dAPI_InterCurveCurve::NbPoints() const
118 return myIntersector.NbPoints();
124 //=======================================================================
127 //=======================================================================
129 gp_Pnt2d Geom2dAPI_InterCurveCurve::Point
130 (const Standard_Integer Index) const
132 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbPoints(),
133 "Geom2dAPI_InterCurveCurve::Points");
135 return (myIntersector.Point(Index)).Value();
139 //=======================================================================
140 //function : NbSegments
142 //=======================================================================
144 Standard_Integer Geom2dAPI_InterCurveCurve::NbSegments() const
147 return myIntersector.NbSegments();
153 //=======================================================================
156 //=======================================================================
158 void Geom2dAPI_InterCurveCurve::Segment
159 (const Standard_Integer Index,
160 Handle(Geom2d_Curve)& Curve1,
161 Handle(Geom2d_Curve)& Curve2) const
163 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbSegments(),
164 "Geom2dAPI_InterCurveCurve::Segment");
166 Standard_NullObject_Raise_if(myCurve2.IsNull(),
167 "Geom2dAPI_InterCurveCurve::Segment");
169 Standard_Real U1, U2, V1, V2;
171 IntRes2d_IntersectionSegment Seg = myIntersector.Segment(Index);
172 if ( Seg.IsOpposite()) {
173 if ( Seg.HasFirstPoint()) {
174 IntRes2d_IntersectionPoint IP1 = Seg.FirstPoint();
175 U1 = IP1.ParamOnFirst();
176 V2 = IP1.ParamOnSecond();
179 U1 = Curve1->FirstParameter();
180 V2 = Curve2->LastParameter();
182 if ( Seg.HasLastPoint()) {
183 IntRes2d_IntersectionPoint IP2 = Seg.LastPoint();
184 U2 = IP2.ParamOnFirst();
185 V1 = IP2.ParamOnSecond();
188 U2 = Curve1->FirstParameter();
189 V1 = Curve2->LastParameter();
193 if ( Seg.HasFirstPoint()) {
194 IntRes2d_IntersectionPoint IP1 = Seg.FirstPoint();
195 U1 = IP1.ParamOnFirst();
196 V1 = IP1.ParamOnSecond();
199 U1 = Curve1->FirstParameter();
200 V1 = Curve2->FirstParameter();
202 if ( Seg.HasLastPoint()) {
203 IntRes2d_IntersectionPoint IP2 = Seg.LastPoint();
204 U2 = IP2.ParamOnFirst();
205 V2 = IP2.ParamOnSecond();
208 U2 = Curve1->FirstParameter();
209 V2 = Curve2->FirstParameter();
213 Curve1 = new Geom2d_TrimmedCurve(myCurve1, U1, U2);
214 Curve2 = new Geom2d_TrimmedCurve(myCurve2, V1, V2);
219 //=======================================================================
222 //=======================================================================
224 void Geom2dAPI_InterCurveCurve::Segment
225 (const Standard_Integer Index,
226 Handle(Geom2d_Curve)& //Curve1
229 Standard_NotImplemented::Raise(" ");
231 Standard_OutOfRange_Raise_if(Index < 0 || Index > NbSegments(),
232 "Geom2dAPI_InterCurveCurve::Segment");