mirror of
https://github.com/konvajs/konva.git
synced 2025-12-04 19:08:24 +08:00
changed isPointInShape() to intersects(). Currently the method accepts a point object, but I may extend this to also accept another shape object
This commit is contained in:
7
dist/kinetic-core.js
vendored
7
dist/kinetic-core.js
vendored
@@ -1529,7 +1529,7 @@ Kinetic.Stage.prototype = {
|
|||||||
this.targetFound = true;
|
this.targetFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shape.attrs.visible && pos !== undefined && shape.isPointInShape(pos)) {
|
if(shape.attrs.visible && pos !== undefined && shape.intersects(pos)) {
|
||||||
// handle onmousedown
|
// handle onmousedown
|
||||||
if(!isDragging && this.mouseDown) {
|
if(!isDragging && this.mouseDown) {
|
||||||
this.mouseDown = false;
|
this.mouseDown = false;
|
||||||
@@ -2323,10 +2323,9 @@ Kinetic.Shape.prototype = {
|
|||||||
this.data = [];
|
this.data = [];
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* custom isPointInPath method which can use path detection
|
* determines if point is in the shape
|
||||||
* or pixel detection
|
|
||||||
*/
|
*/
|
||||||
isPointInShape: function(pos) {
|
intersects: function(pos) {
|
||||||
var stage = this.getStage();
|
var stage = this.getStage();
|
||||||
|
|
||||||
if(this.attrs.detectionType === 'path') {
|
if(this.attrs.detectionType === 'path') {
|
||||||
|
|||||||
4
dist/kinetic-core.min.js
vendored
4
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -171,10 +171,9 @@ Kinetic.Shape.prototype = {
|
|||||||
this.data = [];
|
this.data = [];
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* custom isPointInPath method which can use path detection
|
* determines if point is in the shape
|
||||||
* or pixel detection
|
|
||||||
*/
|
*/
|
||||||
isPointInShape: function(pos) {
|
intersects: function(pos) {
|
||||||
var stage = this.getStage();
|
var stage = this.getStage();
|
||||||
|
|
||||||
if(this.attrs.detectionType === 'path') {
|
if(this.attrs.detectionType === 'path') {
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ Kinetic.Stage.prototype = {
|
|||||||
this.targetFound = true;
|
this.targetFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shape.attrs.visible && pos !== undefined && shape.isPointInShape(pos)) {
|
if(shape.attrs.visible && pos !== undefined && shape.intersects(pos)) {
|
||||||
// handle onmousedown
|
// handle onmousedown
|
||||||
if(!isDragging && this.mouseDown) {
|
if(!isDragging && this.mouseDown) {
|
||||||
this.mouseDown = false;
|
this.mouseDown = false;
|
||||||
|
|||||||
@@ -1303,7 +1303,7 @@ Test.prototype.tests = {
|
|||||||
star.setDetectionType('pixel');
|
star.setDetectionType('pixel');
|
||||||
test(star.getDetectionType() === 'pixel', 'detection type should be pixel');
|
test(star.getDetectionType() === 'pixel', 'detection type should be pixel');
|
||||||
},
|
},
|
||||||
'SHAPES - test isPointInPath()': function(containerId) {
|
'SHAPES - test intersects()': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
width: 578,
|
width: 578,
|
||||||
@@ -1323,30 +1323,30 @@ Test.prototype.tests = {
|
|||||||
layer.add(rect);
|
layer.add(rect);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
test(rect.isPointInShape({
|
test(rect.intersects({
|
||||||
x: 200,
|
x: 200,
|
||||||
y: 100
|
y: 100
|
||||||
}) === true, 'problem with point in shape');
|
}) === true, 'problem with point in shape');
|
||||||
|
|
||||||
test(rect.isPointInShape({
|
test(rect.intersects({
|
||||||
x: 199,
|
x: 199,
|
||||||
y: 99
|
y: 99
|
||||||
}) === false, 'problem with point in shape');
|
}) === false, 'intersects with point in shape');
|
||||||
|
|
||||||
test(rect.isPointInShape({
|
test(rect.intersects({
|
||||||
x: 250,
|
x: 250,
|
||||||
y: 125
|
y: 125
|
||||||
}) === true, 'problem with point in shape');
|
}) === true, 'intersects with point in shape');
|
||||||
|
|
||||||
test(rect.isPointInShape({
|
test(rect.intersects({
|
||||||
x: 300,
|
x: 300,
|
||||||
y: 150
|
y: 150
|
||||||
}) === true, 'problem with point in shape');
|
}) === true, 'intersects with point in shape');
|
||||||
|
|
||||||
test(rect.isPointInShape({
|
test(rect.intersects({
|
||||||
x: 301,
|
x: 301,
|
||||||
y: 151
|
y: 151
|
||||||
}) === false, 'problem with point in shape');
|
}) === false, 'intersects with point in shape');
|
||||||
},
|
},
|
||||||
'Text - add text': function(containerId) {
|
'Text - add text': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
|||||||
Reference in New Issue
Block a user