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

Improve linemerge algorithm by adding prepending ability #496

Merged
merged 2 commits into from
Jun 21, 2022

Conversation

abey79
Copy link
Owner

@abey79 abey79 commented Jun 19, 2022

Description

Currently, the greedy algorithm of linemerge would only attempts to "append", which would make it sensitive to line order. With this PR, the algorithm now attempt to "prepend" as well, which improves on the situation.

Consider 3 points A, B, C and the pair of line AB and BC. The greedy algorithm works by picking the first line and merging it with any line whose endings match the end point (in this case B). Here, AB is picked and, since BC shares an endpoint, it is successfully merged.

If the input lines are swapped (BC then AB), the algorithm would first pick BC and look for lines with endpoint close to C. Since there are none, BC is kept as is, and then AB is processed. Since it's now alone, it's is also kept as is and the result is not merged. Now, the algo will also look for lines whose ending is close to B, finds AB, and successfully merges the two lines.

Obviously, the above is done while respecting the no-flip option.

Checklist

  • feature/fix implemented
  • code formatting ok (black and isort)
  • mypy returns no error
  • tests added/updated and pytest succeeds
  • documentation added/updated
    • command docstring and option/argument help
    • README.md updated (Feature Overview)
    • CHANGELOG.md updated
    • added new command to reference.rst
    • RTD doc updated and building with no error (make clean && make html in docs/)

@codecov
Copy link

codecov bot commented Jun 19, 2022

Codecov Report

Merging #496 (638426c) into master (25454b4) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #496      +/-   ##
==========================================
+ Coverage   94.38%   94.39%   +0.01%     
==========================================
  Files          60       60              
  Lines        5396     5409      +13     
  Branches      786      788       +2     
==========================================
+ Hits         5093     5106      +13     
  Misses        185      185              
  Partials      118      118              
Impacted Files Coverage Δ
vpype/line_index.py 89.13% <ø> (ø)
tests/test_model.py 100.00% <100.00%> (ø)
vpype/model.py 92.20% <100.00%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25454b4...638426c. Read the comment docs.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@abey79 abey79 merged commit 0963eb4 into master Jun 21, 2022
@abey79 abey79 deleted the fix-linemerge branch June 21, 2022 16:00
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.

1 participant