forked from stlab/adobe_source_libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextents.hpp
139 lines (99 loc) · 3.94 KB
/
extents.hpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
Copyright 2013 Adobe
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
/**************************************************************************************************/
#ifndef ADOBE_EXTENTS_HPP
#define ADOBE_EXTENTS_HPP
#include <adobe/config.hpp>
#include <boost/array.hpp>
#include <boost/operators.hpp>
#include <vector>
/**************************************************************************************************/
namespace adobe {
/**************************************************************************************************/
template <typename T = int>
struct point_2d : boost::equality_comparable<point_2d<T>> {
point_2d() : x_m(T()), y_m(T()) {}
point_2d(const T& x, const T& y) : x_m(x), y_m(y) {}
T x_m;
T y_m;
friend inline void swap(const point_2d& x, const point_2d& y) BOOST_NOEXCEPT {
swap(x.x_m, y.x_m);
swap(x.y_m, y.y_m);
}
friend inline bool operator==(const point_2d& x, const point_2d& y) {
return (x.x_m == y.x_m) && (x.y_m == y.y_m);
}
};
typedef std::pair<int, int> pair_long_t;
typedef point_2d<int> point_2d_t;
typedef std::vector<int> guide_set_t;
// REVISIT (sparent) : points of interest need to be named entities. This will become:
#if 0
struct guide_set_t
{
name_t name_m;
int offset_m;
};
typedef std::vector<guide_set_t> point_of_interest_set_t;
#endif
// REVISIT (sparent) : Open issue - are there "alignment" attributes on POIs?
struct extents_slices_t {
enum slice_select_t { horizontal, vertical };
};
/**************************************************************************************************/
struct extents_t :
#if !defined(ADOBE_NO_DOCUMENTATION)
private extents_slices_t,
boost::equality_comparable<extents_t>
#endif
{
struct slice_t : boost::equality_comparable<slice_t> {
slice_t() : length_m(0){};
int length_m;
pair_long_t outset_m;
pair_long_t frame_m;
pair_long_t inset_m;
guide_set_t guide_set_m;
friend bool operator==(const slice_t& x, const slice_t& y);
};
boost::array<slice_t, 2> slice_m;
slice_t& vertical() { return slice_m[extents_slices_t::vertical]; }
slice_t& horizontal() { return slice_m[extents_slices_t::horizontal]; }
const slice_t& vertical() const { return slice_m[extents_slices_t::vertical]; }
const slice_t& horizontal() const { return slice_m[extents_slices_t::horizontal]; }
int& height() { return vertical().length_m; }
int& width() { return horizontal().length_m; }
const int& height() const { return vertical().length_m; }
const int& width() const { return horizontal().length_m; }
friend bool operator==(const extents_t& x, const extents_t& y);
};
/**************************************************************************************************/
#ifndef NDEBUG
std::ostream& operator<<(std::ostream& s, const extents_t& x);
#endif
#ifndef NDEBUG
std::ostream& operator<<(std::ostream& s, const extents_t::slice_t& x);
#endif
/**************************************************************************************************/
} // namespace adobe
/**************************************************************************************************/
namespace std {
template <>
inline void swap(adobe::extents_t::slice_t& x, adobe::extents_t::slice_t& y) BOOST_NOEXCEPT {
swap(x.length_m, y.length_m);
swap(x.outset_m, y.outset_m);
swap(x.frame_m, y.frame_m);
swap(x.inset_m, y.inset_m);
swap(x.guide_set_m, y.guide_set_m);
}
template <>
inline void swap(adobe::extents_t& x, adobe::extents_t& y) BOOST_NOEXCEPT {
swap(x.slice_m, y.slice_m);
}
} // namespace std
/**************************************************************************************************/
#endif
/**************************************************************************************************/