mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 02:37:59 +08:00
Narrow down getIntersection() result. add optional selector parament to getIntersection function. close #74
This commit is contained in:
@@ -133,8 +133,35 @@ suite('Layer', function() {
|
||||
assert.equal(layer.getIntersection({x:300, y:100}).getId(), 'greenCircle', 'shape should be greenCircle');
|
||||
assert.equal(layer.getIntersection({x:380, y:100}).getId(), 'redCircle', 'shape should be redCircle');
|
||||
assert.equal(layer.getIntersection({x:100, y:100}), null, 'shape should be null');
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('layer getIntersection() with selector', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer({
|
||||
name: 'layer'
|
||||
});
|
||||
|
||||
var group = new Konva.Group({
|
||||
name: 'group'
|
||||
});
|
||||
|
||||
var circle = new Konva.Circle({
|
||||
x: stage.getWidth() / 2,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
strokeWidth: 4,
|
||||
fill: 'red',
|
||||
stroke: 'black',
|
||||
});
|
||||
|
||||
group.add(circle)
|
||||
layer.add(group);
|
||||
stage.add(layer);
|
||||
|
||||
assert.equal(layer.getIntersection({x: stage.width() / 2, y: stage.height() / 2}, 'Circle'), circle, 'intersection with shape selector');
|
||||
assert.equal(layer.getIntersection({x: stage.width() / 2, y: stage.height() / 2}, '.group'), group, 'intersection with group selector');
|
||||
assert.equal(layer.getIntersection({x: stage.width() / 2, y: stage.height() / 2}, 'Stage'), stage, 'intersection with stage selector');
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
|
@@ -181,8 +181,35 @@ suite('Stage', function() {
|
||||
assert.equal(stage.getIntersection({x:300, y:100}).getId(), 'greenCircle', 'shape should be greenCircle');
|
||||
assert.equal(stage.getIntersection({x:380, y:100}).getId(), 'redCircle', 'shape should be redCircle');
|
||||
assert.equal(stage.getIntersection({x:100, y:100}), null, 'shape should be null');
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('layer getIntersection() with selector', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer({
|
||||
name: 'layer'
|
||||
});
|
||||
|
||||
var group = new Konva.Group({
|
||||
name: 'group'
|
||||
});
|
||||
|
||||
var circle = new Konva.Circle({
|
||||
x: stage.getWidth() / 2,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
strokeWidth: 4,
|
||||
fill: 'red',
|
||||
stroke: 'black',
|
||||
});
|
||||
|
||||
group.add(circle)
|
||||
layer.add(group);
|
||||
stage.add(layer);
|
||||
|
||||
assert.equal(stage.getIntersection({x: stage.width() / 2, y: stage.height() / 2}, 'Circle'), circle, 'intersection with shape selector');
|
||||
assert.equal(stage.getIntersection({x: stage.width() / 2, y: stage.height() / 2}, '.group'), group, 'intersection with group selector');
|
||||
assert.equal(stage.getIntersection({x: stage.width() / 2, y: stage.height() / 2}, 'Stage'), stage, 'intersection with stage selector');
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
|
Reference in New Issue
Block a user