First, I don't actually know what language you are posting in, I can't identify it. But, this answer is fairly language-agnostic, so please translate back to your preferred language. I have guessed at the syntax below.
You need to find a way to parameterize and calculate your search metric such that any two object a
and b
can be distinctly ordered based on a scalar value without additional information during the sort.
For example, if base
is constant for a given sort operation:
Class VectorSorter : IComparer<Vector3> {
private Vector3 base;
public VectorSorter (Vector3 base) {
this.base = base;
}
public int compare (Vector3 spot1, Vector3 spot2) {
return (base-spot1).magnitude.CompareTo((base-spot2).magnitude);
}
}
Then you pass new VectorSorter(theBaseToUseWhenSorting)
as the comparator to your sort function.
If base
isn't constant then you will need to find another way to express your data set, in a way that has a distinct natural ordering; perhaps create some object that holds calculation results then sort a list of those objects based on a scalar result of the calculation, etc. I can't really give you any more specific advice (or even a good example) there without knowing more about how base
correlates with spot1
and spot2
during the sort operation.