-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortQuantized2.cs
45 lines (41 loc) · 1.09 KB
/
SortQuantized2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Collections.Generic;
/// <summary>
/// Sorts 2D vectors by quantizing them such that nearby vectors will be
/// treated as equal.
/// </summary>
public class SortQuantized2 : IComparer<Vec2>
{
/// <summary>
/// The quantization levels.
/// </summary>
protected readonly int levels;
/// <summary>
/// The quantization levels.
/// </summary>
/// <value>levels</value>
public int Levels
{
get
{
return this.levels;
}
}
/// <summary>
/// Constructs a quantized comparer.
/// </summary>
/// <param name="levels">quantization levels</param>
public SortQuantized2(in int levels = (int)(1.0f / Utils.Epsilon))
{
this.levels = levels < 2 ? 2 : levels;
}
/// <summary>
/// Compares two quantized vectors.
/// </summary>
/// <param name="a">left comparisand</param>
/// <param name="b">right comparisand</param>
/// <returns>evaluation</returns>
public int Compare(Vec2 a, Vec2 b)
{
return Vec2.Quantize(a, levels).CompareTo(Vec2.Quantize(b, levels));
}
}