fix #1106: hit canvas pixel ratio configurable

This commit is contained in:
Raphael Papazikas
2021-05-03 22:54:22 +02:00
parent f288e9bf14
commit 628a8ea9ca
2 changed files with 52 additions and 5 deletions

View File

@@ -1470,4 +1470,42 @@ suite('Caching', function () {
});
});
});
test('hit from cache with custom pixelRatio', function () {
var stage = addStage();
var layer = new Konva.Layer();
var rect = new Konva.Rect({
x: 100,
y: 50,
width: 100,
height: 100,
fill: 'green',
});
layer.add(rect);
stage.add(layer);
rect.cache({
hitCanvasPixelRatio: 0.2,
});
layer.draw();
var hitCanvas = rect._cache.get("canvas").hit;
assert.equal(hitCanvas._canvas.width, rect.width() * 0.2);
assert.equal(hitCanvas._canvas.height, rect.height() * 0.2);
assert.equal(hitCanvas.pixelRatio, 0.2);
var canvas = createCanvas();
var context = canvas.getContext('2d');
context.beginPath();
context.rect(100, 50, 100, 100);
context.closePath();
context.fillStyle = 'green';
context.fill();
showHit(layer);
compareLayerAndCanvas(layer, canvas, 5);
assert.equal(stage.getIntersection({ x: 150, y: 100 }), rect);
});
});