feat(cpp-object-oriented-modular-refactoring): step 8 - element-geometry-vector3
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/math/matrix.h"
|
||||
#include "fesa/math/vector.h"
|
||||
#include "fesa/math/vector3.h"
|
||||
#include "fesa/model/model_types.h"
|
||||
|
||||
namespace fesa {
|
||||
@@ -132,8 +133,6 @@ class Mitc4Shell {
|
||||
const Vector& global_element_displacement24) const;
|
||||
|
||||
private:
|
||||
using Vector3 = std::array<double, 3>;
|
||||
|
||||
/// @brief Stores covariant, reciprocal, frame, and Jacobian data at one
|
||||
/// point.
|
||||
struct GeometryData {
|
||||
|
||||
@@ -21,6 +21,10 @@ class Vector3 {
|
||||
constexpr Vector3(double x, double y, double z) noexcept
|
||||
: components_{{x, y, z}} {}
|
||||
|
||||
/// @brief Copies components from an existing array-backed carrier.
|
||||
explicit constexpr Vector3(const std::array<double, 3>& components) noexcept
|
||||
: components_{components} {}
|
||||
|
||||
/// @brief Returns the first component.
|
||||
constexpr double X() const noexcept { return components_[0]; }
|
||||
|
||||
@@ -36,6 +40,11 @@ class Vector3 {
|
||||
return components_[index];
|
||||
}
|
||||
|
||||
/// @brief Returns the immutable array-backed component carrier.
|
||||
constexpr const std::array<double, 3>& Components() const noexcept {
|
||||
return components_;
|
||||
}
|
||||
|
||||
/// @brief Adds corresponding vector components.
|
||||
constexpr Vector3 operator+(const Vector3& rhs) const noexcept {
|
||||
return Vector3{X() + rhs.X(), Y() + rhs.Y(), Z() + rhs.Z()};
|
||||
@@ -51,6 +60,22 @@ class Vector3 {
|
||||
return Vector3{X() * scalar, Y() * scalar, Z() * scalar};
|
||||
}
|
||||
|
||||
/// @brief Divides every component by a scalar.
|
||||
constexpr Vector3 operator/(double scalar) const noexcept {
|
||||
return Vector3{X() / scalar, Y() / scalar, Z() / scalar};
|
||||
}
|
||||
|
||||
/// @brief Multiplies every component with the scalar as the left operand.
|
||||
friend constexpr Vector3 operator*(double scalar,
|
||||
const Vector3& rhs) noexcept {
|
||||
return Vector3{scalar * rhs.X(), scalar * rhs.Y(), scalar * rhs.Z()};
|
||||
}
|
||||
|
||||
/// @brief Compares every component exactly.
|
||||
constexpr bool operator==(const Vector3& rhs) const noexcept {
|
||||
return X() == rhs.X() && Y() == rhs.Y() && Z() == rhs.Z();
|
||||
}
|
||||
|
||||
/// @brief Computes the Euclidean dot product with rhs.
|
||||
double Dot(const Vector3& rhs) const noexcept {
|
||||
return X() * rhs.X() + Y() * rhs.Y() + Z() * rhs.Z();
|
||||
@@ -63,7 +88,7 @@ class Vector3 {
|
||||
}
|
||||
|
||||
/// @brief Computes the Euclidean norm.
|
||||
double Norm() const noexcept { return std::sqrt(Dot(*this)); }
|
||||
double Norm() const noexcept { return std::hypot(X(), Y(), Z()); }
|
||||
|
||||
/// @brief Returns a unit vector when the norm is usable.
|
||||
/// @return Empty when the norm is exactly zero or nonfinite.
|
||||
|
||||
Reference in New Issue
Block a user