vec3.ixx File
3D vector type and utilities. More...
Included Headers
#include <cassert>
#include <cmath>
#include <memory>
#include <cstddef>
#include <helios.math.utils>
#include <helios.math.traits.FloatingPointType>
#include <helios.math.concepts>
#include <helios.math.types:vec2>
Namespaces Index
| namespace | helios |
| namespace | math |
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:
19export namespace helios::math {
77 constexpr explicit vec3(const helios::math::vec2<T> v) noexcept : v{v[0], v[1], static_cast<T>(0)} {}
86 constexpr explicit vec3(const helios::math::vec2<T> v, T f) noexcept : v{v[0], v[1], f} {}
96 constexpr const T& operator[](const size_t i) const noexcept {
110 constexpr T& operator[](const size_t i) noexcept {
121 FloatingPointType<T> length() const noexcept {
122 return static_cast<FloatingPointType<T>>(std::sqrt(
136 [[nodiscard]] vec3<T> cross(const helios::math::vec3<T>& v2) const noexcept;
145 [[nodiscard]] T dot(const helios::math::vec3<T>& v2) const noexcept;
183 [[nodiscard]] vec3<FloatingPointType<T>> normalize() const noexcept;
215 constexpr bool same(const vec3<T>& rgt, const T epsilon = static_cast<T>(EPSILON_LENGTH)) const noexcept requires std::floating_point<T> {
239 constexpr helios::math::vec3<T> flipY() const noexcept {
240 return helios::math::vec3<T>{v[0], -v[1], v[2]};
249 constexpr helios::math::vec3<T> withY(T y) const noexcept {
250 return helios::math::vec3<T>{v[0], y, v[2]};
258 constexpr helios::math::vec3<T> flipX() const noexcept {
259 return helios::math::vec3<T>{-v[0], v[1], v[2]};
268 constexpr helios::math::vec3<T> withX(T x) const noexcept {
269 return helios::math::vec3<T>{x, v[1], v[2]};
278 constexpr helios::math::vec3<T> withZ(T z) const noexcept {
279 return helios::math::vec3<T>{v[0], v[1], z};
290 constexpr bool isNormalized() const noexcept {
292 static_cast<FloatingPointType<T>>(v[0]) * static_cast<FloatingPointType<T>>(v[0]) +
293 static_cast<FloatingPointType<T>>(v[1]) * static_cast<FloatingPointType<T>>(v[1]) +
294 static_cast<FloatingPointType<T>>(v[2]) * static_cast<FloatingPointType<T>>(v[2]);
296 return std::abs(lenSquared - static_cast<FloatingPointType<T>>(1.0)) <= helios::math::EPSILON_LENGTH;
313 return vec3<T>{v[0] * n, v[1] * n, v[2] * n};
331 return vec3<T>{ v[0] * inv, v[1] * inv, v[2] * inv };
346 return vec3<T>{v[0] * n, v[1] * n, v[2] * n};
361 return vec3<T>{v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]};
376 return vec3<T>{v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]};
391 return vec3{
424 return vec3{v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]};
428 inline vec3<T> vec3<T>::cross(const vec3<T>& v2) const noexcept {
429 return vec3{
437 inline vec4<T> vec3<T>::toVec4() const noexcept {
438 return vec4<T>{v[0], v[1], v[2], static_cast<T>(0)};
442 inline vec2<T> vec3<T>::toVec2() const noexcept {
443 return vec2<T>{v[0], v[1]};
447 inline vec4<T> vec3<T>::toVec4(T w) const noexcept {
448 return vec4<T>{v[0], v[1], v[2], w};
452 inline T vec3<T>::dot(const vec3<T>& v2) const noexcept {
458 inline vec3<FloatingPointType<T>> vec3<T>::normalize() const noexcept {
459 if (this->length() == static_cast<FloatingPointType<T>>(0)) {
460 return vec3<FloatingPointType<T>>(
461 static_cast<FloatingPointType<T>>(0),
462 static_cast<FloatingPointType<T>>(0),
463 static_cast<FloatingPointType<T>>(0)
467 return vec3<FloatingPointType<T>>(
468 static_cast<FloatingPointType<T>>(v[0]) / this->length(),
469 static_cast<FloatingPointType<T>>(v[1]) / this->length(),
470 static_cast<FloatingPointType<T>>(v[2]) / this->length()
477 using vec3f = vec3<float>;
487 using vec3d = vec3<double>;
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.