summaryrefslogtreecommitdiff
path: root/boxes.hh
blob: 5d0be85452fdaf7a0ca9a7fbadecd05876f9cdb6 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
    some 2D geometrical concepts
*/

#ifndef BOXES_HH
#define BOXES_HH

#include "textdb.hh"
#include "real.hh"
#include "vray.hh"

/// 2d vector 
struct Offset {
    Real x,y;

    Offset operator+(Offset o)const {
	Offset r(*this);
	r+=o;
	return r;
    }
    
    Offset operator+=(Offset o) {
	x+=o.x;
	y+=o.y;
	return *this;
    }
    Offset(Real ix , Real iy) {
	x=ix;
	y=iy;
    }
    Offset() {
	x=0.0;
	y=0.0;
    }
};

/// a Real interval
struct Interval {
    Real min, max;

    void translate(Real t) {
	min += t;
	max += t;
    }

    void unite(Interval h) {
	if (h.min<min)
	    min = h.min;
	if (h.max>max)
	    max = h.max;
    }
    Real length() const;
    void set_empty() ;
    bool empty() { return min > max; }
    Interval() {
	set_empty();
    }
    Interval(Real m, Real M) {
	min =m;
	max = M;
    }
};


/// a 4-tuple of #Real#s
struct Box {
    Interval x, y;
    
    void translate(Offset o) {
	x.translate(o.x);
	y.translate(o.y);
    }
    void unite(Box b) {
	x.unite(b.x);
	y.unite(b.y);
    }
    Box(svec<Real> );
    Box();
    Box(Interval ix, Interval iy);
};


#endif