mirror of
https://github.com/konvajs/konva.git
synced 2026-01-23 21:34:50 +08:00
remove rounding from getClientRect
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
Konva,
|
||||
createCanvas,
|
||||
compareLayerAndCanvas,
|
||||
assertAlmostDeepEqual,
|
||||
} from './test-utils';
|
||||
|
||||
describe('Arc', function () {
|
||||
@@ -88,7 +89,7 @@ describe('Arc', function () {
|
||||
layer.add(arc);
|
||||
stage.add(layer);
|
||||
|
||||
assert.deepEqual(arc.getSelfRect(), {
|
||||
assertAlmostDeepEqual(arc.getSelfRect(), {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 80,
|
||||
@@ -116,7 +117,7 @@ describe('Arc', function () {
|
||||
layer.add(arc);
|
||||
stage.add(layer);
|
||||
|
||||
assert.deepEqual(arc.getSelfRect(), {
|
||||
assertAlmostDeepEqual(arc.getSelfRect(), {
|
||||
x: -80,
|
||||
y: -80,
|
||||
width: 160,
|
||||
@@ -140,7 +141,7 @@ describe('Arc', function () {
|
||||
layer.add(arc);
|
||||
stage.add(layer);
|
||||
|
||||
assert.deepEqual(arc.getSelfRect(), {
|
||||
assertAlmostDeepEqual(arc.getSelfRect(), {
|
||||
x: 0,
|
||||
y: -80,
|
||||
width: 80,
|
||||
@@ -163,14 +164,14 @@ describe('Arc', function () {
|
||||
layer.add(arc);
|
||||
stage.add(layer);
|
||||
|
||||
assert.deepEqual(arc.getSelfRect(), {
|
||||
assertAlmostDeepEqual(arc.getSelfRect(), {
|
||||
x: 25,
|
||||
y: 0,
|
||||
width: 55,
|
||||
height: 69,
|
||||
height: 69.282032302755,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('cache', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -831,7 +831,8 @@ describe('Caching', function () {
|
||||
group.cache();
|
||||
|
||||
const canvas = group._cache.get('canvas').scene;
|
||||
assert.equal(canvas.width, 105 * canvas.pixelRatio);
|
||||
console.log(canvas.width / 2);
|
||||
assert.equal(canvas.width, 106 * canvas.pixelRatio);
|
||||
});
|
||||
|
||||
it('cache group with rectangle with fill and opacity', function () {
|
||||
@@ -1468,7 +1469,7 @@ describe('Caching', function () {
|
||||
layer.draw();
|
||||
assert.equal(
|
||||
circle._cache.get('canvas').filter.width,
|
||||
20 * circle._cache.get('canvas').filter.pixelRatio
|
||||
21 * circle._cache.get('canvas').filter.pixelRatio
|
||||
);
|
||||
circle.filters([]);
|
||||
// TODO: should we clear cache canvas?
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
compareLayerAndCanvas,
|
||||
cloneAndCompareLayer,
|
||||
isNode,
|
||||
assertAlmostDeepEqual,
|
||||
} from './test-utils';
|
||||
|
||||
describe('Path', function () {
|
||||
@@ -1280,7 +1281,12 @@ describe('Path', function () {
|
||||
});
|
||||
layer.add(path);
|
||||
var rect = path.getClientRect();
|
||||
assert.deepEqual(rect, { x: 60, y: 184, width: 106, height: 102 });
|
||||
assertAlmostDeepEqual(rect, {
|
||||
x: 59.55,
|
||||
y: 183.55,
|
||||
width: 106,
|
||||
height: 102,
|
||||
});
|
||||
});
|
||||
|
||||
it('getClientRect of complex path', function () {
|
||||
@@ -1310,7 +1316,12 @@ describe('Path', function () {
|
||||
layer.add(back);
|
||||
layer.draw();
|
||||
|
||||
assert.deepEqual(rect, { x: 9, y: 66, width: 95, height: 55 });
|
||||
assertAlmostDeepEqual(rect, {
|
||||
x: 8.6440882161882,
|
||||
y: 65.75902834,
|
||||
width: 94.74182356762,
|
||||
height: 55.4919433,
|
||||
});
|
||||
});
|
||||
|
||||
it('getClientRect of another complex path', function () {
|
||||
@@ -1339,11 +1350,11 @@ describe('Path', function () {
|
||||
layer.add(back);
|
||||
layer.draw();
|
||||
|
||||
assert.deepEqual(rect, {
|
||||
assertAlmostDeepEqual(rect, {
|
||||
x: 49,
|
||||
y: 49.7,
|
||||
y: 49.7086649,
|
||||
width: 215,
|
||||
height: 71.39999999999999,
|
||||
height: 71.3826701999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1372,7 +1383,12 @@ describe('Path', function () {
|
||||
layer.add(back);
|
||||
layer.draw();
|
||||
|
||||
assert.deepEqual(rect, { x: 49, y: 49, width: 43, height: 48 });
|
||||
assertAlmostDeepEqual(rect, {
|
||||
x: 48.981379,
|
||||
y: 48.996825,
|
||||
width: 42.84717526,
|
||||
height: 48.057550000000006,
|
||||
});
|
||||
});
|
||||
|
||||
it('getClientRect for arc', function () {
|
||||
@@ -1408,15 +1424,15 @@ describe('Path', function () {
|
||||
layer.add(back);
|
||||
layer.draw();
|
||||
|
||||
assert.deepEqual(rect, {
|
||||
assertAlmostDeepEqual(rect, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 132.53012048192795,
|
||||
width: 132.4001878816343,
|
||||
height: 100,
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('getClientRect on scaled', function () {
|
||||
it('getClientRect on scaled', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
@@ -1444,7 +1460,7 @@ describe('Path', function () {
|
||||
layer.add(back);
|
||||
layer.draw();
|
||||
|
||||
assert.deepEqual(rect, {
|
||||
assertAlmostDeepEqual(rect, {
|
||||
height: 201.99999999999994,
|
||||
width: 201.99999999999994,
|
||||
x: 99,
|
||||
|
||||
@@ -203,7 +203,7 @@ describe('RegularPolygon', function () {
|
||||
|
||||
var box = poly.getClientRect();
|
||||
|
||||
assertAlmostEqual(box.width, 92.60254037844388);
|
||||
assertAlmostEqual(box.height, 81.00000000000003);
|
||||
assertAlmostEqual(box.width, 91.60254037844388);
|
||||
assertAlmostEqual(box.height, 80.00000000000003);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2509,7 +2509,7 @@ describe('Transformer', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it.only('transform events check', function () {
|
||||
it('transform events check', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
@@ -384,3 +384,9 @@ export const assertAlmostEqual = function (val1, val2) {
|
||||
throw new Error('Expected ' + val1 + ' to be almost equal to ' + val2);
|
||||
}
|
||||
};
|
||||
|
||||
export const assertAlmostDeepEqual = function (obj1, obj2) {
|
||||
for (var key1 in obj1) {
|
||||
assertAlmostEqual(obj1[key1], obj2[key1]);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user