mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:10:54 +08:00
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:
@@ -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({
|
||||
|
@@ -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({
|
||||
|
Reference in New Issue
Block a user