]> git.lyx.org Git - lyx.git/blob - src/box.h
8a53c737a76757919b9759a1dc357234f5fa93ab
[lyx.git] / src / box.h
1 /**
2  * \file box.h
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #ifndef BOX_H
10 #define BOX_H
11
12 #include "support/LOstream.h"
13
14 /**
15  * A simple class representing rectangular regions.
16  * It is expected that the box be constructed in
17  * normalised form, that is to say : x1,y1 is top-left,
18  * x2,y2 is bottom-right.
19  *
20  * Negative values are allowed.
21  */
22 struct Box {
23         int x1;
24         int x2;
25         int y1;
26         int y2;
27
28         Box(int x1_, int x2_,
29                 int y1_, int y2_) :
30                 x1(x1_), x2(x2_), y1(y1_), y2(y2_) {}
31
32         /**
33          * Returns true if the given co-ordinates are within
34          * the box. Check is exclusive (point on a border
35          * returns false).
36          */
37         bool contained(int x, int y) {
38                 return (x1 < x && x2 > x &&
39                         y1 < y && y2 > y);
40         }
41
42          
43 };
44  
45 inline std::ostream & operator<<(std::ostream & o, Box & b)
46 {
47         return o << "x1,y1: " << b.x1 << "," << b.y1
48                 << " x2,y2: " << b.x2 << "," << b.y2 << std::endl;
49 }
50  
51 #endif // BOX_H