1 // Created on: 1991-10-30
2 // Created by: Modelisation
3 // Copyright (c) 1991-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.
17 #include <Bnd_Box2d.ixx>
18 #include <Standard_Stream.hxx>
20 //-- #include <Precision.hxx> Precision::Infinite() -> 1e+100
22 //=======================================================================
25 //=======================================================================
27 void Bnd_Box2d::Update (const Standard_Real x, const Standard_Real y,
28 const Standard_Real X, const Standard_Real Y)
30 if (Flags & VoidMask) {
38 if (!(Flags & XminMask) && (x < Xmin)) Xmin = x;
39 if (!(Flags & XmaxMask) && (X > Xmax)) Xmax = X;
40 if (!(Flags & YminMask) && (y < Ymin)) Ymin = y;
41 if (!(Flags & YmaxMask) && (Y > Ymax)) Ymax = Y;
45 //=======================================================================
48 //=======================================================================
50 void Bnd_Box2d::Update (const Standard_Real X, const Standard_Real Y)
52 if (Flags & VoidMask) {
60 if (!(Flags & XminMask) && (X < Xmin)) Xmin = X;
61 else if (!(Flags & XmaxMask) && (X > Xmax)) Xmax = X;
62 if (!(Flags & YminMask) && (Y < Ymin)) Ymin = Y;
63 else if (!(Flags & YmaxMask) && (Y > Ymax)) Ymax = Y;
67 //=======================================================================
70 //=======================================================================
72 void Bnd_Box2d::Get (Standard_Real& x, Standard_Real& y,
73 Standard_Real& Xm, Standard_Real& Ym) const
76 Standard_ConstructionError::Raise("Bnd_Box is void");
77 Standard_Real pinf = 1e+100; //-- Precision::Infinite();
78 if (Flags & XminMask) x = -pinf;
80 if (Flags & XmaxMask) Xm = pinf;
82 if (Flags & YminMask) y = -pinf;
84 if (Flags & YmaxMask) Ym = pinf;
88 //=======================================================================
89 //function : Transformed
91 //=======================================================================
93 Bnd_Box2d Bnd_Box2d::Transformed (const gp_Trsf2d& T) const
95 gp_TrsfForm F = T.Form();
96 Bnd_Box2d newb(*this);
97 if ( IsVoid() ) return newb;
99 if (F == gp_Identity) {}
100 else if (F == gp_Translation) {
102 (T.TranslationPart()).Coord(DX,DY);
103 if (!(Flags & XminMask)) newb.Xmin += DX;
104 if (!(Flags & XmaxMask)) newb.Xmax += DX;
105 if (!(Flags & YminMask)) newb.Ymin += DY;
106 if (!(Flags & YmaxMask)) newb.Ymax += DY;
110 Standard_Boolean Vertex[4];
112 Vertex[0] = Standard_True;
113 Vertex[1] = Standard_True;
114 Vertex[2] = Standard_True;
115 Vertex[3] = Standard_True;
117 // Standard_Integer vertices = 0;
118 Standard_Integer directions = 0;
120 if (Flags & XminMask) {
121 D[directions].SetCoord(-1., 0.);
123 Vertex[0] = Vertex[2] = Standard_False;
125 if (Flags & XmaxMask) {
126 D[directions].SetCoord( 1., 0.);
128 Vertex[1] = Vertex[3] = Standard_False;
130 if (Flags & YminMask) {
131 D[directions].SetCoord( 0.,-1.);
133 Vertex[0] = Vertex[1] = Standard_False;
135 if (Flags & YmaxMask) {
136 D[directions].SetCoord( 0., 1.);
138 Vertex[2] = Vertex[3] = Standard_False;
143 for (i = 0; i < directions; i++) {
147 P[0].SetCoord(Xmin,Ymin);
148 P[1].SetCoord(Xmax,Ymin);
149 P[2].SetCoord(Xmin,Ymax);
150 P[3].SetCoord(Xmax,Ymax);
172 //=======================================================================
175 //=======================================================================
177 void Bnd_Box2d::Add (const Bnd_Box2d& Other)
179 if (IsWhole()) return;
180 else if (Other.IsVoid()) return;
181 else if (Other.IsWhole()) SetWhole();
182 else if (IsVoid()) (*this) = Other;
185 if ( ! IsOpenXmin() )
187 if (Other.IsOpenXmin()) OpenXmin();
188 else if (Xmin > Other.Xmin) Xmin = Other.Xmin;
190 if ( ! IsOpenXmax() )
192 if (Other.IsOpenXmax()) OpenXmax();
193 else if (Xmax < Other.Xmax) Xmax = Other.Xmax;
195 if ( ! IsOpenYmin() )
197 if (Other.IsOpenYmin()) OpenYmin();
198 else if (Ymin > Other.Ymin) Ymin = Other.Ymin;
200 if ( ! IsOpenYmax() )
202 if (Other.IsOpenYmax()) OpenYmax();
203 else if (Ymax < Other.Ymax) Ymax = Other.Ymax;
205 Gap = Max (Gap, Other.Gap);
209 //=======================================================================
212 //=======================================================================
214 void Bnd_Box2d::Add (const gp_Dir2d& D)
216 Standard_Real DX = D.X();
217 Standard_Real DY = D.Y();
219 if (DX < -RealEpsilon())
221 else if (DX > RealEpsilon())
224 if (DY < -RealEpsilon())
226 else if (DY > RealEpsilon())
230 //=======================================================================
233 //=======================================================================
235 Standard_Boolean Bnd_Box2d::IsOut (const gp_Pnt2d& P) const
237 if (IsWhole()) return Standard_False;
238 else if (IsVoid()) return Standard_True;
240 Standard_Real X = P.X();
241 Standard_Real Y = P.Y();
242 if (!(Flags & XminMask) && (X < (Xmin-Gap))) return Standard_True;
243 else if (!(Flags & XmaxMask) && (X > (Xmax+Gap))) return Standard_True;
244 else if (!(Flags & YminMask) && (Y < (Ymin-Gap))) return Standard_True;
245 else if (!(Flags & YmaxMask) && (Y > (Ymax+Gap))) return Standard_True;
246 else return Standard_False;
250 //=======================================================================
253 //=======================================================================
255 Standard_Boolean Bnd_Box2d::IsOut (const Bnd_Box2d& Other) const
257 if (IsWhole()) return Standard_False;
258 else if (IsVoid()) return Standard_True;
259 else if (Other.IsWhole()) return Standard_False;
260 else if (Other.IsVoid()) return Standard_True;
262 Standard_Real OXmin,OXmax,OYmin,OYmax;
263 Other.Get(OXmin,OYmin,OXmax,OYmax);
264 if (!(Flags & XminMask) && (OXmax < (Xmin-Gap))) return Standard_True;
265 else if (!(Flags & XmaxMask) && (OXmin > (Xmax+Gap))) return Standard_True;
266 else if (!(Flags & YminMask) && (OYmax < (Ymin-Gap))) return Standard_True;
267 else if (!(Flags & YmaxMask) && (OYmin > (Ymax+Gap))) return Standard_True;
269 return Standard_False;
272 //=======================================================================
275 //=======================================================================
277 void Bnd_Box2d::Dump () const
280 if (IsVoid()) cout << "Void";
281 else if (IsWhole()) cout << "Whole";
283 cout << "\n Xmin : ";
284 if (IsOpenXmin()) cout << "Infinite";
286 cout << "\n Xmax : ";
287 if (IsOpenXmax()) cout << "Infinite";
289 cout << "\n Ymin : ";
290 if (IsOpenYmin()) cout << "Infinite";
292 cout << "\n Ymax : ";
293 if (IsOpenYmax()) cout << "Infinite";
296 cout << "\n Gap : " << Gap;