diff --git a/src/PlaneExtensions.cs b/src/PlaneExtensions.cs index 3e09c7f..86d4575 100644 --- a/src/PlaneExtensions.cs +++ b/src/PlaneExtensions.cs @@ -1,18 +1,32 @@ namespace Nine.Geometry { using System; - using System.ComponentModel; using System.Numerics; - [EditorBrowsable(EditorBrowsableState.Never)] public static class PlaneExtensions { + /// + /// Returns whether the plane is valid. + /// + /// + /// + public static bool IsValid(this Plane plane) + => plane.Normal.LengthSquared() > 0.0f; + + /// + /// Returns the with a flipped normal. + /// + /// + /// + 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; diff --git a/test/PlaneExtensionsTest.cs b/test/PlaneExtensionsTest.cs new file mode 100644 index 0000000..29bad91 --- /dev/null +++ b/test/PlaneExtensionsTest.cs @@ -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); + } + } +}