summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/SCsub2
-rw-r--r--core/math/a_star.cpp27
-rw-r--r--core/math/a_star.h5
-rw-r--r--core/math/aabb.cpp2
-rw-r--r--core/math/aabb.h6
-rw-r--r--core/math/audio_frame.h2
-rw-r--r--core/math/bsp_tree.cpp5
-rw-r--r--core/math/bsp_tree.h14
-rw-r--r--core/math/camera_matrix.cpp5
-rw-r--r--core/math/camera_matrix.h5
-rw-r--r--core/math/delaunay.h2
-rw-r--r--core/math/expression.cpp49
-rw-r--r--core/math/face3.cpp3
-rw-r--r--core/math/face3.h8
-rw-r--r--core/math/geometry.cpp3
-rw-r--r--core/math/geometry.h17
-rw-r--r--core/math/math_fieldwise.cpp181
-rw-r--r--core/math/math_fieldwise.h42
-rw-r--r--core/math/math_funcs.cpp12
-rw-r--r--core/math/math_funcs.h4
-rw-r--r--core/math/matrix3.cpp8
-rw-r--r--core/math/matrix3.h6
-rw-r--r--core/math/octree.h14
-rw-r--r--core/math/plane.cpp2
-rw-r--r--core/math/plane.h2
-rw-r--r--core/math/quat.cpp5
-rw-r--r--core/math/quat.h10
-rw-r--r--core/math/quick_hull.cpp3
-rw-r--r--core/math/quick_hull.h8
-rw-r--r--core/math/rect2.cpp2
-rw-r--r--core/math/rect2.h2
-rw-r--r--core/math/transform.cpp7
-rw-r--r--core/math/transform.h8
-rw-r--r--core/math/transform_2d.h2
-rw-r--r--core/math/triangle_mesh.cpp3
-rw-r--r--core/math/triangle_mesh.h5
-rw-r--r--core/math/triangulate.cpp2
-rw-r--r--core/math/triangulate.h2
-rw-r--r--core/math/vector2.h4
-rw-r--r--core/math/vector3.cpp3
-rw-r--r--core/math/vector3.h19
41 files changed, 372 insertions, 139 deletions
diff --git a/core/math/SCsub b/core/math/SCsub
index 4efc902717..1c5f954470 100644
--- a/core/math/SCsub
+++ b/core/math/SCsub
@@ -3,5 +3,3 @@
Import('env')
env.add_source_files(env.core_sources, "*.cpp")
-
-Export('env')
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 021391da83..451c45cade 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -29,9 +29,10 @@
/*************************************************************************/
#include "a_star.h"
-#include "geometry.h"
+
+#include "core/math/geometry.h"
+#include "core/script_language.h"
#include "scene/scene_string_names.h"
-#include "script_language.h"
int AStar::get_available_point_id() const {
@@ -249,14 +250,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
n->distance = _compute_cost(begin_point->id, n->id) * n->weight_scale;
n->last_pass = pass;
open_list.add(&n->list);
-
- if (end_point == n) {
- found_route = true;
- break;
- }
}
- while (!found_route) {
+ while (true) {
if (open_list.first() == NULL) {
// No path found
@@ -276,13 +272,16 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
cost += _estimate_cost(p->id, end_point->id);
if (cost < least_cost) {
-
least_cost_point = E;
least_cost = cost;
}
}
Point *p = least_cost_point->self();
+ if (p == end_point) {
+ found_route = true;
+ break;
+ }
for (Set<Point *>::Element *E = p->neighbours.front(); E; E = E->next()) {
@@ -294,7 +293,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
// Already visited, is this cheaper?
if (e->distance > distance) {
-
e->prev_point = p;
e->distance = distance;
}
@@ -305,18 +303,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
e->distance = distance;
e->last_pass = pass; // Mark as used
open_list.add(&e->list);
-
- if (e == end_point) {
- // End reached; stop algorithm
- found_route = true;
- break;
- }
}
}
- if (found_route)
- break;
-
open_list.remove(least_cost_point);
}
diff --git a/core/math/a_star.h b/core/math/a_star.h
index 8c1b5f64cb..d2ef765006 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -31,8 +31,9 @@
#ifndef ASTAR_H
#define ASTAR_H
-#include "reference.h"
-#include "self_list.h"
+#include "core/reference.h"
+#include "core/self_list.h"
+
/**
A* pathfinding algorithm
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index e2e71dda92..d0cb2b5195 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -30,7 +30,7 @@
#include "aabb.h"
-#include "print_string.h"
+#include "core/print_string.h"
real_t AABB::get_area() const {
diff --git a/core/math/aabb.h b/core/math/aabb.h
index cdb8eb48a3..0b03b7d314 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -31,9 +31,9 @@
#ifndef AABB_H
#define AABB_H
-#include "math_defs.h"
-#include "plane.h"
-#include "vector3.h"
+#include "core/math/math_defs.h"
+#include "core/math/plane.h"
+#include "core/math/vector3.h"
/**
* AABB / AABB (Axis Aligned Bounding Box)
diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h
index 67ba025e1c..fde26e8056 100644
--- a/core/math/audio_frame.h
+++ b/core/math/audio_frame.h
@@ -31,7 +31,7 @@
#ifndef AUDIOFRAME_H
#define AUDIOFRAME_H
-#include "typedefs.h"
+#include "core/typedefs.h"
static inline float undenormalise(volatile float f) {
union {
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index 24096de551..6e51c56357 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "bsp_tree.h"
-#include "error_macros.h"
-#include "print_string.h"
+
+#include "core/error_macros.h"
+#include "core/print_string.h"
void BSP_Tree::from_aabb(const AABB &p_aabb) {
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h
index fb16818ae7..b06e6b8539 100644
--- a/core/math/bsp_tree.h
+++ b/core/math/bsp_tree.h
@@ -31,13 +31,13 @@
#ifndef BSP_TREE_H
#define BSP_TREE_H
-#include "aabb.h"
-#include "dvector.h"
-#include "face3.h"
-#include "method_ptrcall.h"
-#include "plane.h"
-#include "variant.h"
-#include "vector.h"
+#include "core/dvector.h"
+#include "core/math/aabb.h"
+#include "core/math/face3.h"
+#include "core/math/plane.h"
+#include "core/method_ptrcall.h"
+#include "core/variant.h"
+#include "core/vector.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 1ab9b3532e..3a082d5720 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "camera_matrix.h"
-#include "math_funcs.h"
-#include "print_string.h"
+
+#include "core/math/math_funcs.h"
+#include "core/print_string.h"
void CameraMatrix::set_identity() {
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index a689c7238a..bd20908ad9 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -31,8 +31,9 @@
#ifndef CAMERA_MATRIX_H
#define CAMERA_MATRIX_H
-#include "rect2.h"
-#include "transform.h"
+#include "core/math/rect2.h"
+#include "core/math/transform.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/math/delaunay.h b/core/math/delaunay.h
index d47dc5240b..9c5eef9069 100644
--- a/core/math/delaunay.h
+++ b/core/math/delaunay.h
@@ -31,7 +31,7 @@
#ifndef DELAUNAY_H
#define DELAUNAY_H
-#include "rect2.h"
+#include "core/math/rect2.h"
class Delaunay2D {
public:
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 53e6aae36c..a16267cf0a 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -30,13 +30,13 @@
#include "expression.h"
-#include "class_db.h"
-#include "func_ref.h"
-#include "io/marshalls.h"
-#include "math_funcs.h"
-#include "os/os.h"
-#include "reference.h"
-#include "variant_parser.h"
+#include "core/class_db.h"
+#include "core/func_ref.h"
+#include "core/io/marshalls.h"
+#include "core/math/math_funcs.h"
+#include "core/os/os.h"
+#include "core/reference.h"
+#include "core/variant_parser.h"
const char *Expression::func_name[Expression::FUNC_MAX] = {
"sin",
@@ -756,6 +756,10 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
////////
+static bool _is_number(CharType c) {
+ return (c >= '0' && c <= '9');
+}
+
Error Expression::_get_token(Token &r_token) {
while (true) {
@@ -813,17 +817,12 @@ Error Expression::_get_token(Token &r_token) {
r_token.type = TK_COLON;
return OK;
};
- case '.': {
-
- r_token.type = TK_PERIOD;
- return OK;
- };
case '$': {
r_token.type = TK_INPUT;
int index = 0;
do {
- if (expression[str_ofs] < '0' || expression[str_ofs] > '9') {
+ if (!_is_number(expression[str_ofs])) {
_set_error("Expected number after '$'");
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
@@ -832,7 +831,7 @@ Error Expression::_get_token(Token &r_token) {
index += expression[str_ofs] - '0';
str_ofs++;
- } while (expression[str_ofs] >= '0' && expression[str_ofs] <= '9');
+ } while (_is_number(expression[str_ofs]));
r_token.value = index;
return OK;
@@ -979,14 +978,14 @@ Error Expression::_get_token(Token &r_token) {
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
- if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
+ if (!(_is_number(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
_set_error("Malformed hex constant in string");
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
CharType v;
- if (c >= '0' && c <= '9') {
+ if (_is_number(c)) {
v = c - '0';
} else if (c >= 'a' && c <= 'f') {
v = c - 'a';
@@ -1032,7 +1031,8 @@ Error Expression::_get_token(Token &r_token) {
break;
}
- if (cchar >= '0' && cchar <= '9') {
+ CharType next_char = (str_ofs >= expression.length()) ? 0 : expression[str_ofs];
+ if (_is_number(cchar) || (cchar == '.' && _is_number(next_char))) {
//a number
String num;
@@ -1053,7 +1053,7 @@ Error Expression::_get_token(Token &r_token) {
switch (reading) {
case READING_INT: {
- if (c >= '0' && c <= '9') {
+ if (_is_number(c)) {
//pass
} else if (c == '.') {
reading = READING_DEC;
@@ -1067,7 +1067,7 @@ Error Expression::_get_token(Token &r_token) {
} break;
case READING_DEC: {
- if (c >= '0' && c <= '9') {
+ if (_is_number(c)) {
} else if (c == 'e') {
reading = READING_EXP;
@@ -1079,7 +1079,7 @@ Error Expression::_get_token(Token &r_token) {
} break;
case READING_EXP: {
- if (c >= '0' && c <= '9') {
+ if (_is_number(c)) {
exp_beg = true;
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
@@ -1114,7 +1114,7 @@ Error Expression::_get_token(Token &r_token) {
String id;
bool first = true;
- while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) {
+ while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && _is_number(cchar))) {
id += String::chr(cchar);
cchar = GET_CHAR();
@@ -1176,6 +1176,12 @@ Error Expression::_get_token(Token &r_token) {
}
return OK;
+
+ } else if (cchar == '.') {
+ // Handled down there as we support '.[0-9]' as numbers above
+ r_token.type = TK_PERIOD;
+ return OK;
+
} else {
_set_error("Unexpected character.");
r_token.type = TK_ERROR;
@@ -1183,6 +1189,7 @@ Error Expression::_get_token(Token &r_token) {
}
}
}
+#undef GET_CHAR
}
r_token.type = TK_ERROR;
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index 801f2a3b4d..aa46fde7f7 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "face3.h"
-#include "geometry.h"
+
+#include "core/math/geometry.h"
int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_over[3]) const {
diff --git a/core/math/face3.h b/core/math/face3.h
index faed0fa8d4..b41daf04d4 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -31,10 +31,10 @@
#ifndef FACE3_H
#define FACE3_H
-#include "aabb.h"
-#include "plane.h"
-#include "transform.h"
-#include "vector3.h"
+#include "core/math/aabb.h"
+#include "core/math/plane.h"
+#include "core/math/transform.h"
+#include "core/math/vector3.h"
class Face3 {
public:
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index d8cb657b5e..be5e40e4e6 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "geometry.h"
-#include "print_string.h"
+
+#include "core/print_string.h"
bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) {
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 83b9467a30..a813a90774 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -31,14 +31,15 @@
#ifndef GEOMETRY_H
#define GEOMETRY_H
-#include "dvector.h"
-#include "face3.h"
-#include "object.h"
-#include "print_string.h"
-#include "rect2.h"
-#include "triangulate.h"
-#include "vector.h"
-#include "vector3.h"
+#include "core/dvector.h"
+#include "core/math/face3.h"
+#include "core/math/rect2.h"
+#include "core/math/triangulate.h"
+#include "core/math/vector3.h"
+#include "core/object.h"
+#include "core/print_string.h"
+#include "core/vector.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/math/math_fieldwise.cpp b/core/math/math_fieldwise.cpp
new file mode 100644
index 0000000000..20b2341ab0
--- /dev/null
+++ b/core/math/math_fieldwise.cpp
@@ -0,0 +1,181 @@
+/*************************************************************************/
+/* math_fieldwise.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifdef TOOLS_ENABLED
+
+#include "math_fieldwise.h"
+
+#define SETUP_TYPE(m_type) \
+ m_type source = p_source; \
+ m_type target = p_target;
+#define TRY_TRANSFER_FIELD(m_name, m_member) \
+ if (p_field == m_name) { \
+ target.m_member = source.m_member; \
+ }
+
+Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const String &p_field) {
+
+ ERR_FAIL_COND_V(p_target.get_type() != p_source.get_type(), p_target);
+
+ /* clang-format makes a mess of this macro usage */
+ /* clang-format off */
+
+ switch (p_source.get_type()) {
+
+ case Variant::VECTOR2: {
+
+ SETUP_TYPE(Vector2)
+
+ /**/ TRY_TRANSFER_FIELD("x", x)
+ else TRY_TRANSFER_FIELD("y", y)
+
+ return target;
+ }
+
+ case Variant::RECT2: {
+
+ SETUP_TYPE(Rect2)
+
+ /**/ TRY_TRANSFER_FIELD("x", position.x)
+ else TRY_TRANSFER_FIELD("y", position.y)
+ else TRY_TRANSFER_FIELD("w", size.x)
+ else TRY_TRANSFER_FIELD("h", size.y)
+
+ return target;
+ }
+
+ case Variant::VECTOR3: {
+
+ SETUP_TYPE(Vector3)
+
+ /**/ TRY_TRANSFER_FIELD("x", x)
+ else TRY_TRANSFER_FIELD("y", y)
+ else TRY_TRANSFER_FIELD("z", z)
+
+ return target;
+ }
+
+ case Variant::PLANE: {
+
+ SETUP_TYPE(Plane)
+
+ /**/ TRY_TRANSFER_FIELD("x", normal.x)
+ else TRY_TRANSFER_FIELD("y", normal.y)
+ else TRY_TRANSFER_FIELD("z", normal.z)
+ else TRY_TRANSFER_FIELD("d", d)
+
+ return target;
+ }
+
+ case Variant::QUAT: {
+
+ SETUP_TYPE(Quat)
+
+ /**/ TRY_TRANSFER_FIELD("x", x)
+ else TRY_TRANSFER_FIELD("y", y)
+ else TRY_TRANSFER_FIELD("z", z)
+ else TRY_TRANSFER_FIELD("w", w)
+
+ return target;
+ }
+
+ case Variant::AABB: {
+
+ SETUP_TYPE(AABB)
+
+ /**/ TRY_TRANSFER_FIELD("px", position.x)
+ else TRY_TRANSFER_FIELD("py", position.y)
+ else TRY_TRANSFER_FIELD("pz", position.z)
+ else TRY_TRANSFER_FIELD("sx", size.x)
+ else TRY_TRANSFER_FIELD("sy", size.y)
+ else TRY_TRANSFER_FIELD("sz", size.z)
+
+ return target;
+ }
+
+ case Variant::TRANSFORM2D: {
+
+ SETUP_TYPE(Transform2D)
+
+ /**/ TRY_TRANSFER_FIELD("xx", elements[0][0])
+ else TRY_TRANSFER_FIELD("xy", elements[0][1])
+ else TRY_TRANSFER_FIELD("yx", elements[1][0])
+ else TRY_TRANSFER_FIELD("yy", elements[1][1])
+ else TRY_TRANSFER_FIELD("ox", elements[2][0])
+ else TRY_TRANSFER_FIELD("oy", elements[2][1])
+
+ return target;
+ }
+
+ case Variant::BASIS: {
+
+ SETUP_TYPE(Basis)
+
+ /**/ TRY_TRANSFER_FIELD("xx", elements[0][0])
+ else TRY_TRANSFER_FIELD("xy", elements[0][1])
+ else TRY_TRANSFER_FIELD("xz", elements[0][2])
+ else TRY_TRANSFER_FIELD("yx", elements[1][0])
+ else TRY_TRANSFER_FIELD("yy", elements[1][1])
+ else TRY_TRANSFER_FIELD("yz", elements[1][2])
+ else TRY_TRANSFER_FIELD("zx", elements[2][0])
+ else TRY_TRANSFER_FIELD("zy", elements[2][1])
+ else TRY_TRANSFER_FIELD("zz", elements[2][2])
+
+ return target;
+ }
+
+ case Variant::TRANSFORM: {
+
+ SETUP_TYPE(Transform)
+
+ /**/ TRY_TRANSFER_FIELD("xx", basis.elements[0][0])
+ else TRY_TRANSFER_FIELD("xy", basis.elements[0][1])
+ else TRY_TRANSFER_FIELD("xz", basis.elements[0][2])
+ else TRY_TRANSFER_FIELD("yx", basis.elements[1][0])
+ else TRY_TRANSFER_FIELD("yy", basis.elements[1][1])
+ else TRY_TRANSFER_FIELD("yz", basis.elements[1][2])
+ else TRY_TRANSFER_FIELD("zx", basis.elements[2][0])
+ else TRY_TRANSFER_FIELD("zy", basis.elements[2][1])
+ else TRY_TRANSFER_FIELD("zz", basis.elements[2][2])
+ else TRY_TRANSFER_FIELD("xo", origin.x)
+ else TRY_TRANSFER_FIELD("yo", origin.y)
+ else TRY_TRANSFER_FIELD("zo", origin.z)
+
+ return target;
+ }
+
+ default: {
+ ERR_FAIL_V(p_target);
+ }
+ }
+ /* clang-format on */
+}
+
+#endif // TOOLS_ENABLED
diff --git a/core/math/math_fieldwise.h b/core/math/math_fieldwise.h
new file mode 100644
index 0000000000..0e7cc3ea4a
--- /dev/null
+++ b/core/math/math_fieldwise.h
@@ -0,0 +1,42 @@
+/*************************************************************************/
+/* math_fieldwise.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef MATH_FIELDWISE_H
+#define MATH_FIELDWISE_H
+
+#ifdef TOOLS_ENABLED
+
+#include "core/variant.h"
+
+Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const String &p_field);
+
+#endif // TOOLS_ENABLED
+
+#endif // MATH_FIELDWISE_H
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 5c8512d8bd..0c06d2a2b5 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -57,7 +57,7 @@ uint32_t Math::rand() {
}
int Math::step_decimals(double p_step) {
- static const int maxn = 9;
+ static const int maxn = 10;
static const double sd[maxn] = {
0.9999, // somehow compensate for floating point error
0.09999,
@@ -67,17 +67,19 @@ int Math::step_decimals(double p_step) {
0.000009999,
0.0000009999,
0.00000009999,
- 0.000000009999
+ 0.000000009999,
+ 0.0000000009999
};
- double as = Math::abs(p_step);
+ double abs = Math::abs(p_step);
+ double decs = abs - (int)abs; // Strip away integer part
for (int i = 0; i < maxn; i++) {
- if (as >= sd[i]) {
+ if (decs >= sd[i]) {
return i;
}
}
- return maxn;
+ return 0;
}
double Math::dectime(double p_value, double p_amount, double p_step) {
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 992084a653..472baf0484 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -31,8 +31,8 @@
#ifndef MATH_FUNCS_H
#define MATH_FUNCS_H
-#include "math_defs.h"
-#include "typedefs.h"
+#include "core/math/math_defs.h"
+#include "core/typedefs.h"
#include "thirdparty/misc/pcg.h"
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index 7db41756ed..fca54b1556 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -29,9 +29,11 @@
/*************************************************************************/
#include "matrix3.h"
-#include "math_funcs.h"
-#include "os/copymem.h"
-#include "print_string.h"
+
+#include "core/math/math_funcs.h"
+#include "core/os/copymem.h"
+#include "core/print_string.h"
+
#define cofac(row1, col1, row2, col2) \
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
diff --git a/core/math/matrix3.h b/core/math/matrix3.h
index 9ff1a97dc9..35bf75bbe4 100644
--- a/core/math/matrix3.h
+++ b/core/math/matrix3.h
@@ -28,16 +28,18 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "vector3.h"
+// Circular dependency between Vector3 and Basis :/
+#include "core/math/vector3.h"
#ifndef MATRIX3_H
#define MATRIX3_H
-#include "quat.h"
+#include "core/math/quat.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class Basis {
public:
Vector3 elements[3];
diff --git a/core/math/octree.h b/core/math/octree.h
index 4e3d6257f0..cd89743a5a 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -31,12 +31,12 @@
#ifndef OCTREE_H
#define OCTREE_H
-#include "aabb.h"
-#include "list.h"
-#include "map.h"
-#include "print_string.h"
-#include "variant.h"
-#include "vector3.h"
+#include "core/list.h"
+#include "core/map.h"
+#include "core/math/aabb.h"
+#include "core/math/vector3.h"
+#include "core/print_string.h"
+#include "core/variant.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
@@ -478,7 +478,7 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
splits++;
}
} else {
- /* check againt AABB where child should be */
+ /* check against AABB where child should be */
AABB aabb = p_octant->aabb;
aabb.size *= 0.5;
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index 78bb1771a4..3c597d57f8 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -30,7 +30,7 @@
#include "plane.h"
-#include "math_funcs.h"
+#include "core/math/math_funcs.h"
#define _PLANE_EQ_DOT_EPSILON 0.999
#define _PLANE_EQ_D_EPSILON 0.0001
diff --git a/core/math/plane.h b/core/math/plane.h
index e567422dd0..4eedebb79e 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -31,7 +31,7 @@
#ifndef PLANE_H
#define PLANE_H
-#include "vector3.h"
+#include "core/math/vector3.h"
class Plane {
public:
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index 2251571146..d660ce4553 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "quat.h"
-#include "matrix3.h"
-#include "print_string.h"
+
+#include "core/math/matrix3.h"
+#include "core/print_string.h"
// set_euler_xyz expects a vector containing the Euler angles in the format
// (ax,ay,az), where ax is the angle of rotation around x axis,
diff --git a/core/math/quat.h b/core/math/quat.h
index 6dc8d66f60..10d3846c87 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -28,18 +28,20 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "vector3.h"
+// Circular dependency between Vector3 and Basis :/
+#include "core/math/vector3.h"
#ifndef QUAT_H
#define QUAT_H
-#include "math_defs.h"
-#include "math_funcs.h"
-#include "ustring.h"
+#include "core/math/math_defs.h"
+#include "core/math/math_funcs.h"
+#include "core/ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class Quat {
public:
real_t x, y, z, w;
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index 9d4f4f66b7..23823b339a 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "quick_hull.h"
-#include "map.h"
+
+#include "core/map.h"
uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF;
diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h
index eef4a9adff..0ac2758323 100644
--- a/core/math/quick_hull.h
+++ b/core/math/quick_hull.h
@@ -31,10 +31,10 @@
#ifndef QUICK_HULL_H
#define QUICK_HULL_H
-#include "aabb.h"
-#include "geometry.h"
-#include "list.h"
-#include "set.h"
+#include "core/list.h"
+#include "core/math/aabb.h"
+#include "core/math/geometry.h"
+#include "core/set.h"
class QuickHull {
diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp
index 480bccdff1..24c1c8c984 100644
--- a/core/math/rect2.cpp
+++ b/core/math/rect2.cpp
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "transform_2d.h" // Includes rect2.h but Rect2 needs Transform2D
+#include "core/math/transform_2d.h" // Includes rect2.h but Rect2 needs Transform2D
bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const {
diff --git a/core/math/rect2.h b/core/math/rect2.h
index 20329bee0d..96c0e177d3 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -31,7 +31,7 @@
#ifndef RECT2_H
#define RECT2_H
-#include "vector2.h" // also includes math_funcs and ustring
+#include "core/math/vector2.h" // also includes math_funcs and ustring
struct Transform2D;
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 976e0f174e..75257a6e60 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -29,9 +29,10 @@
/*************************************************************************/
#include "transform.h"
-#include "math_funcs.h"
-#include "os/copymem.h"
-#include "print_string.h"
+
+#include "core/math/math_funcs.h"
+#include "core/os/copymem.h"
+#include "core/print_string.h"
void Transform::affine_invert() {
diff --git a/core/math/transform.h b/core/math/transform.h
index c06eaec604..97c8bf9ab0 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -31,12 +31,14 @@
#ifndef TRANSFORM_H
#define TRANSFORM_H
-#include "aabb.h"
-#include "matrix3.h"
-#include "plane.h"
+#include "core/math/aabb.h"
+#include "core/math/matrix3.h"
+#include "core/math/plane.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class Transform {
public:
Basis basis;
diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h
index bf73755f0d..c8fc3c39e3 100644
--- a/core/math/transform_2d.h
+++ b/core/math/transform_2d.h
@@ -31,7 +31,7 @@
#ifndef TRANSFORM_2D_H
#define TRANSFORM_2D_H
-#include "rect2.h" // also includes vector2, math_funcs, and ustring
+#include "core/math/rect2.h" // also includes vector2, math_funcs, and ustring
struct Transform2D {
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper":
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 5475f733c3..6b8dc5eeb3 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "triangle_mesh.h"
-#include "sort.h"
+
+#include "core/sort.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) {
diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h
index bf793fc50f..e5f181fba7 100644
--- a/core/math/triangle_mesh.h
+++ b/core/math/triangle_mesh.h
@@ -31,8 +31,9 @@
#ifndef TRIANGLE_MESH_H
#define TRIANGLE_MESH_H
-#include "face3.h"
-#include "reference.h"
+#include "core/math/face3.h"
+#include "core/reference.h"
+
class TriangleMesh : public Reference {
GDCLASS(TriangleMesh, Reference);
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index 0edc0ea039..69ffc95946 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -186,7 +186,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
nv--;
- /* resest error detection counter */
+ /* reset error detection counter */
count = 2 * nv;
}
}
diff --git a/core/math/triangulate.h b/core/math/triangulate.h
index a0f56f5f27..2b0557ee55 100644
--- a/core/math/triangulate.h
+++ b/core/math/triangulate.h
@@ -31,7 +31,7 @@
#ifndef TRIANGULATE_H
#define TRIANGULATE_H
-#include "vector2.h"
+#include "core/math/vector2.h"
/*
http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
diff --git a/core/math/vector2.h b/core/math/vector2.h
index fbcdc80b60..df49484aaf 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -31,8 +31,8 @@
#ifndef VECTOR2_H
#define VECTOR2_H
-#include "math_funcs.h"
-#include "ustring.h"
+#include "core/math/math_funcs.h"
+#include "core/ustring.h"
struct Vector2i;
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 78d52d5cd1..5dbb01493d 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "vector3.h"
-#include "matrix3.h"
+
+#include "core/math/matrix3.h"
void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) {
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 5f0e8919ff..5302832eeb 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -31,10 +31,10 @@
#ifndef VECTOR3_H
#define VECTOR3_H
-#include "math_defs.h"
-#include "math_funcs.h"
-#include "typedefs.h"
-#include "ustring.h"
+#include "core/math/math_defs.h"
+#include "core/math/math_funcs.h"
+#include "core/typedefs.h"
+#include "core/ustring.h"
class Basis;
@@ -150,13 +150,8 @@ struct Vector3 {
}
};
-#ifdef VECTOR3_IMPL_OVERRIDE
-
-#include "vector3_inline.h"
-
-#else
-
-#include "matrix3.h"
+// Should be included after class definition, otherwise we get circular refs
+#include "core/math/matrix3.h"
Vector3 Vector3::cross(const Vector3 &p_b) const {
@@ -451,6 +446,4 @@ Vector3 Vector3::reflect(const Vector3 &p_normal) const {
return 2.0 * p_normal * this->dot(p_normal) - *this;
}
-#endif
-
#endif // VECTOR3_H