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