Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/Maths/Silk.NET.Maths.Tests/CubeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

namespace Silk.NET.Maths.Tests
{
public class CubeTests
{
[Fact]
public void ContainsCubeTest()
{
var parent = new Cube<float>(Vector3D<float>.Zero, new Vector3D<float>(10.0f, 10.0f, 10.0f));

// Completely inside
var inside = new Cube<float>(new Vector3D<float>(1.0f, 1.0f, 1.0f), new Vector3D<float>(5.0f, 5.0f, 5.0f));
Assert.True(parent.Contains(inside));

// Identical (touching boundaries)
Assert.True(parent.Contains(parent));

// Exceeds max X
var exceedsX = new Cube<float>(new Vector3D<float>(1.0f, 1.0f, 1.0f), new Vector3D<float>(11.0f, 5.0f, 5.0f));
Assert.False(parent.Contains(exceedsX));

// Exceeds max Y
var exceedsY = new Cube<float>(new Vector3D<float>(1.0f, 1.0f, 1.0f), new Vector3D<float>(5.0f, 11.0f, 5.0f));
Assert.False(parent.Contains(exceedsY));

// Exceeds max Z
var exceedsZ = new Cube<float>(new Vector3D<float>(1.0f, 1.0f, 1.0f), new Vector3D<float>(5.0f, 5.0f, 11.0f));
Assert.False(parent.Contains(exceedsZ));

// Origin outside min Z
var outsideMinZ = new Cube<float>(new Vector3D<float>(1.0f, 1.0f, -1.0f), new Vector3D<float>(5.0f, 5.0f, 5.0f));
Assert.False(parent.Contains(outsideMinZ));
}

[Fact]
public void ContainsPointTest()
{
var cube = new Cube<float>(Vector3D<float>.Zero, new Vector3D<float>(10.0f, 10.0f, 10.0f));

Assert.True(cube.Contains(new Vector3D<float>(5.0f, 5.0f, 5.0f)));
Assert.True(cube.Contains(Vector3D<float>.Zero));
Assert.True(cube.Contains(new Vector3D<float>(10.0f, 10.0f, 10.0f)));

Assert.False(cube.Contains(new Vector3D<float>(-1.0f, 5.0f, 5.0f)));
Assert.False(cube.Contains(new Vector3D<float>(5.0f, -1.0f, 5.0f)));
Assert.False(cube.Contains(new Vector3D<float>(5.0f, 5.0f, -1.0f)));
Assert.False(cube.Contains(new Vector3D<float>(11.0f, 5.0f, 5.0f)));
Assert.False(cube.Contains(new Vector3D<float>(5.0f, 11.0f, 5.0f)));
Assert.False(cube.Contains(new Vector3D<float>(5.0f, 5.0f, 11.0f)));
}
}
}
2 changes: 1 addition & 1 deletion src/Maths/Silk.NET.Maths/Cube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public bool Contains(Cube<T> other)
return Scalar.GreaterThanOrEqual(other.Origin.X, this.Origin.X) && Scalar.GreaterThanOrEqual
(other.Origin.Y, this.Origin.Y) && Scalar.GreaterThanOrEqual
(other.Origin.Z, this.Origin.Z) && Scalar.LessThanOrEqual(oMax.X, tMax.X) && Scalar.LessThanOrEqual
(oMax.Y, tMax.Y) && Scalar.LessThanOrEqual(oMax.Y, tMax.Y);
(oMax.Y, tMax.Y) && Scalar.LessThanOrEqual(oMax.Z, tMax.Z);
}

/// <summary>
Expand Down
Loading