Mantid
Loading...
Searching...
No Matches
Quadrilateral.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//-----------------------------------------------------------------------------
12#include <algorithm>
13
14namespace Mantid::Geometry {
15using Kernel::V2D;
16
19Quadrilateral::Quadrilateral(const V2D &lowerLeft, const V2D &lowerRight, const V2D &upperRight, const V2D &upperLeft)
21
25Quadrilateral::Quadrilateral(const double lowerX, const double upperX, const double lowerY, const double upperY)
26 : ConvexPolygon(), m_vertices{
27 {V2D(lowerX, lowerY), V2D(lowerX, upperY), V2D(upperX, upperY), V2D(upperX, lowerY)}} {}
28
35const Kernel::V2D &Quadrilateral::at(const size_t index) const {
36 if (index > 3)
37 throw Kernel::Exception::IndexError(index, npoints(), "Quadrilateral::at()");
38 return (*this)[index];
39}
40
44bool Quadrilateral::contains(const Kernel::V2D &point) const {
45 ConvexPolygon quadAsPoly = this->toPoly();
46 return quadAsPoly.contains(point);
47}
48
52bool Quadrilateral::contains(const ConvexPolygon &poly) const {
53 ConvexPolygon quadAsPoly = this->toPoly();
54 return quadAsPoly.contains(poly);
55}
56
60 points[0] = lowerLeft();
61 points[1] = upperLeft();
62 points[2] = upperRight();
63 points[3] = lowerRight();
64 return ConvexPolygon(points);
65}
66
69 V2D temp = m_vertices[0];
70 m_vertices[0] = m_vertices[1];
71 m_vertices[1] = m_vertices[2];
72 m_vertices[2] = m_vertices[3];
73 m_vertices[3] = temp;
74}
75
76} // namespace Mantid::Geometry
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
An implementation of a convex polygon.
Definition: ConvexPolygon.h:36
ConvexPolygon()
Default constructor.
virtual bool contains(const Kernel::V2D &point) const
Is a point inside this polygon.
std::vector< Kernel::V2D > Vertices
Type of the point list.
Definition: ConvexPolygon.h:40
ConvexPolygon toPoly() const override
Return a new Polygon based on the current Quadrilateral.
virtual void shiftVertexesClockwise()
Shifts the vertexes in a clockwise manner.
const Kernel::V2D & lowerRight() const
Definition: Quadrilateral.h:85
const Kernel::V2D & upperLeft() const
Definition: Quadrilateral.h:83
std::array< Kernel::V2D, 4 > m_vertices
Definition: Quadrilateral.h:88
const Kernel::V2D & upperRight() const
Definition: Quadrilateral.h:84
size_t npoints() const override
Return the number of vertices.
Definition: Quadrilateral.h:41
Quadrilateral(const Kernel::V2D &lowerLeft, const Kernel::V2D &lowerRight, const Kernel::V2D &upperRight, const Kernel::V2D &upperLeft)
Constructor with the four vertices.
const Kernel::V2D & lowerLeft() const
Definition: Quadrilateral.h:82
const Kernel::V2D & at(const size_t index) const override
Bounds-checked index access.
bool contains(const Kernel::V2D &point) const override
Is a point inside this polygon.
Exception for index errors.
Definition: Exception.h:284
Implements a 2-dimensional vector embedded in a 3D space, i.e.
Definition: V2D.h:29