42 char const *
const FOUND_ANTIPODAL_POINT =
43 "The convex hull of the given point set is the "
46 char const *
const NOT_ENOUGH_POINTS =
47 "The convex hull of a point set containing less than "
48 "3 distinct, non-coplanar points is not a convex polygon";
62 UnitVector3d & v0 = points[0];
63 UnitVector3d & v1 = points[1];
66 for (; v !=
end; ++v) {
91 UnitVector3d & v0 = points[0];
92 UnitVector3d & v1 = points[1];
96 UnitVector3d n(v0.robustCross(v1));
97 for (; v !=
end; ++v) {
102 }
else if (ccw < 0) {
109 if (*v == v0 || *v == v1) {
112 if (*v == -v0 || *v == -v1) {
147 VertexIterator hullEnd = points.
begin() + 3;
148 VertexIterator
const end = points.
end();
150 for (VertexIterator v = findTriangle(points); v !=
end; ++v) {
165 VertexIterator i = hullEnd - 1;
166 VertexIterator j = points.
begin();
169 VertexIterator toCCW = hullEnd;
173 VertexIterator fromCCW = hullEnd;
177 bool prevCCW = firstCCW;
181 for (i = j, ++j; j != hullEnd; i = j, ++j) {
187 }
else if (prevCCW) {
198 }
else if (prevCCW) {
199 fromCCW = points.
begin();
203 if (toCCW == hullEnd) {
215 if (toCCW < fromCCW) {
216 if (toCCW != points.
begin()) {
221 }
else if (toCCW > fromCCW) {
223 if (toCCW != fromCCW) {
224 hullEnd =
std::copy(toCCW, hullEnd, fromCCW);
227 if (fromCCW == points.
begin()) {
258 computeHull(_vertices);
265 if (_vertices.size() != p._vertices.size()) {
268 VertexIterator i = _vertices.begin();
269 VertexIterator f = p._vertices.begin();
270 VertexIterator
const ep = p._vertices.end();
272 for (; f != ep; ++f) {
283 for (VertexIterator j = f + 1; j != ep; ++i, ++j) {
288 for (VertexIterator j = p._vertices.begin(); j != f; ++i, ++j) {
317 return (
relate(r) & CONTAINS) != 0;
321 return (
relate(r) & DISJOINT) != 0;
329 return (
relate(r) & WITHIN) != 0;
351 buffer.
reserve(1 + 24 * _vertices.size());
364 if (buffer ==
nullptr || *buffer !=
TYPE_CODE ||
365 n < 1 + 24*3 || (n - 1) % 24 != 0) {
370 size_t nv = (n - 1) / 24;
371 poly->_vertices.reserve(nv);
372 for (
size_t i = 0; i < nv; ++i, buffer += 24) {
386 os <<
"{\"ConvexPolygon\": [" << *v;
387 for (++v; v !=
end; ++v) {
os <<
", " << *v; }
This file declares a class for representing convex polygons with great circle edges on the unit spher...
This file contains the meat of the ConvexPolygon implementation.
Box3d represents a box in ℝ³.
Box represents a rectangle in spherical coordinate space that contains its boundary.
Circle is a circular region on the unit sphere that contains its boundary.
ConvexPolygon is a closed convex polygon on the unit sphere.
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
std::vector< UnitVector3d > const & getVertices() const
bool intersects(Region const &r) const
UnitVector3d getCentroid() const
The centroid of a polygon is its center of mass projected onto S², assuming a uniform mass distributi...
bool isDisjointFrom(Region const &r) const
Relationship relate(Region const &r) const override
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
std::vector< uint8_t > encode() const override
encode serializes this region into an opaque byte string.
static std::unique_ptr< ConvexPolygon > decode(std::vector< uint8_t > const &s)
static constexpr uint8_t TYPE_CODE
virtual bool contains(UnitVector3d const &) const=0
contains tests whether the given unit vector is inside this region.
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
bool operator==(ConvexPolygon const &p) const
Two convex polygons are equal iff they contain the same points.
bool isWithin(Region const &r) const
Ellipse is an elliptical region on the sphere.
Region is a minimal interface for 2-dimensional regions on the unit sphere.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
This file contains simple helper functions for encoding and decoding primitive types to/from byte str...
T copy_backward(T... args)
Low-level polynomials (including special polynomials) in C++.
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
Circle boundingCircle(VertexIterator const begin, VertexIterator const end)
Box3d boundingBox3d(VertexIterator const begin, VertexIterator const end)
UnitVector3d centroid(VertexIterator const begin, VertexIterator const end)
Relationship relate(VertexIterator const begin, VertexIterator const end, Box const &b)
Box boundingBox(VertexIterator const begin, VertexIterator const end)
void encodeDouble(double item, std::vector< uint8_t > &buffer)
encode appends an IEEE double in little-endian byte order to the end of buffer.
std::ostream & operator<<(std::ostream &, Angle const &)
int orientation(UnitVector3d const &a, UnitVector3d const &b, UnitVector3d const &c)
orientation computes and returns the orientations of 3 unit vectors a, b and c.
double decodeDouble(uint8_t const *buffer)
decode extracts an IEEE double from the 8 byte little-endian byte sequence in buffer.
A base class for image defects.
This file declares functions for orienting points on the sphere.