diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..d9cf81d
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,86 @@
+---
+Language: Cpp
+AccessModifierOffset: -4
+AlignAfterOpenBracket: AlwaysBreak
+AlignConsecutiveAssignments: true
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: false
+BinPackParameters: false
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: false
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: true
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 80
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|isl|json)/)'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '$'
+IndentCaseLabels: false
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Left
+ReflowComments: true
+SortIncludes: true
+SpaceAfterCStyleCast: true
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
+
diff --git a/.clang_complete b/.clang_complete
new file mode 100644
index 0000000..25ea966
--- /dev/null
+++ b/.clang_complete
@@ -0,0 +1,5 @@
+-I.
+-Iinclude
+-Ibuild-debug/src
+-Ivendor/Box2D/Box2D/include
+-Ivendor/googletest/include
\ No newline at end of file
diff --git a/include/cece/math/Matrix.hpp b/include/cece/math/Matrix.hpp
new file mode 100644
index 0000000..b11861f
--- /dev/null
+++ b/include/cece/math/Matrix.hpp
@@ -0,0 +1,316 @@
+/* ************************************************************************ */
+/* Georgiev Lab (c) 2015-2017 */
+/* ************************************************************************ */
+/* Department of Cybernetics */
+/* Faculty of Applied Sciences */
+/* University of West Bohemia in Pilsen */
+/* ************************************************************************ */
+/* */
+/* This file is part of CeCe. */
+/* */
+/* CeCe is free software: you can redistribute it and/or modify */
+/* it under the terms of the GNU General Public License as published by */
+/* the Free Software Foundation, either version 3 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* CeCe is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with CeCe. If not, see . */
+/* */
+/* ************************************************************************ */
+
+#pragma once
+
+/* ************************************************************************ */
+
+// CeCe
+#include "cece/math/Zero.hpp"
+#include "cece/math/MatrixBase.hpp"
+#include "cece/math/Vector.hpp"
+#include "cece/unit/Units.hpp"
+
+/* ************************************************************************ */
+
+namespace cece {
+namespace math {
+
+/* ************************************************************************ */
+
+/**
+ * @brief 2D matrix implementation.
+ *
+ * @tparam T Type of stored value.
+ * @tparam R Number of rows.
+ * @tparam C Number of columns.
+ */
+template
+struct Matrix : public MatrixBase
+{
+
+// Public Types
+public:
+
+
+ /// Row type.
+ using RowType = Vector;
+
+ /// Column type.
+ using ColumnType = Vector;
+
+
+// Public Data Members
+public:
+
+
+ /// Matrix data.
+ Vector m;
+
+
+// Public Ctors
+public:
+
+
+ /**
+ * @brief Default constructor.
+ */
+ Matrix();
+
+
+ /**
+ * @brief Zero constructor.
+ *
+ * @param[in] zero Zero value.
+ */
+ Matrix(Zero_t zero);
+
+
+ /**
+ * @brief Constructor.
+ *
+ * @param src Initial data
+ */
+ Matrix(const T (&src)[R][C]);
+
+
+ /**
+ * @brief Constructor.
+ *
+ * @param src Initial data
+ */
+ Matrix(const RowType (&src)[R]);
+
+
+ /**
+ * @brief Copy constructor.
+ *
+ * @param src Source matrix.
+ */
+ Matrix(const Matrix& src);
+
+
+ /**
+ * @brief Move constructor.
+ *
+ * @param src Source matrix.
+ */
+ Matrix(Matrix&& src);
+
+
+// Public Operators
+public:
+
+
+ /**
+ * @brief Copy assignment operator.
+ *
+ * @param src The source matrix.
+ *
+ * @return *this.
+ */
+ Matrix& operator=(const Matrix& src);
+
+
+ /**
+ * @brief Move assignment operator.
+ *
+ * @param src The source matrix.
+ *
+ * @return *this.
+ */
+ Matrix& operator=(Matrix&& src);
+
+
+ /**
+ * @brief Row access operator.
+ *
+ * @param[in] pos The row number.
+ *
+ * @return Row.
+ */
+ RowType& operator[](int pos) noexcept;
+
+
+ /**
+ * @brief Row access operator.
+ *
+ * @param pos The row number.
+ *
+ * @return Row.
+ */
+ const RowType& operator[](int pos) const noexcept;
+
+
+ /**
+ * @brief Element access operator.
+ *
+ * @param coord Coordinates.
+ *
+ * @return Element.
+ */
+ T& operator[](Vector2 coord) noexcept;
+
+
+ /**
+ * @brief Element access operator.
+ *
+ * @param coord Coordinates.
+ *
+ * @return Element.
+ */
+ const T& operator[](Vector2 coord) const noexcept;
+
+};
+
+/* ************************************************************************ */
+
+}
+}
+
+/* ************************************************************************ */
+/* ************************************************************************ */
+/* ************************************************************************ */
+
+namespace cece {
+namespace math {
+
+/* ************************************************************************ */
+
+template
+inline Matrix::Matrix()
+{
+ // Nothing to do
+}
+
+/* ************************************************************************ */
+
+template
+inline Matrix::Matrix(Zero_t zero)
+{
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ m[row][col] = Zero;
+}
+
+/* ************************************************************************ */
+
+template
+inline Matrix::Matrix(const T (&src)[R][C])
+{
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ m[row][col] = src[row][col];
+}
+
+/* ************************************************************************ */
+
+template
+inline Matrix::Matrix(const RowType (&src)[R])
+{
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ m[row][col] = src[row][col];
+}
+
+/* ************************************************************************ */
+
+template
+inline Matrix::Matrix(const Matrix& src)
+{
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ m[row][col] = src[row][col];
+}
+
+/* ************************************************************************ */
+
+template
+inline Matrix::Matrix(Matrix&& src)
+{
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ m[row][col] = std::move(src[row][col]);
+}
+
+/* ************************************************************************ */
+
+template
+inline Matrix& Matrix::operator=(const Matrix& src)
+{
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ m[row][col] = src[row][col];
+}
+
+/* ************************************************************************ */
+
+template
+inline Matrix& Matrix::operator=(Matrix&& src)
+{
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ m[row][col] = std::move(src[row][col]);
+}
+
+/* ************************************************************************ */
+
+template
+inline Matrix::RowType& Matrix::operator[](int pos) noexcept
+{
+ return m[pos];
+}
+
+/* ************************************************************************ */
+
+template
+inline const Matrix::RowType& Matrix::operator[](int pos) const noexcept
+{
+ return m[pos];
+}
+
+/* ************************************************************************ */
+
+template
+inline T& Matrix::operator[](Vector2 coord) noexcept
+{
+ return m[coord.x][coord.y];
+}
+
+/* ************************************************************************ */
+
+template
+inline const T& Matrix::operator[](Vector2 coord) const noexcept
+{
+ return m[coord.x][coord.y];
+}
+
+/* ************************************************************************ */
+
+}
+}
+
+/* ************************************************************************ */
+
diff --git a/include/cece/math/MatrixBase.hpp b/include/cece/math/MatrixBase.hpp
new file mode 100644
index 0000000..13785c3
--- /dev/null
+++ b/include/cece/math/MatrixBase.hpp
@@ -0,0 +1,390 @@
+/* ************************************************************************ */
+/* Georgiev Lab (c) 2015-2017 */
+/* ************************************************************************ */
+/* Department of Cybernetics */
+/* Faculty of Applied Sciences */
+/* University of West Bohemia in Pilsen */
+/* ************************************************************************ */
+/* */
+/* This file is part of CeCe. */
+/* */
+/* CeCe is free software: you can redistribute it and/or modify */
+/* it under the terms of the GNU General Public License as published by */
+/* the Free Software Foundation, either version 3 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* CeCe is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with CeCe. If not, see . */
+/* */
+/* ************************************************************************ */
+
+#pragma once
+
+/* ************************************************************************ */
+
+// CeCe
+#include "cece/math/Vector.hpp"
+
+/* ************************************************************************ */
+
+namespace cece {
+namespace math {
+
+/* ************************************************************************ */
+
+/**
+ * @brief 2D fixed size matrix base class.
+ *
+ * @tparam MatrixType Matrix type.
+ * @tparam T Type of stored value.
+ * @tparam R Number of rows.
+ * @tparam C Number of cols.
+ */
+template<
+ template typename MatrixType,
+ typename T,
+ int R,
+ int C
+>
+struct MatrixBase
+{
+
+// Public Types
+public:
+
+
+ /// VectorBase value type.
+ using ValueType = T;
+
+
+// Public Operators
+public:
+
+
+ /**
+ * @brief Addition operator.
+ *
+ * @param rhs Right operand.
+ *
+ * @tparam T1 The second type.
+ *
+ * @return *this.
+ */
+ template
+ MatrixType& operator+=(const MatrixType& rhs);
+
+
+ /**
+ * @brief Substraction operator.
+ *
+ * @param rhs Right operand.
+ *
+ * @tparam T1 The second type.
+ *
+ * @return *this.
+ */
+ template
+ MatrixType& operator-=(const MatrixType& rhs);
+
+
+ /**
+ * @brief Multiplication operator.
+ *
+ * @param rhs Right operand.
+ *
+ * @tparam T1 The second type.
+ *
+ * @return *this.
+ */
+ template
+ MatrixType& operator*=(const T1& rhs);
+
+
+ /**
+ * @brief Division operator.
+ *
+ * @param rhs Right operand.
+ *
+ * @tparam T1 The second type.
+ *
+ * @return *this.
+ */
+ template
+ MatrixType& operator/=(const T1& rhs);
+
+};
+
+/* ************************************************************************ */
+
+/**
+ * @brief Addition operator.
+ *
+ * @param lhs Left operand.
+ * @param rhs Right operand.
+ *
+ * @tparam T1 Type of value in first matrix.
+ * @tparam T2 Type of value in second matrix.
+ * @tparam R Number of rows.
+ * @tparam C Number of columns.
+ *
+ * @return Result matrix.
+ */
+template
+MatrixBase() + std::declval()), R, C> operator+(
+ const MatrixBase& lhs,
+ const MatrixBase& rhs
+);
+
+/* ************************************************************************ */
+
+/**
+ * @brief Substraction operator.
+ *
+ * @param lhs Left operand.
+ * @param rhs Right operand.
+ *
+ * @tparam T1 Type of value in first matrix.
+ * @tparam T2 Type of value in second matrix.
+ * @tparam R Number of rows.
+ * @tparam C Number of columns.
+ *
+ * @return Result matrix.
+ */
+template
+MatrixBase() - std::declval()), R, C> operator-(
+ const MatrixBase& lhs,
+ const MatrixBase& rhs
+);
+
+/* ************************************************************************ */
+
+/**
+ * @brief Multiplication operator.
+ *
+ * @param lhs Left operand.
+ * @param rhs Right operand.
+ *
+ * @tparam T1 Type of value in first matrix.
+ * @tparam T2 Type of value in second matrix.
+ * @tparam R Number of rows.
+ * @tparam C Number of columns.
+ *
+ * @return Result matrix.
+ */
+template
+MatrixBase() * std::declval()), R, C> operator*(
+ const MatrixBase& lhs,
+ const T2& rhs
+);
+
+/* ************************************************************************ */
+
+/**
+ * @brief Multiplication operator.
+ *
+ * @param lhs Left operand.
+ * @param rhs Right operand.
+ *
+ * @tparam T1 Type of value in first matrix.
+ * @tparam T2 Type of value in second matrix.
+ * @tparam R Number of rows.
+ * @tparam C Number of columns.
+ *
+ * @return Result matrix.
+ */
+template
+MatrixBase() * std::declval()), R, C> operator*(
+ const T2& lhs
+ const MatrixBase& rhs,
+);
+
+/* ************************************************************************ */
+
+/**
+ * @brief Multiplication operator.
+ *
+ * @param lhs Left operand.
+ * @param rhs Right operand.
+ *
+ * @tparam T1 Type of value in first matrix.
+ * @tparam T2 Type of value in second matrix.
+ * @tparam R Number of rows.
+ * @tparam C Number of columns.
+ *
+ * @return Result matrix.
+ */
+template
+MatrixBase() / std::declval()), R, C> operator/(
+ const MatrixBase& lhs,
+ const T2& rhs
+);
+
+/* ************************************************************************ */
+
+}
+}
+
+/* ************************************************************************ */
+/* ************************************************************************ */
+/* ************************************************************************ */
+
+namespace cece {
+namespace math {
+
+/* ************************************************************************ */
+
+template typename MatrixType, typename T, int R, int C>
+template
+inline MatrixType& MatrixBase::operator+=(const MatrixType& rhs)
+{
+ auto& self = *static_cast*>(this);
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ self[row][col] += rhs[row][col];
+
+ return self;
+}
+
+/* ************************************************************************ */
+
+template typename MatrixType, typename T, int R, int C>
+template
+inline MatrixType& MatrixBase::operator-=(const MatrixType& rhs)
+{
+ auto& self = *static_cast*>(this);
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ self[row][col] -= rhs[row][col];
+
+ return self;
+}
+
+/* ************************************************************************ */
+
+template typename MatrixType, typename T, int R, int C>
+template
+inline MatrixType& MatrixBase::operator*=(const T1& rhs)
+{
+ auto& self = *static_cast*>(this);
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ self[row][col] *= rhs;
+
+ return self;
+}
+
+/* ************************************************************************ */
+
+template typename MatrixType, typename T, int R, int C>
+template
+inline MatrixType& MatrixBase::operator/=(const T1& rhs)
+{
+ auto& self = *static_cast*>(this);
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ self[row][col] /= rhs;
+
+ return self;
+}
+
+/* ************************************************************************ */
+
+template
+inline MatrixBase() + std::declval()), R, C> operator+(
+ const MatrixBase& lhs,
+ const MatrixBase& rhs
+)
+{
+ MatrixBase() + std::declval()), R, C> res;
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ res[row][col] = lhs[row][col] + rhs[row][col];
+
+ return res;
+}
+
+/* ************************************************************************ */
+
+template
+inline MatrixBase() - std::declval()), R, C> operator-(
+ const MatrixBase& lhs,
+ const MatrixBase& rhs
+)
+{
+ MatrixBase() + std::declval()), R, C> res;
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ res[row][col] = lhs[row][col] - rhs[row][col];
+
+ return res;
+}
+
+/* ************************************************************************ */
+
+template
+inline MatrixBase() * std::declval()), R, C> operator*(
+ const MatrixBase& lhs,
+ const T2& rhs
+)
+{
+ MatrixBase() * std::declval()), R, C> res;
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ res[row][col] = lhs[row][col] * rhs;
+
+ return res;
+}
+
+/* ************************************************************************ */
+
+template
+inline MatrixBase() * std::declval()), R, C> operator*(
+ const T2& lhs
+ const MatrixBase& rhs,
+)
+{
+ MatrixBase() * std::declval()), R, C> res;
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ res[row][col] = rhs * lhs[row][col];
+
+ return res;
+}
+
+/* ************************************************************************ */
+
+template
+inline MatrixBase() / std::declval()), R, C> operator/(
+ const MatrixBase& lhs,
+ const T2& rhs
+)
+{
+ MatrixBase() + std::declval()), R, C> res;
+
+ for (int row = 0; row < R; ++row)
+ for (int col = 0; col < C; ++col)
+ res[row][col] = lhs[row][col] / rhs;
+
+ return res;
+}
+
+/* ************************************************************************ */
+
+}
+}
+
+/* ************************************************************************ */
+
diff --git a/include/cece/math/Vector.hpp b/include/cece/math/Vector.hpp
index 23c4480..3a8bba9 100644
--- a/include/cece/math/Vector.hpp
+++ b/include/cece/math/Vector.hpp
@@ -1,5 +1,5 @@
/* ************************************************************************ */
-/* Georgiev Lab (c) 2015-2016 */
+/* Georgiev Lab (c) 2015-2017 */
/* ************************************************************************ */
/* Department of Cybernetics */
/* Faculty of Applied Sciences */
@@ -29,6 +29,7 @@
// C++
#include
+#include
#include
// CeCe
@@ -36,10 +37,9 @@
#include "cece/Assert.hpp"
#include "cece/StaticArray.hpp"
#include "cece/math/Zero.hpp"
-#include "cece/io/InStream.hpp"
-#include "cece/io/OutStream.hpp"
#include "cece/unit/math.hpp"
#include "cece/unit/Units.hpp"
+#include "cece/math/VectorBase.hpp"
/* ************************************************************************ */
@@ -49,29 +49,31 @@ namespace math {
/* ************************************************************************ */
/**
- * @brief N dimensional vector.
+ * @brief N dimensional vector.
*
- * @tparam T Element type.
- * @tparam N Number of elements.
+ * @tparam T Element type.
+ * @tparam N Number of elements.
*/
-template
-class BasicVector
+template
+class Vector : public VectorBase
{
+ static_assert(N > 0, "Cannot create empty vector");
+
// Public Types
public:
- /// BasicVector value type.
+ /// Vector value type.
using ValueType = T;
-// Public Contants
+// Public Data Members
public:
- /// Number of elements
- static constexpr unsigned SIZE = N;
+ // Member data.
+ StaticArray m;
// Public Ctors
@@ -79,400 +81,225 @@ class BasicVector
/**
- * @brief Default constructor.
+ * @brief Default constructor.
*/
- BasicVector() noexcept
- : m_data{}
- {
- // Nothing to do
- }
+ constexpr Vector() noexcept;
/**
- * @brief Constructor.
+ * @brief Constructor.
*
- * @param data
- */
- explicit BasicVector(StaticArray data) noexcept
- : m_data(data)
- {
- // Nothing to do
- }
-
-
- /**
- * @brief Zero value constructor.
+ * @param data The source data.
*/
- BasicVector(Zero_t) noexcept
- {
- for (unsigned i = 0; i < N; ++i)
- m_data[i] = T{};
- }
+ Vector(std::initializer_list data);
/**
- * @brief Copy constructor.
+ * @brief Constructor.
*
- * @param v Source vector.
+ * @param data The source data.
*/
- template
- explicit BasicVector(const BasicVector& v) noexcept
- {
- for (unsigned i = 0; i < N; ++i)
- m_data[i] = static_cast(v[i]);
- }
-
-
-// Public Operators
-public:
+ explicit Vector(T (&data)[N]);
/**
- * @brief Unary plus operator.
+ * @brief Constructor.
*
- * @return
+ * @param data The source data.
*/
- BasicVector operator+() const noexcept
- {
- return *this;
- }
+ explicit Vector(const StaticArray& data);
/**
- * @brief Unary minus operator.
+ * @brief Zero value constructor.
*
- * @return
+ * @param[in] zero The zero value.
*/
- BasicVector operator-() const noexcept
- {
- BasicVector res;
-
- for (unsigned i = 0; i < N; ++i)
- res[i] = -m_data[i];
-
- return res;
- }
+ Vector(Zero_t zero);
/**
- * @brief Addition operator.
- *
- * @tparam T1 Type of right operand.
+ * @brief Copy constructor.
*
- * @param rhs Right operand.
- *
- * @return *this.
+ * @param[in] src The source vector.
*/
- template::value>::type* = nullptr>
- BasicVector& operator+=(const BasicVector& rhs) noexcept
- {
- for (unsigned i = 0; i < N; ++i)
- m_data[i] += rhs[i];
-
- return *this;
- }
+ Vector(const Vector& src);
/**
- * @brief Subtraction operator.
+ * @brief Move constructor.
*
- * @tparam T1 Type of value in BasicVector operand.
- *
- * @param rhs Right operand.
- *
- * @return *this.
+ * @param[in] src The source vector.
*/
- template::value>::type* = nullptr>
- BasicVector& operator-=(const BasicVector& rhs) noexcept
- {
- for (unsigned i = 0; i < N; ++i)
- m_data[i] -= rhs[i];
-
- return *this;
- }
+ Vector(Vector&& src);
/**
- * @brief Multiplication operator.
- *
- * @tparam T1 Type of right operand.
+ * @brief Copy constructor.
*
- * @param rhs Right operand.
+ * @param v The source vector.
*
- * @return *this.
+ * @tparam T2 The source vector element type.
*/
- template::value>::type* = nullptr>
- BasicVector& operator*=(T1 rhs) noexcept
- {
- for (unsigned i = 0; i < N; ++i)
- m_data[i] *= rhs;
-
- return *this;
- }
-
+ template::value>::type* = nullptr>
+ explicit Vector(const Vector& src);
- /**
- * @brief Multiplication operator.
- *
- * @tparam T1 Type of value in BasicVector operand.
- *
- * @param rhs Right operand.
- *
- * @return *this.
- */
- template::value>::type* = nullptr>
- BasicVector& operator*=(const BasicVector& rhs) noexcept
- {
- for (unsigned i = 0; i < N; ++i)
- m_data[i] *= rhs[i];
- return *this;
- }
+// Public Operators
+public:
/**
- * @brief Division operator.
- *
- * @tparam T1 Type of right operand.
+ * @brief Copy constructor.
*
- * @param rhs Right operand.
+ * @param[in] zero The zero value.
*
- * @return *this.
+ * @return *this.
*/
- template::value>::type* = nullptr>
- BasicVector& operator/=(T1 rhs) noexcept
- {
- for (unsigned i = 0; i < N; ++i)
- m_data[i] /= rhs;
-
- return *this;
- }
+ Vector& operator=(Zero_t zero);
/**
- * @brief Division operator.
- *
- * @tparam T1 Type of value in BasicVector operand.
+ * @brief Copy constructor.
*
- * @param rhs Right operand.
+ * @param[in] data The source data.
*
- * @return *this.
+ * @return *this.
*/
- template::value>::type* = nullptr>
- BasicVector& operator/=(const BasicVector& rhs) noexcept
- {
- for (unsigned i = 0; i < N; ++i)
- m_data[i] /= rhs[i];
-
- return *this;
- }
+ Vector& operator=(std::initializer_list data);
/**
- * @brief Access operator.
+ * @brief Copy constructor.
*
- * @param pos
+ * @param[in] data The source data.
*
- * @return
+ * @return *this.
*/
- T& operator[](unsigned pos) noexcept
- {
- return m_data[pos];
- }
+ Vector& operator=(T (&data)[N]);
/**
- * @brief Access operator.
+ * @brief Copy constructor.
*
- * @param pos
+ * @param[in] data The source data.
*
- * @return
+ * @return *this.
*/
- const T& operator[](unsigned pos) const noexcept
- {
- return m_data[pos];
- }
-
-
-// Public Accessors
-public:
+ Vector& operator=(const StaticArray& data);
/**
- * @brief Check if given value is in given range.
+ * @brief Copy constructor.
*
- * @param value Given value.
- * @param low Minimum value (>=).
- * @param high Maximum value (<).
+ * @param[in] src The source vector.
*
- * @return
+ * @return *this.
*/
- static bool inRange(T value, T low, T high) noexcept
- {
- return value >= low && value < high;
- }
+ Vector& operator=(const Vector& src);
/**
- * @brief Check if current vector is in given range.
- *
- * @param low Minimum coordinates (>=).
- * @param high Maximum coordinates (<).
+ * @brief Move constructor.
*
- * @return
- */
- bool inRange(const BasicVector& low, const BasicVector& high) const noexcept
- {
- bool res = true;
-
- for (unsigned i = 0; i < N; ++i)
- res = res && inRange(m_data[i], low[i], high[i]);
-
- return res;
- }
-
-
-// Public Operations
-public:
-
-
- /**
- * @brief Calculate vector length.
+ * @param[in] src The source vector.
*
- * @return
+ * @return *this.
*/
- T getLength() const noexcept
- {
- using std::sqrt;
- return static_cast(sqrt(getLengthSquared()));
- }
+ Vector& operator=(Vector&& src);
/**
- * @brief Calculate vector length - squared.
+ * @brief Copy constructor.
*
- * @return
- */
- decltype(T{} * T{}) getLengthSquared() const noexcept
- {
- return dot(*this);
- }
-
-
- /**
- * @brief Calculate dot of two vectors.
+ * @param v The source vector.
*
- * @param rhs Second vector.
+ * @tparam T2 The source vector element type.
*
- * @return Dot product.
+ * @return *this.
*/
- decltype(T{} * T{}) dot(const BasicVector& rhs) const noexcept
- {
- decltype(T{} * T{}) res{};
-
- for (unsigned i = 0; i < N; ++i)
- res += m_data[i] * rhs[i];
-
- return res;
- }
+ template::value>::type* = nullptr>
+ Vector& operator=(const Vector& src);
/**
- * @brief Calculate vectors squared distance.
+ * @brief Access operator.
*
- * @param rhs Second vector.
+ * @param pos The position.
*
- * @return Distance.
+ * @return Reference to the element.
*/
- decltype(std::declval() * std::declval()) distanceSquared(const BasicVector& rhs) const noexcept
- {
- return (*this - rhs).getLengthSquared();
- }
+ T& operator[](int pos) noexcept;
/**
- * @brief Calculate vectors distance.
- *
- * @param rhs Second vector.
+ * @brief Access operator.
*
- * @return Distance.
- */
- T distance(const BasicVector& rhs) const noexcept
- {
- return (*this - rhs).getLength();
- }
-
-
- /**
- * @brief Inverse current vector (1 / *this).
+ * @param pos The position.
*
- * @return
+ * @return Reference to the element.
*/
- template
- BasicVector inversed() const noexcept
- {
- BasicVector res;
-
- for (unsigned i = 0; i < N; ++i)
- res[i] = T2(1) / m_data[i];
-
- return res;
- }
+ constexpr const T& operator[](int pos) const noexcept;
-// Public Operations
+// Public Accessors
public:
/**
- * @brief Create from single value.
- *
- * @param val
+ * @brief Returns vector size.
*
- * @return
+ * @return The size.
*/
- static BasicVector createSingle(T val) noexcept
- {
- BasicVector res;
-
- for (unsigned i = 0; i < N; ++i)
- res[i] = val;
-
- return res;
- }
+ constexpr int getSize() const noexcept;
-
-// Private Data Members
-private:
-
-
- /// BasicVector data.
- StaticArray m_data;
};
/* ************************************************************************ */
/**
- * @brief Two dimensional vector.
+ * @brief 2D vector specialization.
+ *
+ * @tparam T Element type.
*/
template
-class BasicVector
+struct Vector : public VectorBase
{
// Public Types
public:
- /// BasicVector value type.
+ /// Element type.
using ValueType = T;
-// Public Contants
+// Public Data Members
public:
- /// Number of elements
- static constexpr unsigned SIZE = 2;
+ union
+ {
+ struct
+ {
+ /// X coordinate.
+ T x;
+
+ /// Y coordinate.
+ T y;
+ };
+
+ struct
+ {
+ /// Width
+ T width;
+
+ /// Height.
+ T height;
+ };
+
+ T m[2];
+ };
// Public Ctors
@@ -480,215 +307,128 @@ class BasicVector
/**
- * @brief Default constructor.
+ * @brief Default constructor.
*/
- BasicVector() noexcept
- : m_x{}
- , m_y{}
- {
- // Nothing to do
- }
+ constexpr Vector();
/**
- * @brief Constructor.
+ * @brief Constructor.
*
- * @param x
- * @param y
+ * @param x The X and Y coordinate.
*/
- BasicVector(T x, T y) noexcept
- : m_x(x)
- , m_y(y)
- {
- // Nothing to do
- }
+ explicit constexpr Vector(T value);
/**
- * @brief Zero value constructor.
+ * @brief Constructor.
+ *
+ * @param x The X coordinate.
+ * @param y The Y coordinate.
*/
- BasicVector(Zero_t) noexcept
- : m_x{}
- , m_y{}
- {
- // Nothing to do
- }
+ constexpr Vector(T x, T y);
/**
- * @brief Copy constructor.
+ * @brief Zero value constructor.
*
- * @param rhs Source vector.
+ * @param[in] zero The zero value.
*/
- template
- explicit BasicVector(const BasicVector& rhs) noexcept
- : m_x(static_cast(rhs.getX()))
- , m_y(static_cast(rhs.getY()))
- {
- // Nothing to do
- }
-
-
-// Public Operators
-public:
+ constexpr Vector(Zero_t zero);
/**
- * @brief Access operator.
- *
- * @param pos
+ * @brief Copy constructor.
*
- * @return
+ * @param[in] src The source vector.
*/
- T& operator[](unsigned pos) noexcept
- {
- CECE_ASSERT(pos < SIZE);
- return (&m_x)[pos];
- }
+ constexpr Vector(const Vector& src);
/**
- * @brief Access operator.
+ * @brief Move constructor.
*
- * @param pos
- *
- * @return
+ * @param[in] src The source vector.
*/
- const T& operator[](unsigned pos) const noexcept
- {
- CECE_ASSERT(pos < SIZE);
- return (&m_x)[pos];
- }
+ constexpr Vector(Vector&& src);
/**
- * @brief Unary plus operator.
+ * @brief Copy constructor.
+ *
+ * @param rhs Source vector.
*
- * @return
+ * @tparam T2 The source vector element type.
*/
- BasicVector operator+() const noexcept
- {
- return *this;
- }
+ template::value>::type* = nullptr>
+ constexpr Vector(const Vector& rhs);
- /**
- * @brief Unary minus operator.
- *
- * @return
- */
- BasicVector operator-() const noexcept
- {
- return BasicVector{-getX(), -getY()};
- }
+// Public Operators
+public:
/**
- * @brief Addition operator.
- *
- * @tparam T1 Type of right operand.
+ * @brief Copy constructor.
*
- * @param rhs Right operand.
+ * @param[in] zero The zero value.
*
- * @return *this.
+ * @return *this.
*/
- template
- BasicVector& operator+=(const BasicVector& rhs) noexcept
- {
- m_x += rhs.getX();
- m_y += rhs.getY();
- return *this;
- }
+ Vector& operator=(Zero_t zero);
/**
- * @brief Subtraction operator.
+ * @brief Copy constructor.
*
- * @tparam T1 Type of value in BasicVector operand.
+ * @param[in] src The source vector.
*
- * @param rhs Right operand.
- *
- * @return *this.
+ * @return *this.
*/
- template
- BasicVector& operator-=(const BasicVector& rhs) noexcept
- {
- m_x -= rhs.getX();
- m_y -= rhs.getY();
- return *this;
- }
+ Vector& operator=(const Vector& src);
/**
- * @brief Multiplication operator.
- *
- * @tparam T1 Type of right operand.
+ * @brief Move constructor.
*
- * @param rhs Right operand.
+ * @param[in] src The source vector.
*
- * @return *this.
+ * @return *this.
*/
- template
- BasicVector& operator*=(T1 rhs) noexcept
- {
- m_x *= rhs;
- m_y *= rhs;
- return *this;
- }
+ Vector& operator=(Vector&& src);
/**
- * @brief Multiplication operator.
+ * @brief Copy constructor.
*
- * @tparam T1 Type of value in BasicVector operand.
+ * @param v The source vector.
*
- * @param rhs Right operand.
+ * @tparam T2 The source vector element type.
*
- * @return *this.
+ * @return *this.
*/
- template
- BasicVector& operator*=(const BasicVector& rhs) noexcept
- {
- m_x *= rhs.getX();
- m_y *= rhs.getY();
- return *this;
- }
+ template::value>::type* = nullptr>
+ Vector& operator=(const Vector& src);
/**
- * @brief Division operator.
+ * @brief Access operator.
*
- * @tparam T1 Type of right operand.
+ * @param pos The position.
*
- * @param rhs Right operand.
- *
- * @return *this.
+ * @return Reference to the element.
*/
- template
- BasicVector& operator/=(T1 rhs) noexcept
- {
- m_x /= rhs;
- m_y /= rhs;
- return *this;
- }
+ T& operator[](int pos) noexcept;
/**
- * @brief Division operator.
- *
- * @tparam T1 Type of value in BasicVector operand.
+ * @brief Access operator.
*
- * @param rhs Right operand.
+ * @param pos The position.
*
- * @return *this.
+ * @return Reference to the element.
*/
- template
- BasicVector& operator/=(const BasicVector& rhs) noexcept
- {
- m_x /= rhs.getX();
- m_y /= rhs.getY();
- return *this;
- }
+ constexpr const T& operator[](int pos) const noexcept;
// Public Accessors
@@ -696,530 +436,299 @@ class BasicVector
/**
- * @brief Returns vector size.
+ * @brief Returns vector size.
*
- * @return
+ * @return The size.
*/
- unsigned getSize() const noexcept
- {
- return SIZE;
- }
+ constexpr int getSize() const noexcept;
/**
- * @brief Returns X coordinate.
+ * @brief Returns X coordinate.
*
- * @return
+ * @return The X coordinate.
*/
- T& x() noexcept
- {
- return m_x;
- }
+ constexpr const T& getX() const noexcept;
/**
- * @brief Returns X coordinate.
+ * @brief Set X coordinate.
*
- * @return
+ * @param[in] x The X coordinate.
*/
- const T& getX() const noexcept
- {
- return m_x;
- }
+ void setX(T x);
/**
- * @brief Returns Y coordinate.
+ * @brief Returns Y coordinate.
*
- * @return
+ * @return The Y coordinate.
*/
- T& y() noexcept
- {
- return m_y;
- }
+ constexpr const T& getY() const noexcept;
/**
- * @brief Returns Y coordinate.
+ * @brief Set Y coordinate.
*
- * @return
+ * @param[in] y The Y coordinate.
*/
- const T& getY() const noexcept
- {
- return m_y;
- }
+ void setY(T y);
/**
- * @brief Returns width.
+ * @brief Gets the width.
*
- * @return
+ * @return The width.
*/
- T& width() noexcept
- {
- return m_x;
- }
+ constexpr const T& getWidth() const noexcept;
/**
- * @brief Returns width.
+ * @brief Set the width.
*
- * @return
+ * @param[in] width The width.
*/
- const T& getWidth() const noexcept
- {
- return m_x;
- }
+ void setWidth(T width);
/**
- * @brief Returns height.
+ * @brief Gets the height.
*
- * @return
+ * @return The height.
*/
- T& height() noexcept
- {
- return m_y;
- }
+ constexpr const T& getHeight() const noexcept;
/**
- * @brief Returns height.
+ * @brief Sets the height.
*
- * @return
+ * @param[in] height The height
*/
- const T& getHeight() const noexcept
- {
- return m_y;
- }
+ void setHeight(T height);
-// Public Mutators
+// Public Deprecated
public:
- /**
- * @brief Set X coordinate.
- *
- * @param x
- */
- void setX(T x) noexcept
+ // @deprecated
+ bool inRange(const Vector& low, const Vector& high) const noexcept
{
- m_x = x;
+ return math::inRange(*this, low, high);
}
- /**
- * @brief Set Y coordinate.
- *
- * @param y
- */
- void setY(T y) noexcept
+ // @deprecated
+ bool inRange(const Vector& high) const noexcept
{
- m_y = y;
+ return math::inRange(*this, high);
}
- /**
- * @brief Check if given value is in given range.
- *
- * @param value Given value.
- * @param low Minimum value (>=).
- * @param high Maximum value (<).
- *
- * @return
- */
- static bool inRange(T value, T low, T high) noexcept
+ // @deprecated
+ static Vector createSingle(T val) noexcept
{
- return value >= low && value < high;
+ return Vector(val, val);
}
- /**
- * @brief Check if current vector is in given range.
- *
- * @param low Minimum coordinates (>=).
- * @param high Maximum coordinates (<).
- *
- * @return
- */
- bool inRange(const BasicVector& low, const BasicVector& high) const noexcept
+ // @deprecated
+ template
+ Vector inversed() const noexcept
+ {
+ return T2(1) / *this;
+ }
+
+
+ // @deprecated
+ Vector rotated(unit::Angle angle) const noexcept
{
- return (
- inRange(getX(), low.getX(), high.getX()) &&
- inRange(getY(), low.getY(), high.getY())
- );
+ return rotate(*this, angle);
}
+};
+
+/* ************************************************************************ */
+
+/**
+ * @brief 3D vector specialization.
+ *
+ * @tparam T Element type.
+ */
+template
+struct Vector : public VectorBase
+{
-// Public Operations
+// Public Types
public:
- /**
- * @brief Calculate vector length.
- *
- * @return
- */
- T getLength() const noexcept
+ /// Vector element type.
+ using ValueType = T;
+
+
+// Public Data Members
+public:
+
+
+ union
{
- using std::sqrt;
- return static_cast(sqrt(getLengthSquared()));
- }
+ struct
+ {
+ /// X coordinate.
+ T x;
+
+ /// Y coordinate.
+ T y;
+
+ /// Z coordinate.
+ T z;
+ };
+
+ struct
+ {
+ /// Width.
+ T width;
+
+ /// Height.
+ T height;
+
+ /// Depth.
+ T depth;
+ };
+
+ T m[3];
+ };
+
+
+// Public Ctors
+public:
/**
- * @brief Calculate vector length - squared.
- *
- * @return
+ * @brief Default constructor.
*/
- decltype(T{} * T{}) getLengthSquared() const noexcept
- {
- return dot(*this);
- }
+ constexpr Vector() noexcept;
/**
- * @brief Calculate dot of two vectors.
+ * @brief Constructor.
*
- * @param rhs Second vector.
- *
- * @return Dot product.
+ * @param val The X, Y and Z coordinate.
*/
- decltype(T{} * T{}) dot(const BasicVector& rhs) const noexcept
- {
- return {getX() * rhs.getX() + getY() * rhs.getY()};
- }
+ explicit constexpr Vector(T val);
/**
- * @brief Calculate vectors squared distance.
- *
- * @param rhs Second vector.
+ * @brief Constructor.
*
- * @return Distance.
+ * @param x The X coordinate.
+ * @param y The Y coordinate.
+ * @param y The Z coordinate.
*/
- decltype(std::declval() * std::declval()) distanceSquared(const BasicVector& rhs) const noexcept
- {
- return (*this - rhs).getLengthSquared();
- }
+ constexpr Vector(T x, T y, T z);
/**
- * @brief Calculate vectors distance.
+ * @brief Zero value constructor.
*
- * @param rhs Second vector.
- *
- * @return Distance.
+ * @param[in] zero The zero value.
*/
- T distance(const BasicVector& rhs) const noexcept
- {
- return (*this - rhs).getLength();
- }
+ constexpr Vector(Zero_t zero);
/**
- * @brief Inverse current vector (1 / *this).
+ * @brief Copy constructor.
*
- * @return
+ * @param[in] src The source vector.
*/
- template
- BasicVector inversed() const noexcept
- {
- return BasicVector{T2(1) / getX(), T2(1) / getY()};
- }
+ constexpr Vector(const Vector& src);
/**
- * @brief Rotate current vector and return rotated version.
- *
- * @param angle Rotation angle.
+ * @brief Move constructor.
*
- * @return
+ * @param[in] src The source vector.
*/
- BasicVector rotated(unit::Angle angle) const noexcept
- {
- return BasicVector(
- static_cast(getX() * cos(static_cast(angle)) - getY() * sin(static_cast(angle))),
- static_cast(getX() * sin(static_cast(angle)) + getY() * cos(static_cast(angle)))
- );
- }
+ constexpr Vector(Vector&& src);
/**
- * @brief Create from single value.
+ * @brief Copy constructor.
*
- * @param val
+ * @param rhs Source vector.
*
- * @return
+ * @tparam T2 The source vector element type.
*/
- static BasicVector createSingle(T val) noexcept
- {
- return BasicVector{val, val};
- }
+ template::value>::type* = nullptr>
+ constexpr Vector(const Vector& rhs);
-// Private Data Members
-private:
-
- /// X coordinate.
- T m_x{};
-
- /// Y coordinate.
- T m_y{};
-
-};
-
-/* ************************************************************************ */
-
-/**
- * @brief Three dimensional vector.
- */
-template
-class BasicVector
-{
-
-// Public Types
-public:
-
-
- /// BasicVector value type.
- using ValueType = T;
-
-
-// Public Contants
-public:
-
-
- /// Number of elements
- static constexpr unsigned SIZE = 3;
-
-
-// Public Ctors
-public:
-
-
- /**
- * @brief Default constructor.
- */
- BasicVector() noexcept
- : m_x{}
- , m_y{}
- , m_z{}
- {
- // Nothing to do
- }
-
-
- /**
- * @brief Constructor.
- *
- * @param x
- * @param y
- * @param z
- */
- BasicVector(T x, T y, T z) noexcept
- : m_x(x)
- , m_y(y)
- , m_z(z)
- {
- // Nothing to do
- }
-
-
- /**
- * @brief Zero value constructor.
- */
- BasicVector(Zero_t) noexcept
- : m_x{}
- , m_y{}
- , m_z{}
- {
- // Nothing to do
- }
-
-
- /**
- * @brief Copy constructor.
- *
- * @param rhs Source vector.
- */
- template
- explicit BasicVector(const BasicVector& rhs) noexcept
- : m_x(static_cast(rhs.getX()))
- , m_y(static_cast(rhs.getY()))
- , m_z(static_cast(rhs.getZ()))
- {
- // Nothing to do
- }
-
-
-// Public Operators
-public:
-
-
- /**
- * @brief Access operator.
- *
- * @param pos
- *
- * @return
- */
- T& operator[](unsigned pos) noexcept
- {
- CECE_ASSERT(pos < SIZE);
- return (&m_x)[pos];
- }
-
-
- /**
- * @brief Access operator.
- *
- * @param pos
- *
- * @return
- */
- const T& operator[](unsigned pos) const noexcept
- {
- CECE_ASSERT(pos < SIZE);
- return (&m_x)[pos];
- }
-
-
- /**
- * @brief Unary plus operator.
- *
- * @return
- */
- BasicVector operator+() const noexcept
- {
- return *this;
- }
+// Public Operators
+public:
/**
- * @brief Unary minus operator.
+ * @brief Copy constructor.
*
- * @return
- */
- BasicVector operator-() const noexcept
- {
- return BasicVector{-getX(), -getY(), -getZ()};
- }
-
-
- /**
- * @brief Addition operator.
+ * @param[in] zero The zero value.
*
- * @tparam T1 Type of right operand.
- *
- * @param rhs Right operand.
- *
- * @return *this.
+ * @return *this.
*/
- template::value>::type* = nullptr>
- BasicVector& operator+=(const BasicVector& rhs) noexcept
- {
- m_x += rhs.getX();
- m_y += rhs.getY();
- m_z += rhs.getZ();
- return *this;
- }
+ Vector& operator=(Zero_t zero);
/**
- * @brief Subtraction operator.
- *
- * @tparam T1 Type of value in BasicVector operand.
+ * @brief Copy constructor.
*
- * @param rhs Right operand.
+ * @param[in] src The source vector.
*
- * @return *this.
+ * @return *this.
*/
- template::value>::type* = nullptr>
- BasicVector& operator-=(const BasicVector& rhs) noexcept
- {
- m_x -= rhs.getX();
- m_y -= rhs.getY();
- m_z -= rhs.getZ();
- return *this;
- }
+ Vector& operator=(const Vector& src);
/**
- * @brief Multiplication operator.
- *
- * @tparam T1 Type of right operand.
+ * @brief Move constructor.
*
- * @param rhs Right operand.
+ * @param[in] src The source vector.
*
- * @return *this.
+ * @return *this.
*/
- template::value>::type* = nullptr>
- BasicVector& operator*=(T1 rhs) noexcept
- {
- m_x *= rhs;
- m_y *= rhs;
- m_z *= rhs;
- return *this;
- }
+ Vector& operator=(Vector&& src);
/**
- * @brief Multiplication operator.
+ * @brief Copy constructor.
*
- * @tparam T1 Type of value in BasicVector operand.
+ * @param v The source vector.
*
- * @param rhs Right operand.
+ * @tparam T2 The source vector element type.
*
- * @return *this.
+ * @return *this.
*/
- template::value>::type* = nullptr>
- BasicVector& operator*=(const BasicVector& rhs) noexcept
- {
- m_x *= rhs.getX();
- m_y *= rhs.getY();
- m_z *= rhs.getZ();
- return *this;
- }
+ template::value>::type* = nullptr>
+ Vector& operator=(const Vector& src);
/**
- * @brief Division operator.
+ * @brief Access operator.
*
- * @tparam T1 Type of right operand.
+ * @param pos The position.
*
- * @param rhs Right operand.
- *
- * @return *this.
+ * @return Reference to the element.
*/
- template::value>::type* = nullptr>
- BasicVector& operator/=(T1 rhs) noexcept
- {
- m_x /= rhs;
- m_y /= rhs;
- m_z /= rhs;
- return *this;
- }
+ T& operator[](int pos) noexcept;
/**
- * @brief Division operator.
+ * @brief Access operator.
*
- * @tparam T1 Type of value in BasicVector operand.
+ * @param pos The position.
*
- * @param rhs Right operand.
- *
- * @return *this.
+ * @return Reference to the element.
*/
- template::value>::type* = nullptr>
- BasicVector& operator/=(const BasicVector& rhs) noexcept
- {
- m_x /= rhs.getX();
- m_y /= rhs.getY();
- m_z /= rhs.getZ();
- return *this;
- }
+ constexpr const T& operator[](int pos) const noexcept;
// Public Accessors
@@ -1227,1387 +736,1010 @@ class BasicVector
/**
- * @brief Returns vector size.
+ * @brief Returns vector size.
*
- * @return
+ * @return The size.
*/
- unsigned getSize() const noexcept
- {
- return SIZE;
- }
+ constexpr int getSize() const noexcept;
/**
- * @brief Returns X coordinate.
+ * @brief Returns X coordinate.
*
- * @return
+ * @return The X coordinate.
*/
- T& x() noexcept
- {
- return m_x;
- }
+ constexpr const T& getX() const noexcept;
/**
- * @brief Returns X coordinate.
+ * @brief Set X coordinate.
*
- * @return
+ * @param x The X coordinate.
*/
- const T& getX() const noexcept
- {
- return m_x;
- }
+ void setX(T x);
/**
- * @brief Returns Y coordinate.
+ * @brief Returns Y coordinate.
*
- * @return
+ * @return The Y coordinate.
*/
- T& y() noexcept
- {
- return m_y;
- }
+ constexpr const T& getY() const noexcept;
/**
- * @brief Returns Y coordinate.
+ * @brief Set Y coordinate.
*
- * @return
+ * @param y The Y coordinate.
*/
- const T& getY() const noexcept
- {
- return m_y;
- }
+ void setY(T y);
/**
- * @brief Returns Z coordinate.
+ * @brief Returns Z coordinate.
*
- * @return
+ * @return The Z coordinate.
*/
- T& z() noexcept
- {
- return m_z;
- }
+ constexpr const T& getZ() const noexcept;
/**
- * @brief Returns Z coordinate.
+ * @brief Set Z coordinate.
*
- * @return
+ * @param z The Z coordinate.
*/
- const T& getZ() const noexcept
- {
- return m_z;
- }
+ void setZ(T z);
/**
- * @brief Returns width.
+ * @brief Gets the width.
*
- * @return
+ * @return The width.
*/
- T& width() noexcept
- {
- return m_x;
- }
+ constexpr const T& getWidth() const noexcept;
/**
- * @brief Returns width.
+ * @brief Set the width.
*
- * @return
+ * @param[in] width The width.
*/
- const T& getWidth() const noexcept
- {
- return m_x;
- }
+ void setWidth(T width);
/**
- * @brief Returns height.
+ * @brief Gets the height.
*
- * @return
+ * @return The height.
*/
- T& height() noexcept
- {
- return m_y;
- }
+ constexpr const T& getHeight() const noexcept;
/**
- * @brief Returns height.
+ * @brief Sets the height.
*
- * @return
+ * @param[in] height The height
*/
- const T& getHeight() const noexcept
- {
- return m_y;
- }
+ void setHeight(T height);
/**
- * @brief Returns depth.
+ * @brief Gets the depth.
*
- * @return
+ * @return The depth.
*/
- T& depth() noexcept
- {
- return m_z;
- }
+ constexpr const T& getDepth() const noexcept;
/**
- * @brief Returns depth.
+ * @brief Sets the depth.
*
- * @return
+ * @param[in] depth The depth
*/
- const T& getDepth() const noexcept
- {
- return m_z;
- }
+ void setDepth(T depth);
- /**
- * @brief Check if given value is in given range.
- *
- * @param value Given value.
- * @param low Minimum value (>=).
- * @param high Maximum value (<).
- *
- * @return
- */
- static bool inRange(T value, T low, T high) noexcept
- {
- return value >= low && value < high;
- }
+// Public Deprecated
+public:
- /**
- * @brief Check if current vector is in given range.
- *
- * @param low Minimum coordinates (>=).
- * @param high Maximum coordinates (<).
- *
- * @return
- */
- bool inRange(const BasicVector& low, const BasicVector& high) const noexcept
+ // @deprecated
+ bool inRange(const Vector& low, const Vector& high) const noexcept
{
- return (
- inRange(getX(), low.getX(), high.getX()) &&
- inRange(getY(), low.getY(), high.getY()) &&
- inRange(getZ(), low.getZ(), high.getZ())
- );
+ return math::inRange(*this, low, high);
}
-
-// Public Mutators
-public:
-
-
- /**
- * @brief Set X coordinate.
- *
- * @param x
- */
- void setX(T x) noexcept
+ // @deprecated
+ bool inRange(const Vector& high) const noexcept
{
- m_x = x;
+ return math::inRange(*this, high);
}
- /**
- * @brief Set Y coordinate.
- *
- * @param y
- */
- void setY(T y) noexcept
+ // @deprecated
+ static Vector createSingle(T val) noexcept
{
- m_y = y;
+ return Vector(val, val, val);
}
- /**
- * @brief Set Z coordinate.
- *
- * @param z
- */
- void setZ(T z) noexcept
+ // @deprecated
+ template
+ Vector inversed() const noexcept
{
- m_z = z;
+ return T2(1) / *this;
}
+};
+/* ************************************************************************ */
-// Public Operations
-public:
-
-
- /**
- * @brief Calculate vector length.
- *
- * @return
- */
- template::value>::type* = nullptr>
- T getLength() const noexcept
- {
- using std::sqrt;
- return static_cast(sqrt(getLengthSquared()));
- }
+/**
+ * @brief 2D vector alias.
+ */
+template
+using Vector2 = Vector;
+/* ************************************************************************ */
- /**
- * @brief Calculate vector length - squared.
- *
- * @return
- */
- decltype(T{} * T{}) getLengthSquared() const noexcept
- {
- return dot(*this);
- }
+/**
+ * @brief 3D vector alias.
+ */
+template
+using Vector3 = Vector;
+/* ************************************************************************ */
- /**
- * @brief Calculate dot of two vectors.
- *
- * @param rhs Second vector.
- *
- * @return Dot product.
- */
- decltype(T{} * T{}) dot(const BasicVector& rhs) const noexcept
- {
- return {
- getX() * rhs.getX() +
- getY() * rhs.getY() +
- getZ() * rhs.getZ()
- };
- }
+/**
+ * @brief Vector for integer size.
+ * @deprecated
+ */
+using Size = Vector;
+/* ************************************************************************ */
- /**
- * @brief Calculate vectors squared distance.
- *
- * @param rhs Second vector.
- *
- * @return Distance.
- */
- decltype(std::declval() * std::declval()) distanceSquared(const BasicVector& rhs) const noexcept
- {
- return (*this - rhs).getLengthSquared();
- }
+/**
+ * @brief Vector for coordinates.
+ * @deprecated
+ */
+using Coordinate = Vector;
+/* ************************************************************************ */
- /**
- * @brief Calculate vectors distance.
- *
- * @param rhs Second vector.
- *
- * @return Distance.
- */
- T distance(const BasicVector& rhs) const noexcept
- {
- return (*this - rhs).getLength();
- }
+/**
+ * @brief Vector of int.
+ * @deprecated
+ */
+using VectorInt = Vector;
+/* ************************************************************************ */
- /**
- * @brief Inverse current vector (1 / *this).
- *
- * @return
- */
- template
- BasicVector inversed() const noexcept
- {
- return BasicVector{
- T2(1) / getX(),
- T2(1) / getY(),
- T2(1) / getZ()
- };
- }
+/**
+ * @brief Vector of float.
+ * @deprecated
+ */
+using VectorFloat = Vector;
+/* ************************************************************************ */
- /**
- * @brief Create from single value.
- *
- * @param val
- *
- * @return
- */
- static BasicVector createSingle(T val) noexcept
- {
- return {val, val, val};
- }
+/**
+ * @brief Vector of double.
+ * @deprecated
+ */
+using VectorDouble = Vector;
+/* ************************************************************************ */
-// Private Data Members
-private:
+/**
+ * @brief Vector of long double.
+ * @deprecated
+ */
+using VectorLongDouble = Vector;
- /// X coordinate.
- T m_x{};
+/* ************************************************************************ */
- /// Y coordinate.
- T m_y{};
+/**
+ * @brief Vector of float.
+ * @deprecated
+ */
+using VectorReal = Vector;
- /// Z coordinate.
- T m_z{};
+/* ************************************************************************ */
-};
+/**
+ * @brief Vector of integers.
+ */
+using IntVector = Vector;
/* ************************************************************************ */
/**
- * @brief Basic vector.
+ * @brief Vector of float.
*/
-template
-using Vector = BasicVector;
+using FloatVector = Vector;
/* ************************************************************************ */
/**
- * @brief Vector for integer size.
+ * @brief Vector of double.
*/
-using Size = Vector;
+using DoubleVector = Vector;
/* ************************************************************************ */
/**
- * @brief Vector for coordinates.
+ * @brief Vector of long double.
*/
-using Coordinate = Vector;
+using LongDoubleVector = Vector;
/* ************************************************************************ */
/**
- * @brief Vector of int.
+ * @brief Vector of float.
*/
-using VectorInt = Vector;
+using RealVector = Vector;
/* ************************************************************************ */
/**
- * @brief Vector of unsigned int.
+ * @brief Vector for indices.
*/
-using VectorUint = Vector;
+using IndexVector = Vector;
/* ************************************************************************ */
/**
- * @brief Vector of float.
+ * @brief Vector for sizes.
*/
-using VectorFloat = Vector;
+using SizeVector = Vector