Mantid
Loading...
Searching...
No Matches
V3R.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2014 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#include "MantidGeometry/DllConfig.h"
10
12#include "MantidKernel/Matrix.h"
13#include "MantidKernel/V3D.h"
14
15#include <boost/rational.hpp>
16
17namespace Mantid {
18namespace Geometry {
19
35using RationalNumber = boost::rational<int>;
36
37class MANTID_GEOMETRY_DLL V3R {
38public:
39 V3R();
40 V3R(const RationalNumber &x, const RationalNumber &y, const RationalNumber &z);
41 V3R(const std::vector<int> &vector);
42
43 const RationalNumber &x() const;
44 void setX(const RationalNumber &newX);
45
46 const RationalNumber &y() const;
47 void setY(const RationalNumber &newY);
48
49 const RationalNumber &z() const;
50 void setZ(const RationalNumber &newZ);
51
52 RationalNumber &operator[](size_t index);
53 const RationalNumber &operator[](size_t index) const;
54
55 // Operations with other vectors of rational numbers
56 V3R operator+(const V3R &other) const;
57 V3R &operator+=(const V3R &other);
58
59 V3R operator-() const;
60 V3R operator-(const V3R &other) const;
61 V3R &operator-=(const V3R &other);
62
63 // Operations with integers
64 V3R operator+(int other) const;
65 V3R &operator+=(int other);
66
67 V3R operator-(int other) const;
68 V3R &operator-=(int other);
69
70 V3R operator*(int other) const;
71 V3R &operator*=(int other);
72
73 V3R operator/(int other) const;
74 V3R &operator/=(int other);
75
76 // Operations with rational numbers
77 V3R operator+(const RationalNumber &other) const;
78 V3R &operator+=(const RationalNumber &other);
79
80 V3R operator-(const RationalNumber &other) const;
81 V3R &operator-=(const RationalNumber &other);
82
83 V3R operator*(const RationalNumber &other) const;
84 V3R &operator*=(const RationalNumber &other);
85
86 V3R operator/(const RationalNumber &other) const;
87 V3R &operator/=(const RationalNumber &other);
88
89 // Operations with V3D
90 operator Kernel::V3D() const;
91 Kernel::V3D operator+(const Kernel::V3D &other) const;
92 Kernel::V3D operator-(const Kernel::V3D &other) const;
93
94 // Comparison operators
95 bool operator==(const V3R &other) const;
96 bool operator!=(const V3R &other) const;
97 bool operator<(const V3R &other) const;
98
99 bool operator==(int other) const;
100 bool operator!=(int other) const;
101
102 V3R getPositiveVector() const;
103
104 // std::vector<double> operator
105 operator std::vector<double>() const;
106
107protected:
111};
112
115template <typename T> V3R operator*(const Kernel::Matrix<T> &lhs, const V3R &rhs) {
116 size_t rows = lhs.numRows();
117 size_t cols = lhs.numCols();
118
119 if (cols != 3) {
120 throw Kernel::Exception::MisMatch<size_t>(cols, 3, "operator*(IntMatrix, V3R)");
121 }
122
123 V3R result;
124 for (size_t r = 0; r < rows; ++r) {
125 for (size_t c = 0; c < cols; ++c) {
126 result[r] += static_cast<typename RationalNumber::int_type>(lhs[r][c]) * rhs[c];
127 }
128 }
129
130 return result;
131}
132} // namespace Geometry
133} // namespace Mantid
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
RationalNumber m_y
Definition: V3R.h:109
RationalNumber m_z
Definition: V3R.h:110
RationalNumber m_x
Definition: V3R.h:108
Error when two numbers should be identical (or close)
Definition: Exception.h:263
Numerical Matrix class.
Definition: Matrix.h:42
size_t numRows() const
Return the number of rows in the matrix.
Definition: Matrix.h:144
size_t numCols() const
Return the number of columns in the matrix.
Definition: Matrix.h:147
Class for 3D vectors.
Definition: V3D.h:34
MatrixWorkspace_sptr MANTID_API_DLL operator*(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Multiply two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator/=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Divide two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator+=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Adds two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator-=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Subtracts two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator-(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Subtracts two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator*=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Multiply two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator/(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Divide two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator+(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Adds two workspaces.
boost::rational< int > RationalNumber
V3R :
Definition: V3R.h:35
MANTID_GEOMETRY_DLL Group_const_sptr operator*(const Group_const_sptr &lhs, const Group_const_sptr &rhs)
Convenience operator* for directly multiplying groups using shared pointers.
Definition: Group.cpp:248
Helper class which provides the Collimation Length for SANS instruments.
constexpr bool operator==(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
constexpr bool operator!=(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
constexpr bool operator<(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)