Board  0.9.4
Rect.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef _BOARD_RECT_H_
27 #define _BOARD_RECT_H_
28 
29 #include <iostream>
30 #include "board/Point.h"
31 
32 namespace LibBoard {
33 
38 struct Rect {
39  double left;
40  double top;
41  double width;
42  double height;
52  Rect( double left = 0.0f, double top = 0.0f,
53  double width = 0.0f, double height = 0.0f )
54  :left( left ), top( top ), width( width ), height( height ) { }
55 
63  Rect( Point topLeft,
64  double width = 0.0f, double height = 0.0f )
65  :left( topLeft.x ), top( topLeft.y ), width( width ), height( height ) { }
66 
73  Rect( Point topLeft, Point bottomRight )
74  : left( topLeft.x ),
75  top( topLeft.y ),
76  width( bottomRight.x - topLeft.x ),
77  height( topLeft.y - bottomRight.y ) { }
78 
79  Point topLeft() const { return Point( left, top ); }
80  Point topRight() const { return Point( left + width, top ); }
81  Point bottomLeft() const { return Point( left, top - height ); }
82  Point bottomRight() const { return Point( left + width, top - height ); }
83  Point center() const { return Point(left+width/2.0,top-height/2.0); }
84  Point centerLeft() const { return Point(left,top-height/2.0); }
85  Point centerRight() const { return Point(left+width,top-height/2.0); }
86  Point centerTop() const { return Point(left+width/2.0,top); }
87  Point centerBottom() const { return Point(left+width/2.0,top-height); }
88  double bottom() const { return top - height; }
89  double right() const { return left + width; }
90  void growToContain(Point );
91  bool contains(Point ) const;
92  Rect & grow(double margin);
93 };
94 
103 Rect operator||( const Rect & rectA, const Rect & rectB );
104 
113 Rect operator&&( const Rect & rectA, const Rect & rectB );
114 
115 } // mamespace LibBoard
116 
125 std::ostream & operator<<( std::ostream & out, const LibBoard::Rect & rect );
126 
127 #endif // _RECT_H_
Definition: Board.h:41
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
double top
Definition: Rect.h:40
Rect(Point topLeft, double width=0.0f, double height=0.0f)
Definition: Rect.h:63
Rect(double left=0.0f, double top=0.0f, double width=0.0f, double height=0.0f)
Definition: Rect.h:52
double left
Definition: Rect.h:39
Struct representing a 2D point.
Definition: Point.h:39
Rect(Point topLeft, Point bottomRight)
Definition: Rect.h:73
std::ostream & operator<<(std::ostream &out, const LibBoard::Rect &rect)
Definition: Rect.cpp:105
double height
Definition: Rect.h:42
Struct representing a rectangle on the plane.
Definition: Rect.h:38
double width
Definition: Rect.h:41