650a1e35901c2047d1d28e2291dde96e004a90f8
[occt.git] / src / Select3D / Select3D_Box2d.hxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _Select3D_Box2d_HeaderFile
15 #define _Select3D_Box2d_HeaderFile
16
17 #include<Bnd_Box2d.hxx>
18 #include<Standard_ShortReal.hxx>
19 #include<Select3D_Macro.hxx>
20
21 struct Select3D_Box2d
22 {
23  Standard_ShortReal xmin, ymin, xmax, ymax;
24
25  Select3D_Box2d()
26  { 
27    SetVoid();
28  }
29
30  Select3D_Box2d(const Bnd_Box2d& theBox)
31  { 
32    SetField(theBox);
33  }
34
35  inline operator Bnd_Box2d() const
36  {
37    Bnd_Box2d aBox;
38    aBox.SetVoid();
39    if( !IsVoid() )
40      aBox.Update(xmin, ymin, xmax, ymax);
41    return aBox;
42  }
43
44  inline Select3D_Box2d operator = ( const Bnd_Box2d& theBox)
45  { 
46    SetField(theBox); 
47    return *this;
48  }
49
50  inline void Update(const gp_Pnt2d& thePnt)
51  {
52   Bnd_Box2d aBox;
53   aBox.Set(thePnt);
54   if( !IsVoid() )
55     aBox.Update(xmin, ymin, xmax, ymax);
56   SetField(aBox);
57  }
58
59  inline void SetVoid()
60  {
61    xmin = ymin = ShortRealLast();
62    xmax = ymax = ShortRealFirst();
63  }
64
65  inline Standard_Boolean IsVoid() const
66  {
67    return ( xmin == ShortRealLast() && ymin == ShortRealLast() && xmax == ShortRealFirst() && ymax == ShortRealFirst() );
68  }
69
70 private: 
71  inline void SetField(const Bnd_Box2d& theBox)
72  {
73   if( theBox.IsVoid() )
74     SetVoid();
75   else {
76     Standard_Real x, y, x1, y1;
77     theBox.Get(x, y, x1, y1);   
78
79     xmin = DToF(x);
80     ymin = DToF(y);
81     xmax = DToF(x1);
82     ymax = DToF(y1);
83   }
84  }
85
86 };
87
88 #endif
89
90
91
92