Commit graph

88 commits

Author SHA1 Message Date
lawnjelly
6f8e632848 Make acos and asin safe
A common bug with using acos and asin is that input outside -1 to 1 range will result in Nan output. This can occur due to floating point error in the input.

The standard solution is to provide safe_acos function with clamped input. For Godot it may make more sense to make the standard functions safe.
2023-05-11 09:51:44 +01:00
Rémi Verschelde
5faa423944
Math: Prevent division by zero in posmod
Fixes #43932.

Co-authored-by: David Hoppenbrouwers <david@salt-inc.org>
(cherry picked from commit f011d8ca9c)
2023-03-06 13:48:13 +01:00
Rémi Verschelde
1426cd3b3a
One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".

Backported from #70885.
2023-01-10 15:26:54 +01:00
Yuri Rubinsky
d525d902c1 Fix wrapf to correct wrap values with 0.1 stepping
(cherry picked from commit 09418afbc0)
2022-06-16 10:10:48 +02:00
lawnjelly
d24c715678 Float literals - fix math classes to allow 32 bit calculations
Converts float literals from double format (e.g. 0.0) to float format (e.g. 0.0f) where appropriate for 32 bit calculations, and cast to (real_t) or (float) as appropriate.

This ensures that appropriate calculations will be done at 32 bits when real_t is compiled as float, rather than promoted to 64 bits.
2022-02-24 16:46:02 +00:00
lawnjelly
8ea20f5fdd Add OccluderShapePolygon
Add OccluderShapePolygon, glue to Occluder and gizmos etc.
2022-02-01 11:31:06 +00:00
Rémi Verschelde
a627cdafc5
Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-13 15:54:13 +01:00
Rémi Verschelde
42d385b312
clang-format: Disable alignment of operands, too unreliable
Sets `AlignOperands` to `DontAlign`.

`clang-format` developers seem to mostly care about space-based indentation and
every other version of clang-format breaks the bad mismatch of tabs and spaces
that it seems to use for operand alignment. So it's better without, so that it
respects our two-tabs `ContinuationIndentWidth`.
2021-10-28 13:23:38 +02:00
Aaron Franke
ebfba19b59
Use global scope round method for rounding
(cherry picked from commit b01aa69c80)
2021-05-21 13:41:27 +02:00
Hugo Locurcio
66a8654963
Remove #ifdef catering to MSVC 2012 and earlier in math_funcs.h
For the `master` branch, the minimum supported MSVC version is now
MSVC 2017 (with MSVC 2019 being recommended).

(cherry picked from commit b57d9c8005)
2021-05-21 13:41:27 +02:00
Aaron Franke
1154b6264c
[3.x] Make is_equal_approx have explicit float and double versions 2021-05-20 06:50:09 -04:00
Rémi Verschelde
140350d767
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
2021-05-05 15:02:01 +02:00
Rémi Verschelde
b5e1e05ef2
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks 2021-05-04 14:45:16 +02:00
kleonc
f04a964627 Make posmod use int64_t instead of int 2021-05-03 22:03:16 +02:00
Meriipu
347a9df0a1
GDScript: Clarified/fixed inaccuracies in the built-in function docs.
The input to smoothstep is not actually a weight, and the decscription
of smoothstep was pretty hard to understand and easy to misinterpret.

Clarified what it means to be approximately equal.

nearest_po2 does not do what the descriptions says it does. For one,
it returns the same power if the input is a power of 2. Second, it
returns 0 if the input is negative or 0, while the smallest possible
integral power of 2 actually is 1 (2^0 = 1). Due to the implementation
and how it is used in a lot of places, it does not seem wise to change
such a core function however, and I decided it is better to alter the
description of the built-in.

Added a few examples/clarifications/edge-cases.

(cherry picked from commit 7f9bfee0ac)
2021-02-11 13:12:06 +01:00
Rémi Verschelde
49646383f1
Update copyright statements to 2021
Happy new year to the wonderful Godot community!

2020 has been a tough year for most of us personally, but a good year for
Godot development nonetheless with a huge amount of work done towards Godot
4.0 and great improvements backported to the long-lived 3.2 branch.

