Zaflis wrote: Sun Sep 14, 2025 4:21 pm
But i never considered this mod to actually use more than 8 rail directions, the extra angles between were just for immersion. I set it to 8 in mod settings myself.
 
Ok, you are using only 8 directions when playing the game.
Nevertheless the most popular user choice is 16, not 8.
So thank you for making your mod useful for all users, not only for users sharing your position.
"Snapping to Rail Angles" feature is just one more step to make your mod useful for everyone.
I believe it would be a valuable addition to VehicleSnap.
Do you remember your own description of the mod?
> Have you ever faced a problem when trying to drive exactly along a road, coastline or railroad, that car moves a tiny bit off to side?
You have mentioned "moving along a railroad" as what your mod was designed for.
So, it is quite natural for a mod user to expect that this feature will be in sync with Factorio rail system.
In my opinion, the angle (360°/16) does not have any practical value in the game.
All useful angles in Factorio equals to 
arctg(m/n) with some small integers 
m and 
n.
For example, the "half-diagonal rail" angle is not rail-specific: some of my defense structures have wall borders with the same angle (1 step north and 2 steps east, repeat).
Zaflis wrote: Sun Sep 14, 2025 4:21 pm
Your math is also something i don't follow  
 
 
 
I agree, my code is not a good code, it is not easy-to-understand.
My algo of calculating the snapping angle consists of three steps:
1. Calculate which 1/8 part of 360° the current orientation is inside.  I used your own formula "multiply and round" here.
2. The current 1/8 consists of two UNEQUAL halves (1/16 each), so, direct angle comparison is used to determine which 1/16 is ours.
3. The current 1/16 consists of 2 equal 1/32 (or 3 equal 1/48, etc), so again using "multiply and round".
Zaflis wrote: Sun Sep 14, 2025 4:21 pm
My thought after was to record those key angles into a table and then interpolate current angle to closest from the table. It'd just be a table of 16 numbers.
 
Yes, your approach would lead to a more-easy-to-understand code.
It looks like a good idea to write your own implementation instead of using my code as-is.