19#ifndef FENNEC_MATH_EXT_COMMON_H
20#define FENNEC_MATH_EXT_COMMON_H
27#include <fennec/math/ext/quaternion.h>
34template<
typename genType>
35constexpr qua<genType>
sign(
const qua<genType>& x) {
44template<
typename genType>
45constexpr qua<genType>
abs(
const qua<genType>& x) {
47 x.w * fennec::sign(x.w),
48 x.x * fennec::sign(x.x),
49 x.y * fennec::sign(x.y),
50 x.z * fennec::sign(x.z)
57template<
typename genType>
58constexpr qua<genType>
floor(
const qua<genType>& x) {
67template<
typename genType>
68constexpr qua<genType>
ceil(
const qua<genType>& x) {
77template<
typename genType>
78constexpr qua<genType>
trunc(
const qua<genType>& x) {
87template<
typename genType>
88constexpr qua<genType>
round(
const qua<genType>& x) {
97template<
typename genType>
98constexpr qua<genType>
roundEven(
const qua<genType>& x) {
100 fennec::roundEven(x.w),
101 fennec::roundEven(x.x),
102 fennec::roundEven(x.y),
103 fennec::roundEven(x.z)
109template<
typename genType>
110constexpr qua<genType>
fract(
const qua<genType>& x) {
119template<
typename genType>
120constexpr qua<genType>
mod(
const qua<genType>& x) {
129template<
typename genType>
130constexpr qua<genType>
modf(
const qua<genType>& x) {
139template<
typename genType>
140constexpr qua<genType>
isnan(
const qua<genType>& x) {
149template<
typename genType>
150constexpr qua<genType>
isinf(
const qua<genType>& x) {
159template<
typename genType>
160constexpr qua<genType>
fma(
const qua<genType>& a,
const qua<genType>& b,
const qua<genType>& c) {
162 fennec::fma(a.w, b.w, c.w),
163 fennec::fma(a.x, b.x, c.x),
164 fennec::fma(a.y, b.y, c.y),
165 fennec::fma(a.z, b.z, c.z)
172template<
typename genType>
173constexpr qua<genType>
min(
const qua<genType>& x,
const qua<genType>& y) {
175 fennec::min(x.w,
y.w),
176 fennec::min(x.x,
y.x),
177 fennec::min(x.y,
y.y),
178 fennec::min(x.z,
y.z)
182template<
typename genType>
183constexpr qua<genType>
max(
const qua<genType>& x,
const qua<genType>& y) {
185 fennec::max(x.w,
y.w),
186 fennec::max(x.x,
y.x),
187 fennec::max(x.y,
y.y),
188 fennec::max(x.z,
y.z)
192template<
typename genType>
193constexpr qua<genType>
clamp(
const qua<genType>& x, genType minVal, genType maxVal) {
195 fennec::clamp(x.w, minVal, maxVal),
196 fennec::clamp(x.x, minVal, maxVal),
197 fennec::clamp(x.y, minVal, maxVal),
198 fennec::clamp(x.z, minVal, maxVal)
202template<
typename genType>
203constexpr qua<genType>
clamp(
const qua<genType>& x,
const qua<genType>& minVal,
const qua<genType>& maxVal) {
205 fennec::clamp(x.w, minVal.w, maxVal.w),
206 fennec::clamp(x.x, minVal.x, maxVal.x),
207 fennec::clamp(x.y, minVal.y, maxVal.y),
208 fennec::clamp(x.z, minVal.z, maxVal.z)
215template<
typename genType>
216constexpr qua<genType>
mix(
const qua<genType>& x,
const qua<genType>& y, genType a) {
218 qua<genType> z = cT < genType(0) ? -
y :
y;
219 cT = cT < genType(0) ? -cT : cT;
222 return x * (genType(1) - a) + y * a;
226 return (fennec::sin(x * (genType(1) - a) * t) + z * (fennec::sin(a * t))) /
fennec::sin(t);
constexpr genType dot(const vector< genType, i... > &x, const vector< genType, i... > &y)
Returns the dot product of and , i.e., .
Definition geometric.h:133
constexpr genType min(genType x, genType y)
Returns if otherwise it returns .
Definition common.h:688
constexpr genBType isnan(genType x)
Returns true if holds a NaN. Returns false otherwise.
Definition common.h:517
constexpr genType mod(genType x, genType y)
Modulus. Returns .
Definition common.h:479
constexpr genType max(genType x, genType y)
Returns if , otherwise it returns .
Definition common.h:705
constexpr genType trunc(genType x)
Returns a value equal to the nearest integer that is less than or equal to .
Definition common.h:399
constexpr genType roundEven(genType x)
Returns a value equal to the nearest integer. In C++, a fractional part of will always round to the ...
Definition common.h:418
constexpr genType ceil(genType x)
Returns a value equal to the nearest integer that is greater than or equal to .
Definition common.h:365
constexpr genType sign(genType x)
Returns if , if , or if .
Definition common.h:306
constexpr genType floor(genType x)
Returns a value equal to the nearest integer that is less than or equal to .
Definition common.h:348
constexpr genType mix(genType x, genType y, genType a)
Returns the linear blend of and , i.e., .
Definition common.h:799
constexpr genType fma(genType a, genType b, genType c)
Computes and returns .
Definition common.h:613
constexpr genType abs(genType x)
Returns if , otherwise it returns .
Definition common.h:322
constexpr genType fract(genType x)
Returns .
Definition common.h:462
constexpr genType clamp(genType x, genType minVal, genType maxVal)
Returns .
Definition common.h:723
constexpr genType round(genType x)
Returns a value equal to the nearest integer. In C++, a fractional part of will always round up.
Definition common.h:382
constexpr genBType isinf(genType x)
Returns true if holds a positive or negative infinity. Returns false otherwise.
Definition common.h:533
constexpr genType modf(genType x, genType &i)
Returns the fractional part of and stores the integral part in .
Definition common.h:496
constexpr genType y()
Definition constants.h:672
static constexpr TypeT epsilon()
Returns the difference between 1.0 and the next representable value.
Definition limits.h:255
constexpr genType acos(genType x)
Arc Cosine. Returns an angle whose cosine is /a x.
Definition trigonometric.h:268
constexpr genType sin(genType x)
The standard trigonometric sine.
Definition trigonometric.h:204