leftiness / hex_math

MIT License
4 stars 1 forks source link

Implement hex-to-pixel, pixel-to-hex #51

Closed leftiness closed 8 years ago

leftiness commented 8 years ago

I thought I wouldn't need this, but it's actually needed for #41.

Basically, I have two QRT f32 points. One is in the center of the hex ("round"), and the other is a step along the line ("found"). I want to calculate the angle in order to determine which wall the line will exit on the side. However, (found.q - round.q, found.r - round.r) isn't really the (base, height aka adjacent, opposite) of the triangle on which I can use trig to find the angle.

So I need those XY coordinates from hex-to-pixel. Then I'll be able to use the X and Y difference as the triangle side lengths.

leftiness commented 8 years ago

Mm. I'm going to have to change the generic implementation of HasValues again. To do this pixel calculation, I need to add sqrt(3). I can't add sqrt(3) to type T because I can't enforce that type T implements Add<f32> because i32 doesn't do that.

So. Maybe HasValues will not be generic, and all values returned will always be f32 values?