Mantid
Loading...
Searching...
No Matches
Quadrilateral.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//------------------------------------------------------------------------------
13#include "MantidKernel/V2D.h"
14#include <array>
15
16namespace Mantid {
17namespace Geometry {
18
24class MANTID_GEOMETRY_DLL Quadrilateral final : public ConvexPolygon {
25public:
27 Quadrilateral(const Kernel::V2D &lowerLeft, const Kernel::V2D &lowerRight, const Kernel::V2D &upperRight,
28 const Kernel::V2D &upperLeft);
30 Quadrilateral(const double lowerX, const double upperX, const double lowerY, const double upperY);
33 Quadrilateral(const Quadrilateral &) = default;
35
37 inline const Kernel::V2D &operator[](const size_t index) const override { return m_vertices[index]; };
39 const Kernel::V2D &at(const size_t index) const override;
41 inline size_t npoints() const override { return 4; }
43 bool contains(const Kernel::V2D &point) const override;
45 bool contains(const ConvexPolygon &poly) const override;
53 inline double area() const override {
54 const double lhs = lowerLeft().Y() * upperLeft().X() + upperLeft().Y() * upperRight().X() +
55 upperRight().Y() * lowerRight().X() + lowerRight().Y() * lowerLeft().X();
56 const double rhs = lowerLeft().X() * upperLeft().Y() + upperLeft().X() * upperRight().Y() +
57 upperRight().X() * lowerRight().Y() + lowerRight().X() * lowerLeft().Y();
58 return 0.5 * (lhs - rhs);
59 }
60
67 inline double determinant() const override { return 2.0 * area(); }
69 inline double minX() const override { return std::min(lowerLeft().X(), upperLeft().X()); }
71 inline double maxX() const override { return std::max(lowerRight().X(), upperRight().X()); }
73 inline double minY() const override { return std::min(lowerLeft().Y(), lowerRight().Y()); }
75 inline double maxY() const override { return std::max(upperLeft().Y(), upperRight().Y()); }
77 ConvexPolygon toPoly() const override;
79 virtual void shiftVertexesClockwise();
80
81private:
82 inline const Kernel::V2D &lowerLeft() const { return m_vertices[0]; }
83 inline const Kernel::V2D &upperLeft() const { return m_vertices[1]; }
84 inline const Kernel::V2D &upperRight() const { return m_vertices[2]; }
85 inline const Kernel::V2D &lowerRight() const { return m_vertices[3]; }
86
87 // Order=ll,ul,ur,lr
88 std::array<Kernel::V2D, 4> m_vertices;
89};
90
91} // namespace Geometry
92} // namespace Mantid
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
An implementation of a convex polygon.
Definition: ConvexPolygon.h:36
A ConvexPolygon with only 4 vertices.
Definition: Quadrilateral.h:24
Quadrilateral & operator=(const Quadrilateral &)=default
const Kernel::V2D & lowerRight() const
Definition: Quadrilateral.h:85
Quadrilateral(const Quadrilateral &)=default
const Kernel::V2D & upperLeft() const
Definition: Quadrilateral.h:83
const Kernel::V2D & operator[](const size_t index) const override
Index access.
Definition: Quadrilateral.h:37
double area() const override
Compute the area of the polygon using triangulation.
Definition: Quadrilateral.h:53
double minX() const override
Return the lowest X value in the polygon.
Definition: Quadrilateral.h:69
std::array< Kernel::V2D, 4 > m_vertices
Definition: Quadrilateral.h:88
const Kernel::V2D & upperRight() const
Definition: Quadrilateral.h:84
Quadrilateral & operator=(Quadrilateral &&)=default
size_t npoints() const override
Return the number of vertices.
Definition: Quadrilateral.h:41
double maxX() const override
Return the max X value in the polygon.
Definition: Quadrilateral.h:71
double minY() const override
Return the lowest Y value in the polygon.
Definition: Quadrilateral.h:73
double maxY() const override
Return the max Y value in the polygon.
Definition: Quadrilateral.h:75
Quadrilateral(Quadrilateral &&)=default
const Kernel::V2D & lowerLeft() const
Definition: Quadrilateral.h:82
double determinant() const override
Compute the determinant of the set of points as if they were contained in an (N+1)x(N+1) matrix where...
Definition: Quadrilateral.h:67
Implements a 2-dimensional vector embedded in a 3D space, i.e.
Definition: V2D.h:29
double Y() const
Y position.
Definition: V2D.h:49
double X() const
X position.
Definition: V2D.h:44
Helper class which provides the Collimation Length for SANS instruments.