vec3.ixx File
3D vector type and utilities. More...
Included Headers
#include <cassert>
#include <cmath>
#include <memory>
#include <helios.math.utils>
#include <helios.math.traits.FloatingPointType>
#include <helios.math.concepts>
#include <helios.math.types:vec2>
Namespaces Index
| namespace | helios |
| namespace | math |
|
Mathematical operations and types. More... | |
Classes Index
| struct | vec3<T> |
|
Represents a 3-dimensional vector of the generic type <T>. More... | |
Description
3D vector type and utilities.
File Listing
The file content with the documentation metadata removed is:
18export namespace helios::math {
21 struct vec4;
76 constexpr explicit vec3(const helios::math::vec2<T> v) noexcept : v{v[0], v[1], static_cast<T>(0)} {}
85 constexpr explicit vec3(const helios::math::vec2<T> v, T f) noexcept : v{v[0], v[1], f} {}
95 constexpr const T& operator[](const size_t i) const noexcept {
109 constexpr T& operator[](const size_t i) noexcept {
120 FloatingPointType<T> length() const noexcept {
121 return static_cast<FloatingPointType<T>>(std::sqrt(
135 [[nodiscard]] vec3<T> cross(const helios::math::vec3<T>& v2) const noexcept;
144 [[nodiscard]] T dot(const helios::math::vec3<T>& v2) const noexcept;
182 [[nodiscard]] vec3<FloatingPointType<T>> normalize() const noexcept;
204 * @param epsilon The epsilon value to use for comparison. If omitted, the default epsilon (0.0001) is used.
225 constexpr helios::math::vec3<T> flipY() const noexcept {
226 return helios::math::vec3<T>{v[0], -v[1], v[2]};
235 constexpr helios::math::vec3<T> withY(T y) const noexcept {
236 return helios::math::vec3<T>{v[0], y, v[2]};
244 constexpr helios::math::vec3<T> flipX() const noexcept {
245 return helios::math::vec3<T>{-v[0], v[1], v[2]};
254 constexpr helios::math::vec3<T> withX(T x) const noexcept {
255 return helios::math::vec3<T>{x, v[1], v[2]};
266 constexpr bool isNormalized() const noexcept {
268 static_cast<FloatingPointType<T>>(v[0]) * static_cast<FloatingPointType<T>>(v[0]) +
269 static_cast<FloatingPointType<T>>(v[1]) * static_cast<FloatingPointType<T>>(v[1]) +
270 static_cast<FloatingPointType<T>>(v[2]) * static_cast<FloatingPointType<T>>(v[2]);
272 return std::abs(lenSquared - static_cast<FloatingPointType<T>>(1.0)) <= helios::math::EPSILON_LENGTH;
289 return vec3<T>{v[0] * n, v[1] * n, v[2] * n};
307 return vec3<T>{ v[0] * inv, v[1] * inv, v[2] * inv };
322 return vec3<T>{v[0] * n, v[1] * n, v[2] * n};
337 return vec3<T>{v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]};
352 return vec3<T>{v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]};
367 return vec3{
400 return vec3{v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]};
404 inline vec3<T> vec3<T>::cross(const vec3<T>& v2) const noexcept {
405 return vec3{
413 inline vec4<T> vec3<T>::toVec4() const noexcept {
414 return vec4<T>{v[0], v[1], v[2], static_cast<T>(0)};
418 inline vec2<T> vec3<T>::toVec2() const noexcept {
419 return vec2<T>{v[0], v[1]};
423 inline vec4<T> vec3<T>::toVec4(T w) const noexcept {
424 return vec4<T>{v[0], v[1], v[2], w};
428 inline T vec3<T>::dot(const vec3<T>& v2) const noexcept {
434 inline vec3<FloatingPointType<T>> vec3<T>::normalize() const noexcept {
435 if (this->length() == static_cast<FloatingPointType<T>>(0)) {
436 return vec3<FloatingPointType<T>>(
437 static_cast<FloatingPointType<T>>(0),
438 static_cast<FloatingPointType<T>>(0),
439 static_cast<FloatingPointType<T>>(0)
443 return vec3<FloatingPointType<T>>(
444 static_cast<FloatingPointType<T>>(v[0]) / this->length(),
445 static_cast<FloatingPointType<T>>(v[1]) / this->length(),
446 static_cast<FloatingPointType<T>>(v[2]) / this->length()
453 using vec3f = vec3<float>;
463 using vec3d = vec3<double>;
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.