Closed leftiness closed 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.
impl HasValues<f32> for FloatPoint
impl HasValues<i32> for Point
FloatPoint::round() -> Point
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.
f32 doesn't hash... today is a bad day...
Conflicting thoughts:
impl HasValues<i32> for Point<i32>
,impl HasValues<f32> for Point<f32>
impl HasValues<i32> for Point
,impl HasValues<f32> for FloatPoint
use HasValues<f32>
,FloatPoint::round() -> Point
use HasValues<f32>
,HasValues<f32>::round() -> Point
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().