Skip to content
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

Adding Torque #117

Closed
dunmatt opened this issue Mar 24, 2019 · 3 comments
Closed

Adding Torque #117

dunmatt opened this issue Mar 24, 2019 · 3 comments

Comments

@dunmatt
Copy link

dunmatt commented Mar 24, 2019

This is a continuation of #114 (which will be closed when #115 goes in) that adds Torque.

I'm starting to look at adding torque, but I have a question. Over in #114 you mentioned that the new Kind will likely want to implement all of the marker traits, but I'm not sure I understand why you said that. What would it mean to divide a torque by an energy? (for example)

Edit: I think I've figured out the answer to my own question (I'd still appreciate confirmation though). I think it never derives inter-Kind mathematical operators. If that's the case, may I suggest changing the docs on the markers? "Trait to denote that a quantity is able to be X with a quantity of the same dimensions." makes it sound like the Kind isn't taken into account.

@iliekturtles
Copy link
Owner

Kind serves two purposes in uom. Both to distinguish different quantities of the same dimension that are not mutually comparable (e.g. torque and energy) as well as governing what operations (+, -, *, ...) can be used on the quantity. In torque's case we don't want it comparable with energy but we still want to be able to add torques together as well as perform other operations.

The definition should probably look like this:

pub trait TorqueKind: // still haven't done any research to see what the appropriate name would be.
    marker::Add + marker::AddAssign
    + marker::Sub + marker::SubAssign
    + marker::Mul + marker::MulAssign
    + marker::Div + marker::DivAssign
    + marker::Rem + marker::RemAssign
    + marker::Neg + marker::Saturating
{
}

This all works because Kind is one of the associated types of Dimension. impl blocks for traits like Add or Eq only define a single Dimension generic parameter ensuring that you can only add or compare quantities with the exact sameDimension and therefore exact same Kind. Other impl blocks such as for Mul have a generic parameter for each quantity's Dimension but constrain the impl to kinds that implement the marker::Mul trait.

@dunmatt
Copy link
Author

dunmatt commented Mar 24, 2019

That makes sense, and it's consistent with my edit above. The next question, then, is how are lines like

let _: Torque<V> = Force::new::<f::newton>(V::one()) * Length::new::<l::meter>(V::one());

supposed to compile? Right now it's giving me a type mismatch on account of Torque's kind (using the example kind you supplied).

@iliekturtles
Copy link
Owner

Force * Length can be energy or torque. The Mul trait uses Energy as the result as Energy uses the default Kind. The only previous time Kind has been used was for thermodynamic temperature vs. temperature interval and a calculation result like this wasn't relevant. I see a couple possible solutions:

  1. Don't actually use a distinct Kind for Torque. This makes Torque and Energy aliases and directly comparable. Try this one first.
  2. Add a method or trait impl (From?) to allow for the explicit conversion between Torque and Energy.

dunmatt pushed a commit to dunmatt/uom that referenced this issue May 8, 2019
@dunmatt dunmatt closed this as completed May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants