2001-12-17 14:25:04 +00:00
|
|
|
/**
|
|
|
|
* \file box.h
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author John Levon <moz@compsoc.man.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BOX_H
|
|
|
|
#define BOX_H
|
|
|
|
|
2002-01-07 14:17:54 +00:00
|
|
|
#include "support/LOstream.h"
|
|
|
|
|
2001-12-17 14:25:04 +00:00
|
|
|
/**
|
|
|
|
* A simple class representing rectangular regions.
|
|
|
|
* It is expected that the box be constructed in
|
|
|
|
* normalised form, that is to say : x1,y1 is top-left,
|
|
|
|
* x2,y2 is bottom-right.
|
2002-01-07 10:17:44 +00:00
|
|
|
*
|
|
|
|
* Negative values are allowed.
|
2001-12-17 14:25:04 +00:00
|
|
|
*/
|
|
|
|
struct Box {
|
2002-01-07 10:17:44 +00:00
|
|
|
int x1;
|
|
|
|
int x2;
|
|
|
|
int y1;
|
|
|
|
int y2;
|
2001-12-17 14:25:04 +00:00
|
|
|
|
2002-01-07 10:17:44 +00:00
|
|
|
Box(int x1_, int x2_,
|
|
|
|
int y1_, int y2_) :
|
2001-12-17 14:25:04 +00:00
|
|
|
x1(x1_), x2(x2_), y1(y1_), y2(y2_) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given co-ordinates are within
|
|
|
|
* the box. Check is exclusive (point on a border
|
|
|
|
* returns false).
|
|
|
|
*/
|
2002-01-07 10:17:44 +00:00
|
|
|
bool contained(int x, int y) {
|
2001-12-17 14:25:04 +00:00
|
|
|
return (x1 < x && x2 > x &&
|
|
|
|
y1 < y && y2 > y);
|
|
|
|
}
|
2002-01-07 10:17:44 +00:00
|
|
|
|
|
|
|
|
2001-12-17 14:25:04 +00:00
|
|
|
};
|
|
|
|
|
2002-01-07 10:17:44 +00:00
|
|
|
inline std::ostream & operator<<(std::ostream & o, Box & b)
|
|
|
|
{
|
|
|
|
return o << "x1,y1: " << b.x1 << "," << b.y1
|
|
|
|
<< " x2,y2: " << b.x2 << "," << b.y2 << std::endl;
|
|
|
|
}
|
|
|
|
|
2001-12-17 14:25:04 +00:00
|
|
|
#endif // BOX_H
|