Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / lineconn2d / LineConn2d_Box.h
1 // File:      LineConn2d_Box.h
2 // Created:   03.08.05 20:16:45
3 // Author:    Alexander GRIGORIEV
4 // Copyright: Open Cascade 2005
5
6
7 #ifndef LineConn2d_Box_HeaderFile
8 #define LineConn2d_Box_HeaderFile
9
10 #include <gp_XY.hxx>
11
12 class LineConn2d_Segment;
13 class LineConn2d_Object;
14
15 ///  Simple class implementing 2D Bounding Box type
16 //
17
18 class LineConn2d_Box 
19 {
20  public:
21   // ---------- PUBLIC METHODS ----------
22
23   /**
24    * Empty constructor
25    */
26   inline LineConn2d_Box ()
27     : myCenter (::RealLast(), ::RealLast()),
28       myHSize  (-::RealLast(), -::RealLast())
29   {}
30
31   /**
32    * Constructor.
33    * @param theCenter
34    *   Center of the created box
35    * @param theHSize
36    *   Half-diagonal of the box, both X and Y should be non-negative
37    */
38   inline LineConn2d_Box (const gp_XY& theCenter,
39                          const gp_XY& theHSize)
40     : myCenter (theCenter),
41       myHSize  (theHSize) {}
42
43   /**
44    * Reset the box data.
45    */
46   inline void Clear ()
47   {
48     myCenter.SetCoord (::RealLast(), ::RealLast());
49     myHSize .SetCoord (-::RealLast(), -::RealLast());
50   }
51
52   /**
53    * Update the box by a point.
54    */
55   Standard_EXPORT void          Add     (const gp_XY& thePnt);
56
57   /**
58    * Update the box by another box.
59    */
60   inline void                   Add     (const LineConn2d_Box& theBox)
61   {
62     Add (theBox.Center() - theBox.HSize());
63     Add (theBox.Center() + theBox.HSize());
64   }
65
66   /**
67    * Query the box center.
68    */
69   inline const gp_XY&           Center  () const
70   { return myCenter; }
71
72   /**
73    * Query the box half-diagonal.
74    */
75   inline const gp_XY&           HSize   () const
76   { return myHSize; }
77
78   /**
79    * Query the square diagonal.
80    */
81   inline Standard_Real          SquareExtent () const
82   { return 4 * myHSize.SquareModulus(); }
83
84   /*
85    * Extend the Box by the absolute value of aDiff.
86    */
87   Standard_EXPORT void          Enlarge (const Standard_Real theDiff);
88
89   /**
90    * Limit the curent Box with the internals of theBox.
91    */
92   Standard_EXPORT void          Limit   (const LineConn2d_Box& theBox);
93
94   /**
95    * Check the given point for inclusion in the box.
96    * @return
97    *   True if thePnt is outside the box.
98    */
99   Standard_EXPORT Standard_Boolean IsOut(const gp_XY& thePnt) const;
100
101   /**
102    * Check the given box for intersection with the current box.
103    * @return
104    *   True if there is no intersection between the boxes.
105    */
106   Standard_EXPORT Standard_Boolean IsOut(const LineConn2d_Box& theBox) const;
107
108   /**
109    * Check the given box for intersection with an Object
110    * @return
111    *   True if there is no intersection with the object theObj.
112    */
113   Standard_EXPORT Standard_Boolean IsOut(const LineConn2d_Object& theObj) const;
114
115   /**
116    * Check the given box for intersection with a segment
117    * @return
118    *   True if there is no intersection with the segment aSeg.
119    */
120   Standard_EXPORT Standard_Boolean IsOut(const LineConn2d_Segment& aSeg) const;
121
122   /**
123    * Find intersection points between the boundary of the box and
124    * the given Segment. No intersection returned if the segment is entirely
125    * inside or outside the box. Therefore this method can not be used as
126    * replacement of the corresponding IsOut check. 
127    * @param outInter
128    *   Array of 2 output numbers. Contains the parameters ([0..1] inclusive)
129    *   of intersection point(s). If 2 intersections are found, it is ensured
130    *   that outInter[0] < outInter[1].
131    * @param aSeg
132    *   Segment for intersection.
133    * @return
134    *   Number of intersections (0, 1 or 2).
135    */
136   Standard_EXPORT Standard_Integer Intersect
137                                         (Standard_Real             outInter[2],
138                                          const LineConn2d_Segment& aSeg) const;
139
140  private:
141   // ---------- PRIVATE FIELDS ----------
142
143   gp_XY         myCenter;
144   gp_XY         myHSize;
145 };
146
147 #endif