MCPcopy
hub / github.com/paperjs/paper.js / comparePixels

Function comparePixels

test/helpers.js:237–307  ·  view source on GitHub ↗
(actual, expected, message, options)

Source from the content-addressed store, hash-verified

235};
236
237var comparePixels = function(actual, expected, message, options) {
238 function rasterize(item, group, resolution) {
239 var raster = null;
240 if (group) {
241 var parent = item.parent,
242 index = item.index;
243 group.addChild(item);
244 raster = group.rasterize(resolution, false);
245 if (parent) {
246 parent.insertChild(index, item);
247 } else {
248 item.remove();
249 }
250 }
251 return raster;
252 }
253
254 if (!expected) {
255 return QUnit.strictEqual(actual, expected, message, options);
256 } else if (!actual) {
257 // In order to compare pixels, just create an empty item that can be
258 // rasterized to an empty raster.
259 actual = new Group();
260 }
261
262 options = options || {};
263 // In order to properly compare pixel by pixel, we need to put each item
264 // into a group with a white background of the united dimensions of the
265 // bounds of both items before rasterizing.
266 var resolution = options.resolution || 72,
267 actualBounds = actual.strokeBounds,
268 expectedBounds = expected.strokeBounds,
269 bounds = actualBounds.isEmpty()
270 ? expectedBounds
271 : expectedBounds.isEmpty()
272 ? actualBounds
273 : actualBounds.unite(expectedBounds);
274 if (bounds.isEmpty()) {
275 QUnit.equal('empty', 'empty', message);
276 return;
277 }
278 var group = actual && expected && new Group({
279 insert: false,
280 children: [
281 new Shape.Rectangle({
282 rectangle: bounds,
283 fillColor: 'white'
284 })
285 ]
286 }),
287 actualRaster = rasterize(actual, group, resolution),
288 expectedRaster = rasterize(expected, group, resolution);
289 if (!actualRaster || !expectedRaster) {
290 QUnit.push(false, null, null, 'Unable to compare rasterized items: ' +
291 (!actualRaster ? 'actual' : 'expected') + ' item is null',
292 QUnit.stack(2));
293 } else {
294 // Compare the two rasterized items.

Callers 6

compareItemFunction · 0.85
helpers.jsFile · 0.85
compareFunction · 0.85
Item.jsFile · 0.85
Group.jsFile · 0.85
Color.jsFile · 0.85

Calls 2

rasterizeFunction · 0.85
compareImageDataFunction · 0.85

Tested by

no test coverage detected