flower-1.0.2
[lilypond.git] / boxes.hh
blobc9ff3e62efa952b215c98acdee2af1a8af9f10da
1 /*
2 some 2D geometrical concepts
3 */
5 #ifndef BOXES_HH
6 #define BOXES_HH
8 #include "textdb.hh"
9 #include "real.hh"
10 #include "vray.hh"
12 /// 2d vector
13 struct Offset {
14 Real x,y;
16 Offset operator+(Offset o)const {
17 Offset r(*this);
18 r+=o;
19 return r;
22 Offset operator+=(Offset o) {
23 x+=o.x;
24 y+=o.y;
25 return *this;
27 Offset(Real ix , Real iy) {
28 x=ix;
29 y=iy;
31 Offset() {
32 x=0.0;
33 y=0.0;
37 /// a Real interval
38 struct Interval {
39 Real min, max;
41 void translate(Real t) {
42 min += t;
43 max += t;
46 void unite(Interval h) {
47 if (h.min<min)
48 min = h.min;
49 if (h.max>max)
50 max = h.max;
53 void set_empty() ;
54 bool empty() { return min > max; }
55 Interval() {
56 set_empty();
58 Interval(Real m, Real M) {
59 min =m;
60 max = M;
65 /// a 4-tuple of #Real#s
66 struct Box {
67 Interval x, y;
69 void translate(Offset o) {
70 x.translate(o.x);
71 y.translate(o.y);
73 void unite(Box b) {
74 x.unite(b.x);
75 y.unite(b.y);
77 Box(svec<Real> );
78 Box();
79 Box(Interval ix, Interval iy);
83 #endif