-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortQuantized3.cs
45 lines (41 loc) · 1.1 KB
/
SortQuantized3.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 3D vectors by quantizing them such that nearby vectors will be
/// treated as equal.
/// </summary>
public class SortQuantized3 : IComparer<Vec3>
{
/// <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 SortQuantized3(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(Vec3 a, Vec3 b)
{
return Vec3.Quantize(a, levels).CompareTo(Vec3.Quantize(b, levels));
}
}