Browse Source

PorterDuff tests

pull/202/head
Scott Williams 9 years ago
parent
commit
bfed55d4a1
  1. 3
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  2. 183
      tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs
  3. 193
      tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs
  4. 5
      tests/ImageSharp.Tests/PixelFormats/PixelOperations.cs
  5. 60
      tests/ImageSharp.Tests/TestUtilities/TestVector4.cs
  6. 98
      tests/ImageSharp.Tests/VectorAssert.cs

3
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -27,7 +27,4 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="PixelFormats\PixelBlenders\" />
</ItemGroup>
</Project>

183
tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs

@ -0,0 +1,183 @@
// <copyright file="PorterDuffFunctionsTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.PixelFormats.PixelBlenders
{
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using ImageSharp.PixelFormats.PixelBlenders;
using ImageSharp.Tests.TestUtilities;
using Xunit;
public class PorterDuffFunctionsTests
{
public static TheoryData<TestVector4, TestVector4, float, TestVector4> NormalBlendFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(0.6f, 0.6f, 0.6f, 1) },
};
[Theory]
[MemberData(nameof(NormalBlendFunctionData))]
public void NormalBlendFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.NormalBlendFunction(back, source, amount);
Assert.Equal(expected, actual);
}
public static TheoryData<TestVector4, TestVector4, float, TestVector4> MultiplyFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(0.6f, 0.6f, 0.6f, 1) },
{
new TestVector4(0.9f,0.9f,0.9f,0.9f),
new TestVector4(0.4f,0.4f,0.4f,0.4f),
.5f,
new TestVector4(0.7834783f, 0.7834783f, 0.7834783f, 0.92f)
},
};
[Theory]
[MemberData(nameof(MultiplyFunctionData))]
public void MultiplyFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.MultiplyFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 5);
}
public static TheoryData<TestVector4, TestVector4, float, TestVector4> AddFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(.6f, .6f, .6f, 1f) },
{
new TestVector4(0.2f,0.2f,0.2f,0.3f),
new TestVector4(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestVector4(.2075676f, .2075676f, .2075676f, .37f)
},
};
[Theory]
[MemberData(nameof(AddFunctionData))]
public void AddFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.MultiplyFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 5);
}
public static TheoryData<TestVector4, TestVector4, float, TestVector4> SubstractFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(0,0,0,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(1,1,1, 1f) },
{
new TestVector4(0.2f,0.2f,0.2f,0.3f),
new TestVector4(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestVector4(.2027027f, .2027027f, .2027027f, .37f)
},
};
[Theory]
[MemberData(nameof(SubstractFunctionData))]
public void SubstractFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.SubstractFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 5);
}
public static TheoryData<TestVector4, TestVector4, float, TestVector4> ScreenFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(1,1,1, 1f) },
{
new TestVector4(0.2f,0.2f,0.2f,0.3f),
new TestVector4(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestVector4(.2383784f, .2383784f, .2383784f, .37f)
},
};
[Theory]
[MemberData(nameof(ScreenFunctionData))]
public void ScreenFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.ScreenFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 5);
}
public static TheoryData<TestVector4, TestVector4, float, TestVector4> DarkenFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(.6f,.6f,.6f, 1f) },
{
new TestVector4(0.2f,0.2f,0.2f,0.3f),
new TestVector4(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestVector4(.2189189f, .2189189f, .2189189f, .37f)
},
};
[Theory]
[MemberData(nameof(DarkenFunctionData))]
public void DarkenFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.DarkenFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 5);
}
public static TheoryData<TestVector4, TestVector4, float, TestVector4> LightenFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(1,1,1,1f) },
{
new TestVector4(0.2f,0.2f,0.2f,0.3f),
new TestVector4(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestVector4(.227027f, .227027f, .227027f, .37f)
},
};
[Theory]
[MemberData(nameof(LightenFunctionData))]
public void LightenFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.LightenFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 5);
}
public static TheoryData<TestVector4, TestVector4, float, TestVector4> OverlayFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(1,1,1,1f) },
{
new TestVector4(0.2f,0.2f,0.2f,0.3f),
new TestVector4(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestVector4(.2124324f, .2124324f, .2124324f, .37f)
},
};
[Theory]
[MemberData(nameof(OverlayFunctionData))]
public void OverlayFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.OverlayFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 5);
}
public static TheoryData<TestVector4, TestVector4, float, TestVector4> HardLightFunctionData = new TheoryData<TestVector4, TestVector4, float, TestVector4>() {
{ new TestVector4(1,1,1,1), new TestVector4(1,1,1,1), 1, new TestVector4(1,1,1,1) },
{ new TestVector4(1,1,1,1), new TestVector4(0,0,0,.8f), .5f, new TestVector4(0.6f,0.6f,0.6f,1f) },
{
new TestVector4(0.2f,0.2f,0.2f,0.3f),
new TestVector4(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestVector4(.2124324f, .2124324f, .2124324f, .37f)
},
};
[Theory]
[MemberData(nameof(HardLightFunctionData))]
public void HardLightFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
{
Vector4 actual = PorterDuffFunctions.HardLightFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 5);
}
}
}

