1 // Created on: 1995-03-08
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1995-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 //#define No_Standard_OutOfRange
19 #include <CSLib_Class2d.ixx>
20 #include <Standard_ConstructionError.hxx>
23 Standard_Real Transform2d(const Standard_Real u,
24 const Standard_Real umin,
25 const Standard_Real umaxmumin);
27 //=======================================================================
28 //function : CSLib_Class2d
30 //=======================================================================
31 CSLib_Class2d::CSLib_Class2d(const TColgp_Array1OfPnt2d& TP2d,
32 const Standard_Real aTolu,
33 const Standard_Real aTolv,
34 const Standard_Real umin,
35 const Standard_Real vmin,
36 const Standard_Real umax,
37 const Standard_Real vmax)
44 if(umax<=umin || vmax<=vmin) {
51 Standard_Integer i, iLower;
52 Standard_Real du,dv,*Pnts2dX,*Pnts2dY, aPrc;
58 MyPnts2dX = new Standard_Real [N+1];
59 MyPnts2dY = new Standard_Real [N+1];
62 Pnts2dX = (Standard_Real *)MyPnts2dX;
63 Pnts2dY = (Standard_Real *)MyPnts2dY;
66 for(i = 0; i<N; ++i) {
67 const gp_Pnt2d& aP2D=TP2d(i+iLower);
68 Pnts2dX[i] = Transform2d(aP2D.X(), umin, du);
69 Pnts2dY[i] = Transform2d(aP2D.Y(), vmin, dv);
71 Pnts2dX[N]=Pnts2dX[0];
72 Pnts2dY[N]=Pnts2dY[0];
82 //=======================================================================
85 //=======================================================================
86 void CSLib_Class2d::Destroy() {
88 delete [] (Standard_Real *)MyPnts2dX;
92 delete [] (Standard_Real *)MyPnts2dY;
97 //-- Attention Table of 0 ------> N + 1
104 //=======================================================================
107 //=======================================================================
108 Standard_Integer CSLib_Class2d::SiDans(const gp_Pnt2d& P) const
114 Standard_Real x,y, aTolu, aTolv;
116 x = P.X(); y = P.Y();
117 aTolu=Tolu*(Umax-Umin);
118 aTolv=Tolv*(Vmax-Vmin);
120 if(Umin<Umax && Vmin<Vmax) {
121 if( ( x<(Umin-aTolu) ) ||
122 ( x>(Umax+aTolu) ) ||
123 ( y<(Vmin-aTolv) ) ||
124 ( y>(Vmax+aTolv) ) ) {
127 x=Transform2d(x,Umin,Umax-Umin);
128 y=Transform2d(y,Vmin,Vmax-Vmin);
132 Standard_Integer res = InternalSiDansOuOn(x,y);
137 if(res != InternalSiDans(x-Tolu,y-Tolv)) return 0;
138 if(res != InternalSiDans(x+Tolu,y-Tolv)) return 0;
139 if(res != InternalSiDans(x-Tolu,y+Tolv)) return 0;
140 if(res != InternalSiDans(x+Tolu,y+Tolv)) return 0;
143 return((res)? 1: -1);
145 //=======================================================================
146 //function : SiDans_OnMode
148 //=======================================================================
149 Standard_Integer CSLib_Class2d::SiDans_OnMode(const gp_Pnt2d& P,
150 const Standard_Real Tol) const
156 Standard_Real x,y, aTolu, aTolv;
158 x = P.X(); y = P.Y();
162 //-- ****** TO DO LATER, ESTIMATE AT EACH POINT Tol2d depending on Tol3d *****
163 if(Umin<Umax && Vmin<Vmax) {
164 if(x<(Umin-aTolu) || (x>Umax+aTolu) ||
165 (y<Vmin-aTolv) || (y>Vmax+aTolv)) {
168 x=Transform2d(x,Umin,Umax-Umin);
169 y=Transform2d(y,Vmin,Vmax-Vmin);
172 Standard_Integer res = InternalSiDansOuOn(x,y);
174 if(res != InternalSiDans(x-aTolu,y-aTolv)) return 0;
175 if(res != InternalSiDans(x+aTolu,y-aTolv)) return 0;
176 if(res != InternalSiDans(x-aTolu,y+aTolv)) return 0;
177 if(res != InternalSiDans(x+aTolu,y+aTolv)) return 0;
179 return((res)? 1: -1);
181 //=======================================================================
182 //function : InternalSiDans
184 //=======================================================================
185 Standard_Integer CSLib_Class2d::InternalSiDans(const Standard_Real Px,
186 const Standard_Real Py) const
188 Standard_Integer nbc, i, ip1, SH, NH;
189 Standard_Real *Pnts2dX, *Pnts2dY;
190 Standard_Real x, y, nx, ny;
195 Pnts2dX = (Standard_Real *)MyPnts2dX;
196 Pnts2dY = (Standard_Real *)MyPnts2dY;
201 for(i=0; i<N ; i++,ip1++) {
202 nx = Pnts2dX[ip1] - Px;
203 ny = Pnts2dY[ip1] - Py;
205 NH = (ny<0.)? -1 : 1;
212 if((x-y*(nx-x)/(ny-y))>0.) {
223 //modified by NIZNHY-PKV Fri Jan 15 09:03:48 2010f
224 //=======================================================================
225 //function : InternalSiDansOuOn
226 //purpose : same code as above + test on ON (return(-1) in this case
227 //=======================================================================
228 Standard_Integer CSLib_Class2d::InternalSiDansOuOn(const Standard_Real Px,
229 const Standard_Real Py) const
231 Standard_Integer nbc, i, ip1, SH, NH, iRet;
232 Standard_Real *Pnts2dX, *Pnts2dY;
233 Standard_Real x, y, nx, ny, aX;
239 Pnts2dX = (Standard_Real *)MyPnts2dX;
240 Pnts2dY = (Standard_Real *)MyPnts2dY;
245 for(i=0; i<N ; i++, ip1++) {
247 nx = Pnts2dX[ip1] - Px;
248 ny = Pnts2dY[ip1] - Py;
250 if(nx<Tolu && nx>-Tolu && ny<Tolv && ny>-Tolv) {
254 //find Y coordinate of polyline for current X gka
255 //in order to detect possible status ON
256 Standard_Real aDx = (Pnts2dX[ip1] - Pnts2dX[ip1-1]);
257 if( (Pnts2dX[ip1-1] - Px) * nx < 0.)
260 Standard_Real aCurPY = Pnts2dY[ip1] - (Pnts2dY[ip1] - Pnts2dY[ip1-1])/aDx *nx;
261 Standard_Real aDeltaY = aCurPY - Py;
262 if(aDeltaY >= -Tolv && aDeltaY <= Tolv)
270 NH = (ny<0.)? -1 : 1;
277 aX=x-y*(nx-x)/(ny-y);
285 else {// y has same sign as ny
291 }// for(i=0; i<N ; i++,ip1++) {
296 //modified by NIZNHY-PKV Fri Jan 15 09:03:55 2010t
297 //=======================================================================
300 //=======================================================================
301 const CSLib_Class2d& CSLib_Class2d::Copy(const CSLib_Class2d& ) const
303 cerr<<"Copy not allowed in CSLib_Class2d"<<endl;
304 Standard_ConstructionError::Raise();
307 //=======================================================================
308 //function : Transform2d
310 //=======================================================================
311 Standard_Real Transform2d(const Standard_Real u,
312 const Standard_Real umin,
313 const Standard_Real umaxmumin)
315 if(umaxmumin>1e-10) {
316 Standard_Real U = (u-umin)/umaxmumin;