36 throw std::invalid_argument(
"nd must be > 0");
85template <
typename TYPE>
103template <
typename TYPE>
118 throw std::invalid_argument(
"nd must be > 0");
120 for (
size_t d = 0;
d <
nd;
d++)
128 if ((other.nd) != nd) {
133 for (
size_t d = 0;
d < nd;
d++)
134 data[
d] = other.data[
d];
142 other.data =
nullptr;
150 if (
this != &other) {
154 this->data = other.data;
155 other.data =
nullptr;
165 throw std::invalid_argument(
"nd must be > 0");
167 for (
size_t d = 0;
d <
nd;
d++)
176 throw std::invalid_argument(
"nd must be > 0");
178 for (
size_t d = 0;
d <
nd;
d++)
186 for (
size_t d = 0;
d <
nd;
d++)
194 throw std::invalid_argument(
"nd must be > 0");
196 for (
size_t d = 0;
d <
nd;
d++)
204 throw std::invalid_argument(
"nd must be > 0");
206 for (
size_t d = 0;
d <
nd;
d++)
217 std::vector<TYPE> vals;
218 std::transform(strs.
cbegin(), strs.
cend(), std::back_inserter(vals), [](
const std::string &token) {
220 if (!Strings::convert(token, v))
221 throw std::invalid_argument(
"VMDBase: Unable to convert the string '" + token +
"' to a number.");
227 throw std::invalid_argument(
"nd must be > 0");
229 std::copy(vals.cbegin(), vals.cend(), data);
255 std::ostringstream mess;
256 for (
size_t d = 0;
d < nd;
d++)
257 mess << (
d > 0 ? separator :
"") << data[
d];
268 for (
size_t d = 0;
d < nd;
d++)
291 if (v.
nd != this->nd)
292 throw std::runtime_error(
"Mismatch in number of dimensions in operation "
293 "between two VMDBase vectors.");
294 for (
size_t d = 0;
d < nd;
d++)
311 if (v.
nd != this->nd)
312 throw std::runtime_error(
"Mismatch in number of dimensions in operation "
313 "between two VMDBase vectors.");
314 for (
size_t d = 0;
d < nd;
d++)
330 if (v.
nd != this->nd)
331 throw std::runtime_error(
"Mismatch in number of dimensions in operation "
332 "between two VMDBase vectors.");
333 for (
size_t d = 0;
d < nd;
d++)
349 if (v.
nd != this->nd)
350 throw std::runtime_error(
"Mismatch in number of dimensions in operation "
351 "between two VMDBase vectors.");
352 for (
size_t d = 0;
d < nd;
d++)
368 for (
size_t d = 0;
d < nd;
d++)
369 data[
d] *=
TYPE(scalar);
384 for (
size_t d = 0;
d < nd;
d++)
385 data[
d] /=
TYPE(scalar);
393 if (v.
nd != this->nd)
394 throw std::runtime_error(
"Mismatch in number of dimensions in operation "
395 "between two VMDBase vectors.");
396 for (
size_t d = 0;
d < nd;
d++)
397 out += (data[
d] * v.
data[
d]);
404 if (v.
nd != this->nd)
405 throw std::runtime_error(
"Mismatch in number of dimensions in operation "
406 "between two VMDBase vectors.");
408 throw std::runtime_error(
"Cross product of vectors only works in 3 dimensions.");
409 V3D a(data[0], data[1], data[2]);
428 TYPE length = this->length();
429 for (
size_t d = 0;
d < nd;
d++)
439 return TYPE(acos(this->scalar_prod(v) / (this->norm() * v.
norm())));
449template <
typename TYPE>
451 if (vectors.size() != 2)
452 throw std::runtime_error(
"VMDBase::makeVectorsOrthogonal(): Need 2 input vectors.");
453 if (vectors[0].getNumDims() != 3 || vectors[1].getNumDims() != 3)
454 throw std::runtime_error(
"VMDBase::makeVectorsOrthogonal(): Need 3D input vectors.");
455 std::vector<V3D> in, out;
456 for (
size_t i = 0; i < vectors.size(); i++)
457 in.emplace_back(vectors[i][0], vectors[i][1], vectors[i][2]);
459 std::vector<VMDBase> retVal;
460 retVal.reserve(out.size());
461 std::copy(std::make_move_iterator(out.begin()), std::make_move_iterator(out.end()), std::back_inserter(retVal));
496 throw std::invalid_argument(
"VMDBase::getNormalVector: Must give at least 1 vector");
497 size_t nd = vectors[0].getNumDims();
499 throw std::invalid_argument(
"VMDBase::getNormalVector: Must have at least 2 dimensions!");
500 if (vectors.size() != nd - 1)
501 throw std::invalid_argument(
"VMDBase::getNormalVector: Must have as many "
502 "N-1 vectors if there are N dimensions.");
503 for (
size_t i = 0; i < vectors.size(); i++)
504 if (vectors[i].getNumDims() != nd)
505 throw std::invalid_argument(
"VMDBase::getNormalVector: Inconsistent "
506 "number of dimensions in the vectors given!");
511 for (
size_t d = 0;
d < nd;
d++) {
514 for (
size_t row = 0; row < vectors.size(); row++) {
517 for (
size_t i = 0; i < nd; i++) {
520 mat[row][col] = vec[i];
529 normal[
d] = sign * det;
538 throw std::runtime_error(
"VMDBase::getNormalVector: 0-length normal found. "
539 "Are your vectors collinear?");
std::map< DeltaEMode::Type, std::string > index
T determinant() const
Calculate the determinant.
@ TOK_IGNORE_EMPTY
ignore empty tokens
ConstIterator cend() const
Const iterator referring to the past-the-end element in the container.
ConstIterator cbegin() const
Const iterator referring to first element in the container.
static std::vector< V3D > makeVectorsOrthogonal(const std::vector< V3D > &vectors)
Take a list of 2 vectors and makes a 3D orthogonal system out of them The first vector i0 is taken as...
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
Simple vector class for multiple dimensions (i.e.
VMDBase operator+(const VMDBase &v) const
Add two vectors together.
std::string toString(const std::string &separator=" ") const
Return a simple string representation of the vector.
static std::vector< VMDBase > makeVectorsOrthogonal(std::vector< VMDBase > &vectors)
Make an orthogonal system with 2 input 3D vectors.
VMDBase & operator=(const VMDBase &other)
Assignment operator.
TYPE normalize()
Normalize this vector to unity length.
const TYPE * getBareArray() const
bool operator==(const VMDBase &v) const
Equals operator with tolerance factor.
VMDBase & operator*=(const VMDBase &v)
Inner product of two vectors (element-by-element)
VMDBase operator/(const VMDBase &v) const
Inner division of two vectors (element-by-element)
TYPE scalar_prod(const VMDBase &v) const
Scalar product of two vectors.
VMDBase & operator-=(const VMDBase &v)
Subtract two vectors.
size_t nd
Number of dimensions.
TYPE angle(const VMDBase &v) const
Return the angle between this and another vector.
bool operator!=(const VMDBase &v) const
Not-equals operator with tolerance factor.
VMDBase()
Default constructor, build with 1 dimension.
VMDBase cross_prod(const VMDBase &v) const
Cross product of two vectors.
TYPE * data
Data, an array of size nd.
VMDBase operator*(const VMDBase &v) const
Inner product of two vectors (element-by-element)
VMDBase & operator/=(const VMDBase &v)
Inner division of two vectors (element-by-element)
VMDBase & operator+=(const VMDBase &v)
Add two vectors together.
size_t getNumDims() const
VMDBase operator-(const VMDBase &v) const
Subtract two vectors.
static VMDBase getNormalVector(const std::vector< VMDBase > &vectors)
Given N-1 vectors defining a N-1 dimensional hyperplane in N dimensions, returns a vector that is nor...
const TYPE & operator[](const size_t index) const
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.
MANTID_KERNEL_DLL bool operator==(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs)
Compares this to another property for equality.
constexpr double Tolerance
Standard tolerance value.