Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/polygon/segment_utils.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 /* | |
2 Copyright 2012 Lucanus Simonson | |
3 | |
4 Use, modification and distribution are subject to the Boost Software License, | |
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
6 http://www.boost.org/LICENSE_1_0.txt). | |
7 */ | |
8 | |
9 #ifndef BOOST_POLYGON_SEGMENT_UTILS_HPP | |
10 #define BOOST_POLYGON_SEGMENT_UTILS_HPP | |
11 | |
12 #include <set> | |
13 #include <vector> | |
14 #include <utility> | |
15 | |
16 namespace boost { | |
17 namespace polygon { | |
18 | |
19 template <typename Segment, typename SegmentIterator> | |
20 typename enable_if< | |
21 typename gtl_and< | |
22 typename gtl_if< | |
23 typename is_segment_concept< | |
24 typename geometry_concept< | |
25 typename std::iterator_traits<SegmentIterator>::value_type | |
26 >::type | |
27 >::type | |
28 >::type, | |
29 typename gtl_if< | |
30 typename is_segment_concept< | |
31 typename geometry_concept<Segment>::type | |
32 >::type | |
33 >::type | |
34 >::type, | |
35 void | |
36 >::type | |
37 intersect_segments( | |
38 std::vector<std::pair<std::size_t, Segment> >& result, | |
39 SegmentIterator first, SegmentIterator last) { | |
40 typedef typename segment_traits<Segment>::coordinate_type Unit; | |
41 typedef typename scanline_base<Unit>::Point Point; | |
42 typedef typename scanline_base<Unit>::half_edge half_edge; | |
43 typedef int segment_id; | |
44 std::vector<std::pair<half_edge, segment_id> > half_edges; | |
45 std::vector<std::pair<half_edge, segment_id> > half_edges_out; | |
46 segment_id id_in = 0; | |
47 half_edges.reserve(std::distance(first, last)); | |
48 for (; first != last; ++first) { | |
49 Point l, h; | |
50 assign(l, low(*first)); | |
51 assign(h, high(*first)); | |
52 half_edges.push_back(std::make_pair(half_edge(l, h), id_in++)); | |
53 } | |
54 half_edges_out.reserve(half_edges.size()); | |
55 // Apparently no need to pre-sort data when calling validate_scan. | |
56 if (half_edges.size() != 0) { | |
57 line_intersection<Unit>::validate_scan( | |
58 half_edges_out, half_edges.begin(), half_edges.end()); | |
59 } | |
60 | |
61 result.reserve(result.size() + half_edges_out.size()); | |
62 for (std::size_t i = 0; i < half_edges_out.size(); ++i) { | |
63 std::size_t id = (std::size_t)(half_edges_out[i].second); | |
64 Point l = half_edges_out[i].first.first; | |
65 Point h = half_edges_out[i].first.second; | |
66 result.push_back(std::make_pair(id, construct<Segment>(l, h))); | |
67 } | |
68 } | |
69 | |
70 template <typename SegmentContainer, typename SegmentIterator> | |
71 typename enable_if< | |
72 typename gtl_and< | |
73 typename gtl_if< | |
74 typename is_segment_concept< | |
75 typename geometry_concept< | |
76 typename std::iterator_traits<SegmentIterator>::value_type | |
77 >::type | |
78 >::type | |
79 >::type, | |
80 typename gtl_if< | |
81 typename is_segment_concept< | |
82 typename geometry_concept< | |
83 typename SegmentContainer::value_type | |
84 >::type | |
85 >::type | |
86 >::type | |
87 >::type, | |
88 void | |
89 >::type | |
90 intersect_segments( | |
91 SegmentContainer& result, | |
92 SegmentIterator first, | |
93 SegmentIterator last) { | |
94 typedef typename SegmentContainer::value_type segment_type; | |
95 typedef typename segment_traits<segment_type>::coordinate_type Unit; | |
96 typedef typename scanline_base<Unit>::Point Point; | |
97 typedef typename scanline_base<Unit>::half_edge half_edge; | |
98 typedef int segment_id; | |
99 std::vector<std::pair<half_edge, segment_id> > half_edges; | |
100 std::vector<std::pair<half_edge, segment_id> > half_edges_out; | |
101 segment_id id_in = 0; | |
102 half_edges.reserve(std::distance(first, last)); | |
103 for (; first != last; ++first) { | |
104 Point l, h; | |
105 assign(l, low(*first)); | |
106 assign(h, high(*first)); | |
107 half_edges.push_back(std::make_pair(half_edge(l, h), id_in++)); | |
108 } | |
109 half_edges_out.reserve(half_edges.size()); | |
110 // Apparently no need to pre-sort data when calling validate_scan. | |
111 if (half_edges.size() != 0) { | |
112 line_intersection<Unit>::validate_scan( | |
113 half_edges_out, half_edges.begin(), half_edges.end()); | |
114 } | |
115 | |
116 result.reserve(result.size() + half_edges_out.size()); | |
117 for (std::size_t i = 0; i < half_edges_out.size(); ++i) { | |
118 Point l = half_edges_out[i].first.first; | |
119 Point h = half_edges_out[i].first.second; | |
120 result.push_back(construct<segment_type>(l, h)); | |
121 } | |
122 } | |
123 | |
124 template <typename Rectangle, typename SegmentIterator> | |
125 typename enable_if< | |
126 typename gtl_and< | |
127 typename gtl_if< | |
128 typename is_rectangle_concept< | |
129 typename geometry_concept<Rectangle>::type | |
130 >::type | |
131 >::type, | |
132 typename gtl_if< | |
133 typename is_segment_concept< | |
134 typename geometry_concept< | |
135 typename std::iterator_traits<SegmentIterator>::value_type | |
136 >::type | |
137 >::type | |
138 >::type | |
139 >::type, | |
140 bool | |
141 >::type | |
142 envelope_segments( | |
143 Rectangle& rect, | |
144 SegmentIterator first, | |
145 SegmentIterator last) { | |
146 for (SegmentIterator it = first; it != last; ++it) { | |
147 if (it == first) { | |
148 set_points(rect, low(*it), high(*it)); | |
149 } else { | |
150 encompass(rect, low(*it)); | |
151 encompass(rect, high(*it)); | |
152 } | |
153 } | |
154 return first != last; | |
155 } | |
156 } // polygon | |
157 } // boost | |
158 | |
159 #endif // BOOST_POLYGON_SEGMENT_UTILS_HPP |