godotengine / godotengine/godot

Geometry functions returning null Variants in GDScript returns (possibly) false values in C#

Open
#89,850 5 comments 0 reactions 0 assignees View on GitHub
needs testing topic:dotnet
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- v4.2.1.stable.mono.official [b09f793f5]

### System information

Godot v4.2.1.stable.mono - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2070 SUPER (NVIDIA; 31.0.15.5176) - AMD Ryzen 7 3800XT 8-Core Processor (16 Threads)

### Issue description

There may be other instances where this happens, but these are the ones I've found:

- https://docs.godotengine.org/en/stable/classes/class_geometry2d.html#class-geometry2d-method-segment-intersects-segment
- https://docs.godotengine.org/en/stable/classes/class_geometry2d.html#class-geometry2d-method-line-intersects-line
- https://docs.godotengine.org/en/stable/classes/class_geometry3d.html#class-geometry3d-method-ray-intersects-triangle

Vector2/3.Zero may be the actual intersection point so there is no way can check if an intersection actually exists or not using these functions in C#.

### Steps to reproduce

```C#

using static Godot.Geometry2D;
....
// Correctly returns (0,0)
var undeterminable = SegmentIntersectsSegment(new Vector2(-1,0), new Vector2(1, 0), new Vector2(0, -1), new Vector2(0, 1)).AsVector2();

// Erroneously returns (0,0)
undeterminable = SegmentIntersectsSegment(new Vector2(-1, 0), new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 2)).AsVector2();

//
// CS0019 Operator '==' cannot be applied to operands of type 'Variant' and ''
// if(undeterminable == null) {
//
// }

```

The two first vectors intersect at (0,0), but we can't determine that since it might also be a default constructed Vector2, i.e. null. The second two also results in (0,0)

### Minimal reproduction project (MRP)

See steps to reproduce.

Edit: Make example code more explicit for Vector2.

Contributor guide

Open the contributing guide

Research direction

Start with the Geometry2D methods segment-intersects-segment and line-intersects-line, and Geometry3D ray-intersects-triangle, using the C# reproduction in the issue. Compare their documented null or no-intersection behavior with the returned Variant conversion; done means C# can distinguish a real Vector2/Vector3.Zero intersection from no intersection.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, godot
Domain
api, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.