Mantid
Loading...
Searching...
No Matches
ConvexPolygon.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 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#pragma once
8
9//-----------------------------------------------------------------------------
10// Includes
11//-----------------------------------------------------------------------------
12#include "MantidGeometry/DllConfig.h"
13#include "MantidKernel/V2D.h"
14#include <iosfwd>
15#include <vector>
16
17namespace Mantid {
18namespace Geometry {
19//---------------------------------------------------------------------------
20// Forward declarations
21//---------------------------------------------------------------------------
22class PolygonEdge;
23
36class MANTID_GEOMETRY_DLL ConvexPolygon {
37
38public:
40 using Vertices = std::vector<Kernel::V2D>;
41
42 //-----------------------------------------------------------------
43 // Forward directional iterator inner class
44 //-----------------------------------------------------------------
45 class MANTID_GEOMETRY_DLL Iterator {
46 public:
48 Iterator(const ConvexPolygon &polygon);
49
51 const Kernel::V2D &operator*() const;
53 void operator++();
55 PolygonEdge edge() const;
56
57 private:
59 size_t nextIndex() const;
60
62 size_t m_index;
63 };
64
65 //-----------------------------------------------------------------
66 // ConvexPolygon class
67 //-----------------------------------------------------------------
68
72 ConvexPolygon(Vertices vertices);
74 virtual ~ConvexPolygon() = default;
77 ConvexPolygon(const ConvexPolygon &) = default;
79
81 bool isValid() const;
83 void clear();
86 void insert(const Kernel::V2D &pt);
88 void insert(double x, double y);
90 virtual const Kernel::V2D &operator[](const size_t index) const;
92 virtual const Kernel::V2D &at(const size_t index) const;
94 virtual size_t npoints() const;
96 virtual bool contains(const Kernel::V2D &point) const;
98 virtual bool contains(const ConvexPolygon &poly) const;
100 virtual double area() const;
102 virtual double determinant() const;
104 virtual double minX() const;
106 virtual double maxX() const;
108 virtual double minY() const;
110 virtual double maxY() const;
112 virtual ConvexPolygon toPoly() const;
113
114private:
116 void setup();
118 double triangleArea(const Kernel::V2D &a, const Kernel::V2D &b, const Kernel::V2D &c) const;
120 double m_minX;
122 double m_maxX;
124 double m_minY;
126 double m_maxY;
127 // Points of the polygon
129};
130
132MANTID_GEOMETRY_DLL std::ostream &operator<<(std::ostream &os, const ConvexPolygon &polygon);
133
134} // namespace Geometry
135} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
An implementation of a convex polygon.
Definition: ConvexPolygon.h:36
double m_minX
Lowest X value.
ConvexPolygon & operator=(ConvexPolygon &&)=default
double m_maxY
Highest Y value.
double m_minY
Lowest Y value.
virtual ~ConvexPolygon()=default
Destructor.
double m_maxX
Highest X value.
ConvexPolygon & operator=(const ConvexPolygon &)=default
ConvexPolygon(ConvexPolygon &&)=default
ConvexPolygon(const ConvexPolygon &)=default
std::vector< Kernel::V2D > Vertices
Type of the point list.
Definition: ConvexPolygon.h:40
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
MatrixWorkspace_sptr MANTID_API_DLL operator*(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Multiply two workspaces.
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.
Definition: PointGroup.cpp:312
Helper class which provides the Collimation Length for SANS instruments.