Commit Graph

99 Commits

Author SHA1 Message Date
f6f93b5b12 BLI: add safe_divide, safe_modf and safe_logf
Those are defined exactly as their corresponding functions in Cycles.
2020-07-16 11:05:30 +02:00
35bfe1702c BLI: add safe_powf function
The same function is also used by cycles.
2020-07-16 10:46:18 +02:00
498bd0772e Merge branch 'blender-v2.83-release' 2020-05-13 13:03:55 +02:00
2afb597572 Fix T76665: Wrong files selected when using box select
Reviewers: Severin

Differential Revision: https://developer.blender.org/D7705
2020-05-13 12:50:14 +02:00
6f985574b7 Cleanup: take includes out of 'extern "C"' blocks
Surrounding includes with an 'extern "C"' block is not necessary anymore.
Also that made it harder to add any C++ code to some headers, or include headers
that have "optional" C++ code like `MEM_guardedalloc.h`.

I tested compilation on linux and windows (and got help from @LazyDodo).
If this still breaks compilation due to some linker error, the header containing
the symbol in question is probably missing an 'extern "C"' block.

Differential Revision: https://developer.blender.org/D7653
2020-05-08 18:22:41 +02:00
6e272b9ba4 BLI_math: add min/max utils for chars. 2020-04-14 11:29:46 +02:00
2d1cce8331 Cleanup: make format after SortedIncludes change 2020-03-19 09:33:58 +01:00
1a502097c7 Cleanup: Fix build warnings on windows.
Two headers define the _USE_MATH_DEFINES symbol now, if both
are included warnings are generated.

Added some guards, all good again.
2020-03-18 11:23:56 -06:00
598ab525da Cleanup: Replace ABS/SQUARE/CUBE with function calls
While it might be handy to have type-less functionality which is
similar to how C++ math is implemented it can not be easily achieved
with just preprocessor in a way which does not have side-effects on
wrong usage.

There macros where often used on a non-trivial expression, and there
was at least one usage where it was causing an actual side effect/bug
on Windows (see change around square_f(sh[index++]) in studiolight.c).

For such cases it is handy to have a function which is guaranteed to
have zero side-effects. The motivation behind actually removing the
macros is that there is already a way to do similar calculation. Also,
not having such macros is a way to guarantee that its usage is not
changed in a way which have side-effects and that it's not used as an
inspiration for cases where it should not be used.

Differential Revision: https://developer.blender.org/D7051
2020-03-09 14:47:59 +01:00
1c44d08a69 BLI: new C++ hash table data structures
This commit adds some new hashing based data structures to blenlib.
All of them use open addressing with probing currently.
Furthermore, they support small object optimization, but it is not
customizable yet. I'll add support for this when necessary.
The following main data structures are included:

**Set**
A collection of values, where every value must exist at most once.
This is similar to a Python `set`.

**SetVector**
A combination of a Set and a Vector. It supports fast search for
elements and maintains insertion order when there are no deletes.
All elements are stored in a continuous array. So they can be
iterated over using a normal `ArrayRef`.

**Map**
A set of key-value-pairs, where every key must exist at most once.
This is similar to a Python `dict`.

**StringMap**
A special map for the case when the keys are strings. This case is
fairly common and allows for some optimizations. Most importantly,
many unnecessary allocations can be avoided by storing strings in
a single buffer. Furthermore, the interface of this class uses
`StringRef` to avoid unnecessary conversions.

This commit is a continuation of rB369d5e8ad2bb7.
2019-09-13 10:06:02 +02:00
749567e0b2 Move math and vector double routines into blenlib from delaunay code 2019-08-28 18:33:24 -06:00
8bee9af462 BLI: double version of some math functions. 2019-08-20 21:09:55 +08:00
760dbd1cbf Cleanup: misc spelling fixes
T68035 by @luzpaz
2019-08-01 14:02:41 +10:00
cda4cd0705 Cleanup: comments (long lines) in blenlib 2019-04-22 06:30:08 +10:00
e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00
de13d0a80c doxygen: add newline after \file
While \file doesn't need an argument, it can't have another doxy
command after it.
2019-02-18 08:22:12 +11:00
eef4077f18 Cleanup: remove redundant doxygen \file argument
Move \ingroup onto same line to be more compact and
make it clear the file is in the group.
2019-02-06 15:45:22 +11:00
65ec7ec524 Cleanup: remove redundant, invalid info from headers
BF-admins agree to remove header information that isn't useful,
to reduce noise.

- BEGIN/END license blocks

  Developers should add non license comments as separate comment blocks.
  No need for separator text.

- Contributors

  This is often invalid, outdated or misleading
  especially when splitting files.

  It's more useful to git-blame to find out who has developed the code.

