mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 10:47:59 +08:00
rewrote intersects method, which now leverages the new getIntersection method. fixed up unit tests. also fixed bug with getIntersection method
This commit is contained in:
19
dist/kinetic-core.js
vendored
19
dist/kinetic-core.js
vendored
@@ -3048,18 +3048,15 @@ Kinetic.Stage = Kinetic.Container.extend({
|
||||
|
||||
return {
|
||||
shape: shape,
|
||||
pixels: p
|
||||
pixel: p
|
||||
};
|
||||
}
|
||||
// if no shape mapped to that pixel, return pixel array
|
||||
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
|
||||
return {
|
||||
pixels: p
|
||||
pixel: p
|
||||
};
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -3157,7 +3154,7 @@ Kinetic.Stage = Kinetic.Container.extend({
|
||||
if(obj) {
|
||||
var shape = obj.shape;
|
||||
if(shape) {
|
||||
if(!go.drag.moving && obj.pixels[3] === 255 && (!this.targetShape || this.targetShape._id !== shape._id)) {
|
||||
if(!go.drag.moving && obj.pixel[3] === 255 && (!this.targetShape || this.targetShape._id !== shape._id)) {
|
||||
if(this.targetShape) {
|
||||
this.targetShape._handleEvent('mouseout', evt, shape);
|
||||
}
|
||||
@@ -4100,11 +4097,11 @@ Kinetic.Shape = Kinetic.Node.extend({
|
||||
intersects: function() {
|
||||
var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments));
|
||||
var stage = this.getStage();
|
||||
|
||||
// TODO: need to re-implement
|
||||
|
||||
// default
|
||||
return false;
|
||||
var bufferCanvas = stage.bufferCanvas;
|
||||
bufferCanvas.clear();
|
||||
this._draw(bufferCanvas);
|
||||
var obj = stage.getIntersection(pos);
|
||||
return !!(obj && obj.pixel[3] > 0);
|
||||
},
|
||||
_draw: function(canvas) {
|
||||
if(this.attrs.drawFunc) {
|
||||
|
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
10
src/Shape.js
10
src/Shape.js
@@ -313,11 +313,11 @@ Kinetic.Shape = Kinetic.Node.extend({
|
||||
intersects: function() {
|
||||
var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments));
|
||||
var stage = this.getStage();
|
||||
|
||||
// TODO: need to re-implement
|
||||
|
||||
// default
|
||||
return false;
|
||||
var bufferCanvas = stage.bufferCanvas;
|
||||
bufferCanvas.clear();
|
||||
this._draw(bufferCanvas);
|
||||
var obj = stage.getIntersection(pos);
|
||||
return !!(obj && obj.pixel[3] > 0);
|
||||
},
|
||||
_draw: function(canvas) {
|
||||
if(this.attrs.drawFunc) {
|
||||
|
@@ -369,18 +369,15 @@ Kinetic.Stage = Kinetic.Container.extend({
|
||||
|
||||
return {
|
||||
shape: shape,
|
||||
pixels: p
|
||||
pixel: p
|
||||
};
|
||||
}
|
||||
// if no shape mapped to that pixel, return pixel array
|
||||
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
|
||||
return {
|
||||
pixels: p
|
||||
pixel: p
|
||||
};
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -478,7 +475,7 @@ Kinetic.Stage = Kinetic.Container.extend({
|
||||
if(obj) {
|
||||
var shape = obj.shape;
|
||||
if(shape) {
|
||||
if(!go.drag.moving && obj.pixels[3] === 255 && (!this.targetShape || this.targetShape._id !== shape._id)) {
|
||||
if(!go.drag.moving && obj.pixel[3] === 255 && (!this.targetShape || this.targetShape._id !== shape._id)) {
|
||||
if(this.targetShape) {
|
||||
this.targetShape._handleEvent('mouseout', evt, shape);
|
||||
}
|
||||
|
@@ -444,6 +444,11 @@ Test.prototype.tests = {
|
||||
layer.add(greenEllipse);
|
||||
|
||||
stage.add(layer);
|
||||
|
||||
//greenEllipse.hide();
|
||||
layer.draw();
|
||||
|
||||
//document.body.appendChild(layer.bufferCanvas.element);
|
||||
},
|
||||
'EVENTS - move mouse from shape in one group to shape in another group': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
|
@@ -378,7 +378,6 @@ Test.prototype.tests = {
|
||||
//console.log(stage.toJSON());
|
||||
//test(stage.toJSON() === json, "problem loading stage with custom shape json");
|
||||
},
|
||||
/*
|
||||
'EVENTS - test getIntersections': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
@@ -458,7 +457,6 @@ Test.prototype.tests = {
|
||||
test(group.getIntersections(350, 118).length === 1, 'getIntersections should return two shapes');
|
||||
test(group.getIntersections(350, 118)[0].getId() === 'redCircle', 'first intersection should be redCircle');
|
||||
},
|
||||
*/
|
||||
'STAGE - scale stage after add layer': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
@@ -1826,7 +1824,6 @@ Test.prototype.tests = {
|
||||
setTimeout(function() {
|
||||
sprite.stop();
|
||||
}, 3000);
|
||||
|
||||
//document.body.appendChild(layer.bufferCanvas.element)
|
||||
};
|
||||
imageObj.src = '../assets/scorpion-sprite.png';
|
||||
@@ -2524,32 +2521,31 @@ Test.prototype.tests = {
|
||||
layer.add(rect);
|
||||
stage.add(layer);
|
||||
|
||||
/*
|
||||
test(rect.intersects({
|
||||
x: 200,
|
||||
y: 100
|
||||
}) === true, 'problem with point in shape');
|
||||
}) === true, '(200,100) should intersect the shape');
|
||||
|
||||
test(rect.intersects({
|
||||
x: 199,
|
||||
y: 99
|
||||
}) === false, 'intersects with point in shape');
|
||||
x: 197,
|
||||
y: 97
|
||||
}) === false, '(197, 97) should not intersect the shape');
|
||||
|
||||
test(rect.intersects({
|
||||
x: 250,
|
||||
y: 125
|
||||
}) === true, 'intersects with point in shape');
|
||||
}) === true, '(250, 125) should intersect the shape');
|
||||
|
||||
test(rect.intersects({
|
||||
x: 300,
|
||||
y: 150
|
||||
}) === true, 'intersects with point in shape');
|
||||
}) === true, '(300, 150) should intersect the shape');
|
||||
|
||||
test(rect.intersects({
|
||||
x: 301,
|
||||
y: 151
|
||||
}) === false, 'intersects with point in shape');
|
||||
*/
|
||||
x: 303,
|
||||
y: 153
|
||||
}) === false, '(303, 153) should not intersect the shape');
|
||||
|
||||
},
|
||||
'CONTAINER - node type selector': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
|
Reference in New Issue
Block a user