Skip to content

Cannot implement Mul with different RHS and/or different Return type on one type #7935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeaye opened this issue Jul 20, 2013 · 2 comments
Closed
Labels
A-trait-system Area: Trait system

Comments

@jeaye
Copy link

jeaye commented Jul 20, 2013

I wrote this thinking it would be possible, but it turns out it isn't yet. It would be very nice if this could be done.

impl Mul<Quaternion, Quaternion> for Quaternion
{
  fn mul(&self, rhs: &Quaternion) -> Quaternion
  {
    Quaternion::new
    (
      self.w * rhs.x + self.x * self.w + self.y * rhs.z - self.z * rhs.y,
      self.w * rhs.y + self.y * self.w + self.z * rhs.x - self.x * rhs.z,
      self.w * rhs.z + self.z * self.w + self.x * rhs.y - self.y * rhs.x,
      self.w * rhs.w - self.x * self.x - self.y * rhs.y - self.z * rhs.z
    )
  }
}

impl Mul<math::Vec3f, math::Vec3f> for Quaternion
{
  fn mul(&self, rhs: &math::Vec3f) -> math::Vec3f
  {
    let vn = math::Vec3f::new_normalized(rhs);
    let vecq = Quaternion::new(vn.x, vn.y, vn.z, 0.0);
    let resq = (vecq * self.get_conjugate()) * self;

    math::Vec3f::new(resq.x, resq.y, resq.z)
  }
}

impl Mul<Component, Quaternion> for Quaternion
{
  fn mul(&self, rhs: &Component) -> Quaternion
  {
    Quaternion::new
    (
      self.x * *rhs,
      self.y * *rhs,
      self.z * *rhs,
      self.w * *rhs
    )
  }
}
@huonw
Copy link
Member

huonw commented Jul 21, 2013

There is a work-around, described here under "what if I want overloading?", but hopefully the code you write will be legal some day.

@huonw
Copy link
Member

huonw commented Nov 15, 2013

Triage: dupe of #7590.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

2 participants