32#ifndef LIB2GEOM_SEEN_CONVEX_HULL_H
33#define LIB2GEOM_SEEN_CONVEX_HULL_H
38#include <boost/operators.hpp>
39#include <boost/range/iterator_range.hpp>
51class ConvexHullLowerIterator
52 :
public boost::random_access_iterator_helper
53 < ConvexHullLowerIterator
61 using Self = ConvexHullLowerIterator;
62 ConvexHullLowerIterator() =
default;
63 ConvexHullLowerIterator(std::vector<Point>
const &pts, std::size_t x)
85 std::ptrdiff_t
operator-(Self
const &other)
const {
96 return _data == other._data &&
_x == other._x;
99 return _data == other._data &&
_x < other._x;
117 using iterator = std::vector<Point>::const_iterator;
142 template <
typename Iter>
221 boost::iterator_range<UpperIterator>
upperHull()
const {
228 boost::iterator_range<LowerIterator>
lowerHull()
const {
271 void swap(std::vector<Point> &pts);
277 template <
typename Iter>
278 static void _prune(Iter first, Iter last, std::vector<Point> &out) {
279 std::optional<Point> ymin, ymax, xmin, xmax;
280 for (Iter i = first; i != last; ++i) {
282 if (!ymin || Point::LexLess<Y>()(p, *ymin)) {
285 if (!xmin || Point::LexLess<X>()(p, *xmin)) {
288 if (!ymax || Point::LexGreater<Y>()(p, *ymax)) {
291 if (!xmax || Point::LexGreater<X>()(p, *xmax)) {
298 for (Iter i = first; i != last; ++i) {
303 out.push_back(*xmin);
304 out.push_back(*xmax);
305 out.push_back(*ymin);
306 out.push_back(*ymax);
307 std::sort(out.begin(), out.end(), Point::LexLess<X>());
308 out.erase(std::unique(out.begin(), out.end()), out.end());
320 out <<
"ConvexHull(";
321 for (
auto i :
hull) {
Cartesian point / 2D vector and related operations.
pair< double, double > Point
static bool operator<(const Baseline &a, const Baseline &b)
Convex hull based on the Andrew's monotone chain algorithm.
std::vector< Point > _boundary
Sequence of points forming the convex hull polygon.
bool empty() const
Check for emptiness.
std::vector< Point >::const_iterator iterator
Point bottomPoint() const
Get the bottommost (maximum Y) point of the hull.
iterator end() const
Get the end iterator to the points that form the hull.
Point const & back() const
Get the penultimate point of the lower hull.
boost::iterator_range< UpperIterator > upperHull() const
Get an iterator range to the upper part of the hull.
Point rightPoint() const
Get the rightmost (maximum X) point of the hull.
ConvexHull()=default
Create an empty convex hull.
static void _prune(Iter first, Iter last, std::vector< Point > &out)
Take a vector of points and produce a pruned sorted vector.
boost::iterator_range< LowerIterator > lowerHull() const
Get an iterator range to the lower part of the hull.
size_t size() const
Get the number of points in the hull.
ConvexHullLowerIterator LowerIterator
ConvexHull(Point const &a)
Construct a singular convex hull.
Coord bottom() const
Get the bottommost (maximum Y) coordinate of the hull.
Coord left() const
Get the leftmost (minimum X) coordinate of the hull.
bool contains(Point const &p) const
Check whether the given point is inside the hull.
bool isSingular() const
Check whether the hull contains only one point.
std::vector< Point >::const_iterator UpperIterator
std::pair< Rotate, OptRect > minAreaRotation() const
Return a rotation that puts the convex hull into a position such that bounds() has minimal area,...
iterator begin() const
Get the begin iterator to the points that form the hull.
Point leftPoint() const
Get the leftmost (minimum X) point of the hull.
double area() const
Calculate the area of the convex hull.
std::vector< Point >::const_iterator const_iterator
Point const & front() const
Get the first, leftmost point in the hull.
ConvexHull(Iter first, Iter last)
Create a convex hull of a range of points.
bool isLinear() const
Check whether the hull is a line.
Coord right() const
Get the rightmost (maximum X) coordinate of the hull.
Point topPoint() const
Get the topmost (minimum Y) point of the hull.
Coord top() const
Get the topmost (minimum Y) coordinate of the hull.
Point const & operator[](std::size_t i) const
bool isDegenerate() const
Check whether the hull has zero area.
std::size_t _lower
Index one past the rightmost point, where the lower part of the boundary starts.
Axis-aligned rectangle that can be empty.
Two-dimensional point that doubles as a vector.
Axis aligned, non-empty rectangle.
double Coord
Floating point type used to store coordinates.
Various utility functions.
std::ostream & operator<<(std::ostream &os, const Bezier &b)
D2< T > operator+=(D2< T > &a, D2< T > const &b)
D2< T > operator-(D2< T > const &a, D2< T > const &b)
Bezier operator*(Bezier const &f, Bezier const &g)
D2< T > operator-=(D2< T > &a, D2< T > const &b)
bool operator==(D2< T > const &a, D2< T > const &b)