]> git.lyx.org Git - lyx.git/blob - src/box.h
various fixes from John, Martin and Kayvan, plus one of mine. Read ChangeLogs
[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 /**
13  * A simple class representing rectangular regions.
14  * It is expected that the box be constructed in
15  * normalised form, that is to say : x1,y1 is top-left,
16  * x2,y2 is bottom-right.
17  *
18  * Negative values are allowed.
19  */
20 struct Box {
21         int x1;
22         int x2;
23         int y1;
24         int y2;
25
26         Box(int x1_, int x2_,
27                 int y1_, int y2_) :
28                 x1(x1_), x2(x2_), y1(y1_), y2(y2_) {}
29
30         /**
31          * Returns true if the given co-ordinates are within
32          * the box. Check is exclusive (point on a border
33          * returns false).
34          */
35         bool contained(int x, int y) {
36                 return (x1 < x && x2 > x &&
37                         y1 < y && y2 > y);
38         }
39
40          
41 };
42  
43 inline std::ostream & operator<<(std::ostream & o, Box & b)
44 {
45         return o << "x1,y1: " << b.x1 << "," << b.y1
46                 << " x2,y2: " << b.x2 << "," << b.y2 << std::endl;
47 }
48  
49 #endif // BOX_H