leftiness / hex_math

MIT License
4 stars 1 forks source link

impl Add for HasValues #16

Closed leftiness closed 8 years ago

leftiness commented 8 years ago

I'm currently doing something like this for #7:

pub fn distance_2d<T: HasValues>(point: &T, other: &T) -> i32 {
  let diff: Point = &point.to_point() - &other.to_point();
  let (q, r, s) = diff.values_cube_2d();
  let distance = (q.abs() + r.abs() + s.abs()) / 2;

  distance
}

I'd like to do let diff: Point = &point - &other; or let (q, r, t) = &point - &other; Maybe the second one is better since it doesn't require a conversion to Point unless I'm actually looking for that... in which case I'll use the new From::from or Point::from_values stuff.

Anyway, this HasValues - HasValues bit wasn't working. If I had it, then I could also get rid of the Add/Sub implementation on Point.

leftiness commented 8 years ago

impl Add<&HasValues> for &HasValues would require impl From<(i32, i32, i32)> for HasValues. I don't want to do that because a HasValues isn't necessarily just a coordinate tuple like Point is. If I want to add or subtract, I've got HasValues::to_point().