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

hit detection position/pivot selection versus center selection #1249

Closed
dexterial opened this issue Feb 2, 2017 · 8 comments
Closed

hit detection position/pivot selection versus center selection #1249

dexterial opened this issue Feb 2, 2017 · 8 comments

Comments

@dexterial
Copy link

as per issue #980 this should be resolved, however the position.selected = true actually triggers a call to getCenter, that attaches itself to bounds.getCenter. All is nice and fine unless you have an uneven shape, in that case, after rotation the 2 points do not coincide anymore, ergo the hit test does not give you the actual position/pivot, but the bounds center.

@dexterial dexterial changed the title pivot selection versus center selection hit detection position/pivot selection versus center selection Feb 2, 2017
@dexterial
Copy link
Author

dexterial commented Feb 2, 2017

i also have a sort of quick fix if one can integrate it in bold/italic https://github.com/paperjs/paper.js/blob/da52f1f6850fbd820cc3c70b4609f4cb639861f2/src/item/Item.js
starting with line 1941, I tested this in manual edited file and it works, you just add the options.pivot = true to the hitTest call

if (checkSelf && (options.pivot || options.center || options.bounds) && this._parent) {
bounds = this.getInternalBounds();
if (options.center) {
res = checkBounds('center', 'Center');
}
if (!res && options.pivot) {
var pt = this.getPivot();
if (point.subtract(pt).divide(tolerancePadding).length <= 1) {
res = new HitResult('pivot', that,
{ name: 'pivot', point: pt });
}
}

@dexterial
Copy link
Author

or if one inverts the return order pivot on top of center

if (checkSelf && (options.pivot || options.center || options.bounds) && this._parent) {
if (options.pivot) {
var pt = this.getPivot();
if (point.subtract(pt).divide(tolerancePadding).length <= 1) {
res = new HitResult('pivot', that,
{ name: 'pivot', point: pt });
}
}

bounds = this.getInternalBounds();
if (!res && options.center) {
res = checkBounds('center', 'Center');
}

@dexterial
Copy link
Author

or a better option to check for position instead of pivot , there is also the HitResult definitiof file that needs to be updated with a default value if one wants to be complete

// Hit test the pivot/position of the bounds
position: false,

if (checkSelf && (options.position || options.center || options.bounds) && this._parent) {
// Don't get the transformed bounds, check against transformed
// points instead
if (options.position) {
var pt = this.getPosition();
if (point.subtract(pt).divide(tolerancePadding).length <= 1) {
res = new HitResult('position', that,
{ name: 'position', point: pt });
}
}

if (!res)bounds = this.getInternalBounds();
if (!res && options.center) {
res = checkBounds('center', 'Center');
}

@lehni
Copy link
Member

lehni commented Mar 8, 2017

Could you provide a simple demo script that demonstrates the problem, e.g. on http://sketch.paperjs.org/? Thanks!

@dexterial
Copy link
Author

http://sketch.paperjs.org/#S/dVdNb9w2FPwrD744BSxH/JSYoqf00kOBAjk2PSiyEi+8XhmSnDQp+t87M9TGi6I97HIpku9j3ryh9q+r0/A4Xb25evcwbeP91c3VON9x/nlY7GnY7n8etsF+sutfc28+l2RjE7I1weGTrEnZMHMdFjHrogWPaZvNdxi5wzntcsEa71qLmPrcWajbE7e10Zzr8SPDGkZ8epgpGFoax1acLsHkuXXW4VR00QpsJQtY7J0lDA5TjzMxWsRQnOEXHCTjQDcwgIHncdDJF116xJJhLsAxDtK9l8uGezn6ngvOZR2FMcw65oZTGdYjcUCWTNAhYWaGM64vjNU8R18sErDsjcG0wZKzY+wZJYMLNiIpQmIuEyjgybQQIzMPyI0JFPPKgPlH84wYnpJ1SqwCgjrgWRML3BBaOFIoPnol3GUrfI69jqe8R81gHN5ViSQTFfy4l9G5tOdJVLsgnJmcqACrgaE7r+LCWKopCCofrO8QqGs7ppoQXlbGiVHjOSNFFX1hrTAhPsxMzECQgtcS65it5xCs80LDZaYNCsJ2U0EAvEGBWgwygjjpHOcAJd0DVFdJEdo6JGwUCzpt6OzoxCmLMAjsRuLmWFOS2xcUkQmHvvKqZA0OifMUl2rMQolgMmpkhmKQM+SUj5U0gCfVNmIkTV9rqD763lCIvRUdPIHOTJ6uipHQYDg2uqQIzccdgqI8Y8W8BV/QHxhZdE8DYL3LhMdrFMeFG/YyAO4FOkBDiKPUzjMeUKdjIoC6MGcwpOd+ftXaNyqbV11q0uzLpOYgeYi5bO6MbsBL7euE7a4KskmmNDhNr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jjXqiubP2omR4fTJ/z4czf35X5apmG93FyTpC14WSaU4fB5sm3WnvV+eJrsaT6ctvXGhtOdfTmABbu103xaD4/TthxQ2H2XfZ2fbcLG56e6d7DHw7o+DvhbYnCiWsLbOUf8VfmAkB7q6as3v//x9z8=

@dexterial
Copy link
Author

dexterial commented Mar 8, 2017 via email

@lehni
Copy link
Member

lehni commented Mar 8, 2017

Great, thanks! Trip: If you use PathItem.create(pathData); instead of new Path(pathData);, then it will always produce the right type of path, in this case a CompoundPath for you.

@lehni
Copy link
Member

lehni commented Mar 8, 2017

Ok, I understand the issue now. I agree that adding the options.position option is the best way to go.

@lehni lehni closed this as completed in f9d06d8 Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants