Periodic tag matching

I tried something earlier to order different vectors by their angle. Would this also work for the recent periodic tag matching?

I would just use the xAxis (1, 0, 0) for the "a" vector.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    float angle(Vector3 a, Vector3 b) {
        
        float result = 0
        
        if b.y <= 0 {
            result = -1 - dotProduct(a, b)
        }
        
        if b.y > 0 {
            result = 1 + dotProduct(a, b)
        }
        
        return result
    }

Edited by elle on
If you do this, then you must be sure that vectors a and b is normalized. Depending on how many asset queries will be needed that may be too expensive.

And this will make asset creating a bit more difficult. Because, let's say you want hero asset that faces 45 degree direction. That is in "middle" of 0 and 1. But in your case it is not 0.5. It is 0.7071 = cos(pi/4). For angle variant what is used in stream it is easy - middle of 0 and pi/2 is pi/4.

Also to avoid branches do this:
1
result = sign(b.y) * (1 + dot(a,b))

This assuming sign returns only -1 or +1, but never 0.