Mantid
Loading...
Searching...
No Matches
ConvexPolygonIterator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//-----------------------------------------------------------------------------
8// Includes
9//-----------------------------------------------------------------------------
13
14namespace Mantid::Geometry {
15
16//-----------------------------------------------------------------------------
17// Public member functions
18//-----------------------------------------------------------------------------
22ConvexPolygon::Iterator::Iterator(const ConvexPolygon &polygon) : m_polygon(polygon), m_index(0) {
23 if (!polygon.isValid()) {
24 throw std::invalid_argument("Cannot create iterator for invalid polygon.");
25 }
26}
27
31const Kernel::V2D &ConvexPolygon::Iterator::operator*() const { return m_polygon[m_index]; }
32
37void ConvexPolygon::Iterator::operator++() { m_index = nextIndex(); }
38
42PolygonEdge ConvexPolygon::Iterator::edge() const { return PolygonEdge(**this, m_polygon[nextIndex()]); }
43
44//-----------------------------------------------------------------------------
45// Private member functions
46//-----------------------------------------------------------------------------
48size_t ConvexPolygon::Iterator::nextIndex() const { return (m_index + 1) % m_polygon.npoints(); }
49
50} // namespace Mantid::Geometry
Iterator(const ConvexPolygon &polygon)
Constructor.
PolygonEdge edge() const
Create a directed edge between this and the next point.
void operator++()
Prefix increment operator.
const Kernel::V2D & operator*() const
Dereference operator.
size_t nextIndex() const
Compute the next index.
An implementation of a convex polygon.
Definition: ConvexPolygon.h:36
bool isValid() const
Check if polygon is valid.
PolygonEdge Defines a directed edge between two points on a polygon.
Definition: PolygonEdge.h:23
Implements a 2-dimensional vector embedded in a 3D space, i.e.
Definition: V2D.h:29