Skip to content

Add hypotnuse method to Distance #7666

Open
@MrTinker64

Description

@MrTinker64

Is your feature request related to a problem? Please describe.
I'm always frustrated when I have to do distance.in(distanceUnit) followed by some math and then unit.of(resultOfMyMath)

Describe the solution you'd like
The same way there is .div and .plus methods for Distance I would like a .hypot(otherDistance) method. Using the plus method at Line 59 of Distance as an example I would write it like this:

@Override
default Distance hypot(Measure<? extends DistanceUnit> other) {
  return (Distance) unit().ofBaseUnits(Math.hypot(baseUnitMagnitude() + other.baseUnitMagnitude()));
}

Additional context
Here's what I'm currently using as a work around in my code:

public static Distance hypot(Distance a, Distance b) {
  return a.unit().of(Math.hypot(a.magnitude(), b.magnitude()));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: wpiunitsJava units librarytype: featureBrand new functionality, features, pages, workflows, endpoints, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions