summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/a_star.cpp38
-rw-r--r--core/math/a_star.h2
-rw-r--r--core/math/a_star_grid_2d.cpp2
-rw-r--r--core/math/bvh.h8
-rw-r--r--core/math/bvh_abb.h2
-rw-r--r--core/math/bvh_split.inc8
-rw-r--r--core/math/color.cpp2
-rw-r--r--core/math/delaunay_3d.h12
-rw-r--r--core/math/expression.cpp9
-rw-r--r--core/math/geometry_3d.cpp28
10 files changed, 52 insertions, 59 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index a54804c5dc..646bdea758 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -106,11 +106,11 @@ void AStar3D::remove_point(int64_t p_id) {
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_MSG(!p_exists, vformat("Can't remove point. Point with id: %d doesn't exist.", p_id));
- for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
+ for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) {
Segment s(p_id, (*it.key));
segments.erase(s);
- (*it.value)->neighbours.remove(p->id);
+ (*it.value)->neighbors.remove(p->id);
(*it.value)->unlinked_neighbours.remove(p->id);
}
@@ -118,7 +118,7 @@ void AStar3D::remove_point(int64_t p_id) {
Segment s(p_id, (*it.key));
segments.erase(s);
- (*it.value)->neighbours.remove(p->id);
+ (*it.value)->neighbors.remove(p->id);
(*it.value)->unlinked_neighbours.remove(p->id);
}
@@ -138,10 +138,10 @@ void AStar3D::connect_points(int64_t p_id, int64_t p_with_id, bool bidirectional
bool to_exists = points.lookup(p_with_id, b);
ERR_FAIL_COND_MSG(!to_exists, vformat("Can't connect points. Point with id: %d doesn't exist.", p_with_id));
- a->neighbours.set(b->id, b);
+ a->neighbors.set(b->id, b);
if (bidirectional) {
- b->neighbours.set(a->id, a);
+ b->neighbors.set(a->id, a);
} else {
b->unlinked_neighbours.set(a->id, a);
}
@@ -155,7 +155,7 @@ void AStar3D::connect_points(int64_t p_id, int64_t p_with_id, bool bidirectional
if (element) {
s.direction |= element->direction;
if (s.direction == Segment::BIDIRECTIONAL) {
- // Both are neighbours of each other now
+ // Both are neighbors of each other now
a->unlinked_neighbours.remove(b->id);
b->unlinked_neighbours.remove(a->id);
}
@@ -183,9 +183,9 @@ void AStar3D::disconnect_points(int64_t p_id, int64_t p_with_id, bool bidirectio
// Erase the directions to be removed
s.direction = (element->direction & ~remove_direction);
- a->neighbours.remove(b->id);
+ a->neighbors.remove(b->id);
if (bidirectional) {
- b->neighbours.remove(a->id);
+ b->neighbors.remove(a->id);
if (element->direction != Segment::BIDIRECTIONAL) {
a->unlinked_neighbours.remove(b->id);
b->unlinked_neighbours.remove(a->id);
@@ -226,7 +226,7 @@ Vector<int64_t> AStar3D::get_point_connections(int64_t p_id) {
Vector<int64_t> point_list;
- for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
+ for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) {
point_list.push_back((*it.key));
}
@@ -346,8 +346,8 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) {
open_list.remove_at(open_list.size() - 1);
p->closed_pass = pass; // Mark the point as closed
- for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
- Point *e = *(it.value); // The neighbour point
+ for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) {
+ Point *e = *(it.value); // The neighbor point
if (!e->enabled || e->closed_pass == pass) {
continue;
@@ -794,7 +794,7 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
bool found_route = false;
- Vector<AStar3D::Point *> open_list;
+ LocalVector<AStar3D::Point *> open_list;
SortArray<AStar3D::Point *, AStar3D::SortPoints> sorter;
begin_point->g_score = 0;
@@ -802,19 +802,19 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
open_list.push_back(begin_point);
while (!open_list.is_empty()) {
- AStar3D::Point *p = open_list[0]; // The currently processed point
+ AStar3D::Point *p = open_list[0]; // The currently processed point.
if (p == end_point) {
found_route = true;
break;
}
- sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list
+ sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list.
open_list.remove_at(open_list.size() - 1);
- p->closed_pass = astar.pass; // Mark the point as closed
+ p->closed_pass = astar.pass; // Mark the point as closed.
- for (OAHashMap<int64_t, AStar3D::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
- AStar3D::Point *e = *(it.value); // The neighbour point
+ for (OAHashMap<int64_t, AStar3D::Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) {
+ AStar3D::Point *e = *(it.value); // The neighbor point.
if (!e->enabled || e->closed_pass == astar.pass) {
continue;
@@ -837,9 +837,9 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
e->f_score = e->g_score + _estimate_cost(e->id, end_point->id);
if (new_point) { // The position of the new points is already known.
- sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr());
} else {
- sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr());
}
}
}
diff --git a/core/math/a_star.h b/core/math/a_star.h
index a475e4f2fc..fc4bb09f03 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -52,7 +52,7 @@ class AStar3D : public RefCounted {
real_t weight_scale = 0;
bool enabled = false;
- OAHashMap<int64_t, Point *> neighbours = 4u;
+ OAHashMap<int64_t, Point *> neighbors = 4u;
OAHashMap<int64_t, Point *> unlinked_neighbours = 4u;
// Used for pathfinding.
diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp
index 30d50073d7..677e609763 100644
--- a/core/math/a_star_grid_2d.cpp
+++ b/core/math/a_star_grid_2d.cpp
@@ -401,7 +401,7 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) {
List<Point *> nbors;
_get_nbors(p, nbors);
for (List<Point *>::Element *E = nbors.front(); E; E = E->next()) {
- Point *e = E->get(); // The neighbour point.
+ Point *e = E->get(); // The neighbor point.
real_t weight_scale = 1.0;
if (jumping_enabled) {
diff --git a/core/math/bvh.h b/core/math/bvh.h
index 9de704834b..357d483375 100644
--- a/core/math/bvh.h
+++ b/core/math/bvh.h
@@ -444,9 +444,7 @@ private:
params.result_array = nullptr;
params.subindex_array = nullptr;
- for (unsigned int n = 0; n < changed_items.size(); n++) {
- const BVHHandle &h = changed_items[n];
-
+ for (const BVHHandle &h : changed_items) {
// use the expanded aabb for pairing
const BOUNDS &expanded_aabb = tree._pairs[h.id()].expanded_aabb;
BVHABB_CLASS abb;
@@ -465,9 +463,7 @@ private:
params.result_count_overall = 0; // might not be needed
tree.cull_aabb(params, false);
- for (unsigned int i = 0; i < tree._cull_hits.size(); i++) {
- uint32_t ref_id = tree._cull_hits[i];
-
+ for (const uint32_t ref_id : tree._cull_hits) {
// don't collide against ourself
if (ref_id == changed_item_ref_id) {
continue;
diff --git a/core/math/bvh_abb.h b/core/math/bvh_abb.h
index 32b011bd3b..fb0207e0bd 100644
--- a/core/math/bvh_abb.h
+++ b/core/math/bvh_abb.h
@@ -87,7 +87,7 @@ struct BVH_ABB {
return -neg_max - min;
}
- POINT calculate_centre() const {
+ POINT calculate_center() const {
return POINT((calculate_size() * 0.5) + min);
}
diff --git a/core/math/bvh_split.inc b/core/math/bvh_split.inc
index 180bbfb511..875abedb70 100644
--- a/core/math/bvh_split.inc
+++ b/core/math/bvh_split.inc
@@ -25,7 +25,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
return;
}
- POINT centre = full_bound.calculate_centre();
+ POINT center = full_bound.calculate_center();
POINT size = full_bound.calculate_size();
int order[POINT::AXIS_COUNT];
@@ -43,7 +43,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
for (int a = 0; a < num_a; a++) {
uint32_t ind = group_a[a];
- if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) {
+ if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) {
// add to b
group_b[num_b++] = ind;
@@ -75,7 +75,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
for (int a = 0; a < num_a; a++) {
uint32_t ind = group_a[a];
- if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) {
+ if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) {
count++;
}
}
@@ -100,7 +100,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
for (int a = 0; a < num_a; a++) {
uint32_t ind = group_a[a];
- if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) {
+ if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) {
// add to b
group_b[num_b++] = ind;
diff --git a/core/math/color.cpp b/core/math/color.cpp
index 5bae8d25d6..3e5fa7b402 100644
--- a/core/math/color.cpp
+++ b/core/math/color.cpp
@@ -194,7 +194,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
a = p_alpha;
if (p_s == 0.0f) {
- // Achromatic (grey)
+ // Achromatic (gray)
r = g = b = p_v;
return;
}
diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h
index 8ca38d571a..55923e0133 100644
--- a/core/math/delaunay_3d.h
+++ b/core/math/delaunay_3d.h
@@ -313,20 +313,20 @@ public:
//remove simplex and continue
simplex_list.erase(simplex->SE);
- for (uint32_t k = 0; k < simplex->grid_positions.size(); k++) {
- Vector3i p = simplex->grid_positions[k].pos;
- acceleration_grid[p.x][p.y][p.z].erase(simplex->grid_positions[k].E);
+ for (const GridPos &gp : simplex->grid_positions) {
+ Vector3i p = gp.pos;
+ acceleration_grid[p.x][p.y][p.z].erase(gp.E);
}
memdelete(simplex);
}
E = N;
}
- for (uint32_t j = 0; j < triangles.size(); j++) {
- if (triangles[j].bad) {
+ for (const Triangle &triangle : triangles) {
+ if (triangle.bad) {
continue;
}
- Simplex *new_simplex = memnew(Simplex(triangles[j].triangle[0], triangles[j].triangle[1], triangles[j].triangle[2], i));
+ Simplex *new_simplex = memnew(Simplex(triangle.triangle[0], triangle.triangle[1], triangle.triangle[2], i));
circum_sphere_compute(points, new_simplex);
new_simplex->SE = simplex_list.push_back(new_simplex);
{
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index da52bb9465..d1ec987d56 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -434,14 +434,13 @@ Error Expression::_get_token(Token &r_token) {
}
return OK;
- } else if (is_ascii_char(cchar) || is_underscore(cchar)) {
- String id;
- bool first = true;
+ } else if (is_unicode_identifier_start(cchar)) {
+ String id = String::chr(cchar);
+ cchar = GET_CHAR();
- while (is_ascii_char(cchar) || is_underscore(cchar) || (!first && is_digit(cchar))) {
+ while (is_unicode_identifier_continue(cchar)) {
id += String::chr(cchar);
cchar = GET_CHAR();
- first = false;
}
str_ofs--; //go back one
diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp
index 51523ea296..4786110054 100644
--- a/core/math/geometry_3d.cpp
+++ b/core/math/geometry_3d.cpp
@@ -141,21 +141,19 @@ real_t Geometry3D::get_closest_distance_between_segments(const Vector3 &p_p0, co
void Geometry3D::MeshData::optimize_vertices() {
HashMap<int, int> vtx_remap;
- for (uint32_t i = 0; i < faces.size(); i++) {
- for (uint32_t j = 0; j < faces[i].indices.size(); j++) {
- int idx = faces[i].indices[j];
- if (!vtx_remap.has(idx)) {
+ for (MeshData::Face &face : faces) {
+ for (int &index : face.indices) {
+ if (!vtx_remap.has(index)) {
int ni = vtx_remap.size();
- vtx_remap[idx] = ni;
+ vtx_remap[index] = ni;
}
-
- faces[i].indices[j] = vtx_remap[idx];
+ index = vtx_remap[index];
}
}
- for (uint32_t i = 0; i < edges.size(); i++) {
- int a = edges[i].vertex_a;
- int b = edges[i].vertex_b;
+ for (MeshData::Edge edge : edges) {
+ int a = edge.vertex_a;
+ int b = edge.vertex_b;
if (!vtx_remap.has(a)) {
int ni = vtx_remap.size();
@@ -166,8 +164,8 @@ void Geometry3D::MeshData::optimize_vertices() {
vtx_remap[b] = ni;
}
- edges[i].vertex_a = vtx_remap[a];
- edges[i].vertex_b = vtx_remap[b];
+ edge.vertex_a = vtx_remap[a];
+ edge.vertex_b = vtx_remap[b];
}
LocalVector<Vector3> new_vertices;
@@ -673,10 +671,10 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes
MeshData::Face face;
// Add face indices.
- for (uint32_t j = 0; j < vertices.size(); j++) {
+ for (const Vector3 &vertex : vertices) {
int idx = -1;
for (uint32_t k = 0; k < mesh.vertices.size(); k++) {
- if (mesh.vertices[k].distance_to(vertices[j]) < 0.001f) {
+ if (mesh.vertices[k].distance_to(vertex) < 0.001f) {
idx = k;
break;
}
@@ -684,7 +682,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes
if (idx == -1) {
idx = mesh.vertices.size();
- mesh.vertices.push_back(vertices[j]);
+ mesh.vertices.push_back(vertex);
}
face.indices.push_back(idx);