summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/a_star.cpp10
-rw-r--r--core/math/delaunay_3d.h3
-rw-r--r--core/math/dynamic_bvh.cpp2
-rw-r--r--core/math/expression.cpp4
-rw-r--r--core/math/face3.h4
-rw-r--r--core/math/geometry_3d.h2
-rw-r--r--core/math/math_defs.h2
-rw-r--r--core/math/math_funcs.cpp10
-rw-r--r--core/math/math_funcs.h1
-rw-r--r--core/math/quick_hull.cpp34
-rw-r--r--core/math/triangle_mesh.cpp12
-rw-r--r--core/math/vector2.h8
12 files changed, 40 insertions, 52 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 88e11a630c..322eb7ac61 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -35,18 +35,12 @@
#include "scene/scene_string_names.h"
int AStar::get_available_point_id() const {
- if (points.is_empty()) {
- return 1;
- }
-
- // calculate our new next available point id if bigger than before or next id already contained in set of points.
if (points.has(last_free_id)) {
- int cur_new_id = last_free_id;
+ int cur_new_id = last_free_id + 1;
while (points.has(cur_new_id)) {
cur_new_id++;
}
- int &non_const = const_cast<int &>(last_free_id);
- non_const = cur_new_id;
+ const_cast<int &>(last_free_id) = cur_new_id;
}
return last_free_id;
diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h
index 6f7209556e..81adf4d19a 100644
--- a/core/math/delaunay_3d.h
+++ b/core/math/delaunay_3d.h
@@ -375,8 +375,7 @@ public:
OutputSimplex *ret_simplicesw = ret_simplices.ptrw();
uint32_t simplices_written = 0;
- for (List<Simplex *>::Element *E = simplex_list.front(); E; E = E->next()) {
- Simplex *simplex = E->get();
+ for (Simplex *simplex : simplex_list) {
bool invalid = false;
for (int j = 0; j < 4; j++) {
if (simplex->points[j] >= point_count) {
diff --git a/core/math/dynamic_bvh.cpp b/core/math/dynamic_bvh.cpp
index 8e596f0f9d..f3fb473981 100644
--- a/core/math/dynamic_bvh.cpp
+++ b/core/math/dynamic_bvh.cpp
@@ -181,7 +181,7 @@ DynamicBVH::Volume DynamicBVH::_bounds(Node **leaves, int p_count) {
void DynamicBVH::_bottom_up(Node **leaves, int p_count) {
while (p_count > 1) {
- real_t minsize = Math_INF;
+ real_t minsize = INFINITY;
int minidx[2] = { -1, -1 };
for (int i = 0; i < p_count; ++i) {
for (int j = i + 1; j < p_count; ++j) {
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 0146c345f0..05f2c8dac9 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -397,10 +397,10 @@ Error Expression::_get_token(Token &r_token) {
r_token.value = Math_TAU;
} else if (id == "INF") {
r_token.type = TK_CONSTANT;
- r_token.value = Math_INF;
+ r_token.value = INFINITY;
} else if (id == "NAN") {
r_token.type = TK_CONSTANT;
- r_token.value = Math_NAN;
+ r_token.value = NAN;
} else if (id == "not") {
r_token.type = TK_OP_NOT;
} else if (id == "or") {
diff --git a/core/math/face3.h b/core/math/face3.h
index 5091b338ef..9e9026e54e 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -50,8 +50,8 @@ public:
/**
*
* @param p_plane plane used to split the face
- * @param p_res array of at least 3 faces, amount used in functio return
- * @param p_is_point_over array of at least 3 booleans, determining which face is over the plane, amount used in functio return
+ * @param p_res array of at least 3 faces, amount used in function return
+ * @param p_is_point_over array of at least 3 booleans, determining which face is over the plane, amount used in function return
* @param _epsilon constant used for numerical error rounding, to add "thickness" to the plane (so coplanar points can happen)
* @return amount of faces generated by the split, either 0 (means no split possible), 2 or 3
*/
diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h
index 4ef9b4dbe6..766689e222 100644
--- a/core/math/geometry_3d.h
+++ b/core/math/geometry_3d.h
@@ -40,7 +40,7 @@ class Geometry3D {
public:
static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) {
-// Do the function 'd' as defined by pb. I think is is dot product of some sort.
+// Do the function 'd' as defined by pb. I think it's a dot product of some sort.
#define d_of(m, n, o, p) ((m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z))
// Calculate the parametric position on the 2 curves, mua and mub.
diff --git a/core/math/math_defs.h b/core/math/math_defs.h
index df2223fb78..7692e1be47 100644
--- a/core/math/math_defs.h
+++ b/core/math/math_defs.h
@@ -43,8 +43,6 @@
#define Math_TAU 6.2831853071795864769252867666
#define Math_PI 3.1415926535897932384626433833
#define Math_E 2.7182818284590452353602874714
-#define Math_INF INFINITY
-#define Math_NAN NAN
#ifdef DEBUG_ENABLED
#define MATH_CHECKS
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index e92bb9f4aa..bbed257f60 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -88,16 +88,6 @@ int Math::range_step_decimals(double p_step) {
return step_decimals(p_step);
}
-double Math::dectime(double p_value, double p_amount, double p_step) {
- double sgn = p_value < 0 ? -1.0 : 1.0;
- double val = Math::abs(p_value);
- val -= p_amount * p_step;
- if (val < 0.0) {
- val = 0.0;
- }
- return val * sgn;
-}
-
double Math::ease(double p_x, double p_c) {
if (p_x < 0) {
p_x = 0;
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 3389407e72..4e4f566517 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -296,7 +296,6 @@ public:
static int step_decimals(double p_step);
static int range_step_decimals(double p_step);
static double snapped(double p_value, double p_step);
- static double dectime(double p_value, double p_amount, double p_step);
static uint32_t larger_prime(uint32_t p_val);
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index 0d77bfe933..0960fe19a6 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -192,9 +192,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
continue;
}
- for (List<Face>::Element *E = faces.front(); E; E = E->next()) {
- if (E->get().plane.distance_to(p_points[i]) > over_tolerance) {
- E->get().points_over.push_back(i);
+ for (Face &E : faces) {
+ if (E.plane.distance_to(p_points[i]) > over_tolerance) {
+ E.points_over.push_back(i);
break;
}
}
@@ -292,8 +292,8 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
//distribute points into new faces
- for (List<List<Face>::Element *>::Element *F = lit_faces.front(); F; F = F->next()) {
- Face &lf = F->get()->get();
+ for (List<Face>::Element *&F : lit_faces) {
+ Face &lf = F->get();
for (int i = 0; i < lf.points_over.size(); i++) {
if (lf.points_over[i] == f.points_over[next]) { //do not add current one
@@ -301,8 +301,8 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
}
Vector3 p = p_points[lf.points_over[i]];
- for (List<List<Face>::Element *>::Element *E = new_faces.front(); E; E = E->next()) {
- Face &f2 = E->get()->get();
+ for (List<Face>::Element *&E : new_faces) {
+ Face &f2 = E->get();
if (f2.plane.distance_to(p) > over_tolerance) {
f2.points_over.push_back(lf.points_over[i]);
break;
@@ -320,10 +320,10 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
//put faces that contain no points on the front
- for (List<List<Face>::Element *>::Element *E = new_faces.front(); E; E = E->next()) {
- Face &f2 = E->get()->get();
+ for (List<Face>::Element *&E : new_faces) {
+ Face &f2 = E->get();
if (f2.points_over.size() == 0) {
- faces.move_to_front(E->get());
+ faces.move_to_front(E);
}
}
@@ -336,19 +336,19 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
Map<Edge, RetFaceConnect> ret_edges;
List<Geometry3D::MeshData::Face> ret_faces;
- for (List<Face>::Element *E = faces.front(); E; E = E->next()) {
+ for (const Face &E : faces) {
Geometry3D::MeshData::Face f;
- f.plane = E->get().plane;
+ f.plane = E.plane;
for (int i = 0; i < 3; i++) {
- f.indices.push_back(E->get().vertices[i]);
+ f.indices.push_back(E.vertices[i]);
}
List<Geometry3D::MeshData::Face>::Element *F = ret_faces.push_back(f);
for (int i = 0; i < 3; i++) {
- uint32_t a = E->get().vertices[i];
- uint32_t b = E->get().vertices[(i + 1) % 3];
+ uint32_t a = E.vertices[i];
+ uint32_t b = E.vertices[(i + 1) % 3];
Edge e(a, b);
Map<Edge, RetFaceConnect>::Element *G = ret_edges.find(e);
@@ -439,8 +439,8 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
r_mesh.faces.resize(ret_faces.size());
int idx = 0;
- for (List<Geometry3D::MeshData::Face>::Element *E = ret_faces.front(); E; E = E->next()) {
- r_mesh.faces.write[idx++] = E->get();
+ for (const Geometry3D::MeshData::Face &E : ret_faces) {
+ r_mesh.faces.write[idx++] = E;
}
r_mesh.edges.resize(ret_edges.size());
idx = 0;
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 903d5951a8..bf06c848c5 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -32,9 +32,9 @@
#include "core/templates/sort_array.h"
-int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc) {
- if (p_depth > max_depth) {
- max_depth = p_depth;
+int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &r_max_depth, int &r_max_alloc) {
+ if (p_depth > r_max_depth) {
+ r_max_depth = p_depth;
}
if (p_size == 1) {
@@ -70,10 +70,10 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in
} break;
}
- int left = _create_bvh(p_bvh, p_bb, p_from, p_size / 2, p_depth + 1, max_depth, max_alloc);
- int right = _create_bvh(p_bvh, p_bb, p_from + p_size / 2, p_size - p_size / 2, p_depth + 1, max_depth, max_alloc);
+ int left = _create_bvh(p_bvh, p_bb, p_from, p_size / 2, p_depth + 1, r_max_depth, r_max_alloc);
+ int right = _create_bvh(p_bvh, p_bb, p_from + p_size / 2, p_size - p_size / 2, p_depth + 1, r_max_depth, r_max_alloc);
- int index = max_alloc++;
+ int index = r_max_alloc++;
BVH *_new = &p_bvh[index];
_new->aabb = aabb;
_new->center = aabb.position + aabb.size * 0.5;
diff --git a/core/math/vector2.h b/core/math/vector2.h
index 78deb473b4..4d9f3126e9 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -300,6 +300,14 @@ struct Vector2i {
return p_idx ? y : x;
}
+ _FORCE_INLINE_ int min_axis() const {
+ return x < y ? 0 : 1;
+ }
+
+ _FORCE_INLINE_ int max_axis() const {
+ return x < y ? 1 : 0;
+ }
+
Vector2i min(const Vector2i &p_vector2i) const {
return Vector2(MIN(x, p_vector2i.x), MIN(y, p_vector2i.y));
}