wxArt2D
bbox.h
Go to the documentation of this file.
1 /*! \file wx/artbase/bbox.h
2  \brief bounding class for optimizing drawing speed.
3  \author Probably Klaas Holwerda
4 
5  Copyright: 2001-2004 (C) Probably Klaas Holwerda
6 
7  Licence: wxWidgets Licence
8 
9  RCS-ID: $Id: bbox.h,v 1.14 2009/06/05 19:41:03 titato Exp $
10 */
11 
12 #ifndef __WXBOUNDINGBOX_H__
13 #define __WXBOUNDINGBOX_H__
14 
15 #ifndef WX_PRECOMP
16 #include "wx/wx.h"
17 #endif
18 
19 #include "wx/artbase/afmatrix.h"
20 #include "wx/geometry.h"
21 
22 
23 //! Result of a a2dBoundingBox intersection or hittest \ingroup canvasobject
24 enum OVERLAP
25 {
26  _IN = 0x01, /*!< Test was completely in the boundingbox */
27  _ON = 0x02, /*!< Test was overlapping the boundingbox its border */
28  _OUT = 0x04 /*!< Test was completely out of the boundingbox */
29 };
30 
31 //!The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
32 /*!
33  The a2dBoundingBox is defined by two coordiates,
34  a upperleft coordinate and a lowerright coordinate.
35  It has a valid flag to tell if the boundingbox contains valid information or not.
36 
37  \ingroup canvasobject
38 */
39 class A2DARTBASEDLLEXP a2dBoundingBox
40 {
41 public:
42 
43  //! constructor
45 
46  //! boundingbox constructor given another boundingbox
47  a2dBoundingBox( const a2dBoundingBox& box );
48 
49  //! boundingbox constructor given a point
50  a2dBoundingBox( const a2dPoint2D& point );
51 
52  //! boundingbox constructor given two sets of coordinates
53  a2dBoundingBox( double x1, double y1, double x2, double y2 );
54 
55  //! And operation on two boxes
56  a2dBoundingBox& operator+( a2dBoundingBox& );
57 
58  //! OR box to this
59  const a2dBoundingBox& operator+=( const a2dBoundingBox& box );
60 
61  //! set this boundingbox to another boundingbox
62  a2dBoundingBox& operator=( const a2dBoundingBox& );
63 
64  //!intersect the boundingbox with another, return true if the result is non zero
65  bool And( a2dBoundingBox*, double Marge = 0 );
66 
67  //!enlarge with the given amount
68  void Enlarge( const double Marge );
69 
70  //!enlarge with the given amount
71  void EnlargeXY( const double MargeX, const double MargeY );
72 
73  //!shrink with the given amount
74  void Shrink( const double Marge );
75 
76  //!expand boundingbox width two points
77  void Expand( const a2dPoint2D& , const a2dPoint2D& );
78 
79  //!expand boundingbox width one points
80  void Expand( const a2dPoint2D& );
81 
82  //!expand boundingbox width one coordinate
83  void Expand( double x, double y );
84 
85  //!expand boundingbox width another boundingbox
86  void Expand( const a2dBoundingBox& bbox );
87 
88  //!check intersection
89  //!\return OVERLAP: _IN,_ON,_OUT
90  OVERLAP Intersect( const a2dBoundingBox&, double Marge = 0 ) const;
91 
92  //!intersection with a line
93  //!\return true if interseting
94  bool LineIntersect( const a2dPoint2D& begin, const a2dPoint2D& end ) const;
95 
96  //!is the point within the boundingbox
97  bool PointInBox( const a2dPoint2D&, double Marge = 0 ) const;
98 
99  //!is the coordinate within the boundingbox
100  bool PointInBox( double x, double y, double Marge = 0 ) const;
101 
102  //!is the coordinate on the border of the boundingbox
103  bool PointOnBox( double x, double y, double Marge ) const;
104 
105  //!set invalid
106  void Reset();
107 
108  //!translate with given vector
109  const a2dBoundingBox& Translate( a2dPoint2D& );
110 
111  //!translate with given vector
112  const a2dBoundingBox& Translate( double x, double y );
113 
114  //!map the boundingbox using the matrix.
115  //!The boundingbox is first transformed, and at the new position and angle etc.
116  //!recalculated.
117  void MapBbox( const a2dAffineMatrix& matrix );
118 
119  //! returns width of the boundingbox
120  double GetWidth() const;
121  //! returns height of the boundingbox
122  double GetHeight() const;
123 
124  //! returns true if boundingbox is calculated properly and therefore its valid flag is set.
125  bool GetValid() const;
126 
127  //! \see GetValid()
128  void SetValid( bool );
129 
130  //! set the bounding box to be this point
131  void SetBoundingBox( const a2dPoint2D& a_point );
132 
133  //! set the bounding box its maximum
134  void SetMin( double px, double py );
135 
136  //! set the bounding box its minimum
137  void SetMax( double px, double py );
138 
139  //! get the bounding box its minimum
140  a2dPoint2D GetMin() const;
141 
142  //! get the bounding box its maximum
143  a2dPoint2D GetMax() const;
144 
145  //! get minimum X of the boundingbox
146  double GetMinX() const;
147 
148  //! get minimum Y of the boundingbox
149  double GetMinY() const;
150 
151  //! get maximum X of the boundingbox
152  double GetMaxX() const;
153 
154  //! get maximum Y of the boundingbox
155  double GetMaxY() const;
156 
157  inline double GetSize()
158  {
159  if ( !m_validbbox )
160  return 0;
161 
162  return wxMax( fabs( m_maxx - m_minx ), fabs( m_maxy - m_miny ) );
163  }
164 
165  //! get centre
166  a2dPoint2D GetCentre() const;
167 
168  //! set the bounding box its minimum X, does not validate the box
169  void SetMinX( double minx ) { m_minx = minx; }
170  //! set the bounding box its minimum Y, does not validate the box
171  void SetMinY( double miny ) { m_miny = miny; }
172  //! set the bounding box its maximum X, does not validate the box
173  void SetMaxX( double maxx ) { m_maxx = maxx; }
174  //! set the bounding box its maximum Y, does not validate the box
175  void SetMaxY( double maxy ) { m_maxy = maxy; }
176 
177 #ifdef _DEBUG
178  //! dump to debug screen
179  void Dump() const;
180 #endif
181 
182 protected:
183 
184  //!mininum X of bounding box in world coordinates
185  double m_minx;
186  //!mininum Y of bounding box in world coordinates
187  double m_miny;
188  //!maximum X of bounding box in world coordinates
189  double m_maxx;
190  //!maximum Y of bounding box in world coordinates
191  double m_maxy;
192 
193  //!true if boundingbox is valid
195 };
196 
197 //! global non valid boundingbox to use as default argument etc.
198 A2DARTBASEDLLEXP_DATA( extern a2dBoundingBox ) wxNonValidBbox;
199 
200 #endif
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
Definition: artglob.h:47
void SetMaxY(double maxy)
set the bounding box its maximum Y, does not validate the box
Definition: bbox.h:175
void SetMaxX(double maxx)
set the bounding box its maximum X, does not validate the box
Definition: bbox.h:173
OVERLAP
Result of a a2dBoundingBox intersection or hittest.
Definition: bbox.h:24
a2dBoundingBox wxNonValidBbox
global non valid boundingbox to use as default argument etc.
Definition: bbox.cpp:23
bool m_validbbox
true if boundingbox is valid
Definition: bbox.h:194
Definition: bbox.h:26
Definition: bbox.h:27
void SetMinY(double miny)
set the bounding box its minimum Y, does not validate the box
Definition: bbox.h:171
double m_maxx
maximum X of bounding box in world coordinates
Definition: bbox.h:189
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
Definition: bbox.h:28
double m_maxy
maximum Y of bounding box in world coordinates
Definition: bbox.h:191
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
affine matrix class
double m_miny
mininum Y of bounding box in world coordinates
Definition: bbox.h:187
void SetMinX(double minx)
set the bounding box its minimum X, does not validate the box
Definition: bbox.h:169
double m_minx
mininum X of bounding box in world coordinates
Definition: bbox.h:185
bbox.h Source File -- Sun Oct 12 2014 17:04:12 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation