-
-
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
perPixelTargetFind not working in nested group. #5287
Merged
asturur
merged 12 commits into
fabricjs:master
from
doouding:fix-nested-perpixeltargertfind
Oct 13, 2018
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
34afb37
fix perPixelTargetFind in nested object
doouding 02cfb33
fix: lint
doouding 5985429
add methods doc
doouding 940a9f2
doc: update _serachPossibleTarget doc
doouding b0b0eb0
test: add test case
doouding f453fd3
fix: remove pointer check
doouding cc81ea5
fix: object in nested group should normalize just once
doouding 9865efd
test: add test case
doouding 4c92474
restore to previous code style
doouding b7b8a26
fix: update test case descriptions
doouding 1d22391
fix: test case
doouding 9bb43a5
test: add skew and angle test case
doouding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -790,6 +790,67 @@ | |
canvas.remove(triangle); | ||
}); | ||
|
||
QUnit.test('findTarget with perPixelTargetFind in nested group', function(assert) { | ||
assert.ok(typeof canvas.findTarget === 'function'); | ||
var triangle = makeTriangle({ left: 0, top: 0, width: 30, height: 30, fill: 'yellow' }), | ||
circle = new fabric.Circle({ radius: 30, top: 0, left: 30, fill: 'blue' }), | ||
circle2 = new fabric.Circle({ scaleX: 2, scaleY: 2, radius: 10, top: 120, left: -20, fill: 'purple' }), | ||
rect = new fabric.Rect({ width: 100, height: 80, top: 50, left: 60, fill: 'green' }), | ||
group1 = new fabric.Group([triangle, circle], { subTargetCheck: true }), | ||
group2 = new fabric.Group([group1, circle2, rect], { subTargetCheck: true }), | ||
group3 = new fabric.Group([group2], { subTargetCheck: true }), | ||
target; | ||
|
||
canvas.add(group3); | ||
canvas.perPixelTargetFind = true; | ||
target = canvas.findTarget({ | ||
clientX: 5, clientY: 5 | ||
}); | ||
assert.equal(target, null, 'Should return null because of transparency checks case 1'); | ||
target = canvas.findTarget({ | ||
clientX: 21, clientY: 9 | ||
}); | ||
assert.equal(target, null, 'Should return null because of transparency checks case 2'); | ||
target = canvas.findTarget({ | ||
clientX: 37, clientY: 7 | ||
}); | ||
assert.equal(target, null, 'Should return null because of transparency checks case 3'); | ||
target = canvas.findTarget({ | ||
clientX: 89, clientY: 47 | ||
}); | ||
assert.equal(target, null, 'Should return null because of transparency checks case 4'); | ||
target = canvas.findTarget({ | ||
clientX: 16, clientY: 122 | ||
}); | ||
assert.equal(target, null, 'Should return null because of transparency checks case 5'); | ||
target = canvas.findTarget({ | ||
clientX: 15, clientY: 15 | ||
}); | ||
assert.equal(target, group3, 'Should return the group3 now'); | ||
assert.equal(canvas.targets.length, 3, 'Subtargets length should be 3'); | ||
assert.equal(canvas.targets[0], triangle, 'The deepest target should be triangle'); | ||
target = canvas.findTarget({ | ||
clientX: 50, clientY: 20 | ||
}); | ||
assert.equal(target, group3, 'Should return the group3 now'); | ||
assert.equal(canvas.targets.length, 3, 'Subtargets length should be 3'); | ||
assert.equal(canvas.targets[0], circle, 'The deepest target should be circle'); | ||
target = canvas.findTarget({ | ||
clientX: 100, clientY: 90 | ||
}); | ||
assert.equal(target, group3, 'Should return the group3 now'); | ||
assert.equal(canvas.targets.length, 2, 'Subtargets length should be 2'); | ||
assert.equal(canvas.targets[0], rect, 'The deepest target should be rect'); | ||
target = canvas.findTarget({ | ||
clientX: 9, clientY: 145 | ||
}); | ||
assert.equal(target, group3, 'Should return the group3 now'); | ||
assert.equal(canvas.targets.length, 2, 'Subtargets length should be 2'); | ||
assert.equal(canvas.targets[0], circle2, 'The deepest target should be circle2'); | ||
canvas.perPixelTargetFind = false; | ||
canvas.remove(triangle); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is group3, not triangle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about that. I will fix it soon. |
||
}); | ||
|
||
QUnit.test('findTarget on activegroup', function(assert) { | ||
var rect1 = makeRect({ left: 0, top: 0 }), target; | ||
var rect2 = makeRect({ left: 20, top: 20 }); | ||
|
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.
even if those 2 methods are private, we could still document them
can you complete the JSDOC information for _searchPossibleTargets and checkTarget ?
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.
sure