193
tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs

@ -0,0 +1,193 @@
// <copyright file="PorterDuffFunctions<TPixel>Tests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.PixelFormats.PixelBlenders
{
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using ImageSharp.PixelFormats;
using ImageSharp.PixelFormats.PixelBlenders;
using ImageSharp.Tests.TestUtilities;
using Xunit;
public class PorterDuffFunctionsTests_TPixel
{
public static TheoryData<object, object, float, object> NormalBlendFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(1,1,1,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(0.6f, 0.6f, 0.6f, 1) },
};
[Theory]
[MemberData(nameof(NormalBlendFunctionData))]
public void NormalBlendFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.NormalBlendFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 3);
}
public static TheoryData<object, object, float, object> MultiplyFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(1,1,1,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(0.6f, 0.6f, 0.6f, 1) },
{
new TestPixel<Rgba32>(0.9f,0.9f,0.9f,0.9f),
new TestPixel<Rgba32>(0.4f,0.4f,0.4f,0.4f),
.5f,
new TestPixel<Rgba32>(0.7834783f, 0.7834783f, 0.7834783f, 0.92f)
},
};
[Theory]
[MemberData(nameof(MultiplyFunctionData))]
public void MultiplyFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.MultiplyFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 2);
}
public static TheoryData<object, object, float, object> AddFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(1,1,1,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(.6f, .6f, .6f, 1f) },
{
new TestPixel<Rgba32>(0.2f,0.2f,0.2f,0.3f),
new TestPixel<Rgba32>(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestPixel<Rgba32>(.2075676f, .2075676f, .2075676f, .37f)
},
};
[Theory]
[MemberData(nameof(AddFunctionData))]
public void AddFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.MultiplyFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 2);
}
public static TheoryData<object, object, float, object> SubstractFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(0,0,0,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(1,1,1, 1f) },
{
new TestPixel<Rgba32>(0.2f,0.2f,0.2f,0.3f),
new TestPixel<Rgba32>(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestPixel<Rgba32>(.2027027f, .2027027f, .2027027f, .37f)
},
};
[Theory]
[MemberData(nameof(SubstractFunctionData))]
public void SubstractFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.SubstractFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 2);
}
public static TheoryData<object, object, float, object> ScreenFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(1,1,1,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(1,1,1, 1f) },
{
new TestPixel<Rgba32>(0.2f,0.2f,0.2f,0.3f),
new TestPixel<Rgba32>(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestPixel<Rgba32>(.2383784f, .2383784f, .2383784f, .37f)
},
};
[Theory]
[MemberData(nameof(ScreenFunctionData))]
public void ScreenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.ScreenFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 2);
}
public static TheoryData<object, object, float, object> DarkenFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(1,1,1,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(.6f,.6f,.6f, 1f) },
{
new TestPixel<Rgba32>(0.2f,0.2f,0.2f,0.3f),
new TestPixel<Rgba32>(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestPixel<Rgba32>(.2189189f, .2189189f, .2189189f, .37f)
},
};
[Theory]
[MemberData(nameof(DarkenFunctionData))]
public void DarkenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.DarkenFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 2);
}
public static TheoryData<object, object, float, object> LightenFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(1,1,1,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(1,1,1,1f) },
{
new TestPixel<Rgba32>(0.2f,0.2f,0.2f,0.3f),
new TestPixel<Rgba32>(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestPixel<Rgba32>(.227027f, .227027f, .227027f, .37f)
},
};
[Theory]
[MemberData(nameof(LightenFunctionData))]
public void LightenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.LightenFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 2);
}
public static TheoryData<object, object, float, object> OverlayFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(1,1,1,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(1,1,1,1f) },
{
new TestPixel<Rgba32>(0.2f,0.2f,0.2f,0.3f),
new TestPixel<Rgba32>(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestPixel<Rgba32>(.2124324f, .2124324f, .2124324f, .37f)
},
};
[Theory]
[MemberData(nameof(OverlayFunctionData))]
public void OverlayFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.OverlayFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 2);
}
public static TheoryData<object, object, float, object> HardLightFunctionData = new TheoryData<object, object, float, object>() {
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(1,1,1,1), 1, new TestPixel<Rgba32>(1,1,1,1) },
{ new TestPixel<Rgba32>(1,1,1,1), new TestPixel<Rgba32>(0,0,0,.8f), .5f, new TestPixel<Rgba32>(0.6f,0.6f,0.6f,1f) },
{
new TestPixel<Rgba32>(0.2f,0.2f,0.2f,0.3f),
new TestPixel<Rgba32>(0.3f,0.3f,0.3f,0.2f),
.5f,
new TestPixel<Rgba32>(.2124324f, .2124324f, .2124324f, .37f)
},
};
[Theory]
[MemberData(nameof(HardLightFunctionData))]
public void HardLightFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel>
{
TPixel actual = PorterDuffFunctions<TPixel>.HardLightFunction(back, source, amount);
VectorAssert.Equal(expected, actual, 2);
}
}
}

