Fix Line#getSignedDistance and add tests to avoid regression#1880
Open
roissard wants to merge 1 commit intopaperjs:developfrom
Open
Fix Line#getSignedDistance and add tests to avoid regression#1880roissard wants to merge 1 commit intopaperjs:developfrom
roissard wants to merge 1 commit intopaperjs:developfrom
Conversation
Member
|
I am getting this error when running the tests locally, rebased on top of the Strangely this only happens in the tests that run in Node, and not the browser ones… I need to look more into which test actually fails, the message is somehow missing. But we need to figure this out before being able to merge. |
Member
|
If you rebase on top of So in short, it's this test: const p1 = PathItem.create([[249.53400844979302, 269.5706278725207, 0, 0, -5.202299838213264, 1.3434437726778015], [243.02912232136828, 272.45353289318496, -0.02459817048722357, 0.029126503110205704, 0, 0], [197.1892333604494, 233.7404268430289], true])
const p2 = PathItem.create([[243.02912232136822, 272.453532893185, 0, 0, 0.44566136595048533, -0.527704170852985], [242.66927041668393, 276.2408467361064, -0.16957999946740188, -3.971488536288973, 0, 0], [197.18923336044946, 233.74042684302884], true])
p1.strokeColor = 'red'
p2.strokeColor = 'green'
p1.strokeScaling = p2.strokeScaling = false;
const result = p1.intersect(p2)
result.fillColor = 'yellow'
result.selected = true
view.matrix = [1769.1029649736397, 0, 0, 1769.1029649736397, -429598.57726305583, -481524.06395399297]If I run this against But run against your change, the result is empty… |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
The proposed calculation for
getSignedDistanceis wrong.When rewriting:
Math.sqrt(vxvx+vyvy)
into:
vy * Math.sqrt(1 + (vx * vx) / (vy * vy))
The sign of vy may break the equivalence, it should be:
Math.abs(vy) * Math.sqrt(1 + (vx * vx) / (vy * vy))
Related issues
Checklist
npm run jshintpasses)