Mantid
|
An implementation of a convex polygon. More...
#include <ConvexPolygon.h>
Classes | |
class | Iterator |
Public Types | |
using | Vertices = std::vector< Kernel::V2D > |
Type of the point list. More... | |
Public Member Functions | |
virtual double | area () const |
Compute the area of the polygon using triangulation. More... | |
virtual const Kernel::V2D & | at (const size_t index) const |
Bounds-checked index access. More... | |
void | clear () |
Clears all points. More... | |
virtual bool | contains (const ConvexPolygon &poly) const |
Is a the given polygon completely encosed by this one. More... | |
virtual bool | contains (const Kernel::V2D &point) const |
Is a point inside this polygon. More... | |
ConvexPolygon () | |
Default constructor. More... | |
ConvexPolygon (const ConvexPolygon &)=default | |
ConvexPolygon (ConvexPolygon &&)=default | |
ConvexPolygon (Vertices vertices) | |
Construct a polygon from a collection of points. More... | |
virtual double | determinant () const |
Compute the 'determinant' of the points. More... | |
void | insert (const Kernel::V2D &pt) |
Insert a new vertex. More... | |
void | insert (double x, double y) |
Insert a new vertex based on x,y values. More... | |
bool | isValid () const |
Check if polygon is valid. More... | |
virtual double | maxX () const |
Return the largest X value in the polygon. More... | |
virtual double | maxY () const |
Return the largest Y value in the polygon. More... | |
virtual double | minX () const |
Return the lowest X value in the polygon. More... | |
virtual double | minY () const |
Return the lowest Y value in the polygon. More... | |
virtual size_t | npoints () const |
Return the number of vertices. More... | |
ConvexPolygon & | operator= (const ConvexPolygon &)=default |
ConvexPolygon & | operator= (ConvexPolygon &&)=default |
virtual const Kernel::V2D & | operator[] (const size_t index) const |
Index access. More... | |
virtual ConvexPolygon | toPoly () const |
Return a new Polygon based on the current type. More... | |
virtual | ~ConvexPolygon ()=default |
Destructor. More... | |
Private Member Functions | |
void | setup () |
Setup the meta-data. More... | |
double | triangleArea (const Kernel::V2D &a, const Kernel::V2D &b, const Kernel::V2D &c) const |
Compute the area of a triangle given by 3 points. More... | |
Private Attributes | |
double | m_maxX |
Highest X value. More... | |
double | m_maxY |
Highest Y value. More... | |
double | m_minX |
Lowest X value. More... | |
double | m_minY |
Lowest Y value. More... | |
Vertices | m_vertices |
An implementation of a convex polygon.
It contains a list of vertices that make up a convex polygon and the list is assumed to be ordered in a clockwise manner and the polygon is assumed to be closed.
A polygon is convex if:
Definition at line 36 of file ConvexPolygon.h.
using Mantid::Geometry::ConvexPolygon::Vertices = std::vector<Kernel::V2D> |
Type of the point list.
Definition at line 40 of file ConvexPolygon.h.
Mantid::Geometry::ConvexPolygon::ConvexPolygon | ( | ) |
Default constructor.
Constructs a 'null' polygon with no points.
Definition at line 29 of file ConvexPolygon.cpp.
Referenced by Mantid::Geometry::Quadrilateral::toPoly().
Mantid::Geometry::ConvexPolygon::ConvexPolygon | ( | Vertices | vertices | ) |
Construct a polygon from a collection of points.
vertices | A list of points that form the polygon |
Definition at line 34 of file ConvexPolygon.cpp.
References setup().
|
virtualdefault |
Destructor.
|
default |
|
default |
|
virtual |
Compute the area of the polygon using triangulation.
As this is a convex polygon the calculation is exact. The algorithm uses one vertex as a common vertex and sums the areas of the triangles formed by this and two other vertices, moving in an anti-clockwise direction.
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 132 of file ConvexPolygon.cpp.
References determinant().
Referenced by Mantid::DataObjects::FractionalRebinning::calcGeneralIntersections(), Mantid::Geometry::intersection(), and Mantid::DataObjects::FractionalRebinning::rebinToOutput().
|
virtual |
Bounds-checked index access.
Return the vertex at the given index.
The index is checked for validity
index | :: An index, starting at 0 |
Exception::IndexError | if the index is out of range |
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 83 of file ConvexPolygon.cpp.
References index, m_vertices, and npoints().
void Mantid::Geometry::ConvexPolygon::clear | ( | ) |
Clears all points.
Definition at line 40 of file ConvexPolygon.cpp.
References m_maxX, m_maxY, m_minX, m_minY, and m_vertices.
Referenced by Mantid::DataObjects::FractionalRebinning::calcGeneralIntersections(), and Mantid::DataObjects::FractionalRebinning::rebinToOutput().
|
virtual |
Is a the given polygon completely encosed by this one.
Is the given polygon completely encosed by this one.
poly | Another polygon |
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 115 of file ConvexPolygon.cpp.
References contains(), and npoints().
|
virtual |
Is a point inside this polygon.
point | :: The point to test |
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 99 of file ConvexPolygon.cpp.
References Mantid::Geometry::classify(), m_vertices, npoints(), and Mantid::Geometry::OnLeft.
Referenced by contains(), Mantid::Geometry::Quadrilateral::contains(), and Mantid::Geometry::intersection().
|
virtual |
Compute the 'determinant' of the points.
Compute the determinant of the set of points as if they were contained in an (N+1)x(N+1) matrix where N=number of vertices.
Each row contains the [X,Y] values of the vertex padded with zeroes to the column length.
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 140 of file ConvexPolygon.cpp.
References m_vertices, npoints(), rhs, Mantid::Kernel::V2D::X(), and Mantid::Kernel::V2D::Y().
Referenced by area().
void Mantid::Geometry::ConvexPolygon::insert | ( | const Kernel::V2D & | pt | ) |
Insert a new vertex.
The point is assumed that it forms the next point in a clockwise-sense around the shape
pt | A new point for the shape |
Definition at line 52 of file ConvexPolygon.cpp.
References m_maxX, m_maxY, m_minX, m_minY, m_vertices, Mantid::Kernel::V2D::X(), and Mantid::Kernel::V2D::Y().
Referenced by insert(), and Mantid::Geometry::intersection().
void Mantid::Geometry::ConvexPolygon::insert | ( | double | x, |
double | y | ||
) |
Insert a new vertex based on x,y values.
x | X coordinate |
y | Y coordinate |
Definition at line 65 of file ConvexPolygon.cpp.
References insert(), Mantid::Geometry::x, and Mantid::Geometry::y.
bool Mantid::Geometry::ConvexPolygon::isValid | ( | ) | const |
Check if polygon is valid.
Definition at line 37 of file ConvexPolygon.cpp.
References npoints().
Referenced by Mantid::Geometry::intersection(), and Mantid::Geometry::ConvexPolygon::Iterator::Iterator().
|
virtual |
Return the largest X value in the polygon.
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 172 of file ConvexPolygon.cpp.
References m_maxX.
Referenced by Mantid::DataObjects::FractionalRebinning::rebinToOutput().
|
virtual |
Return the largest Y value in the polygon.
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 184 of file ConvexPolygon.cpp.
References m_maxY.
|
virtual |
Return the lowest X value in the polygon.
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 166 of file ConvexPolygon.cpp.
References m_minX.
Referenced by Mantid::DataObjects::FractionalRebinning::rebinToOutput().
|
virtual |
Return the lowest Y value in the polygon.
Return the lowest X value in the polygon.
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 178 of file ConvexPolygon.cpp.
References m_minY.
|
virtual |
Return the number of vertices.
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 92 of file ConvexPolygon.cpp.
References m_vertices.
Referenced by at(), contains(), determinant(), Mantid::Geometry::intersection(), isValid(), and Mantid::Geometry::operator<<().
|
default |
|
default |
|
virtual |
Index access.
Return the vertex at the given index.
The index is assumed to be valid. See at() for a bounds-checking version. Out-of-bounds access is undefined
index | :: An index, starting at 0 |
Exception::IndexError | if the index is out of range |
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 75 of file ConvexPolygon.cpp.
References index, and m_vertices.
|
private |
Setup the meta-data.
Setup the meta-data: no of vertices, high/low points.
Definition at line 194 of file ConvexPolygon.cpp.
References m_maxX, m_maxY, m_minX, m_minY, m_vertices, Mantid::Geometry::x, and Mantid::Geometry::y.
Referenced by ConvexPolygon().
|
virtual |
Return a new Polygon based on the current type.
Reimplemented in Mantid::Geometry::Quadrilateral.
Definition at line 189 of file ConvexPolygon.cpp.
Referenced by Mantid::Geometry::intersection().
|
private |
Compute the area of a triangle given by 3 points.
Compute the area of a triangle given by 3 points (a,b,c) using the convention in "Computational Geometry in C" by J.
O'Rourke
a | :: The first vertex in the set |
b | :: The second vertex in the set |
c | :: The third vertex in the set |
Definition at line 216 of file ConvexPolygon.cpp.
References Mantid::Kernel::V2D::X(), and Mantid::Kernel::V2D::Y().
|
private |
|
private |
|
private |
|
private |
|
private |
Definition at line 128 of file ConvexPolygon.h.
Referenced by at(), clear(), contains(), determinant(), insert(), npoints(), operator[](), and setup().