Skip to content

Commit

Permalink
feat: Add IsValid and Flip to Plane
Browse files Browse the repository at this point in the history
  • Loading branch information
erictuvesson committed Jun 7, 2021
1 parent 5413a99 commit 84d284d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/PlaneExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
namespace Nine.Geometry
{
using System;
using System.ComponentModel;
using System.Numerics;

[EditorBrowsable(EditorBrowsableState.Never)]
public static class PlaneExtensions
{
/// <summary>
/// Returns whether the plane is valid.
/// </summary>
/// <param name="plane"></param>
/// <returns></returns>
public static bool IsValid(this Plane plane)
=> plane.Normal.LengthSquared() > 0.0f;

/// <summary>
/// Returns the <see cref="Plane"/> with a flipped normal.
/// </summary>
/// <param name="plane"></param>
/// <returns></returns>
public static Plane Flip(this Plane plane)
=> new Plane(plane.Normal * -1.0f, plane.D * -1.0f);

public static PlaneIntersectionType Intersects(this Plane plane, Vector3 vector)
{
// TODO: Implement
throw new NotImplementedException();
}

public static PlaneIntersectionType Intersects(this Plane plane, BoundingBox boundingBox)
{
PlaneIntersectionType result;
Expand Down
52 changes: 52 additions & 0 deletions test/PlaneExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Nine.Geometry.Test
{
using System.Numerics;
using Xunit;

public class PlaneExtensionsTest
{
[Fact]
public void IsValid()
{
var plane = Plane.CreateFromVertices(
new Vector3(0, 0, 0),
new Vector3(0, 1, 0),
new Vector3(1, 1, 0)
);

var valid = plane.IsValid();

Assert.True(valid);
}

[Fact]
public void IsValid_False()
{
var plane = Plane.CreateFromVertices(
new Vector3(0, 0, 0),
new Vector3(0, 0, 0),
new Vector3(0, 0, 0)
);

var valid = plane.IsValid();

Assert.False(valid);
}

[Fact]
public void Flip()
{
var plane = Plane.CreateFromVertices(
new Vector3(0, 0, 0),
new Vector3(0, 1, 0),
new Vector3(1, 1, 0)
);

var org_normal = plane.Normal;
var new_normal = plane.Flip().Normal;

Assert.Equal(new Vector3(0, 0, -1), org_normal);
Assert.Equal(new Vector3(0, 0, 1), new_normal);
}
}
}

0 comments on commit 84d284d

Please sign in to comment.