-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
refactor() change common ancenstors returned data to help isInFrontOf #7906
Conversation
@ShaMan123 this is how i would like to change findCommonAncestors so that we don't have to repeat the logic in isInFronOf. Code amount is the same ( i think i added 3 lines ) but the logic is less. Let me know what do you think |
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.
This is much better!
- Now I think of another change that will make it more comprehensible.
I think we should renameancestors
prop tocommon
so the return value will be an object offork, otherFork, common
.
Then we handle the 2 cases ofthis
other
that are descendants of each other as follows:
Ifb
is a child ofa
then:
var retVal = b.findCommonAncestors(a);
retVal === { fork: [b], otherFork: [], common: [a] }
instead of
var retVal = b.findCommonAncestors(a);
retVal === { fork: [b, a], otherFork: [a], ancestors: [] }
because strictly thinking of the meaning of fork isn't suitable to how it's used currently.
-
The other suggestion is logic. Don't you prefer unshifting the ancestor arrays and removing the equality checks of
this === otherAncestor[j]
|other=== ancestor[i]
I think it's less confusing. -
Maybe add some more comments as it is logically complicated.
-
we might want to rename the method to
compareTrees
orcompareAncestors
updated review comment |
The only reason for not unshifiting is not readibility, but is that once you put the object inside the array, you don't know anymore which is a parent and which not. If it stay outside for the internal logic is better. I have no issue with having the function oriented on commonTree VS commonAncestors, but if there is not a direct practical advantage in doing that now, i prefer to move forward. |
How else this function is used? right now just for isInFrontOf and is doing its job fine enough. |
Only isInFrontOf uses it. but devs will use it probably. And it is healthier what I suggested. |
Ahh the return value needs to be changed to utilize the |
What does it mean healtier? in this case we have 3 parts, the common trunk and the branches. in the other case we have a slightly different point of view of the same data structure. |
The advantage is that the forks are entirely different. |
I have in mind what you said about |
no they can't have the same top ancestor right now, how would that happen? |
I meant 2 forks can have the same |
Pushed 2319d4f |
@@ -62,28 +66,37 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot | |||
} | |||
var ancestors = this.getAncestors(strict); | |||
var otherAncestors = other.getAncestors(strict); | |||
// if `this` has no ancestors and `this` is top ancestor of `other` we must handle the following 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.
maybe this condition should come after the for loop for readability
Not sure why that would happen, but is fine by me changing, i wouldn't have re-typed everything, but since you did is fine.
In general try to don't push on others PRs without a prior agreement. |
Have findCommonAncestors return 3 arrays, representing, the common ancestors, and the forks of non common ancestors down to the objects themselves.
Rules:
this | other
, forks are completely different