Skip to content

fix(maths): correct coordinate subtraction in DistanceFormula.euclideanDistance - #7747

Merged
DenizAltunkapan merged 2 commits into
TheAlgorithms:masterfrom
spidervirus:fix/euclidean-distance-formula
Nov 12, 2026
Merged

DenizAltunkapan merged 2 commits into
TheAlgorithms:masterfrom
spidervirus:fix/euclidean-distance-formula

Conversation

@spidervirus

Copy link
Copy Markdown
Contributor
  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Description

Fixes #7746

In DistanceFormula.euclideanDistance, the variable dY was calculated using Math.pow(y2 - x1, 2) where x1 was incorrectly used instead of y1.

This PR:

  1. Fixes dY to compute Math.pow(y2 - y1, 2).
  2. Updates DistanceFormulaTest.java with the mathematically exact Euclidean distances.
  3. Adds test cases covering zero distance, a 3-4-5 Pythagorean triangle, and negative coordinates.

@codecov-commenter

codecov-commenter commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.34%. Comparing base (c468089) to head (8368e91).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7747   +/-   ##
=========================================
  Coverage     82.34%   82.34%           
- Complexity     8446     8447    +1     
=========================================
  Files           843      843           
  Lines         26156    26156           
  Branches       5110     5110           
=========================================
+ Hits          21537    21539    +2     
+ Misses         3831     3830    -1     
+ Partials        788      787    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@spidervirus
spidervirus marked this pull request as ready for review November 11, 2026 14:41

@DenizAltunkapan DenizAltunkapan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@spidervirus thanks

@DenizAltunkapan
DenizAltunkapan merged commit 02ebe07 into TheAlgorithms:master Nov 12, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

[BUG] Incorrect coordinate subtraction in DistanceFormula.euclideanDistance

3 participants