1 // Created on: 1994-09-23
2 // Created by: Yves FRICAUD
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 <Geom2dLProp_CurAndInf2d.hxx>
21 #include <gp_Pnt2d.hxx>
22 #include <MAT2d_CutCurve.hxx>
23 #include <Precision.hxx>
24 #include <Standard_OutOfRange.hxx>
25 #include <TColGeom2d_SequenceOfCurve.hxx>
27 //=======================================================================
28 //function : MAT2d_CutCurve
30 //=======================================================================
31 MAT2d_CutCurve::MAT2d_CutCurve()
36 //=======================================================================
37 //function : MAT2d_CutCurve
39 //=======================================================================
41 MAT2d_CutCurve::MAT2d_CutCurve(const Handle(Geom2d_Curve)& C)
47 //=======================================================================
50 //=======================================================================
52 void MAT2d_CutCurve::Perform(const Handle(Geom2d_Curve)& C)
56 Geom2dLProp_CurAndInf2d Sommets;
57 Handle(Geom2d_TrimmedCurve) TrimC;
58 Standard_Real UF,UL,UC;
60 Standard_Real PTol = Precision::PConfusion()*10;
61 Standard_Real Tol = Precision::Confusion()*10;
62 Standard_Boolean YaCut = Standard_False;
65 if (Sommets.IsDone() && !Sommets.IsEmpty()) {
66 UF = C->FirstParameter();
67 UL = C->LastParameter ();
71 for (Standard_Integer i = 1; i <= Sommets.NbPoints(); i++) {
72 UC = Sommets.Parameter(i);
75 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
76 if ( UL - UC < PTol || PL.Distance(PC) < Tol) {
79 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
80 theCurves.Append(TrimC);
83 YaCut = Standard_True;
87 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
88 theCurves.Append(TrimC);
94 //=======================================================================
95 //function : UnModified
97 //=======================================================================
99 Standard_Boolean MAT2d_CutCurve::UnModified() const
101 return theCurves.IsEmpty();
105 //=======================================================================
106 //function : NbCurves
108 //=======================================================================
110 Standard_Integer MAT2d_CutCurve::NbCurves() const
112 if (UnModified()) {throw Standard_OutOfRange();}
113 return theCurves.Length();
117 //=======================================================================
120 //=======================================================================
122 Handle(Geom2d_TrimmedCurve) MAT2d_CutCurve::Value (
123 const Standard_Integer Index)
126 if (UnModified()) {throw Standard_OutOfRange();}
127 if ( Index < 1 || Index > theCurves.Length()) {
128 throw Standard_OutOfRange();
130 return Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(Index));