b311480e |
1 | // Created on: 1994-03-24 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1994-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <Geom2dAPI_InterCurveCurve.ixx> |
18 | |
19 | #include <Geom2dAdaptor_Curve.hxx> |
20 | #include <Geom2d_TrimmedCurve.hxx> |
21 | #include <IntRes2d_IntersectionPoint.hxx> |
22 | #include <IntRes2d_IntersectionSegment.hxx> |
23 | |
24 | #include <Standard_NotImplemented.hxx> |
ec357c5c |
25 | #include <Geom2d_Curve.hxx> |
7fd59977 |
26 | |
27 | //======================================================================= |
28 | //function : Geom2dAPI_InterCurveCurve |
29 | //purpose : |
30 | //======================================================================= |
31 | |
32 | Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve() |
33 | { |
34 | myIsDone = Standard_False; |
35 | } |
36 | |
37 | |
38 | //======================================================================= |
39 | //function : Geom2dAPI_InterCurveCurve |
40 | //purpose : |
41 | //======================================================================= |
42 | |
43 | Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve |
44 | (const Handle(Geom2d_Curve)& C1, |
45 | const Handle(Geom2d_Curve)& C2, |
46 | const Standard_Real Tol) |
47 | { |
48 | Init( C1, C2, Tol); |
49 | } |
50 | |
51 | |
52 | //======================================================================= |
53 | //function : Geom2dAPI_InterCurveCurve |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve |
58 | (const Handle(Geom2d_Curve)& C1, |
59 | const Standard_Real Tol) |
60 | { |
61 | Init( C1, Tol); |
62 | } |
63 | |
64 | |
65 | //======================================================================= |
66 | //function : Init |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | void Geom2dAPI_InterCurveCurve::Init |
71 | (const Handle(Geom2d_Curve)& C1, |
72 | const Handle(Geom2d_Curve)& C2, |
73 | const Standard_Real Tol) |
74 | { |
75 | myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy()); |
76 | myCurve2 = Handle(Geom2d_Curve)::DownCast(C2->Copy()); |
77 | |
78 | Geom2dAdaptor_Curve AC1(C1); |
79 | Geom2dAdaptor_Curve AC2(C2); |
80 | myIntersector = Geom2dInt_GInter( AC1, AC2, Tol, Tol); |
81 | myIsDone = myIntersector.IsDone(); |
82 | |
83 | } |
84 | |
85 | |
86 | //======================================================================= |
87 | //function : Init |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | void Geom2dAPI_InterCurveCurve::Init |
92 | (const Handle(Geom2d_Curve)& C1, |
93 | const Standard_Real Tol) |
94 | { |
95 | myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy()); |
96 | myCurve2.Nullify(); |
97 | |
98 | Geom2dAdaptor_Curve AC1(C1); |
99 | myIntersector = Geom2dInt_GInter( AC1, Tol, Tol); |
100 | myIsDone = myIntersector.IsDone(); |
101 | |
102 | } |
103 | |
104 | |
105 | //======================================================================= |
106 | //function : NbPoints |
107 | //purpose : |
108 | //======================================================================= |
109 | |
110 | Standard_Integer Geom2dAPI_InterCurveCurve::NbPoints() const |
111 | { |
112 | if ( myIsDone) |
113 | return myIntersector.NbPoints(); |
114 | else |
115 | return 0; |
116 | } |
117 | |
118 | |
119 | //======================================================================= |
120 | //function : Point |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | gp_Pnt2d Geom2dAPI_InterCurveCurve::Point |
125 | (const Standard_Integer Index) const |
126 | { |
127 | Standard_OutOfRange_Raise_if(Index < 0 || Index > NbPoints(), |
128 | "Geom2dAPI_InterCurveCurve::Points"); |
129 | |
130 | return (myIntersector.Point(Index)).Value(); |
131 | } |
132 | |
133 | |
134 | //======================================================================= |
135 | //function : NbSegments |
136 | //purpose : |
137 | //======================================================================= |
138 | |
139 | Standard_Integer Geom2dAPI_InterCurveCurve::NbSegments() const |
140 | { |
141 | if ( myIsDone) |
142 | return myIntersector.NbSegments(); |
143 | else |
144 | return 0; |
145 | } |
146 | |
147 | |
148 | //======================================================================= |
149 | //function : Segment |
150 | //purpose : |
5b055f07 |
151 | // If aSeg.IsOpposite() == TRUE |
152 | // |
153 | // U1 U2 |
154 | // Curve 1: *------------>* |
155 | // |
156 | // V2 V1 |
157 | // Curve 2: *<------------* |
158 | // |
159 | // Segment: FirstPoint--->LastPoint |
160 | // |
161 | // |
162 | // If aSeg.IsOpposite() == FALSE |
163 | // |
164 | // U1 U2 |
165 | // Curve 1: *------------>* |
166 | // |
167 | // V1 V2 |
168 | // Curve 2: *------------>* |
169 | // |
170 | // Segment: FirstPoint--->LastPoint |
7fd59977 |
171 | //======================================================================= |
172 | |
173 | void Geom2dAPI_InterCurveCurve::Segment |
5b055f07 |
174 | (const Standard_Integer theIndex, |
175 | Handle(Geom2d_Curve)& theCurve1, |
176 | Handle(Geom2d_Curve)& theCurve2) const |
7fd59977 |
177 | { |
5b055f07 |
178 | Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > NbSegments(), |
179 | "Geom2dAPI_InterCurveCurve::Segment"); |
180 | |
181 | Standard_NullObject_Raise_if(myCurve1.IsNull() || myCurve2.IsNull(), |
182 | "Geom2dAPI_InterCurveCurve::Segment"); |
183 | |
184 | Standard_Real aU1 = myCurve1->FirstParameter(), |
185 | aU2 = myCurve1->LastParameter(), |
186 | aV1 = myCurve2->FirstParameter(), |
187 | aV2 = myCurve2->LastParameter(); |
188 | |
189 | const IntRes2d_IntersectionSegment& aSeg = myIntersector.Segment(theIndex); |
190 | const Standard_Boolean isOpposite = aSeg.IsOpposite(); |
191 | |
192 | if(aSeg.HasFirstPoint()) |
193 | { |
194 | const IntRes2d_IntersectionPoint& anIPF = aSeg.FirstPoint(); |
195 | aU1 = anIPF.ParamOnFirst(); |
196 | |
197 | if(isOpposite) |
198 | aV2 = anIPF.ParamOnSecond(); |
199 | else |
200 | aV1 = anIPF.ParamOnSecond(); |
201 | } |
7fd59977 |
202 | |
5b055f07 |
203 | if(aSeg.HasLastPoint()) |
204 | { |
205 | const IntRes2d_IntersectionPoint& anIPL = aSeg.LastPoint(); |
206 | aU2 = anIPL.ParamOnFirst(); |
7fd59977 |
207 | |
5b055f07 |
208 | if(isOpposite) |
209 | aV1 = anIPL.ParamOnSecond(); |
210 | else |
211 | aV2 = anIPL.ParamOnSecond(); |
7fd59977 |
212 | } |
7fd59977 |
213 | |
5b055f07 |
214 | theCurve1 = new Geom2d_TrimmedCurve(myCurve1, aU1, aU2); |
215 | theCurve2 = new Geom2d_TrimmedCurve(myCurve2, aV1, aV2); |
7fd59977 |
216 | } |
217 | |
7fd59977 |
218 | //======================================================================= |
219 | //function : Segment |
220 | //purpose : |
221 | //======================================================================= |
222 | |
498ce76b |
223 | void Geom2dAPI_InterCurveCurve::Segment (const Standard_Integer Index, |
224 | Handle(Geom2d_Curve)&) const |
7fd59977 |
225 | { |
226 | Standard_NotImplemented::Raise(" "); |
105aae76 |
227 | (void)Index; // avoid compiler warning in Release mode |
7fd59977 |
228 | Standard_OutOfRange_Raise_if(Index < 0 || Index > NbSegments(), |
229 | "Geom2dAPI_InterCurveCurve::Segment"); |
7fd59977 |
230 | } |