-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrvg-bbox.h
71 lines (56 loc) · 1.7 KB
/
rvg-bbox.h
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
// Stroke-to-fill conversion program and test harness
// Copyright (C) 2020 Diego Nehab
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// Contact information: diego.nehab@gmail.com
//
#ifndef RVG_BBOX_H
#define RVG_BBOX_H
#include <limits>
#include <array>
#include <tuple>
namespace rvg {
template <typename F>
class bbox {
std::array<F, 4> m_corners;
constexpr static F lo = std::numeric_limits<F>::lowest();
constexpr static F hi = std::numeric_limits<F>::max();
public:
using value_type = F;
bbox(): m_corners{{hi, hi, lo, lo}} { ; }
bbox(F xl, F yb, F xr, F yt): m_corners{{xl, yb, xr, yt}} { ; }
std::tuple<F, F> bl(void) const {
return std::tuple<F, F>(m_corners[0], m_corners[1]);
}
std::tuple<F, F> tr(void) const {
return std::tuple<F, F>(m_corners[2], m_corners[3]);
}
void set_bl(F xl, F yb) {
m_corners[0] = xl;
m_corners[1] = yb;
}
void set_tr(F xr, F yt) {
m_corners[2] = xr;
m_corners[3] = yt;
}
const std::array<F, 4> &corners(void) const {
return m_corners;
}
F operator[](int i) const {
return m_corners[i];
}
F &operator[](int i) {
return m_corners[i];
}
};
} // namespace rvg
#endif