leftiness / hex_math

MIT License
4 stars 1 forks source link

Figure out f32 Point #52

Closed leftiness closed 7 years ago

leftiness commented 7 years ago

Conflicting thoughts:

At any rate, I want a struct to hold f32 points for use in line(), and I want to get the round() function out of line().

leftiness commented 7 years ago

This morning, I tried making a generic Point<T = i32> where T: Add + Sub + From<f32>, where i32 is the default but you can give it a different type like f32. I also then made HasValues<T = i32> where T....

I used that From<f32> bit because my Point::new_2d() function requires that I provide a default 0 value for the T coordinate.

The problem is that Rust requires you to keep track of number types in order to allocate memory. Generic numbers are a real mess for that. I feel like it's working against Rust to even try: http://stackoverflow.com/questions/26810793/how-can-i-create-an-is-prime-function-that-is-generic-over-various-integer-types/26811100#26811100

My use case is limited. I don't actually want or need anything like a Point<i8> or a Point<AnyNumberType>. I need a FloatPoint struct.

leftiness commented 7 years ago

Just gonna use f32 for all points? Is that a problem? I mean. The max f32 is 1e38. That's obscenely large still. It would mean that a point struct represents not the center of a hex but in fact just a point on a hex grid. Another struct would enforce a center value. For example, prism accepts a point at construction. It could Point::round() to get the point representing the center of the hex.

leftiness commented 7 years ago

f32 doesn't hash... today is a bad day...