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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jjatie struct in swift 4.2 is still copied on assigning right?just checked the doc it's still copied.refresh()
will override_touchMatrix
withmatrix
@anton-filimonov in
refresh()->limitTransAndScale()
,matrix
will be different anyway so it makesmatrix != originalMatrix
always true to me... and invalidates this changeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liuxuan30 yes, value types are copied on assigning, but that doesn't mean that comparing those values is useless because they are compared by value not by address. And since we are on the edge of available region we always get equal matrixes back from
refresh()->limitTransAndScale()
. And test shows that this change prevents calls ofchartTranslated
when no translation really happens.The thing I really forgot to do is to do the same check when scale is performed. So I'll update this PR with that change soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liuxuan30 well I checked the situation with scale and same change there is not needed this much because delegate method calls there are limited with some other conditions. False calls are still possible there but it's only one call, for example when we zoom out the chart when it's already zoomed out to minimum (on the first call object think that we zoom in because no scale was made before)
So I'm not sure this change is needed. What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anton-filimonov @liuxuan30 A struct is not copied on assigning. While a struct is passed by value, it is copy-on-write, meaning it is only copied when the two values diverge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jjatie
from https://docs.swift.org/swift-book/LanguageGuide/ClassesAndStructures.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested on the edge, there are some
matrix == originalMatrix
cases, but there are also multiple false cases mixing up at the same time?is this why you asked
So I'm not sure this change is needed.
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm not sure this change is needed.
was about adding the same change to pinch gesture handling before callingchartScaled
. There are two checks before all the work is done (canZoomMoreX
,canZoomMoreY
) and they eliminate almost all false calls, that's why I'm not sure this change is needed for that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's much easier to reproduce the issue with false calls of
chartTranslated
when you scroll to the corner (I edited two last steps to reproduce the issue in #3803 ) so that translation is blocked in two directions and every scrolling step will cause no change to the transformation matrixThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but there are also multiple false cases mixing up at the same time
Probably some translation still occurs in this case. Maybe for example you reached the right edge but scrolled right-up.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I mean, adding this fix can filter a few calls, but generally, it won't prevent the delegate get called no matter where you are. You cannot rely on it to judge if you are on edge or something.