diff options
author | Hendrik Brucker <hendrik.brucker@mail.de> | 2024-01-18 16:16:17 +0100 |
---|---|---|
committer | Hendrik Brucker <hendrik.brucker@mail.de> | 2024-01-18 16:53:15 +0100 |
commit | 9d7c2978f4799e84bcaa4c5692c58391ea7448eb (patch) | |
tree | 0b9bc62212b721a427c73b70e561c79f0eb6f8cf /core | |
parent | 1952f64b07b2a0d63d5ba66902fd88190b0dcf08 (diff) | |
download | redot-engine-9d7c2978f4799e84bcaa4c5692c58391ea7448eb.tar.gz |
Rework GraphEdit connections (drawing, API, optimizations)
- GraphEdit now uses Line2D nodes to draw connection lines and uses a dedicated canvas item shader for them
Diffstat (limited to 'core')
-rw-r--r-- | core/math/geometry_2d.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index b37fce9e9c..9907d579a5 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -119,6 +119,10 @@ public: } } + static real_t get_distance_to_segment(const Vector2 &p_point, const Vector2 *p_segment) { + return p_point.distance_to(get_closest_point_to_segment(p_point, p_segment)); + } + static bool is_point_in_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) { Vector2 an = a - s; Vector2 bn = b - s; @@ -249,6 +253,28 @@ public: return -1; } + static bool segment_intersects_rect(const Vector2 &p_from, const Vector2 &p_to, const Rect2 &p_rect) { + if (p_rect.has_point(p_from) || p_rect.has_point(p_to)) { + return true; + } + + const Vector2 rect_points[4] = { + p_rect.position, + p_rect.position + Vector2(p_rect.size.x, 0), + p_rect.position + p_rect.size, + p_rect.position + Vector2(0, p_rect.size.y) + }; + + // Check if any of the rect's edges intersect the segment. + for (int i = 0; i < 4; i++) { + if (segment_intersects_segment(p_from, p_to, rect_points[i], rect_points[(i + 1) % 4], nullptr)) { + return true; + } + } + + return false; + } + enum PolyBooleanOperation { OPERATION_UNION, OPERATION_DIFFERENCE, |