Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/variant/variant_utility.h
9896 views
1
/**************************************************************************/
2
/* variant_utility.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "variant.h"
34
35
struct VariantUtilityFunctions {
36
// Math
37
static double sin(double arg);
38
static double cos(double arg);
39
static double tan(double arg);
40
static double sinh(double arg);
41
static double cosh(double arg);
42
static double tanh(double arg);
43
static double asin(double arg);
44
static double acos(double arg);
45
static double atan(double arg);
46
static double atan2(double y, double x);
47
static double asinh(double arg);
48
static double acosh(double arg);
49
static double atanh(double arg);
50
static double sqrt(double x);
51
static double fmod(double b, double r);
52
static double fposmod(double b, double r);
53
static int64_t posmod(int64_t b, int64_t r);
54
static Variant floor(const Variant &x, Callable::CallError &r_error);
55
static double floorf(double x);
56
static int64_t floori(double x);
57
static Variant ceil(const Variant &x, Callable::CallError &r_error);
58
static double ceilf(double x);
59
static int64_t ceili(double x);
60
static Variant round(const Variant &x, Callable::CallError &r_error);
61
static double roundf(double x);
62
static int64_t roundi(double x);
63
static Variant abs(const Variant &x, Callable::CallError &r_error);
64
static double absf(double x);
65
static int64_t absi(int64_t x);
66
static Variant sign(const Variant &x, Callable::CallError &r_error);
67
static double signf(double x);
68
static int64_t signi(int64_t x);
69
static double pow(double x, double y);
70
static double log(double x);
71
static double exp(double x);
72
static bool is_nan(double x);
73
static bool is_inf(double x);
74
static bool is_equal_approx(double x, double y);
75
static bool is_zero_approx(double x);
76
static bool is_finite(double x);
77
static double ease(float x, float curve);
78
static int step_decimals(float step);
79
static Variant snapped(const Variant &x, const Variant &step, Callable::CallError &r_error);
80
static double snappedf(double x, double step);
81
static int64_t snappedi(double x, int64_t step);
82
static Variant lerp(const Variant &from, const Variant &to, double weight, Callable::CallError &r_error);
83
static double lerpf(double from, double to, double weight);
84
static double cubic_interpolate(double from, double to, double pre, double post, double weight);
85
static double cubic_interpolate_angle(double from, double to, double pre, double post, double weight);
86
static double cubic_interpolate_in_time(double from, double to, double pre, double post, double weight,
87
double to_t, double pre_t, double post_t);
88
static double cubic_interpolate_angle_in_time(double from, double to, double pre, double post, double weight,
89
double to_t, double pre_t, double post_t);
90
static double bezier_interpolate(double p_start, double p_control_1, double p_control_2, double p_end, double p_t);
91
static double bezier_derivative(double p_start, double p_control_1, double p_control_2, double p_end, double p_t);
92
static double angle_difference(double from, double to);
93
static double lerp_angle(double from, double to, double weight);
94
static double inverse_lerp(double from, double to, double weight);
95
static double remap(double value, double istart, double istop, double ostart, double ostop);
96
static double smoothstep(double from, double to, double val);
97
static double move_toward(double from, double to, double delta);
98
static double rotate_toward(double from, double to, double delta);
99
static double deg_to_rad(double angle_deg);
100
static double rad_to_deg(double angle_rad);
101
static double linear_to_db(double linear);
102
static double db_to_linear(double db);
103
static Variant wrap(const Variant &p_x, const Variant &p_min, const Variant &p_max, Callable::CallError &r_error);
104
static int64_t wrapi(int64_t value, int64_t min, int64_t max);
105
static double wrapf(double value, double min, double max);
106
static double pingpong(double value, double length);
107
static Variant max(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
108
static double maxf(double x, double y);
109
static int64_t maxi(int64_t x, int64_t y);
110
static Variant min(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
111
static double minf(double x, double y);
112
static int64_t mini(int64_t x, int64_t y);
113
static Variant clamp(const Variant &x, const Variant &min, const Variant &max, Callable::CallError &r_error);
114
static double clampf(double x, double min, double max);
115
static int64_t clampi(int64_t x, int64_t min, int64_t max);
116
static int64_t nearest_po2(int64_t x);
117
// Random
118
static void randomize();
119
static int64_t randi();
120
static double randf();
121
static double randfn(double mean, double deviation);
122
static int64_t randi_range(int64_t from, int64_t to);
123
static double randf_range(double from, double to);
124
static void seed(int64_t s);
125
static PackedInt64Array rand_from_seed(int64_t seed);
126
// Utility
127
static Variant weakref(const Variant &obj, Callable::CallError &r_error);
128
static int64_t _typeof(const Variant &obj);
129
static Variant type_convert(const Variant &p_variant, const Variant::Type p_type);
130
static String str(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
131
static String error_string(Error error);
132
static String type_string(Variant::Type p_type);
133
static void print(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
134
static void print_rich(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
135
static void _print_verbose(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
136
static void printerr(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
137
static void printt(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
138
static void prints(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
139
static void printraw(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
140
static void push_error(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
141
static void push_warning(const Variant **p_args, int p_arg_count, Callable::CallError &r_error);
142
static String var_to_str(const Variant &p_var);
143
static Variant str_to_var(const String &p_var);
144
static PackedByteArray var_to_bytes(const Variant &p_var);
145
static PackedByteArray var_to_bytes_with_objects(const Variant &p_var);
146
static Variant bytes_to_var(const PackedByteArray &p_arr);
147
static Variant bytes_to_var_with_objects(const PackedByteArray &p_arr);
148
static int64_t hash(const Variant &p_arr);
149
static Object *instance_from_id(int64_t p_id);
150
static bool is_instance_id_valid(int64_t p_id);
151
static bool is_instance_valid(const Variant &p_instance);
152
static uint64_t rid_allocate_id();
153
static RID rid_from_int64(uint64_t p_base);
154
static bool is_same(const Variant &p_a, const Variant &p_b);
155
static String join_string(const Variant **p_args, int p_arg_count);
156
};
157
158