diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2023-04-11 21:01:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-11 21:01:58 +0200 |
commit | 16a6bdd423aa85272837d0bc6b9e709febdb4ec0 (patch) | |
tree | a7f70f8ed81aec219e990c0b3f174dbd200ae793 /scene/resources | |
parent | 4762303f182e65c5293db8d22a4ce88521eba445 (diff) | |
parent | 177be9bd37e3dfa4d591eea3bb8ab14a17d06007 (diff) |
Merge pull request #75786 from YuriSizov/4.0-cherrypicks
Cherry-picks for the 4.0 branch (future 4.0.3) - 1st batch
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/convex_polygon_shape_2d.cpp | 30 | ||||
-rw-r--r-- | scene/resources/text_paragraph.cpp | 20 |
2 files changed, 40 insertions, 10 deletions
diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index 7f19dd63e6..0d9e570149 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -38,11 +38,41 @@ bool ConvexPolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, dou return Geometry2D::is_point_in_polygon(p_point, points); } +#ifdef DEBUG_ENABLED +// Check if point p3 is to the left of [p1, p2] segment or on it. +bool left_test(const Vector2 &p1, const Vector2 &p2, const Vector2 &p3) { + Vector2 p12 = p2 - p1; + Vector2 p13 = p3 - p1; + // If the value of the cross product is positive or zero; p3 is to the left or on the segment, respectively. + return p12.cross(p13) >= 0; +} + +bool is_convex(const Vector<Vector2> &p_points) { + // Pre-condition: Polygon is in counter-clockwise order. + int polygon_size = p_points.size(); + for (int i = 0; i < polygon_size && polygon_size > 3; i++) { + int j = (i + 1) % polygon_size; + int k = (j + 1) % polygon_size; + // If any consecutive three points fail left-test, then there is a concavity. + if (!left_test(p_points[i], p_points[j], p_points[k])) { + return false; + } + } + + return true; +} +#endif + void ConvexPolygonShape2D::_update_shape() { Vector<Vector2> final_points = points; if (Geometry2D::is_polygon_clockwise(final_points)) { //needs to be counter clockwise final_points.reverse(); } +#ifdef DEBUG_ENABLED + if (!is_convex(final_points)) { + WARN_PRINT("Concave polygon is assigned to ConvexPolygonShape2D."); + } +#endif PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), final_points); emit_changed(); } diff --git a/scene/resources/text_paragraph.cpp b/scene/resources/text_paragraph.cpp index 729063245c..191b71f301 100644 --- a/scene/resources/text_paragraph.cpp +++ b/scene/resources/text_paragraph.cpp @@ -233,27 +233,27 @@ void TextParagraph::_shape_lines() { } if (alignment == HORIZONTAL_ALIGNMENT_FILL) { for (int i = 0; i < (int)lines_rid.size(); i++) { + float line_w = (i <= dropcap_lines) ? (width - h_offset) : width; if (i < visible_lines - 1 || (int)lines_rid.size() == 1) { - TS->shaped_text_fit_to_width(lines_rid[i], width, jst_flags); + TS->shaped_text_fit_to_width(lines_rid[i], line_w, jst_flags); } else if (i == (visible_lines - 1)) { - TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags); + TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], line_w, overrun_flags); } } - } else if (lines_hidden) { - TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags); + TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], (visible_lines - 1 <= dropcap_lines) ? (width - h_offset) : width, overrun_flags); } - } else { // Autowrap disabled. - for (const RID &line_rid : lines_rid) { + for (int i = 0; i < (int)lines_rid.size(); i++) { + float line_w = (i <= dropcap_lines) ? (width - h_offset) : width; if (alignment == HORIZONTAL_ALIGNMENT_FILL) { - TS->shaped_text_fit_to_width(line_rid, width, jst_flags); + TS->shaped_text_fit_to_width(lines_rid[i], line_w, jst_flags); overrun_flags.set_flag(TextServer::OVERRUN_JUSTIFICATION_AWARE); - TS->shaped_text_overrun_trim_to_width(line_rid, width, overrun_flags); - TS->shaped_text_fit_to_width(line_rid, width, jst_flags | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS); + TS->shaped_text_overrun_trim_to_width(lines_rid[i], line_w, overrun_flags); + TS->shaped_text_fit_to_width(lines_rid[i], line_w, jst_flags | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS); } else { - TS->shaped_text_overrun_trim_to_width(line_rid, width, overrun_flags); + TS->shaped_text_overrun_trim_to_width(lines_rid[i], line_w, overrun_flags); } } } |