2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
* Copyright 2001-2002 NaN Holding BV. All rights reserved. */
|
2009-11-09 22:42:41 +00:00
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2009-11-09 22:42:41 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
2011-02-18 13:58:08 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-18 11:23:56 -06:00
|
|
|
#if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
|
2012-09-20 01:02:39 +00:00
|
|
|
# define _USE_MATH_DEFINES
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
|
2018-03-16 06:03:29 +11:00
|
|
|
#include "BLI_assert.h"
|
2010-01-22 11:10:24 +00:00
|
|
|
#include "BLI_math_inline.h"
|
2020-05-13 12:50:14 +02:00
|
|
|
#include "BLI_sys_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <math.h>
|
2009-11-09 22:42:41 +00:00
|
|
|
|
|
|
|
#ifndef M_PI
|
2015-01-31 17:17:12 +11:00
|
|
|
# define M_PI 3.14159265358979323846 /* pi */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
#ifndef M_PI_2
|
2015-01-31 17:17:12 +11:00
|
|
|
# define M_PI_2 1.57079632679489661923 /* pi/2 */
|
|
|
|
#endif
|
|
|
|
#ifndef M_PI_4
|
|
|
|
# define M_PI_4 0.78539816339744830962 /* pi/4 */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
#ifndef M_SQRT2
|
2014-11-22 18:11:46 +01:00
|
|
|
# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
#ifndef M_SQRT1_2
|
2014-11-22 18:11:46 +01:00
|
|
|
# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
2012-05-31 11:57:09 +00:00
|
|
|
#ifndef M_SQRT3
|
2014-11-22 18:11:46 +01:00
|
|
|
# define M_SQRT3 1.73205080756887729352 /* sqrt(3) */
|
|
|
|
#endif
|
|
|
|
#ifndef M_SQRT1_3
|
|
|
|
# define M_SQRT1_3 0.57735026918962576450 /* 1/sqrt(3) */
|
2012-05-31 11:57:09 +00:00
|
|
|
#endif
|
2009-11-09 22:42:41 +00:00
|
|
|
#ifndef M_1_PI
|
2015-01-31 17:17:12 +11:00
|
|
|
# define M_1_PI 0.318309886183790671538 /* 1/pi */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
#ifndef M_E
|
2015-01-31 17:17:12 +11:00
|
|
|
# define M_E 2.7182818284590452354 /* e */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
#ifndef M_LOG2E
|
2015-01-31 17:17:12 +11:00
|
|
|
# define M_LOG2E 1.4426950408889634074 /* log_2 e */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
#ifndef M_LOG10E
|
2015-01-31 17:17:12 +11:00
|
|
|
# define M_LOG10E 0.43429448190325182765 /* log_10 e */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
#ifndef M_LN2
|
2015-01-31 17:17:12 +11:00
|
|
|
# define M_LN2 0.69314718055994530942 /* log_e 2 */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
#ifndef M_LN10
|
2015-01-31 17:17:12 +11:00
|
|
|
# define M_LN10 2.30258509299404568402 /* log_e 10 */
|
2009-11-09 22:42:41 +00:00
|
|
|
#endif
|
|
|
|
|
2013-08-13 10:40:23 +00:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
# define NAN_FLT __builtin_nanf("")
|
2021-12-20 19:01:14 +11:00
|
|
|
#else /* evil quiet NaN definition */
|
2013-08-13 10:09:27 +00:00
|
|
|
static const int NAN_INT = 0x7FC00000;
|
2013-08-13 10:40:23 +00:00
|
|
|
# define NAN_FLT (*((float *)(&NAN_INT)))
|
|
|
|
#endif
|
2013-08-13 10:09:27 +00:00
|
|
|
|
2012-11-23 15:12:13 +00:00
|
|
|
#if BLI_MATH_DO_INLINE
|
2010-01-22 11:10:24 +00:00
|
|
|
# include "intern/math_base_inline.c"
|
|
|
|
#endif
|
|
|
|
|
2013-03-13 15:41:14 +00:00
|
|
|
#ifdef BLI_MATH_GCC_WARN_PRAGMA
|
2013-03-11 20:27:38 +00:00
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wredundant-decls"
|
|
|
|
#endif
|
|
|
|
|
2020-05-08 18:16:39 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-11-09 22:42:41 +00:00
|
|
|
/******************************* Float ******************************/
|
|
|
|
|
2021-12-20 19:01:14 +11:00
|
|
|
/* `powf` is really slow for raising to integer powers. */
|
|
|
|
|
2014-11-11 18:16:20 +01:00
|
|
|
MINLINE float pow2f(float x);
|
|
|
|
MINLINE float pow3f(float x);
|
|
|
|
MINLINE float pow4f(float x);
|
|
|
|
MINLINE float pow7f(float x);
|
|
|
|
|
2010-01-22 11:10:24 +00:00
|
|
|
MINLINE float sqrt3f(float f);
|
|
|
|
MINLINE double sqrt3d(double d);
|
|
|
|
|
2013-11-26 20:53:26 +11:00
|
|
|
MINLINE float sqrtf_signed(float f);
|
|
|
|
|
2010-01-22 11:10:24 +00:00
|
|
|
MINLINE float saacosf(float f);
|
|
|
|
MINLINE float saasinf(float f);
|
|
|
|
MINLINE float sasqrtf(float f);
|
|
|
|
MINLINE float saacos(float fac);
|
|
|
|
MINLINE float saasin(float fac);
|
|
|
|
MINLINE float sasqrt(float fac);
|
2009-11-09 22:42:41 +00:00
|
|
|
|
2023-02-13 17:23:57 +01:00
|
|
|
/* Compute linear interpolation (lerp) between origin and target. */
|
|
|
|
MINLINE float interpf(float target, float origin, float t);
|
|
|
|
MINLINE double interpd(double target, double origin, double t);
|
2009-11-09 22:42:41 +00:00
|
|
|
|
2021-03-16 19:35:53 +01:00
|
|
|
MINLINE float ratiof(float min, float max, float pos);
|
|
|
|
MINLINE double ratiod(double min, double max, double pos);
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Map a normalized value, i.e. from interval [0, 1] to interval [a, b].
|
|
|
|
*/
|
2021-08-04 10:38:03 -03:00
|
|
|
MINLINE float scalenorm(float a, float b, float x);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Map a normalized value, i.e. from interval [0, 1] to interval [a, b].
|
|
|
|
*/
|
2021-08-04 10:38:03 -03:00
|
|
|
MINLINE double scalenormd(double a, double b, double x);
|
|
|
|
|
2020-03-06 17:18:10 +01:00
|
|
|
/* NOTE: Compilers will upcast all types smaller than int to int when performing arithmetic
|
|
|
|
* operation. */
|
2021-12-09 20:01:44 +11:00
|
|
|
|
2020-03-06 17:18:10 +01:00
|
|
|
MINLINE int square_s(short a);
|
|
|
|
MINLINE int square_uchar(unsigned char a);
|
|
|
|
MINLINE int cube_s(short a);
|
|
|
|
MINLINE int cube_uchar(unsigned char a);
|
|
|
|
|
|
|
|
MINLINE int square_i(int a);
|
|
|
|
MINLINE unsigned int square_uint(unsigned int a);
|
|
|
|
MINLINE float square_f(float a);
|
|
|
|
MINLINE double square_d(double a);
|
|
|
|
|
|
|
|
MINLINE int cube_i(int a);
|
|
|
|
MINLINE unsigned int cube_uint(unsigned int a);
|
|
|
|
MINLINE float cube_f(float a);
|
|
|
|
MINLINE double cube_d(double a);
|
|
|
|
|
2012-10-23 13:28:22 +00:00
|
|
|
MINLINE float min_ff(float a, float b);
|
|
|
|
MINLINE float max_ff(float a, float b);
|
2013-12-06 03:46:27 +11:00
|
|
|
MINLINE float min_fff(float a, float b, float c);
|
|
|
|
MINLINE float max_fff(float a, float b, float c);
|
|
|
|
MINLINE float min_ffff(float a, float b, float c, float d);
|
|
|
|
MINLINE float max_ffff(float a, float b, float c, float d);
|
2012-10-23 13:28:22 +00:00
|
|
|
|
2019-08-28 18:33:24 -06:00
|
|
|
MINLINE double min_dd(double a, double b);
|
|
|
|
MINLINE double max_dd(double a, double b);
|
|
|
|
|
2012-10-23 13:28:22 +00:00
|
|
|
MINLINE int min_ii(int a, int b);
|
|
|
|
MINLINE int max_ii(int a, int b);
|
2013-12-06 03:46:27 +11:00
|
|
|
MINLINE int min_iii(int a, int b, int c);
|
|
|
|
MINLINE int max_iii(int a, int b, int c);
|
|
|
|
MINLINE int min_iiii(int a, int b, int c, int d);
|
|
|
|
MINLINE int max_iiii(int a, int b, int c, int d);
|
2009-11-09 22:42:41 +00:00
|
|
|
|
2021-06-04 09:14:15 +02:00
|
|
|
MINLINE uint min_uu(uint a, uint b);
|
|
|
|
MINLINE uint max_uu(uint a, uint b);
|
|
|
|
|
2017-12-21 10:39:15 +01:00
|
|
|
MINLINE size_t min_zz(size_t a, size_t b);
|
|
|
|
MINLINE size_t max_zz(size_t a, size_t b);
|
|
|
|
|
2020-04-14 11:29:10 +02:00
|
|
|
MINLINE char min_cc(char a, char b);
|
|
|
|
MINLINE char max_cc(char a, char b);
|
|
|
|
|
2018-02-14 11:21:27 +01:00
|
|
|
MINLINE int clamp_i(int value, int min, int max);
|
|
|
|
MINLINE float clamp_f(float value, float min, float max);
|
|
|
|
MINLINE size_t clamp_z(size_t value, size_t min, size_t max);
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Almost-equal for IEEE floats, using absolute difference method.
|
|
|
|
*
|
|
|
|
* \param max_diff: the maximum absolute difference.
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
MINLINE int compare_ff(float a, float b, float max_diff);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Almost-equal for IEEE floats, using their integer representation
|
|
|
|
* (mixing ULP and absolute difference methods).
|
|
|
|
*
|
|
|
|
* \param max_diff: is the maximum absolute difference (allows to take care of the near-zero area,
|
|
|
|
* where relative difference methods cannot really work).
|
|
|
|
* \param max_ulps: is the 'maximum number of floats + 1'
|
|
|
|
* allowed between \a a and \a b to consider them equal.
|
|
|
|
*
|
|
|
|
* \see https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
MINLINE int compare_ff_relative(float a, float b, float max_diff, int max_ulps);
|
|
|
|
MINLINE bool compare_threshold_relative(float value1, float value2, float thresh);
|
2015-07-10 14:32:35 +02:00
|
|
|
|
2010-09-25 11:30:46 +00:00
|
|
|
MINLINE float signf(float f);
|
2014-12-27 16:47:42 +11:00
|
|
|
MINLINE int signum_i_ex(float a, float eps);
|
|
|
|
MINLINE int signum_i(float a);
|
2010-09-25 11:30:46 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Used for zoom values.
|
|
|
|
*/
|
2010-01-22 11:10:24 +00:00
|
|
|
MINLINE float power_of_2(float f);
|
2009-11-09 22:42:41 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Returns number of (base ten) *significant* digits of integer part of given float
|
|
|
|
* (negative in case of decimal-only floats, 0.01 returns -1 e.g.).
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
MINLINE int integer_digits_f(float f);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Returns number of (base ten) *significant* digits of integer part of given double
|
|
|
|
* (negative in case of decimal-only floats, 0.01 returns -1 e.g.).
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
MINLINE int integer_digits_d(double d);
|
|
|
|
MINLINE int integer_digits_i(int i);
|
2017-08-01 16:34:02 +02:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/* These don't really fit anywhere but were being copied about a lot. */
|
|
|
|
|
2011-12-16 09:25:07 +00:00
|
|
|
MINLINE int is_power_of_2_i(int n);
|
2022-05-18 21:31:10 +02:00
|
|
|
|
|
|
|
MINLINE unsigned int log2_floor_u(unsigned int x);
|
|
|
|
MINLINE unsigned int log2_ceil_u(unsigned int x);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns next (or previous) power of 2 or the input number if it is already a power of 2.
|
|
|
|
*/
|
2011-12-16 09:25:07 +00:00
|
|
|
MINLINE int power_of_2_max_i(int n);
|
|
|
|
MINLINE int power_of_2_min_i(int n);
|
2014-04-05 21:39:46 +11:00
|
|
|
MINLINE unsigned int power_of_2_max_u(unsigned int x);
|
|
|
|
MINLINE unsigned int power_of_2_min_u(unsigned int x);
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Integer division that rounds 0.5 up, particularly useful for color blending
|
|
|
|
* with integers, to avoid gradual darkening when rounding down.
|
|
|
|
*/
|
2013-04-25 14:16:22 +00:00
|
|
|
MINLINE int divide_round_i(int a, int b);
|
2022-07-01 10:30:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Integer division that returns the ceiling, instead of flooring like normal C division.
|
|
|
|
*/
|
|
|
|
MINLINE uint divide_ceil_u(uint a, uint b);
|
|
|
|
MINLINE uint64_t divide_ceil_ul(uint64_t a, uint64_t b);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns \a a if it is a multiple of \a b or the next multiple or \a b after \b a .
|
|
|
|
*/
|
|
|
|
MINLINE uint ceil_to_multiple_u(uint a, uint b);
|
|
|
|
MINLINE uint64_t ceil_to_multiple_ul(uint64_t a, uint64_t b);
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* modulo that handles negative numbers, works the same as Python's.
|
|
|
|
*/
|
2013-09-05 20:54:32 +00:00
|
|
|
MINLINE int mod_i(int i, int n);
|
2013-04-25 14:16:22 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Round to closest even number, halfway cases are rounded away from zero.
|
|
|
|
*/
|
2021-08-23 15:30:31 +02:00
|
|
|
MINLINE float round_to_even(float f);
|
|
|
|
|
2017-09-27 11:13:03 +10:00
|
|
|
MINLINE signed char round_fl_to_char(float a);
|
|
|
|
MINLINE unsigned char round_fl_to_uchar(float a);
|
|
|
|
MINLINE short round_fl_to_short(float a);
|
|
|
|
MINLINE unsigned short round_fl_to_ushort(float a);
|
|
|
|
MINLINE int round_fl_to_int(float a);
|
|
|
|
MINLINE unsigned int round_fl_to_uint(float a);
|
|
|
|
|
|
|
|
MINLINE signed char round_db_to_char(double a);
|
|
|
|
MINLINE unsigned char round_db_to_uchar(double a);
|
|
|
|
MINLINE short round_db_to_short(double a);
|
|
|
|
MINLINE unsigned short round_db_to_ushort(double a);
|
|
|
|
MINLINE int round_db_to_int(double a);
|
|
|
|
MINLINE unsigned int round_db_to_uint(double a);
|
|
|
|
|
2017-09-18 21:03:10 +10:00
|
|
|
MINLINE signed char round_fl_to_char_clamp(float a);
|
|
|
|
MINLINE unsigned char round_fl_to_uchar_clamp(float a);
|
|
|
|
MINLINE short round_fl_to_short_clamp(float a);
|
|
|
|
MINLINE unsigned short round_fl_to_ushort_clamp(float a);
|
|
|
|
MINLINE int round_fl_to_int_clamp(float a);
|
|
|
|
MINLINE unsigned int round_fl_to_uint_clamp(float a);
|
|
|
|
|
|
|
|
MINLINE signed char round_db_to_char_clamp(double a);
|
|
|
|
MINLINE unsigned char round_db_to_uchar_clamp(double a);
|
|
|
|
MINLINE short round_db_to_short_clamp(double a);
|
|
|
|
MINLINE unsigned short round_db_to_ushort_clamp(double a);
|
|
|
|
MINLINE int round_db_to_int_clamp(double a);
|
|
|
|
MINLINE unsigned int round_db_to_uint_clamp(double a);
|
|
|
|
|
2015-04-24 11:37:48 +10:00
|
|
|
int pow_i(int base, int exp);
|
2021-12-09 20:01:44 +11:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \param ndigits: must be between 0 and 21.
|
|
|
|
*/
|
2009-11-29 22:42:33 +00:00
|
|
|
double double_round(double x, int ndigits);
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Floor to the nearest power of 10, e.g.:
|
|
|
|
* - 15.0 -> 10.0
|
|
|
|
* - 0.015 -> 0.01
|
|
|
|
* - 1.0 -> 1.0
|
|
|
|
*
|
|
|
|
* \param f: Value to floor, must be over 0.0.
|
|
|
|
* \note If we wanted to support signed values we could if this becomes necessary.
|
|
|
|
*/
|
2020-11-13 16:58:14 +11:00
|
|
|
float floor_power_of_10(float f);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Ceiling to the nearest power of 10, e.g.:
|
|
|
|
* - 15.0 -> 100.0
|
|
|
|
* - 0.015 -> 0.1
|
|
|
|
* - 1.0 -> 1.0
|
|
|
|
*
|
|
|
|
* \param f: Value to ceiling, must be over 0.0.
|
|
|
|
* \note If we wanted to support signed values we could if this becomes necessary.
|
|
|
|
*/
|
2020-11-13 16:58:14 +11:00
|
|
|
float ceil_power_of_10(float f);
|
|
|
|
|
2013-03-13 15:41:14 +00:00
|
|
|
#ifdef BLI_MATH_GCC_WARN_PRAGMA
|
2013-03-11 20:27:38 +00:00
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/* Asserts, some math functions expect normalized inputs
|
|
|
|
* check the vector is unit length, or zero length (which can't be helped in some cases). */
|
|
|
|
|
2014-05-13 19:50:55 +02:00
|
|
|
#ifndef NDEBUG
|
2023-02-12 14:37:16 +11:00
|
|
|
/** \note 0.0001 is too small because normals may be converted from short's: see #34322. */
|
2013-02-19 14:14:37 +00:00
|
|
|
# define BLI_ASSERT_UNIT_EPSILON 0.0002f
|
2021-06-14 12:30:11 +02:00
|
|
|
# define BLI_ASSERT_UNIT_EPSILON_DB 0.0002
|
2018-06-06 19:49:27 +02:00
|
|
|
/**
|
2019-04-22 00:54:27 +10:00
|
|
|
* \note Checks are flipped so NAN doesn't assert.
|
|
|
|
* This is done because we're making sure the value was normalized and in the case we
|
|
|
|
* don't want NAN to be raising asserts since there is nothing to be done in that case.
|
2018-06-06 19:49:27 +02:00
|
|
|
*/
|
2013-02-19 13:15:34 +00:00
|
|
|
# define BLI_ASSERT_UNIT_V3(v) \
|
|
|
|
{ \
|
|
|
|
const float _test_unit = len_squared_v3(v); \
|
2018-06-06 19:49:27 +02:00
|
|
|
BLI_assert(!(fabsf(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \
|
|
|
|
!(fabsf(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \
|
2013-02-19 13:15:34 +00:00
|
|
|
} \
|
|
|
|
(void)0
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-28 10:56:44 -04:00
|
|
|
# define BLI_ASSERT_UNIT_V3_DB(v) \
|
|
|
|
{ \
|
|
|
|
const double _test_unit = len_squared_v3_db(v); \
|
2021-06-14 12:30:11 +02:00
|
|
|
BLI_assert(!(fabs(_test_unit - 1.0) >= BLI_ASSERT_UNIT_EPSILON_DB) || \
|
|
|
|
!(fabs(_test_unit) >= BLI_ASSERT_UNIT_EPSILON_DB)); \
|
2020-08-28 10:56:44 -04:00
|
|
|
} \
|
|
|
|
(void)0
|
|
|
|
|
2013-02-19 13:15:34 +00:00
|
|
|
# define BLI_ASSERT_UNIT_V2(v) \
|
|
|
|
{ \
|
|
|
|
const float _test_unit = len_squared_v2(v); \
|
2018-06-06 19:49:27 +02:00
|
|
|
BLI_assert(!(fabsf(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \
|
|
|
|
!(fabsf(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \
|
2013-02-19 13:15:34 +00:00
|
|
|
} \
|
|
|
|
(void)0
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-20 14:39:32 +11:00
|
|
|
# define BLI_ASSERT_UNIT_QUAT(q) \
|
|
|
|
{ \
|
|
|
|
const float _test_unit = dot_qtqt(q, q); \
|
2018-06-06 19:49:27 +02:00
|
|
|
BLI_assert(!(fabsf(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON * 10) || \
|
|
|
|
!(fabsf(_test_unit) >= BLI_ASSERT_UNIT_EPSILON * 10)); \
|
2014-03-20 14:39:32 +11:00
|
|
|
} \
|
|
|
|
(void)0
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-08 13:00:52 +00:00
|
|
|
# define BLI_ASSERT_ZERO_M3(m) \
|
|
|
|
{ \
|
2014-04-19 15:36:47 +10:00
|
|
|
BLI_assert(dot_vn_vn((const float *)m, (const float *)m, 9) != 0.0); \
|
2013-05-08 13:00:52 +00:00
|
|
|
} \
|
|
|
|
(void)0
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-08 13:00:52 +00:00
|
|
|
# define BLI_ASSERT_ZERO_M4(m) \
|
|
|
|
{ \
|
|
|
|
BLI_assert(dot_vn_vn((const float *)m, (const float *)m, 16) != 0.0); \
|
|
|
|
} \
|
|
|
|
(void)0
|
2014-04-19 15:36:47 +10:00
|
|
|
# define BLI_ASSERT_UNIT_M3(m) \
|
|
|
|
{ \
|
|
|
|
BLI_ASSERT_UNIT_V3((m)[0]); \
|
|
|
|
BLI_ASSERT_UNIT_V3((m)[1]); \
|
|
|
|
BLI_ASSERT_UNIT_V3((m)[2]); \
|
|
|
|
} \
|
|
|
|
(void)0
|
2013-02-19 13:15:34 +00:00
|
|
|
#else
|
2013-05-08 13:00:52 +00:00
|
|
|
# define BLI_ASSERT_UNIT_V2(v) (void)(v)
|
|
|
|
# define BLI_ASSERT_UNIT_V3(v) (void)(v)
|
2021-06-14 13:22:11 +02:00
|
|
|
# define BLI_ASSERT_UNIT_V3_DB(v) (void)(v)
|
2014-03-20 14:39:32 +11:00
|
|
|
# define BLI_ASSERT_UNIT_QUAT(v) (void)(v)
|
2013-05-08 13:00:52 +00:00
|
|
|
# define BLI_ASSERT_ZERO_M3(m) (void)(m)
|
|
|
|
# define BLI_ASSERT_ZERO_M4(m) (void)(m)
|
2014-04-19 15:36:47 +10:00
|
|
|
# define BLI_ASSERT_UNIT_M3(m) (void)(m)
|
2013-02-19 13:15:34 +00:00
|
|
|
#endif
|
2009-11-09 22:42:41 +00:00
|
|
|
|
2020-05-08 18:16:39 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|