C#: Sync Plane with Core

- Add `Plane(Vector3)` constructor.
- Rename `IntersectRay` to `IntersectsRay`.
- Rename `IntersectSegment` to `IntersectsSegment`.
- Replace `Center` property with `GetCenter` method.
- Add and fix documentation about the _normal_ parameter
to Core and C# documentation.
This commit is contained in:
Raul Santos 2023-01-15 05:35:09 +01:00
parent cd3e03432a
commit 7a19c87c7e
No known key found for this signature in database
GPG key ID: B532473AE3A803E4
2 changed files with 30 additions and 23 deletions

View file

@ -38,6 +38,7 @@
<param index="0" name="normal" type="Vector3" />
<description>
Creates a plane from the normal vector. The plane will intersect the origin.
The [param normal] of the plane must be a unit vector.
</description>
</constructor>
<constructor name="Plane">
@ -46,6 +47,7 @@
<param index="1" name="d" type="float" />
<description>
Creates a plane from the normal vector and the plane's distance from the origin.
The [param normal] of the plane must be a unit vector.
</description>
</constructor>
<constructor name="Plane">
@ -54,6 +56,7 @@
<param index="1" name="point" type="Vector3" />
<description>
Creates a plane from the normal vector and a point on the plane.
The [param normal] of the plane must be a unit vector.
</description>
</constructor>
<constructor name="Plane">
@ -152,7 +155,7 @@
In the scalar equation of the plane [code]ax + by + cz = d[/code], this is [code]d[/code], while the [code](a, b, c)[/code] coordinates are represented by the [member normal] property.
</member>
<member name="normal" type="Vector3" setter="" getter="" default="Vector3(0, 0, 0)">
The normal of the plane, which must be normalized.
The normal of the plane, which must be a unit vector.
In the scalar equation of the plane [code]ax + by + cz = d[/code], this is the vector [code](a, b, c)[/code], where [code]d[/code] is the [member d] property.
</member>
<member name="x" type="float" setter="" getter="" default="0.0">

View file

@ -15,7 +15,7 @@ namespace Godot
private Vector3 _normal;
/// <summary>
/// The normal of the plane, which must be normalized.
/// The normal of the plane, which must be a unit vector.
/// In the scalar equation of the plane <c>ax + by + cz = d</c>, this is
/// the vector <c>(a, b, c)</c>, where <c>d</c> is the <see cref="D"/> property.
/// </summary>
@ -84,23 +84,6 @@ namespace Godot
/// <value>The plane's distance from the origin.</value>
public real_t D { get; set; }
/// <summary>
/// The center of the plane, the point where the normal line intersects the plane.
/// </summary>
/// <value>Equivalent to <see cref="Normal"/> multiplied by <see cref="D"/>.</value>
public Vector3 Center
{
readonly get
{
return _normal * D;
}
set
{
_normal = value.Normalized();
D = value.Length();
}
}
/// <summary>
/// Returns the shortest distance from this plane to the position <paramref name="point"/>.
/// </summary>
@ -111,6 +94,16 @@ namespace Godot
return _normal.Dot(point) - D;
}
/// <summary>
/// Returns the center of the plane, the point on the plane closest to the origin.
/// The point where the normal line going through the origin intersects the plane.
/// </summary>
/// <value>Equivalent to <see cref="Normal"/> multiplied by <see cref="D"/>.</value>
public readonly Vector3 GetCenter()
{
return _normal * D;
}
/// <summary>
/// Returns <see langword="true"/> if point is inside the plane.
/// Comparison uses a custom minimum tolerance threshold.
@ -155,7 +148,7 @@ namespace Godot
/// <param name="from">The start of the ray.</param>
/// <param name="dir">The direction of the ray, normalized.</param>
/// <returns>The intersection, or <see langword="null"/> if none is found.</returns>
public readonly Vector3? IntersectRay(Vector3 from, Vector3 dir)
public readonly Vector3? IntersectsRay(Vector3 from, Vector3 dir)
{
real_t den = _normal.Dot(dir);
@ -183,7 +176,7 @@ namespace Godot
/// <param name="begin">The start of the line segment.</param>
/// <param name="end">The end of the line segment.</param>
/// <returns>The intersection, or <see langword="null"/> if none is found.</returns>
public readonly Vector3? IntersectSegment(Vector3 begin, Vector3 end)
public readonly Vector3? IntersectsSegment(Vector3 begin, Vector3 end)
{
Vector3 segment = begin - end;
real_t den = _normal.Dot(segment);
@ -289,11 +282,22 @@ namespace Godot
D = d;
}
/// <summary>
/// Constructs a <see cref="Plane"/> from a <paramref name="normal"/> vector.
/// The plane will intersect the origin.
/// </summary>
/// <param name="normal">The normal of the plane, must be a unit vector.</param>
public Plane(Vector3 normal)
{
_normal = normal;
D = 0;
}
/// <summary>
/// Constructs a <see cref="Plane"/> from a <paramref name="normal"/> vector and
/// the plane's distance to the origin <paramref name="d"/>.
/// </summary>
/// <param name="normal">The normal of the plane, must be normalized.</param>
/// <param name="normal">The normal of the plane, must be a unit vector.</param>
/// <param name="d">The plane's distance from the origin. This value is typically non-negative.</param>
public Plane(Vector3 normal, real_t d)
{
@ -305,7 +309,7 @@ namespace Godot
/// Constructs a <see cref="Plane"/> from a <paramref name="normal"/> vector and
/// a <paramref name="point"/> on the plane.
/// </summary>
/// <param name="normal">The normal of the plane, must be normalized.</param>
/// <param name="normal">The normal of the plane, must be a unit vector.</param>
/// <param name="point">The point on the plane.</param>
public Plane(Vector3 normal, Vector3 point)
{