From f7eb16c4b1a20eab66431e665d9660b16568485e Mon Sep 17 00:00:00 2001 From: Grahame Watt Date: Wed, 5 Jun 2024 10:26:16 -0700 Subject: [PATCH] Clarify documentation for Geometry2D.line_intersects_line --- doc/classes/Geometry2D.xml | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/doc/classes/Geometry2D.xml b/doc/classes/Geometry2D.xml index dfcf299fe62..ff6f2c30add 100644 --- a/doc/classes/Geometry2D.xml +++ b/doc/classes/Geometry2D.xml @@ -125,8 +125,34 @@ - Checks if the two lines ([param from_a], [param dir_a]) and ([param from_b], [param dir_b]) intersect. If yes, return the point of intersection as [Vector2]. If no intersection takes place, returns [code]null[/code]. - [b]Note:[/b] The lines are specified using direction vectors, not end points. + Returns the point of intersection between the two lines ([param from_a], [param dir_a]) and ([param from_b], [param dir_b]). Returns a [Vector2], or [code]null[/code] if the lines are parallel. + [code]from[/code] and [code]dir[/code] are [i]not[/i] endpoints of a line segment or ray but the slope ([code]dir[/code]) and a known point ([code]from[/code]) on that line. + [codeblocks] + [gdscript] + var from_a = Vector2.ZERO + var dir_a = Vector2.RIGHT + var from_b = Vector2.DOWN + + # Returns Vector2(1, 0) + Geometry2D.line_intersects_line(from_a, dir_a, from_b, Vector2(1, -1)) + # Returns Vector2(-1, 0) + Geometry2D.line_intersects_line(from_a, dir_a, from_b, Vector2(-1, -1)) + # Returns null + Geometry2D.line_intersects_line(from_a, dir_a, from_b, Vector2.RIGHT) + [/gdscript] + [csharp] + var fromA = Vector2.Zero; + var dirA = Vector2.Right; + var fromB = Vector2.Down; + + // Returns new Vector2(1, 0) + Geometry2D.LineIntersectsLine(fromA, dirA, fromB, new Vector2(1, -1)); + // Returns new Vector2(-1, 0) + Geometry2D.LineIntersectsLine(fromA, dirA, fromB, new Vector2(-1, -1)); + // Returns null + Geometry2D.LineIntersectsLine(fromA, dirA, fromB, Vector2.Right); + [/csharp] + [/codeblocks]