summaryrefslogtreecommitdiff
path: root/modules/mono
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2019-10-08 22:47:22 -0400
committerAaron Franke <arnfranke@yahoo.com>2019-10-08 22:47:22 -0400
commit643874f8caff3a284a70bf4c114cca9f165deea2 (patch)
tree1fa30fc5d7f2b7e18a34817a7f5890315b46a2d1 /modules/mono
parentbb41f0b0cbc8ceff55a77cec42664c2ee81bb2f2 (diff)
[Mono] Change Plane intersect methods to return nullable Vector3
Diffstat (limited to 'modules/mono')
-rw-r--r--modules/mono/glue/Managed/Files/Plane.cs23
1 files changed, 12 insertions, 11 deletions
diff --git a/modules/mono/glue/Managed/Files/Plane.cs b/modules/mono/glue/Managed/Files/Plane.cs
index a13161d2e6..26e717e089 100644
--- a/modules/mono/glue/Managed/Files/Plane.cs
+++ b/modules/mono/glue/Managed/Files/Plane.cs
@@ -82,12 +82,12 @@ namespace Godot
return Mathf.Abs(dist) <= epsilon;
}
- public Vector3 Intersect3(Plane b, Plane c)
+ public Vector3? Intersect3(Plane b, Plane c)
{
real_t denom = _normal.Cross(b._normal).Dot(c._normal);
- if (Mathf.Abs(denom) <= Mathf.Epsilon)
- return new Vector3();
+ if (Mathf.IsZeroApprox(denom))
+ return null;
Vector3 result = b._normal.Cross(c._normal) * D +
c._normal.Cross(_normal) * b.D +
@@ -96,34 +96,35 @@ namespace Godot
return result / denom;
}
- public Vector3 IntersectRay(Vector3 from, Vector3 dir)
+ public Vector3? IntersectRay(Vector3 from, Vector3 dir)
{
real_t den = _normal.Dot(dir);
- if (Mathf.Abs(den) <= Mathf.Epsilon)
- return new Vector3();
+ if (Mathf.IsZeroApprox(den))
+ return null;
real_t dist = (_normal.Dot(from) - D) / den;
// This is a ray, before the emitting pos (from) does not exist
if (dist > Mathf.Epsilon)
- return new Vector3();
+ return null;
return from + dir * -dist;
}
- public Vector3 IntersectSegment(Vector3 begin, Vector3 end)
+ public Vector3? IntersectSegment(Vector3 begin, Vector3 end)
{
Vector3 segment = begin - end;
real_t den = _normal.Dot(segment);
- if (Mathf.Abs(den) <= Mathf.Epsilon)
- return new Vector3();
+ if (Mathf.IsZeroApprox(den))
+ return null;
real_t dist = (_normal.Dot(begin) - D) / den;
+ // Only allow dist to be in the range of 0 to 1, with tolerance.
if (dist < -Mathf.Epsilon || dist > 1.0f + Mathf.Epsilon)
- return new Vector3();
+ return null;
return begin + segment * -dist;
}