skia2/experimental/pathkit/tests/path.spec.js
Kevin Lubick 644d8e7175 [PathKit] Add PathOps Op and Simplify tests imported from the C++ tests.
Because of https://skia-review.googlesource.com/c/skia/+/146165 and
https://skia-review.googlesource.com/c/skia/+/146100 we have a way
to turn PathOps tests into JSON, which has input paths (as Cmd arrays),
combination verb and expected output.

In this CL, we make tests from the JSON, compare them to the expected
output and, optionally, create SVGs to visualize the difference if any.

API changes (nothing breaking on release builds):
 - Exposes SkRect as a JS Object.  No need to call delete() on this.
 - expose path.getBounds() and path.computeTightBounds()
 - Remove SkRegion exposure (debug/test only), which was going to be
used for this purpose, but the approach in this CL works fine.
 - Add loadCmdsTypedArray(cmd) helper function to JS [see helper.js].
This was previously known as `floatTypedArrayFrom2D` in the
old shell.html, and is now exposed to avoid clients having to
implement this boilerplate by themselves.
 - Add set/getFillType - mostly for testing the difference between
a Winding and an EvenOdd path.

Bug: skia:8216
Change-Id: I2cd25ce2e1e7f285c79c596678678e62135963f0
Reviewed-on: https://skia-review.googlesource.com/146524
Reviewed-by: Cary Clark <caryclark@google.com>
2018-08-09 18:13:48 +00:00

51 lines
1.8 KiB
JavaScript

describe('PathKit\'s Path Behavior', function() {
// Note, don't try to print the PathKit object - it can cause Karma/Jasmine to lock up.
var PathKit = null;
const LoadPathKit = new Promise(function(resolve, reject){
if (PathKit) {
resolve();
} else {
PathKitInit({
locateFile: (file) => '/base/npm-wasm/bin/test/'+file,
}).then((_PathKit) => {
PathKit = _PathKit;
resolve();
});
}
});
it('dynamically updates getBounds()', function(done){
LoadPathKit.then(() => {
// Based on test_bounds_crbug_513799
let path = PathKit.NewPath();
expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(0, 0, 0, 0));
path.moveTo(-5, -8);
expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, -5, -8));
path.rect(1, 2, 2, 2);
expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, 3, 4));
path.moveTo(1, 2);
expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, 3, 4));
path.delete();
done();
});
});
it('has getBounds() and computeTightBounds()', function(done){
LoadPathKit.then(() => {
// Based on PathOpsTightBoundsIllBehaved
let path = PathKit.NewPath();
path.moveTo(1, 1);
path.quadraticCurveTo(4, 3, 2, 2);
expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(1, 1, 4, 3));
expect(path.computeTightBounds()).toEqual(PathKit.MakeLTRBRect(1, 1,
PathKit.SkBits2FloatUnsigned(parseInt("0x40333334")), // 2.8
PathKit.SkBits2FloatUnsigned(parseInt("0x40155556")))); // 2.3333333
path.delete();
done();
});
});
});