summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/a_star.cpp30
-rw-r--r--core/math/a_star.h7
-rw-r--r--core/math/camera_matrix.cpp5
-rw-r--r--core/math/camera_matrix.h1
-rw-r--r--core/math/color.cpp61
-rw-r--r--core/math/color.h8
-rw-r--r--core/math/expression.cpp2
-rw-r--r--core/math/math_funcs.h12
-rw-r--r--core/math/quick_hull.cpp2
-rw-r--r--core/math/quick_hull.h2
-rw-r--r--core/math/static_raycaster.h2
11 files changed, 109 insertions, 23 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index a3ee259030..efa970c681 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -151,15 +151,15 @@ void AStar3D::connect_points(int p_id, int p_with_id, bool bidirectional) {
s.direction = Segment::BIDIRECTIONAL;
}
- RBSet<Segment>::Element *element = segments.find(s);
- if (element != nullptr) {
- s.direction |= element->get().direction;
+ HashSet<Segment, Segment>::Iterator element = segments.find(s);
+ if (element) {
+ s.direction |= element->direction;
if (s.direction == Segment::BIDIRECTIONAL) {
// Both are neighbours of each other now
a->unlinked_neighbours.remove(b->id);
b->unlinked_neighbours.remove(a->id);
}
- segments.erase(element);
+ segments.remove(element);
}
segments.insert(s);
@@ -177,16 +177,16 @@ void AStar3D::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
Segment s(p_id, p_with_id);
int remove_direction = bidirectional ? (int)Segment::BIDIRECTIONAL : s.direction;
- RBSet<Segment>::Element *element = segments.find(s);
- if (element != nullptr) {
+ HashSet<Segment, Segment>::Iterator element = segments.find(s);
+ if (element) {
// s is the new segment
// Erase the directions to be removed
- s.direction = (element->get().direction & ~remove_direction);
+ s.direction = (element->direction & ~remove_direction);
a->neighbours.remove(b->id);
if (bidirectional) {
b->neighbours.remove(a->id);
- if (element->get().direction != Segment::BIDIRECTIONAL) {
+ if (element->direction != Segment::BIDIRECTIONAL) {
a->unlinked_neighbours.remove(b->id);
b->unlinked_neighbours.remove(a->id);
}
@@ -198,7 +198,7 @@ void AStar3D::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
}
}
- segments.erase(element);
+ segments.remove(element);
if (s.direction != Segment::NONE) {
segments.insert(s);
}
@@ -235,10 +235,10 @@ Vector<int> AStar3D::get_point_connections(int p_id) {
bool AStar3D::are_points_connected(int p_id, int p_with_id, bool bidirectional) const {
Segment s(p_id, p_with_id);
- const RBSet<Segment>::Element *element = segments.find(s);
+ const HashSet<Segment, Segment>::Iterator element = segments.find(s);
- return element != nullptr &&
- (bidirectional || (element->get().direction & s.direction) == s.direction);
+ return element &&
+ (bidirectional || (element->direction & s.direction) == s.direction);
}
void AStar3D::clear() {
@@ -293,10 +293,10 @@ Vector3 AStar3D::get_closest_position_in_segment(const Vector3 &p_point) const {
real_t closest_dist = 1e20;
Vector3 closest_point;
- for (const RBSet<Segment>::Element *E = segments.front(); E; E = E->next()) {
+ for (const Segment &E : segments) {
Point *from_point = nullptr, *to_point = nullptr;
- points.lookup(E->get().u, from_point);
- points.lookup(E->get().v, to_point);
+ points.lookup(E.u, from_point);
+ points.lookup(E.v, to_point);
if (!(from_point->enabled && to_point->enabled)) {
continue;
diff --git a/core/math/a_star.h b/core/math/a_star.h
index 086be839b5..e2f75ad18c 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -92,7 +92,10 @@ class AStar3D : public RefCounted {
};
unsigned char direction = NONE;
- bool operator<(const Segment &p_s) const { return key < p_s.key; }
+ static uint32_t hash(const Segment &p_seg) {
+ return hash_one_uint64(p_seg.key);
+ }
+ bool operator==(const Segment &p_s) const { return key == p_s.key; }
Segment() {}
Segment(int p_from, int p_to) {
@@ -112,7 +115,7 @@ class AStar3D : public RefCounted {
uint64_t pass = 1;
OAHashMap<int, Point *> points;
- RBSet<Segment> segments;
+ HashSet<Segment, Segment> segments;
bool _solve(Point *begin_point, Point *end_point);
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 9443addd22..57c53b0adb 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -710,6 +710,11 @@ void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) {
matrix[3][3] = 1;
}
+void CameraMatrix::add_jitter_offset(const Vector2 &p_offset) {
+ matrix[3][0] += p_offset.x;
+ matrix[3][1] += p_offset.y;
+}
+
CameraMatrix::operator Transform3D() const {
Transform3D tr;
const real_t *m = &matrix[0][0];
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index f1aea5e4e8..a4051cee3b 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -95,6 +95,7 @@ struct CameraMatrix {
operator String() const;
void scale_translate_to_fit(const AABB &p_aabb);
+ void add_jitter_offset(const Vector2 &p_offset);
void make_scale(const Vector3 &p_scale);
int get_pixels_per_meter(int p_for_pixel_width) const;
operator Transform3D() const;
diff --git a/core/math/color.cpp b/core/math/color.cpp
index 74552a2894..4bdeafd2f2 100644
--- a/core/math/color.cpp
+++ b/core/math/color.cpp
@@ -35,6 +35,8 @@
#include "core/string/print_string.h"
#include "core/templates/rb_map.h"
+#include "thirdparty/misc/ok_color.h"
+
uint32_t Color::to_argb32() const {
uint32_t c = (uint8_t)Math::round(a * 255);
c <<= 8;
@@ -240,6 +242,20 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
}
}
+void Color::set_ok_hsl(float p_h, float p_s, float p_l, float p_alpha) {
+ ok_color::HSL hsl;
+ hsl.h = p_h;
+ hsl.s = p_s;
+ hsl.l = p_l;
+ ok_color new_ok_color;
+ ok_color::RGB rgb = new_ok_color.okhsl_to_srgb(hsl);
+ Color c = Color(rgb.r, rgb.g, rgb.b, p_alpha).clamp();
+ r = c.r;
+ g = c.g;
+ b = c.b;
+ a = c.a;
+}
+
bool Color::is_equal_approx(const Color &p_color) const {
return Math::is_equal_approx(r, p_color.r) && Math::is_equal_approx(g, p_color.g) && Math::is_equal_approx(b, p_color.b) && Math::is_equal_approx(a, p_color.a);
}
@@ -568,3 +584,48 @@ Color Color::operator-() const {
1.0f - b,
1.0f - a);
}
+
+Color Color::from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha) {
+ Color c;
+ c.set_ok_hsl(p_h, p_s, p_l, p_alpha);
+ return c;
+}
+
+float Color::get_ok_hsl_h() const {
+ ok_color::RGB rgb;
+ rgb.r = r;
+ rgb.g = g;
+ rgb.b = b;
+ ok_color new_ok_color;
+ ok_color::HSL ok_hsl = new_ok_color.srgb_to_okhsl(rgb);
+ if (Math::is_nan(ok_hsl.h)) {
+ return 0.0f;
+ }
+ return CLAMP(ok_hsl.h, 0.0f, 1.0f);
+}
+
+float Color::get_ok_hsl_s() const {
+ ok_color::RGB rgb;
+ rgb.r = r;
+ rgb.g = g;
+ rgb.b = b;
+ ok_color new_ok_color;
+ ok_color::HSL ok_hsl = new_ok_color.srgb_to_okhsl(rgb);
+ if (Math::is_nan(ok_hsl.s)) {
+ return 0.0f;
+ }
+ return CLAMP(ok_hsl.s, 0.0f, 1.0f);
+}
+
+float Color::get_ok_hsl_l() const {
+ ok_color::RGB rgb;
+ rgb.r = r;
+ rgb.g = g;
+ rgb.b = b;
+ ok_color new_ok_color;
+ ok_color::HSL ok_hsl = new_ok_color.srgb_to_okhsl(rgb);
+ if (Math::is_nan(ok_hsl.l)) {
+ return 0.0f;
+ }
+ return CLAMP(ok_hsl.l, 0.0f, 1.0f);
+}
diff --git a/core/math/color.h b/core/math/color.h
index 91e0bf5532..0afa6006a8 100644
--- a/core/math/color.h
+++ b/core/math/color.h
@@ -56,6 +56,10 @@ struct _NO_DISCARD_ Color {
float get_s() const;
float get_v() const;
void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0);
+ float get_ok_hsl_h() const;
+ float get_ok_hsl_s() const;
+ float get_ok_hsl_l() const;
+ void set_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0);
_FORCE_INLINE_ float &operator[](int p_idx) {
return components[p_idx];
@@ -195,6 +199,7 @@ struct _NO_DISCARD_ Color {
static Color get_named_color(int p_idx);
static Color from_string(const String &p_string, const Color &p_default);
static Color from_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0);
+ static Color from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0);
static Color from_rgbe9995(uint32_t p_rgbe);
_FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys
@@ -213,6 +218,9 @@ struct _NO_DISCARD_ Color {
_FORCE_INLINE_ void set_h(float p_h) { set_hsv(p_h, get_s(), get_v()); }
_FORCE_INLINE_ void set_s(float p_s) { set_hsv(get_h(), p_s, get_v()); }
_FORCE_INLINE_ void set_v(float p_v) { set_hsv(get_h(), get_s(), p_v); }
+ _FORCE_INLINE_ void set_ok_hsl_h(float p_h) { set_ok_hsl(p_h, get_ok_hsl_s(), get_ok_hsl_l()); }
+ _FORCE_INLINE_ void set_ok_hsl_s(float p_s) { set_ok_hsl(get_ok_hsl_h(), p_s, get_ok_hsl_l()); }
+ _FORCE_INLINE_ void set_ok_hsl_l(float p_l) { set_ok_hsl(get_ok_hsl_h(), get_ok_hsl_s(), p_l); }
_FORCE_INLINE_ Color() {}
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 97dc175d94..5a90f68b66 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -1245,7 +1245,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
case Expression::ENode::TYPE_INPUT: {
const Expression::InputNode *in = static_cast<const Expression::InputNode *>(p_node);
if (in->index < 0 || in->index >= p_inputs.size()) {
- r_error_str = vformat(RTR("Invalid input %i (not passed) in expression"), in->index);
+ r_error_str = vformat(RTR("Invalid input %d (not passed) in expression"), in->index);
return true;
}
r_ret = p_inputs[in->index];
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 068bc0397e..c8a55341aa 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -302,11 +302,19 @@ public:
}
static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) {
double range = max - min;
- return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
+ double result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
+ if (is_equal_approx(result, max)) {
+ return min;
+ }
+ return result;
}
static _ALWAYS_INLINE_ float wrapf(float value, float min, float max) {
float range = max - min;
- return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
+ float result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
+ if (is_equal_approx(result, max)) {
+ return min;
+ }
+ return result;
}
static _ALWAYS_INLINE_ float fract(float value) {
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index 43744deeb0..c7727a44a1 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -52,7 +52,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
Vector<bool> valid_points;
valid_points.resize(p_points.size());
- RBSet<Vector3> valid_cache;
+ HashSet<Vector3> valid_cache;
for (int i = 0; i < p_points.size(); i++) {
Vector3 sp = p_points[i].snapped(Vector3(0.0001, 0.0001, 0.0001));
diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h
index 1c354880b4..6783743fc2 100644
--- a/core/math/quick_hull.h
+++ b/core/math/quick_hull.h
@@ -33,8 +33,8 @@
#include "core/math/aabb.h"
#include "core/math/geometry_3d.h"
+#include "core/templates/hash_set.h"
#include "core/templates/list.h"
-#include "core/templates/rb_set.h"
class QuickHull {
public:
diff --git a/core/math/static_raycaster.h b/core/math/static_raycaster.h
index adc81906d7..bc6511c073 100644
--- a/core/math/static_raycaster.h
+++ b/core/math/static_raycaster.h
@@ -102,7 +102,7 @@ public:
virtual void add_mesh(const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices, unsigned int p_id) = 0;
virtual void commit() = 0;
- virtual void set_mesh_filter(const RBSet<int> &p_mesh_ids) = 0;
+ virtual void set_mesh_filter(const HashSet<int> &p_mesh_ids) = 0;
virtual void clear_mesh_filter() = 0;
static Ref<StaticRaycaster> create();