5
tests/ImageSharp.Tests/PixelFormats/PixelOperations.cs

@ -1,4 +1,7 @@

// <copyright file="PixelOperations.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.PixelFormats
{

60
tests/ImageSharp.Tests/TestUtilities/TestVector4.cs

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using ImageSharp.PixelFormats;
using Xunit.Abstractions;
namespace ImageSharp.Tests.TestUtilities
{
public class TestVector4 : IXunitSerializable
{
public TestVector4()
{
}
public TestVector4(float x, float y, float z, float w)
{
this.X = x;
this.Y = y;
this.Z = x;
this.W = w;
}
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public float W { get; set; }
public static implicit operator Vector4(TestVector4 d)
{
return d?.AsVector() ?? default(Vector4);
}
public Vector4 AsVector()
{
return new Vector4(this.X, this.Y, this.Z, this.W);
}
public void Deserialize(IXunitSerializationInfo info)
{
this.X = info.GetValue<float>("x");
this.Y = info.GetValue<float>("y");
this.Z= info.GetValue<float>("z");
this.W= info.GetValue<float>("w");
}
public void Serialize(IXunitSerializationInfo info)
{
info.AddValue("x", this.X);
info.AddValue("y", this.Y);
info.AddValue("z", this.Z);
info.AddValue("w", this.W);
}
public override string ToString()
{
return $"{this.AsVector().ToString()}";
}
}
}

98
tests/ImageSharp.Tests/VectorAssert.cs

@ -0,0 +1,98 @@
// <copyright file="VectorAssert.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// ReSharper disable MemberHidesStaticFromOuterClass
namespace ImageSharp.Tests
{
using System;
using System.Collections.Generic;
using System.Numerics;
using ImageSharp;
using ImageSharp.PixelFormats;
using Xunit;
/// <summary>
/// Class to perform simple image comparisons.
/// </summary>
public static class VectorAssert
{
public static void Equal<TPixel>(TPixel expected, TPixel actual, int precision = int.MaxValue)
where TPixel : struct, IPixel<TPixel>
{
Equal(expected.ToVector4(), actual.ToVector4(), precision);
}
public static void Equal(Vector4 expected, Vector4 actual, int precision = int.MaxValue)
{
Assert.Equal(expected, actual, new PrecisionEqualityComparer(precision));
}
public static void Equal(Vector3 expected, Vector3 actual, int precision = int.MaxValue)
{
Assert.Equal(expected, actual, new PrecisionEqualityComparer(precision));
}
public static void Equal(Vector2 expected, Vector2 actual, int precision = int.MaxValue)
{
Assert.Equal(expected, actual, new PrecisionEqualityComparer(precision));
}
private struct PrecisionEqualityComparer : IEqualityComparer<float>, IEqualityComparer<Vector4>, IEqualityComparer<Vector3>, IEqualityComparer<Vector2>
{
private readonly int precision;
public PrecisionEqualityComparer(int precision)
{
this.precision = precision;
}
public bool Equals(Vector2 x, Vector2 y)
{
return Equals(x.X, y.X) &&
Equals(x.Y, y.Y);
}
public bool Equals(Vector3 x, Vector3 y)
{
return Equals(x.X, y.X) &&
Equals(x.Y, y.Y) &&
Equals(x.Z, y.Z);
}
public bool Equals(Vector4 x, Vector4 y)
{
return Equals(x.W, y.W) &&
Equals(x.X, y.X) &&
Equals(x.Y, y.Y) &&
Equals(x.Z, y.Z);
}
public bool Equals(float x, float y)
{
return Math.Round(x, this.precision) == Math.Round(y, this.precision);
}
public int GetHashCode(Vector4 obj)
{
return obj.GetHashCode();
}
public int GetHashCode(Vector3 obj)
{
return obj.GetHashCode();
}
public int GetHashCode(Vector2 obj)
{
return obj.GetHashCode();
}
public int GetHashCode(float obj)
{
return obj.GetHashCode();
}
}
}
}
Loading…
Cancel
Save