mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 10:47:59 +08:00
changed getIntersections() to getAllIntersections() to indicate that the method returns more than may be needed. Updatee docs, and clarified the differences between intersects(), getIntersection(), and getAllIntersections()
This commit is contained in:
@@ -155,12 +155,12 @@
|
|||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* get shapes that intersect a point
|
* get all shapes that intersect a point
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
* @param {Object} point
|
* @param {Object} pos
|
||||||
*/
|
*/
|
||||||
getIntersections: function() {
|
getAllIntersections: function() {
|
||||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
|
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
|
||||||
var arr = [];
|
var arr = [];
|
||||||
var shapes = this.get('Shape');
|
var shapes = this.get('Shape');
|
||||||
|
@@ -74,7 +74,7 @@ var Kinetic = {};
|
|||||||
* context.quadraticCurveTo(300, 100, 260, 170);<br>
|
* context.quadraticCurveTo(300, 100, 260, 170);<br>
|
||||||
* context.closePath();<br>
|
* context.closePath();<br>
|
||||||
* canvas.fillStroke(this);<br>
|
* canvas.fillStroke(this);<br>
|
||||||
* }
|
* }<br>
|
||||||
*});
|
*});
|
||||||
*/
|
*/
|
||||||
Kinetic.Shape = function(config) {
|
Kinetic.Shape = function(config) {
|
||||||
|
@@ -11,9 +11,11 @@
|
|||||||
this.hitCanvas = new Kinetic.HitCanvas();
|
this.hitCanvas = new Kinetic.HitCanvas();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* get intersection object that contains shape and pixel data
|
* get visible intersection object that contains shape and pixel data. This is the preferred
|
||||||
|
* method for determining if a point intersects a shape or not
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Node.prototype
|
* @memberof Kinetic.Layer.prototype
|
||||||
|
* @param {Object} pos point object
|
||||||
*/
|
*/
|
||||||
getIntersection: function() {
|
getIntersection: function() {
|
||||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
||||||
|
@@ -76,7 +76,7 @@
|
|||||||
/**
|
/**
|
||||||
* determines if point is in the shape, regardless if other shapes are on top of it. Note: because
|
* determines if point is in the shape, regardless if other shapes are on top of it. Note: because
|
||||||
* this method clears a temp hit canvas, and redraws the shape, it performs very poorly if executed many times
|
* this method clears a temp hit canvas, and redraws the shape, it performs very poorly if executed many times
|
||||||
* consecutively. If possible, it's better to use the stage.getIntersections() method instead
|
* consecutively. If possible, it's better to use the stage.getIntersection() method instead
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Shape.prototype
|
* @memberof Kinetic.Shape.prototype
|
||||||
* @param {Object} point point can be an object containing
|
* @param {Object} point point can be an object containing
|
||||||
|
@@ -252,7 +252,8 @@
|
|||||||
this.toDataURL(config);
|
this.toDataURL(config);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* get intersection object that contains shape and pixel data
|
* get visible intersection object that contains shape and pixel data. This is the preferred
|
||||||
|
* method for determining if a point intersects a shape or not
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Stage.prototype
|
* @memberof Kinetic.Stage.prototype
|
||||||
* @param {Object} pos point object
|
* @param {Object} pos point object
|
||||||
|
@@ -77,7 +77,7 @@ Test.Modules.STAGE = {
|
|||||||
|
|
||||||
test(stage.getContent().className === 'kineticjs-content', 'stage DOM class name is wrong');
|
test(stage.getContent().className === 'kineticjs-content', 'stage DOM class name is wrong');
|
||||||
},
|
},
|
||||||
'stage getIntersections()': function(containerId) {
|
'stage getAllIntersections()': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
width: 578,
|
width: 578,
|
||||||
@@ -116,7 +116,7 @@ Test.Modules.STAGE = {
|
|||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
'test getIntersections': function(containerId) {
|
'test getAllIntersections': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
width: 578,
|
width: 578,
|
||||||
@@ -150,50 +150,50 @@ Test.Modules.STAGE = {
|
|||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
// test individual shapes
|
// test individual shapes
|
||||||
test(stage.getIntersections(266, 114).length === 1, '17) getIntersections should return one shape');
|
test(stage.getAllIntersections(266, 114).length === 1, '17) getAllIntersections should return one shape');
|
||||||
test(stage.getIntersections(266, 114)[0].getId() === 'greenCircle', '19) first intersection should be greenCircle');
|
test(stage.getAllIntersections(266, 114)[0].getId() === 'greenCircle', '19) first intersection should be greenCircle');
|
||||||
|
|
||||||
test(stage.getIntersections(414, 115).length === 1, '18) getIntersections should return one shape');
|
test(stage.getAllIntersections(414, 115).length === 1, '18) getAllIntersections should return one shape');
|
||||||
test(stage.getIntersections(414, 115)[0].getId() === 'redCircle', '20) first intersection should be redCircle');
|
test(stage.getAllIntersections(414, 115)[0].getId() === 'redCircle', '20) first intersection should be redCircle');
|
||||||
|
|
||||||
test(stage.getIntersections(350, 118).length === 2, '1) getIntersections should return two shapes');
|
test(stage.getAllIntersections(350, 118).length === 2, '1) getAllIntersections should return two shapes');
|
||||||
test(stage.getIntersections(350, 118)[0].getId() === 'redCircle', '2) first intersection should be redCircle');
|
test(stage.getAllIntersections(350, 118)[0].getId() === 'redCircle', '2) first intersection should be redCircle');
|
||||||
test(stage.getIntersections(350, 118)[1].getId() === 'greenCircle', '3) second intersection should be greenCircle');
|
test(stage.getAllIntersections(350, 118)[1].getId() === 'greenCircle', '3) second intersection should be greenCircle');
|
||||||
|
|
||||||
// hide green circle. make sure only red circle is in result set
|
// hide green circle. make sure only red circle is in result set
|
||||||
greenCircle.hide();
|
greenCircle.hide();
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
test(stage.getIntersections(350, 118).length === 1, '4) getIntersections should return one shape');
|
test(stage.getAllIntersections(350, 118).length === 1, '4) getAllIntersections should return one shape');
|
||||||
test(stage.getIntersections(350, 118)[0].getId() === 'redCircle', '5) first intersection should be redCircle');
|
test(stage.getAllIntersections(350, 118)[0].getId() === 'redCircle', '5) first intersection should be redCircle');
|
||||||
|
|
||||||
// show green circle again. make sure both circles are in result set
|
// show green circle again. make sure both circles are in result set
|
||||||
greenCircle.show();
|
greenCircle.show();
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
test(stage.getIntersections(350, 118).length === 2, '6) getIntersections should return two shapes');
|
test(stage.getAllIntersections(350, 118).length === 2, '6) getAllIntersections should return two shapes');
|
||||||
test(stage.getIntersections(350, 118)[0].getId() === 'redCircle', '7) first intersection should be redCircle');
|
test(stage.getAllIntersections(350, 118)[0].getId() === 'redCircle', '7) first intersection should be redCircle');
|
||||||
test(stage.getIntersections(350, 118)[1].getId() === 'greenCircle', '8) second intersection should be greenCircle');
|
test(stage.getAllIntersections(350, 118)[1].getId() === 'greenCircle', '8) second intersection should be greenCircle');
|
||||||
|
|
||||||
// hide red circle. make sure only green circle is in result set
|
// hide red circle. make sure only green circle is in result set
|
||||||
redCircle.hide();
|
redCircle.hide();
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
test(stage.getIntersections(350, 118).length === 1, '9) getIntersections should return one shape');
|
test(stage.getAllIntersections(350, 118).length === 1, '9) getAllIntersections should return one shape');
|
||||||
test(stage.getIntersections(350, 118)[0].getId() === 'greenCircle', '10) first intersection should be greenCircle');
|
test(stage.getAllIntersections(350, 118)[0].getId() === 'greenCircle', '10) first intersection should be greenCircle');
|
||||||
|
|
||||||
// show red circle again. make sure both circles are in result set
|
// show red circle again. make sure both circles are in result set
|
||||||
redCircle.show();
|
redCircle.show();
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
test(stage.getIntersections(350, 118).length === 2, '11) getIntersections should return two shapes');
|
test(stage.getAllIntersections(350, 118).length === 2, '11) getAllIntersections should return two shapes');
|
||||||
test(stage.getIntersections(350, 118)[0].getId() === 'redCircle', '12) first intersection should be redCircle');
|
test(stage.getAllIntersections(350, 118)[0].getId() === 'redCircle', '12) first intersection should be redCircle');
|
||||||
test(stage.getIntersections(350, 118)[1].getId() === 'greenCircle', '13) second intersection should be greenCircle');
|
test(stage.getAllIntersections(350, 118)[1].getId() === 'greenCircle', '13) second intersection should be greenCircle');
|
||||||
|
|
||||||
// test from layer
|
// test from layer
|
||||||
test(layer.getIntersections(350, 118).length === 2, '14) getIntersections should return two shapes');
|
test(layer.getAllIntersections(350, 118).length === 2, '14) getAllIntersections should return two shapes');
|
||||||
test(layer.getIntersections(350, 118)[0].getId() === 'redCircle', '15) first intersection should be redCircle');
|
test(layer.getAllIntersections(350, 118)[0].getId() === 'redCircle', '15) first intersection should be redCircle');
|
||||||
test(layer.getIntersections(350, 118)[1].getId() === 'greenCircle', '16) second intersection should be greenCircle');
|
test(layer.getAllIntersections(350, 118)[1].getId() === 'greenCircle', '16) second intersection should be greenCircle');
|
||||||
|
|
||||||
},
|
},
|
||||||
'scale stage after add layer': function(containerId) {
|
'scale stage after add layer': function(containerId) {
|
||||||
|
Reference in New Issue
Block a user