Mantid
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Geometry::ConvexPolygon Class Reference

An implementation of a convex polygon. More...

#include <ConvexPolygon.h>

Inheritance diagram for Mantid::Geometry::ConvexPolygon:
Mantid::Geometry::Quadrilateral

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::V2Dat (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...
 
ConvexPolygonoperator= (const ConvexPolygon &)=default
 
ConvexPolygonoperator= (ConvexPolygon &&)=default
 
virtual const Kernel::V2Doperator[] (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
 

Detailed Description

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.

Member Typedef Documentation

◆ Vertices

Type of the point list.

Definition at line 40 of file ConvexPolygon.h.

Constructor & Destructor Documentation

◆ ConvexPolygon() [1/4]

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().

◆ ConvexPolygon() [2/4]

Mantid::Geometry::ConvexPolygon::ConvexPolygon ( Vertices  vertices)

Construct a polygon from a collection of points.

Parameters
verticesA list of points that form the polygon

Definition at line 34 of file ConvexPolygon.cpp.

References setup().

◆ ~ConvexPolygon()

virtual Mantid::Geometry::ConvexPolygon::~ConvexPolygon ( )
virtualdefault

Destructor.

◆ ConvexPolygon() [3/4]

Mantid::Geometry::ConvexPolygon::ConvexPolygon ( ConvexPolygon &&  )
default

◆ ConvexPolygon() [4/4]

Mantid::Geometry::ConvexPolygon::ConvexPolygon ( const ConvexPolygon )
default

Member Function Documentation

◆ area()

double Mantid::Geometry::ConvexPolygon::area ( ) const
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.

Returns
The area of the polygon

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().

◆ at()

const Kernel::V2D & Mantid::Geometry::ConvexPolygon::at ( const size_t  index) const
virtual

Bounds-checked index access.

Return the vertex at the given index.

The index is checked for validity

Parameters
index:: An index, starting at 0
Returns
A reference to the polygon at that index
Exceptions
Exception::IndexErrorif 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().

◆ clear()

void Mantid::Geometry::ConvexPolygon::clear ( )

◆ contains() [1/2]

bool Mantid::Geometry::ConvexPolygon::contains ( const ConvexPolygon poly) const
virtual

Is a the given polygon completely encosed by this one.

Is the given polygon completely encosed by this one.

Parameters
polyAnother polygon
Returns
True if the given polygon is enclosed by this, false otherwise

Reimplemented in Mantid::Geometry::Quadrilateral.

Definition at line 115 of file ConvexPolygon.cpp.

References contains(), and npoints().

◆ contains() [2/2]

bool Mantid::Geometry::ConvexPolygon::contains ( const Kernel::V2D point) const
virtual

Is a point inside this polygon.

Parameters
point:: The point to test
Returns
True if the point is inside the polygon

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().

◆ determinant()

double Mantid::Geometry::ConvexPolygon::determinant ( ) const
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.

Returns
The determinant of the set of points

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().

◆ insert() [1/2]

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

Parameters
ptA 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().

◆ insert() [2/2]

void Mantid::Geometry::ConvexPolygon::insert ( double  x,
double  y 
)

Insert a new vertex based on x,y values.

Parameters
xX coordinate
yY coordinate

Definition at line 65 of file ConvexPolygon.cpp.

References insert(), Mantid::Geometry::x, and Mantid::Geometry::y.

◆ isValid()

bool Mantid::Geometry::ConvexPolygon::isValid ( ) const

Check if polygon is valid.

Returns
True if polygon has 3 or more points

Definition at line 37 of file ConvexPolygon.cpp.

References npoints().

Referenced by Mantid::Geometry::intersection(), and Mantid::Geometry::ConvexPolygon::Iterator::Iterator().

◆ maxX()

double Mantid::Geometry::ConvexPolygon::maxX ( ) const
virtual

Return the largest X value in the polygon.

Returns
A double indicating the smallest 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().

◆ maxY()

double Mantid::Geometry::ConvexPolygon::maxY ( ) const
virtual

Return the largest Y value in the polygon.

Returns
A double indicating the smallest Y value in the polygon

Reimplemented in Mantid::Geometry::Quadrilateral.

Definition at line 184 of file ConvexPolygon.cpp.

References m_maxY.

◆ minX()

double Mantid::Geometry::ConvexPolygon::minX ( ) const
virtual

Return the lowest X value in the polygon.

Returns
A double indicating the smallest 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().

◆ minY()

double Mantid::Geometry::ConvexPolygon::minY ( ) const
virtual

Return the lowest Y value in the polygon.

Return the lowest X value in the polygon.

Returns
A double indicating the smallest Y value in the polygon

Reimplemented in Mantid::Geometry::Quadrilateral.

Definition at line 178 of file ConvexPolygon.cpp.

References m_minY.

◆ npoints()

size_t Mantid::Geometry::ConvexPolygon::npoints ( ) const
virtual

Return the number of vertices.

Returns
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<<().

◆ operator=() [1/2]

ConvexPolygon & Mantid::Geometry::ConvexPolygon::operator= ( const ConvexPolygon )
default

◆ operator=() [2/2]

ConvexPolygon & Mantid::Geometry::ConvexPolygon::operator= ( ConvexPolygon &&  )
default

◆ operator[]()

const V2D & Mantid::Geometry::ConvexPolygon::operator[] ( const size_t  index) const
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

Parameters
index:: An index, starting at 0
Returns
A reference to the polygon at that index
Exceptions
Exception::IndexErrorif the index is out of range

Reimplemented in Mantid::Geometry::Quadrilateral.

Definition at line 75 of file ConvexPolygon.cpp.

References index, and m_vertices.

◆ setup()

void Mantid::Geometry::ConvexPolygon::setup ( )
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().

◆ toPoly()

ConvexPolygon Mantid::Geometry::ConvexPolygon::toPoly ( ) const
virtual

Return a new Polygon based on the current type.

Returns
A copy of the current polygon

Reimplemented in Mantid::Geometry::Quadrilateral.

Definition at line 189 of file ConvexPolygon.cpp.

Referenced by Mantid::Geometry::intersection().

◆ triangleArea()

double Mantid::Geometry::ConvexPolygon::triangleArea ( const Kernel::V2D a,
const Kernel::V2D b,
const Kernel::V2D c 
) const
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

Parameters
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().

Member Data Documentation

◆ m_maxX

double Mantid::Geometry::ConvexPolygon::m_maxX
private

Highest X value.

Definition at line 122 of file ConvexPolygon.h.

Referenced by clear(), insert(), maxX(), and setup().

◆ m_maxY

double Mantid::Geometry::ConvexPolygon::m_maxY
private

Highest Y value.

Definition at line 126 of file ConvexPolygon.h.

Referenced by clear(), insert(), maxY(), and setup().

◆ m_minX

double Mantid::Geometry::ConvexPolygon::m_minX
private

Lowest X value.

Definition at line 120 of file ConvexPolygon.h.

Referenced by clear(), insert(), minX(), and setup().

◆ m_minY

double Mantid::Geometry::ConvexPolygon::m_minY
private

Lowest Y value.

Definition at line 124 of file ConvexPolygon.h.

Referenced by clear(), insert(), minY(), and setup().

◆ m_vertices

Vertices Mantid::Geometry::ConvexPolygon::m_vertices
private

Definition at line 128 of file ConvexPolygon.h.

Referenced by at(), clear(), contains(), determinant(), insert(), npoints(), operator[](), and setup().


The documentation for this class was generated from the following files: