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)} {}
96 constexpr const T& operator[](const size_t i) const noexcept {
98 return this->v[i];
110 constexpr T& operator[](const size_t i) noexcept {
112 return this->v[i];
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;
226 constexpr helios::math::vec3<T> flipY() const noexcept {
227 return helios::math::vec3<T>{v[0], -v[1], v[2]};
236 constexpr helios::math::vec3<T> withY(T y) const noexcept {
237 return helios::math::vec3<T>{v[0], y, v[2]};
245 constexpr helios::math::vec3<T> flipX() const noexcept {
246 return helios::math::vec3<T>{-v[0], v[1], v[2]};
255 constexpr helios::math::vec3<T> withX(T x) const noexcept {
256 return helios::math::vec3<T>{x, v[1], v[2]};
267 constexpr bool isNormalized() const noexcept {
268 const auto lenSquared =
269 static_cast<FloatingPointType<T>>(v[0]) * static_cast<FloatingPointType<T>>(v[0]) +
270 static_cast<FloatingPointType<T>>(v[1]) * static_cast<FloatingPointType<T>>(v[1]) +
271 static_cast<FloatingPointType<T>>(v[2]) * static_cast<FloatingPointType<T>>(v[2]);
273 return std::abs(lenSquared - static_cast<FloatingPointType<T>>(1.0)) <= helios::math::EPSILON_LENGTH;
368 return vec3{
405 inline vec3<T> vec3<T>::cross(const vec3<T>& v2) const noexcept {
406 return vec3{
414 inline vec4<T> vec3<T>::toVec4() const noexcept {
415 return vec4<T>{v[0], v[1], v[2], static_cast<T>(0)};
419 inline vec2<T> vec3<T>::toVec2() const noexcept {
420 return vec2<T>{v[0], v[1]};
424 inline vec4<T> vec3<T>::toVec4(T w) const noexcept {
429 inline T vec3<T>::dot(const vec3<T>& v2) const noexcept {
435 inline vec3<FloatingPointType<T>> vec3<T>::normalize() const noexcept {
436 if (this->length() == static_cast<FloatingPointType<T>>(0)) {
437 return vec3<FloatingPointType<T>>(
438 static_cast<FloatingPointType<T>>(0),
439 static_cast<FloatingPointType<T>>(0),
440 static_cast<FloatingPointType<T>>(0)
444 return vec3<FloatingPointType<T>>(
445 static_cast<FloatingPointType<T>>(v[0]) / this->length(),
446 static_cast<FloatingPointType<T>>(v[1]) / this->length(),
447 static_cast<FloatingPointType<T>>(v[2]) / this->length()
454 using vec3f = vec3<float>;
464 using vec3d = vec3<double>;
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.