The 2024 Wheel Reinvention Jam is in 16 days. September 23-29, 2024. More info

GetBestMatchAssestFrom: handling periodic ranges

Currently, the handling of periodic ranges in GetBestMatchAssestFrom is implemented as

1
2
3
real32 D0 = AbsoluteValue(A - B);
real32 D1 = AbsoluteValue((A - Assets->TagRange[Tag->ID]*SignOf(A)) - B);
real32 Difference = Minimum(D0, D1);


An alternative implementation might be
1
2
3
real32 Difference = AbsoluteValue(A - B);
if (Difference > TagRange[Tag->ID])
   Difference = 2 * TagRange[Tag->ID] - Difference;


I don't think the alternative implementation is necessarily any better. Although, at least for me, it is easier to visualize what is going on with the math.

Thanks!
I agree that the alternative might be easier to visualize.

The original does have one additional advantage in it's current form. The TagRange could be set to 0 to indicate a non-periodic tag. Currently Casey set the period to 100,000 or something high. But the code would still work and might even be better with a TagRange of 0.

Of course this non-periodicity could be added in you alternative implementation by adding a test for 0 too, though it is another test.
That point about 0 is a pretty good point... we probably should do it that way...

- Casey