Skip to content

Conversation

@SuleymanSade
Copy link

Adds a simple .hplot() method with tests that gets the hypothenuse between two distances. Contains both static and instance versions. Fixes #7666

@SuleymanSade SuleymanSade requested a review from a team as a code owner December 21, 2025 01:11
@github-actions github-actions bot added the component: wpiunits Java units library label Dec 21, 2025
@auscompgeek
Copy link
Member

I'm confused as to why this PR was recreated, when it looks like it's the same commits.

@SuleymanSade
Copy link
Author

SuleymanSade commented Dec 21, 2025

It is not the same. The previous implementation of hypot() was using Measure with some other things, which was wrong. Like the implementation itself was wrong, I think. And I added some more detail to the comments. I think it should work now, and yet it still didn't pass the tests.

Here is a more clear comparison of the static hypot():
current:
static Distance hypot(Distance a, Distance b) {
return a.unit().ofBaseUnits(
Math.hypot(a.in(a.unit().getBaseUnit()), b.in(b.unit().getBaseUnit()))
);
}

old version:
static Distance hypot(Measure<? extends DistanceUnit> a, Measure<? extends DistanceUnit> b) {
return (Distance) a.unit().ofBaseUnits(Math.hypot(a.baseUnitMagnitude(), b.baseUnitMagnitude()));
}

I might be wrong.

@auscompgeek
Copy link
Member

From what I can see, both #8495 and this PR have e5eb237 as the latest commit.

@SuleymanSade
Copy link
Author

SuleymanSade commented Dec 21, 2025

Now I see the problem. I pushed my new commit on the same repo, so the PR #8495 was also updated with the new commit. I thought I had to create a new PR with the new commit. Because when I did the PR #8495 I originally only had the commit a2dcf09. So you are right, this was an unnecessary extra PR that I hadn't realized. Sorry about that, I didn't know PRs worked this way.

*/
static Distance hypot(Distance a, Distance b) {
return a.unit().ofBaseUnits(
Math.hypot(a.in(a.unit().getBaseUnit()), b.in(b.unit().getBaseUnit()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not use the same unit for both values?

Copy link
Author

@SuleymanSade SuleymanSade Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? I am confused. It uses Distance for both of the parameters and the return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: wpiunits Java units library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add hypotnuse method to Distance

3 participants