25 # ifndef DSGGEOMETRICALGORITHMS_H 26 # define DSGGEOMETRICALGORITHMS_H 43 template <
class PolygonType>
46 using PointType =
typename PolygonType::PointType;
47 using SegmentType =
typename PolygonType::SegmentType;
51 bool cmp_point(
const PointType & p1,
const PointType & p2)
const 53 if (p1.get_x() < p2.get_x())
56 return not (p2.get_x() < p1.get_x()) and p1.get_y() < p2.get_y();
59 bool operator () (
const SegmentType & s1,
const SegmentType & s2)
61 if (cmp_point(s1.get_src_point(), s2.get_src_point()))
64 return not (cmp_point(s2.get_src_point(), s1.get_src_point())) and
65 cmp_point(s1.get_tgt_point(), s2.get_tgt_point());
74 const SegmentType & s)
76 return l.
all([&s] (
const PointType & p)
79 p.is_to_left_on_from(s.get_src_point(), s.get_tgt_point());
87 for (PointTypeIt i(point_set); i.has_curr(); i.next())
89 const PointType & p_i = i.get_curr();
91 for (PointTypeIt j(point_set); j.has_curr(); j.next())
93 const PointType & p_j = j.get_curr();
98 SegmentType s(p_i, p_j);
100 if (are_all_points_on_left(point_set, s))
115 SegmentType first_segment = extremes.remove_pos(0);
116 ret.add_vertex(first_segment.get_src_point());
117 ret.add_vertex(first_segment.get_tgt_point());
121 const PointType & last_vertex = ret.get_last_vertex();
124 extremes.search_ptr([&last_vertex](
const SegmentType & s) {
125 return s.get_src_point() == last_vertex;
128 assert(ptr !=
nullptr);
130 if (ptr->get_tgt_point() == ret.get_first_vertex())
133 ret.add_vertex(ptr->get_tgt_point());
135 extremes.remove(*ptr);
147 template <
class PolygonType>
150 using PointType =
typename PolygonType::PointType;
151 using SegmentType =
typename PolygonType::SegmentType;
152 using NumType =
typename PointType::NumberType;
156 const SegmentType & s)
158 NumType max_distance = 0;
161 for (PointTypeIt it(point_set); it.has_curr(); it.next())
163 const PointType & p = it.
get_curr();
165 SegmentType s1 = s.get_perpendicular(p);
167 NumType sz = s1.length();
169 if (sz > max_distance)
181 const PointType & a,
const PointType & b,
190 if (p != a and p != c and p.is_to_right_from(a, c))
196 if (p != c and p != b and p.is_to_right_from(c, b))
197 ret.second.append(p);
210 PointType c = get_fartest_point(point_set, SegmentType(a, b));
212 auto r = get_right_points(point_set, a, b, c);
222 std::pair<PointType, PointType>
225 PointTypeIt it(point_set);
226 PointType leftmost = it.get_curr();
227 PointType rightmost = it.get_curr();
230 for ( ; it.has_curr(); it.next())
232 const PointType & p = it.get_curr();
234 if (p.get_x() < leftmost.get_x())
237 if (p.get_x() > rightmost.get_x())
241 return std::make_pair(leftmost, rightmost);
250 for (PointTypeIt it(point_set); it.has_curr(); it.next())
252 const PointType & p = it.get_curr();
254 if (p.is_to_right_from(a, b))
257 ret.second.append(p);
268 auto e = search_extremes(point_set);
269 auto p =
partition(point_set, e.first, e.second);
275 convex_set.
append(e.first);
277 convex_set.
append(e.second);
280 for (PointTypeIt it(convex_set); it.has_curr(); it.next())
281 ret.add_vertex(it.get_curr());
289 # endif // DSGGEOMETRICALGORITHMS_H RetType< RET_CPY, T, T & > get_curr()
Definition: iterator.H:55
T remove_first()
Definition: list.H:313
void concat(SLList &l)
Definition: list.H:331
T & append(const T &item)
Definition: list.H:265
PolygonType operator()(const SLList< PointType > &point_set)
Definition: geometricalgorithms.H:109
Definition: geometricalgorithms.H:44
bool is_empty() const
Definition: list.H:80
Definition: geometricalgorithms.H:148
Definition: italgorithms.H:33
lint_t partition(ArrayType &, lint_t, lint_t, Cmp &)
Definition: sort.H:224
bool all(Pred &pred) const
Definition: containeralgorithms.H:161