Merge branch '20-06-16-click-detect' into 20-06-18-merge

This commit is contained in:
Pieter-Jan Briers
2020-06-18 02:35:03 +02:00
10 changed files with 456 additions and 26 deletions

View File

@@ -0,0 +1,49 @@
using Content.Client;
using NUnit.Framework;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
namespace Content.Tests.Client
{
[TestFixture]
public class ClickMapTest
{
[Test]
public void TestBasic()
{
var img = new Image<Rgba32>(2, 2)
{
[0, 0] = new Rgba32(0, 0, 0, 0f),
[1, 0] = new Rgba32(0, 0, 0, 1f),
[0, 1] = new Rgba32(0, 0, 0, 1f),
[1, 1] = new Rgba32(0, 0, 0, 0f)
};
var clickMap = ClickMapManager.ClickMap.FromImage(img, 0.5f);
Assert.That(clickMap.IsOccluded(0, 0), Is.False);
Assert.That(clickMap.IsOccluded(1, 0), Is.True);
Assert.That(clickMap.IsOccluded(0, 1), Is.True);
Assert.That(clickMap.IsOccluded(1, 1), Is.False);
}
[Test]
public void TestThreshold()
{
var img = new Image<Rgba32>(2, 2)
{
[0, 0] = new Rgba32(0, 0, 0, 0f),
[1, 0] = new Rgba32(0, 0, 0, 0.25f),
[0, 1] = new Rgba32(0, 0, 0, 0.75f),
[1, 1] = new Rgba32(0, 0, 0, 1f)
};
var clickMap = ClickMapManager.ClickMap.FromImage(img, 0.5f);
Assert.That(clickMap.IsOccluded(0, 0), Is.False);
Assert.That(clickMap.IsOccluded(1, 0), Is.False);
Assert.That(clickMap.IsOccluded(0, 1), Is.True);
Assert.That(clickMap.IsOccluded(1, 1), Is.True);
}
}
}