Inkscape
Vector Graphics Editor
|
Convex hull based on the Andrew's monotone chain algorithm. More...
#include <convex-hull.h>
Public Types | |
using | iterator = std::vector< Point >::const_iterator |
using | const_iterator = std::vector< Point >::const_iterator |
using | UpperIterator = std::vector< Point >::const_iterator |
using | LowerIterator = ConvexHullLowerIterator |
Public Member Functions | |
void | swap (ConvexHull &other) |
void | swap (std::vector< Point > &pts) |
Construct a convex hull. | |
ConvexHull ()=default | |
Create an empty convex hull. | |
ConvexHull (Point const &a) | |
Construct a singular convex hull. | |
ConvexHull (Point const &a, Point const &b) | |
Construct a convex hull of two points. | |
ConvexHull (Point const &a, Point const &b, Point const &c) | |
Construct a convex hull of three points. | |
ConvexHull (Point const &a, Point const &b, Point const &c, Point const &d) | |
Construct a convex hull of four points. | |
ConvexHull (std::vector< Point > const &pts) | |
Create a convex hull of a vector of points. | |
template<typename Iter > | |
ConvexHull (Iter first, Iter last) | |
Create a convex hull of a range of points. | |
Inspect basic properties. | |
bool | empty () const |
Check for emptiness. | |
size_t | size () const |
Get the number of points in the hull. | |
bool | isSingular () const |
Check whether the hull contains only one point. | |
bool | isLinear () const |
Check whether the hull is a line. | |
bool | isDegenerate () const |
Check whether the hull has zero area. | |
double | area () const |
Calculate the area of the convex hull. | |
Inspect bounds and extreme points. | |
OptRect | bounds () const |
Compute the bounding rectangle of the convex hull. | |
std::pair< Rotate, OptRect > | minAreaRotation () const |
Return a rotation that puts the convex hull into a position such that bounds() has minimal area, and return those bounds. | |
Coord | left () const |
Get the leftmost (minimum X) coordinate of the hull. | |
Coord | right () const |
Get the rightmost (maximum X) coordinate of the hull. | |
Coord | top () const |
Get the topmost (minimum Y) coordinate of the hull. | |
Coord | bottom () const |
Get the bottommost (maximum Y) coordinate of the hull. | |
Point | leftPoint () const |
Get the leftmost (minimum X) point of the hull. | |
Point | rightPoint () const |
Get the rightmost (maximum X) point of the hull. | |
Point | topPoint () const |
Get the topmost (minimum Y) point of the hull. | |
Point | bottomPoint () const |
Get the bottommost (maximum Y) point of the hull. | |
Iterate over points. | |
iterator | begin () const |
Get the begin iterator to the points that form the hull. | |
iterator | end () const |
Get the end iterator to the points that form the hull. | |
Point const & | front () const |
Get the first, leftmost point in the hull. | |
Point const & | back () const |
Get the penultimate point of the lower hull. | |
Point const & | operator[] (std::size_t i) const |
boost::iterator_range< UpperIterator > | upperHull () const |
Get an iterator range to the upper part of the hull. | |
boost::iterator_range< LowerIterator > | lowerHull () const |
Get an iterator range to the lower part of the hull. | |
Check for containment and intersection. | |
bool | contains (Point const &p) const |
Check whether the given point is inside the hull. | |
bool | contains (Rect const &r) const |
Check whether the given axis-aligned rectangle is inside the hull. | |
bool | contains (ConvexHull const &other) const |
Check whether the given convex hull is completely contained in this one. | |
Private Member Functions | |
void | _construct () |
Static Private Member Functions | |
template<typename Iter > | |
static void | _prune (Iter first, Iter last, std::vector< Point > &out) |
Take a vector of points and produce a pruned sorted vector. | |
Private Attributes | |
std::vector< Point > | _boundary |
Sequence of points forming the convex hull polygon. | |
std::size_t | _lower |
Index one past the rightmost point, where the lower part of the boundary starts. | |
Convex hull based on the Andrew's monotone chain algorithm.
Definition at line 114 of file convex-hull.h.
using Geom::ConvexHull::const_iterator = std::vector<Point>::const_iterator |
Definition at line 118 of file convex-hull.h.
using Geom::ConvexHull::iterator = std::vector<Point>::const_iterator |
Definition at line 117 of file convex-hull.h.
using Geom::ConvexHull::LowerIterator = ConvexHullLowerIterator |
Definition at line 120 of file convex-hull.h.
using Geom::ConvexHull::UpperIterator = std::vector<Point>::const_iterator |
Definition at line 119 of file convex-hull.h.
|
default |
Create an empty convex hull.
|
inlineexplicit |
Construct a singular convex hull.
Definition at line 128 of file convex-hull.h.
Construct a convex hull of two points.
Definition at line 62 of file convex-hull.cpp.
References _boundary, and _construct().
Construct a convex hull of three points.
Definition at line 72 of file convex-hull.cpp.
References _boundary, _construct(), and c.
Construct a convex hull of four points.
Definition at line 83 of file convex-hull.cpp.
References _boundary, _construct(), and c.
Geom::ConvexHull::ConvexHull | ( | std::vector< Point > const & | pts | ) |
Create a convex hull of a vector of points.
Definition at line 95 of file convex-hull.cpp.
References _boundary, and _construct().
|
inline |
Create a convex hull of a range of points.
Definition at line 143 of file convex-hull.h.
References _boundary, _construct(), and _prune().
|
private |
Definition at line 113 of file convex-hull.cpp.
References _boundary, _lower, and Geom::is_clockwise_turn().
Referenced by ConvexHull(), ConvexHull(), ConvexHull(), ConvexHull(), ConvexHull(), and swap().
|
inlinestaticprivate |
Take a vector of points and produce a pruned sorted vector.
Definition at line 278 of file convex-hull.h.
References contains().
Referenced by ConvexHull().
double Geom::ConvexHull::area | ( | ) | const |
Calculate the area of the convex hull.
Definition at line 151 of file convex-hull.cpp.
References _boundary, Geom::cross(), and size().
Referenced by minAreaRotation(), and wrap_convex_cover().
|
inline |
Get the penultimate point of the lower hull.
Definition at line 215 of file convex-hull.h.
References _boundary.
Referenced by cairo_convex_hull(), and Geom::Path::Path().
|
inline |
Get the begin iterator to the points that form the hull.
Points are returned beginning with the leftmost one, going along the upper (minimum Y) side, and then along the bottom. Thus the points are always ordered clockwise. No point is repeated.
Definition at line 209 of file convex-hull.h.
References _boundary.
Referenced by Geom::andrew_merge(), and Geom::graham_merge().
|
inline |
Get the bottommost (maximum Y) coordinate of the hull.
Definition at line 186 of file convex-hull.h.
References bottomPoint(), and Geom::Y.
Referenced by bounds().
Point Geom::ConvexHull::bottomPoint | ( | ) | const |
Get the bottommost (maximum Y) point of the hull.
If the bottommost edge is horizontal, the left point of the edge is returned.
Definition at line 248 of file convex-hull.cpp.
References lowerHull(), Geom::Y, and Geom::Point::y().
Referenced by bottom().
OptRect Geom::ConvexHull::bounds | ( | ) | const |
bool Geom::ConvexHull::contains | ( | ConvexHull const & | other | ) | const |
Check whether the given convex hull is completely contained in this one.
Definition at line 316 of file convex-hull.cpp.
References contains().
bool Geom::ConvexHull::contains | ( | Point const & | p | ) | const |
Check whether the given point is inside the hull.
This takes logarithmic time.
Definition at line 286 of file convex-hull.cpp.
References _boundary, _lower, Geom::below_x_monotonic_polyline(), lowerHull(), upperHull(), and Geom::X.
Referenced by _prune(), contains(), contains(), HullContainsPoint(), and Geom::sbasis_to_cubic_bezier().
bool Geom::ConvexHull::contains | ( | Rect const & | r | ) | const |
Check whether the given axis-aligned rectangle is inside the hull.
A rectangle is inside the hull if all of its corners are inside.
Definition at line 308 of file convex-hull.cpp.
References contains(), and Geom::GenericRect< C >::corner().
|
inline |
Check for emptiness.
Definition at line 155 of file convex-hull.h.
References _boundary.
Referenced by bounds(), cairo_convex_hull(), cairo_convex_hull(), minAreaRotation(), Geom::Path::Path(), and wrap_convex_cover().
|
inline |
Get the end iterator to the points that form the hull.
Definition at line 211 of file convex-hull.h.
References _boundary.
Referenced by Geom::andrew_merge(), and Geom::graham_merge().
|
inline |
Get the first, leftmost point in the hull.
Definition at line 213 of file convex-hull.h.
References _boundary.
Referenced by minAreaRotation(), and Geom::Path::Path().
|
inline |
Check whether the hull has zero area.
Definition at line 163 of file convex-hull.h.
References _boundary.
|
inline |
Check whether the hull is a line.
Definition at line 161 of file convex-hull.h.
References _boundary.
|
inline |
Check whether the hull contains only one point.
Definition at line 159 of file convex-hull.h.
References _boundary.
|
inline |
Get the leftmost (minimum X) coordinate of the hull.
Definition at line 180 of file convex-hull.h.
References _boundary, and Geom::X.
Referenced by bounds().
|
inline |
Get the leftmost (minimum X) point of the hull.
If the leftmost edge is vertical, the top point of the edge is returned.
Definition at line 190 of file convex-hull.h.
References _boundary.
|
inline |
Get an iterator range to the lower part of the hull.
This returns a range that includes the leftmost point, all points of the lower hull, and the rightmost point.
Definition at line 228 of file convex-hull.h.
References _boundary, and _lower.
Referenced by bottomPoint(), and contains().
Return a rotation that puts the convex hull into a position such that bounds() has minimal area, and return those bounds.
Definition at line 169 of file convex-hull.cpp.
References _boundary, area(), Geom::dot(), empty(), Geom::GenericRect< Coord >::from_xywh(), front(), Geom::Rotate::inverse(), Geom::Point::length(), size(), and w.
Referenced by Inkscape::UI::Widget::Stores::snapshot_combine().
|
inline |
Definition at line 216 of file convex-hull.h.
References _boundary.
|
inline |
|
inline |
Get the rightmost (maximum X) point of the hull.
If the rightmost edge is vertical, the bottom point edge is returned.
Definition at line 193 of file convex-hull.h.
|
inline |
Get the number of points in the hull.
Definition at line 157 of file convex-hull.h.
References _boundary.
Referenced by area(), Geom::bridges(), cairo_convex_hull(), cairo_convex_hull(), Geom::detail::bezier_clipping::clip_interval(), Geom::detail::bezier_clipping::clip_interval(), Geom::find_bottom_right(), Geom::merge(), minAreaRotation(), Geom::Path::Path(), and Geom::sweepline_intersection().
void Geom::ConvexHull::swap | ( | ConvexHull & | other | ) |
Definition at line 335 of file convex-hull.cpp.
References _boundary, and _lower.
Referenced by Geom::detail::bezier_clipping::clip_interval(), and Geom::detail::bezier_clipping::clip_interval().
void Geom::ConvexHull::swap | ( | std::vector< Point > & | pts | ) |
Definition at line 341 of file convex-hull.cpp.
References _boundary, _construct(), and _lower.
|
inline |
Get the topmost (minimum Y) coordinate of the hull.
Definition at line 184 of file convex-hull.h.
References topPoint(), and Geom::Y.
Referenced by bounds().
Point Geom::ConvexHull::topPoint | ( | ) | const |
Get the topmost (minimum Y) point of the hull.
If the topmost edge is horizontal, the right point of the edge is returned.
Definition at line 232 of file convex-hull.cpp.
References upperHull(), Geom::Y, and Geom::Point::y().
Referenced by top().
|
inline |
Get an iterator range to the upper part of the hull.
This returns a range that includes the leftmost point, all points of the upper hull, and the rightmost point.
Definition at line 221 of file convex-hull.h.
References _boundary, and _lower.
Referenced by contains(), and topPoint().
|
private |
Sequence of points forming the convex hull polygon.
Definition at line 312 of file convex-hull.h.
Referenced by _construct(), area(), back(), begin(), contains(), ConvexHull(), ConvexHull(), ConvexHull(), ConvexHull(), ConvexHull(), empty(), end(), front(), isDegenerate(), isLinear(), isSingular(), left(), leftPoint(), lowerHull(), minAreaRotation(), operator[](), right(), rightPoint(), size(), swap(), swap(), and upperHull().
|
private |
Index one past the rightmost point, where the lower part of the boundary starts.
Definition at line 314 of file convex-hull.h.
Referenced by _construct(), contains(), lowerHull(), right(), rightPoint(), swap(), swap(), and upperHull().