extended getIntersection method for Layer to improve flexibility. Replaced instances of Math.round to bitwise round via | 0 for a small performance gain

This commit is contained in:
Eric Rowell
2013-04-11 23:51:21 -07:00
parent 60c9ef5bcd
commit bfbd42b232
5 changed files with 120 additions and 27 deletions

View File

@@ -27,6 +27,45 @@ Test.Modules.LAYER = {
test(style.margin === '0px', 'canvas margin style should be 0px');
test(style.padding === '0px', 'canvas padding style should be 0px');
test(style.backgroundColor === 'transparent', 'canvas backgroundColor style should be transparent');
},
'layer getIntersections()': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200,
throttle: 999
});
var layer = new Kinetic.Layer();
var redCircle = new Kinetic.Circle({
x: 380,
y: stage.getHeight() / 2,
radius: 70,
strokeWidth: 4,
fill: 'red',
stroke: 'black',
id: 'redCircle'
});
var greenCircle = new Kinetic.Circle({
x: 300,
y: stage.getHeight() / 2,
radius: 70,
strokeWidth: 4,
fill: 'green',
stroke: 'black',
id: 'greenCircle'
});
layer.add(redCircle);
layer.add(greenCircle);
stage.add(layer);
test(layer.getIntersection(300, 100).shape.getId() === 'greenCircle', 'shape should be greenCircle');
test(layer.getIntersection(380, 100).shape.getId() === 'redCircle', 'shape should be redCircle');
test(layer.getIntersection(100, 100) === null, 'shape should be null');
},
'redraw hit graph': function(containerId) {
var stage = new Kinetic.Stage({

View File

@@ -76,6 +76,45 @@ Test.Modules.STAGE = {
});
test(stage.getContent().className === 'kineticjs-content', 'stage DOM class name is wrong');
},
'stage getIntersections()': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200,
throttle: 999
});
var layer = new Kinetic.Layer();
var redCircle = new Kinetic.Circle({
x: 380,
y: stage.getHeight() / 2,
radius: 70,
strokeWidth: 4,
fill: 'red',
stroke: 'black',
id: 'redCircle'
});
var greenCircle = new Kinetic.Circle({
x: 300,
y: stage.getHeight() / 2,
radius: 70,
strokeWidth: 4,
fill: 'green',
stroke: 'black',
id: 'greenCircle'
});
layer.add(redCircle);
layer.add(greenCircle);
stage.add(layer);
test(stage.getIntersection(300, 100).shape.getId() === 'greenCircle', 'shape should be greenCircle');
test(stage.getIntersection(380, 100).shape.getId() === 'redCircle', 'shape should be redCircle');
test(stage.getIntersection(100, 100) === null, 'shape should be null');
},
'test getIntersections': function(containerId) {
var stage = new Kinetic.Stage({