See P901 for script to perform these edits.
2019-02-02 01:36:28 +11:00
0e68751b8a Fix BLI_ASSERT_UNIT macro w/ non-finite numbers 2018-06-06 19:49:27 +02:00
995ccf8168 BLI_assert: extract from BLI_utildefines
BLI_utildefines is quite large, defining many unrelated things.
Add BLI_assert to include in inline headers, so math defines don't
pull in too much.
2018-03-16 06:03:29 +11:00
c09e4ae08a Math utils: Add clamping functions 2018-02-14 11:21:27 +01:00
Dalai Felinto
431d5772bb Fixup for integer digits commit 2018-01-19 17:04:19 -02:00
f0610563ee math utils: Add size_t version of min and max functions 2018-01-10 11:06:44 +01:00
43b4913051 Math Lib: Add non-clamped round_* functions
Replace iroundf with round_fl_to_int, add other types
2017-09-27 11:13:03 +10:00
c4fc9c4a8e Math Lib: clamped rounding utility functions 2017-09-18 23:55:41 +10:00
c1e177ad29 BLI_math: add simple helper to get amount of 'integer' digits in a float number. 2017-08-01 16:34:02 +02:00
1a01ef4ae9 Fix macOS build with openimageio 1.7.8 and openexr.
These macros conflict and are no longer needed with C99 or C++ anyway.
2016-12-03 15:19:49 +01:00
21fddf7d1c C99/C++11: replace deprecated finite() by isfinite(). 2016-05-17 21:39:16 +02:00
7837f0e833 BLI_math 'compare' cleanup & enhancements.
This commit:
* Adds a 'compare_ff' function for absolute 'almost equal' comparison of floats.
* Makes 'compare_vxvx' functions use that new 'compare_ff' one.
* Adds a 'compare_ff_relative' function for secured ulp-based relative comparison of floats.
* Adds matching 'compare_vxvx_relative' functions.
* Adds some basic tests for compare_ff_relative.

See https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Note that we could replace our python/mathutils' EXPP_FloatsAreEqual() by BLI's compare_ff_relative
(using a very small absolute max_diff), but these do not have exact same behavior...
Left a comment there for now, we can do it later if/when we are sure it won't break anything!
2015-07-10 15:02:43 +02:00
74b32a23f7 Cleanup: checks for unsupported MSVC versions 2015-06-20 15:17:32 +10:00
bdf6393c98 Math Lib: pow_i for int power-of 2015-04-24 11:37:48 +10:00
c9f9e29538 Math Lib: handling bits handling into own file 2015-04-22 04:44:24 +10:00
535de7ec1f Comment for math defines, also add M_PI_4 2015-02-01 00:37:55 +11:00
01c04333f5 Fix T43034: beautify-fill leaves zero area tri's 2014-12-27 16:47:42 +11:00
25c5542fe7 Math Lib: add constant: M_SQRT1_3 1/sqrt(3) 2014-11-22 18:21:52 +01:00
52d571e189 Avoid calling powf with integer exponent in more places
Move powX functions from particle code into math library and use them.
2014-11-11 18:16:20 +01:00
504370cafb Code cleanup: Fix silly duplication of typecheck and swap macro 2014-10-10 21:13:19 +06:00
5ecbd5c871 Use native float math functions for MSVC12
`double` surrogates are slow (e.g. pow is 2x slower than powf), and MSVC12
supports fp-math functions from C99.
2014-09-30 13:39:03 +04:00
28054d8e38 remove MAXFLOAT define 2014-08-14 10:36:07 +10:00
e3ed13cbd4 Cleanup: Remove special code for Visual Studio 2008.
Goodbye VC2008, it has been a pleasure (more or less) :D SCons / CMake cleaenup will follow.
Differential Revision: https://developer.blender.org/D715
2014-08-07 13:52:15 +02:00
88a0d5ebe8 Make CHECK_TYPE_NONCONST macro portable
also replace __typeof -> typeof
2014-08-02 18:08:44 +10:00
9531091eb8 Fix compilation error with debug SCons
For some reason SCons defines _DEBUG, not DEBUG as mathutils was
expecting it to be.

Made it so mathutils checks for NDEBUG which mimics BLI_assert
define.
2014-05-13 19:52:50 +02:00
a51a0ca772 Math Lib: add shell_v3v3_normalized_to_dist and v2 version
bypass angle calculation to avoids (asin, sqrt, cos).
2014-04-19 22:17:10 +10:00
fabc46b41f Math Lib: add rotation_between_vecs_to_mat3
- behaves like rotation_between_vecs_to_quat
- avoids calling sin,cos calls (approx 1.6x faster).
2014-04-19 15:36:47 +10:00
c04e73f386 Math Lib: use less strict epsilon with BLI_ASSERT_UNIT_QUAT
was causing issues with pointcache
2014-04-11 18:20:30 +10:00
2a82b8ade5 Math Lib: add power of 2 min/max for unsigned ints 2014-04-05 21:54:20 +11:00
c6252d6e60 Math Lib: add angle_qt functions 2014-03-20 15:15:29 +11:00
aa517ab3a4 Compile fix for 004decc1d940... 2014-02-15 14:38:49 +01:00
004decc1d9 Code cleanup: warnings 2014-02-15 18:21:07 +11:00
da8619fe23 Math Lib: add iroundf function for: (int)floorf(a + 0.5f) 2014-01-15 13:40:40 +11:00