We've had close to 400 contributors to engine code this year, authoring near
7,000 commit! (And that's only for the `master` branch and for the engine code,
there's a lot more when counting docs, demos and other first-party repos.)

Here's to a great year 2021 for all Godot users 🎆

(cherry picked from commit b5334d14f7)
2021-01-13 16:17:06 +01:00
Rémi Verschelde
cb78a5d7ae
Linux/BSD: Fix support for NetBSD
Add __NetBSD__ to `platform_config.h` so that it can find `alloca`
and use the proper `pthread_setname_np` format.

Rename RANDOM_MAX to avoid conflict with NetBSD stdlib.

Fixes #42145.

(cherry picked from commit 5f4d64f4f3)
2020-09-18 10:29:52 +02:00
Rémi Verschelde
a7f49ac9a1 Update copyright statements to 2020
Happy new year to the wonderful Godot community!

We're starting a new decade with a well-established, non-profit, free
and open source game engine, and tons of further improvements in the
pipeline from hundreds of contributors.

Godot will keep getting better, and we're looking forward to all the
games that the community will keep developing and releasing with it.
2020-01-01 11:16:22 +01:00
Aaron Franke
8754e21f48
Fix "seperate" typos 2019-10-31 08:52:26 -04:00
Aaron Franke
f8b4cf0fc4
Check for exact equality before approximate equality 2019-09-01 14:02:14 -04:00
Aaron Franke
a9c10450bd
[Core] [Mono] Optimize Wrap functions
Use is_zero_approx(), avoid a negative, and also rename "rng" to "range".
2019-08-04 20:38:38 -07:00
Rémi Verschelde
d844e30614 Inspector: Make default float step configurable
Also allow lifting the decimal step formatting with a hint range step
of 0. A new `range_step_decimals()` is added for this to avoid breaking
compatibility on the general purpose `step_decimals()` (which still
returns 0 for an input step of 0).

Supersedes #25470.
Partial fix for #18251.
2019-07-23 17:31:38 +02:00
Chaosus
6694c119d0 Added lerp_angles built-in function
Co-authored-by: Xrayez <https://github.com/Xrayez>
Co-authored-by: DleanJeans <https://github.com/DleanJeans>
2019-07-20 12:59:41 +03:00
Aaron Franke
a60f242982 Add integer posmod and rename default arg names
"posmod" is the integer version of "fposmod". We do not need a "mod" because of the % operator.

I changed the default arg names from "x" and "y" to "a" and "b" because they are not coordinates. I also changed pow's arg names to "base" and "exp". Also, I reorganized the code in the VS built-in funcs switch statement.
2019-07-18 16:33:43 -04:00
Giacom
c00427add3 Added move_toward functions for float, Vector2 and Vector3 2019-05-28 11:39:35 +01:00
Daw11
28bff3d1ad Implement Lanczos image filter 2019-05-05 14:03:56 +02:00
Aaron Franke
b2e1c9c276
[Core] Approximate equality 2019-04-25 13:20:29 -04:00
Rémi Verschelde
d211aff777
Merge pull request #27231 from Chaosus/smoothstep
Added smoothstep built-in function
2019-04-08 10:03:42 +02:00
Chaosus
514a3fb96a Added smoothstep built-in function 2019-04-07 14:11:26 +03:00
Juan Linietsky
dee98d3b6d Some improvements to is_equal_approx, restored Quat operator. 2019-04-01 11:11:02 -03:00
Juan Linietsky
a32b26dfa2 Several fixes to make GLES2 on HTML5 work much better.
Changed math class error reporting to be a bit less paranoid.
2019-02-25 21:47:29 -03:00
Chaosus
bc4d781277 Fix wrapi to use int64_t instead int 2019-02-25 10:51:04 +03:00
Hugo Locurcio
18b90508a1
Fix crash when using wrapi() with a range of zero
`wrapi()` and `wrapf()` will now return the value of
the `min` parameter if the range is equal to zero.
2019-02-23 16:16:32 +01:00
Pierrick Brunet
3b6d05db3e Fix typo for randd and randf
* And improve documentation according to issue #25938
2019-02-16 21:05:18 +01:00
Rémi Verschelde
b16c309f82 Update copyright statements to 2019
Happy new year to the wonderful Godot community!
2019-01-01 12:58:10 +01:00
Chaosus
f8151a9e50 Implement random number generator
Co-authored-by: Zirak <zirakertan@gmail.com>
2018-11-13 10:50:07 +03:00
Aaron Franke
81be9542eb Remove unused "dtoll" methods
These methods aren't used anywhere in Godot's code, and all they do is cast floating types to int64_t. There's no reason to have these lines, they literally do nothing, and they aren't useful functions to begin with.
2018-11-02 05:02:27 -04:00
Leon Krause
5f45476dc1 Fix warnings in HTML5 build outside platform files 2018-10-06 00:08:17 +02:00
Rémi Verschelde
277b24dfb7 Make core/ includes absolute, remove subfolders from include path
This allows more consistency in the manner we include core headers,
where previously there would be a mix of absolute, relative and
include path-dependent includes.
2018-09-12 09:52:22 +02:00
Aaron Franke
9170d932e3 [Core] Grammar, move defs to defs
Math constant definitions belong in `math_defs.h`. Also, the grammer in these files really needed some updating.
2018-08-10 22:42:02 -05:00
Aaron Franke
eebe41b1b0 [Core] [Math] Fix fposmod() function
ffff


meth
2018-06-10 15:06:44 -05:00
Chaosus
ac4c340a45 Small performance fix to wrapf 2018-04-13 13:50:17 +03:00
Chaosus
70bb31a7b2 Update wrap functions 2018-03-06 10:34:37 +03:00
Rémi Verschelde
e4213e66b2 Add missing copyright headers and fix formatting
Using `misc/scripts/fix_headers.py` on all Godot files.
Some missing header guards were added, and the header inclusion order
was fixed in the Bullet module.
2018-01-05 01:22:23 +01:00
Rémi Verschelde
b50a9114b1 Update copyright statements to 2018
Happy new year to the wonderful Godot community!
2018-01-01 14:40:47 +01:00
Rémi Verschelde
13c2ff9320 Style: Apply new clang-format 5.0 style to all files 2017-12-07 08:02:00 +01:00
Goutte
91ca725f9b Add support for the TAU constant. Fixes #12094. 2017-11-12 13:32:35 +01:00
Rémi Verschelde
ed57f0a0d4 Remove get_default_video_mode definition on OSX/iOS
It had been missed in d09160a8b6 and broke compilation
for those platforms.

Took the opportunity to run clang-format on the code base to fix some corner cases
that went through our static tests/were overlooked recently.
2017-11-09 23:36:08 +01:00
Rémi Verschelde
ea0e942617
Merge pull request #12035 from Chaosus/wrapfunc
Added new Wrap functions for numbers
2017-10-31 23:30:50 +01:00
Rémi Verschelde
99c8a8c7b1 Merge pull request #11401 from SaracenOne/snapped_drag
Added snapping to spatial drag and drop.
2017-10-22 12:06:00 +02:00