stlab.adobe.com Adobe Systems Incorporated
extents.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /****************************************************************************************************/
8 
9 #ifndef ADOBE_EXTENTS_HPP
10 #define ADOBE_EXTENTS_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <boost/array.hpp>
15 #include <boost/operators.hpp>
16 
17 #include <vector>
18 
19 /****************************************************************************************************/
20 
21 namespace adobe {
22 
23 /****************************************************************************************************/
24 
25 template <typename T = int>
26 struct point_2d : boost::equality_comparable<point_2d<T> >
27 {
29  x_m(T()), y_m(T())
30  { }
31 
32  point_2d(const T& x, const T& y) :
33  x_m(x), y_m(y)
34  { }
35 
36  T x_m;
37  T y_m;
38 
39  friend inline void swap(const point_2d& x, const point_2d& y)
40  {
41  swap(x.x_m, y.x_m);
42  swap(x.y_m, y.y_m);
43  }
44 
45  friend inline bool operator==(const point_2d& x, const point_2d& y)
46  {
47  return (x.x_m == y.x_m) && (x.y_m == y.y_m);
48  }
49 };
50 
51 typedef std::pair<int, int> pair_long_t;
53 typedef std::vector<int> guide_set_t;
54 
55 // REVISIT (sparent) : points of interest need to be named entities. This will become:
56 
57 #if 0
58 struct guide_set_t
59 {
60  name_t name_m;
61  int offset_m;
62 };
63 typedef std::vector<guide_set_t> point_of_interest_set_t;
64 #endif
65 
66 // REVISIT (sparent) : Open issue - are there "alignment" attributes on POIs?
67 
69 {
70  enum slice_select_t { horizontal, vertical };
71 };
72 
73 /****************************************************************************************************/
74 
75 struct extents_t :
76 #if !defined(ADOBE_NO_DOCUMENTATION)
77  private extents_slices_t, boost::equality_comparable<extents_t>
78 #endif
79 {
80  struct slice_t : boost::equality_comparable<slice_t>
81  {
82  slice_t() : length_m(0) { };
83 
84  int length_m;
85  pair_long_t outset_m;
86  pair_long_t frame_m;
87  pair_long_t inset_m;
88  guide_set_t guide_set_m;
89 
90  friend bool operator ==(const slice_t& x, const slice_t& y);
91  };
92 
93  boost::array<slice_t, 2> slice_m;
94 
97 
98  const slice_t& vertical() const { return slice_m[extents_slices_t::vertical]; }
99  const slice_t& horizontal() const { return slice_m[extents_slices_t::horizontal]; }
100 
101  int& height() { return vertical().length_m; }
102  int& width() { return horizontal().length_m; }
103 
104  const int& height() const { return vertical().length_m; }
105  const int& width() const { return horizontal().length_m; }
106 
107  friend bool operator == (const extents_t& x, const extents_t& y);
108 };
109 
110 /****************************************************************************************************/
111 
112 #ifndef NDEBUG
113 std::ostream& operator << (std::ostream& s, const extents_t& x);
114 #endif
115 
116 #ifndef NDEBUG
117 std::ostream& operator << (std::ostream& s, const extents_t::slice_t& x);
118 #endif
119 
120 /*************************************************************************************************/
121 
122 } // namespace adobe
123 
124 /****************************************************************************************************/
125 
126 namespace std {
127 
129 {
130  swap(x.length_m, y.length_m);
131  swap(x.outset_m, y.outset_m);
132  swap(x.frame_m, y.frame_m);
133  swap(x.inset_m, y.inset_m);
135 }
136 
137 template <> inline void swap(adobe::extents_t& x, adobe::extents_t& y)
138 { swap(x.slice_m, y.slice_m); }
139 
140 } // namespace std
141 
142 /****************************************************************************************************/
143 
144 #endif
145 
146 /****************************************************************************************************/
friend void swap(const point_2d &x, const point_2d &y)
Definition: extents.hpp:39
boost::array< slice_t, 2 > slice_m
Definition: extents.hpp:93
point_2d< int > point_2d_t
Definition: extents.hpp:52
STL namespace.
int & height()
Definition: extents.hpp:101
const int & width() const
Definition: extents.hpp:105
point_2d(const T &x, const T &y)
Definition: extents.hpp:32
slice_t & vertical()
Definition: extents.hpp:95
An intrinsic geometry class for objects with a graphical representation.
Definition: extents.hpp:75
const int & height() const
Definition: extents.hpp:104
friend bool operator==(const point_2d &x, const point_2d &y)
Definition: extents.hpp:45
const slice_t & vertical() const
Definition: extents.hpp:98
guide_set_t guide_set_m
Definition: extents.hpp:88
A utility class for referencing the two slices of a extents_t.
Definition: extents.hpp:68
const slice_t & horizontal() const
Definition: extents.hpp:99
std::pair< int, int > pair_long_t
Definition: extents.hpp:51
std::vector< int > guide_set_t
Definition: extents.hpp:53
A class containing element geometry for a single orientation.
Definition: extents.hpp:80
std::ostream & operator<<(std::ostream &s, const extents_t &x)
slice_t & horizontal()
Definition: extents.hpp:96

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google