2018-08-09 17:58:04 +00:00
|
|
|
|
|
|
|
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;
|
2018-08-10 19:53:16 +00:00
|
|
|
const LoadPathKit = new Promise(function(resolve, reject) {
|
2018-08-09 17:58:04 +00:00
|
|
|
if (PathKit) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
PathKitInit({
|
2018-08-10 19:53:16 +00:00
|
|
|
locateFile: (file) => '/pathkit/'+file,
|
2018-08-09 17:58:04 +00:00
|
|
|
}).then((_PathKit) => {
|
|
|
|
PathKit = _PathKit;
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
[PathKit] Rework API to avoid extra copies unless explicitly called for.
Breaking Changes:
- All method calls that mutate a path now return the same JS path
object to allow chaining (moveTo, lineTo, trim, op, simplify, etc).
Pre-existing code likely will need to have some delete() methods
removed because the path will be deleted multiple times. See
chaining.js for this code (basically, we wrote our own binding code
since the default code wasn't quite flexible enough)
- GetCanvasFillType -> GetFillTypeString (Was in https://skia-review.googlesource.com/c/skia/+/147209)
Since Canvas and SVG use the same strings, it seemed logical to make
them share.
- stroke() now takes a single object instead of 3 params. This object
currently can have up to 4 params, cap, join, width, miter_limit.
This object can be expanded on in future versions as more configuration
options are added.
As per custom with v0 software, we bump the minor version to 0.2.X
to indicate breaking changes in a pre-release software package.
Other changes of note:
- Simple tests added for effects (see effects.specs.js) A follow up
CL will handle the Gold (correctness tests)
- Simple tests added for equals and copy constructors (from https://skia-review.googlesource.com/c/skia/+/147209)
- Added transform() to allow for arbitrary matrix transforms
- Added SimpleMatrix as a value_array, which means users can
provide a 9 element array which will be converted to SimpleMatrix
and then SkMatrix on the C++ side.
- Renamed helpers_externs.js to externs.js and expanded it greatly.
This was necessitated by the code written in chaining.js
- Fixed a few bugs in previous tests (svg gold test race condition,
uncaught exception in svg reporting)
See also https://skia-review.googlesource.com/c/skia/+/147209 which
allows .moveTo .lineTo, etc to chain on the C++ SkPath.
Bug: skia:8216
Change-Id: I7450cd8b7b5377cf15c962b02d161677b62d7e15
Reviewed-on: https://skia-review.googlesource.com/147115
Reviewed-by: Mike Reed <reed@google.com>
2018-08-17 17:52:56 +00:00
|
|
|
describe('Basic Path Features', function() {
|
|
|
|
function drawSimplePath() {
|
2018-08-09 17:58:04 +00:00
|
|
|
let path = PathKit.NewPath();
|
[PathKit] Rework API to avoid extra copies unless explicitly called for.
Breaking Changes:
- All method calls that mutate a path now return the same JS path
object to allow chaining (moveTo, lineTo, trim, op, simplify, etc).
Pre-existing code likely will need to have some delete() methods
removed because the path will be deleted multiple times. See
chaining.js for this code (basically, we wrote our own binding code
since the default code wasn't quite flexible enough)
- GetCanvasFillType -> GetFillTypeString (Was in https://skia-review.googlesource.com/c/skia/+/147209)
Since Canvas and SVG use the same strings, it seemed logical to make
them share.
- stroke() now takes a single object instead of 3 params. This object
currently can have up to 4 params, cap, join, width, miter_limit.
This object can be expanded on in future versions as more configuration
options are added.
As per custom with v0 software, we bump the minor version to 0.2.X
to indicate breaking changes in a pre-release software package.
Other changes of note:
- Simple tests added for effects (see effects.specs.js) A follow up
CL will handle the Gold (correctness tests)
- Simple tests added for equals and copy constructors (from https://skia-review.googlesource.com/c/skia/+/147209)
- Added transform() to allow for arbitrary matrix transforms
- Added SimpleMatrix as a value_array, which means users can
provide a 9 element array which will be converted to SimpleMatrix
and then SkMatrix on the C++ side.
- Renamed helpers_externs.js to externs.js and expanded it greatly.
This was necessitated by the code written in chaining.js
- Fixed a few bugs in previous tests (svg gold test race condition,
uncaught exception in svg reporting)
See also https://skia-review.googlesource.com/c/skia/+/147209 which
allows .moveTo .lineTo, etc to chain on the C++ SkPath.
Bug: skia:8216
Change-Id: I7450cd8b7b5377cf15c962b02d161677b62d7e15
Reviewed-on: https://skia-review.googlesource.com/147115
Reviewed-by: Mike Reed <reed@google.com>
2018-08-17 17:52:56 +00:00
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.lineTo(10, 0);
|
|
|
|
path.lineTo(10, 10);
|
|
|
|
path.close();
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
it('supports.equals()', function(done) {
|
|
|
|
LoadPathKit.then(() => {
|
|
|
|
let path = drawSimplePath();
|
|
|
|
let otherPath = drawSimplePath();
|
|
|
|
let blank = PathKit.NewPath();
|
|
|
|
|
|
|
|
expect(path.equals(path)).toBe(true);
|
|
|
|
expect(otherPath.equals(path)).toBe(true);
|
|
|
|
expect(path.equals(otherPath)).toBe(true);
|
|
|
|
|
|
|
|
expect(path.equals(blank)).toBe(false);
|
|
|
|
expect(otherPath.equals(blank)).toBe(false);
|
|
|
|
expect(blank.equals(path)).toBe(false);
|
|
|
|
expect(blank.equals(otherPath)).toBe(false);
|
|
|
|
|
|
|
|
path.delete();
|
|
|
|
otherPath.delete();
|
|
|
|
blank.delete();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has a copy constructor', function(done) {
|
|
|
|
LoadPathKit.then(() => {
|
|
|
|
let orig = drawSimplePath();
|
|
|
|
let copy = new PathKit.SkPath(orig);
|
|
|
|
|
|
|
|
expect(orig.toSVGString()).toEqual(copy.toSVGString());
|
|
|
|
expect(orig.equals(copy)).toBe(true);
|
|
|
|
|
|
|
|
orig.delete();
|
|
|
|
copy.delete();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has a copy method', function(done) {
|
|
|
|
LoadPathKit.then(() => {
|
|
|
|
let orig = drawSimplePath();
|
|
|
|
let copy = orig.copy();
|
|
|
|
|
|
|
|
expect(orig.toSVGString()).toEqual(copy.toSVGString());
|
|
|
|
expect(orig.equals(copy)).toBe(true);
|
|
|
|
|
|
|
|
orig.delete();
|
|
|
|
copy.delete();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can create a copy with MakePath', function(done) {
|
|
|
|
LoadPathKit.then(() => {
|
|
|
|
let orig = drawSimplePath();
|
|
|
|
let copy = PathKit.NewPath(orig);
|
|
|
|
|
|
|
|
expect(orig.toSVGString()).toEqual(copy.toSVGString());
|
|
|
|
expect(orig.equals(copy)).toBe(true);
|
|
|
|
|
|
|
|
orig.delete();
|
|
|
|
copy.delete();
|
|
|
|
done();
|
|
|
|
});
|
2018-08-09 17:58:04 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
[PathKit] Rework API to avoid extra copies unless explicitly called for.
Breaking Changes:
- All method calls that mutate a path now return the same JS path
object to allow chaining (moveTo, lineTo, trim, op, simplify, etc).
Pre-existing code likely will need to have some delete() methods
removed because the path will be deleted multiple times. See
chaining.js for this code (basically, we wrote our own binding code
since the default code wasn't quite flexible enough)
- GetCanvasFillType -> GetFillTypeString (Was in https://skia-review.googlesource.com/c/skia/+/147209)
Since Canvas and SVG use the same strings, it seemed logical to make
them share.
- stroke() now takes a single object instead of 3 params. This object
currently can have up to 4 params, cap, join, width, miter_limit.
This object can be expanded on in future versions as more configuration
options are added.
As per custom with v0 software, we bump the minor version to 0.2.X
to indicate breaking changes in a pre-release software package.
Other changes of note:
- Simple tests added for effects (see effects.specs.js) A follow up
CL will handle the Gold (correctness tests)
- Simple tests added for equals and copy constructors (from https://skia-review.googlesource.com/c/skia/+/147209)
- Added transform() to allow for arbitrary matrix transforms
- Added SimpleMatrix as a value_array, which means users can
provide a 9 element array which will be converted to SimpleMatrix
and then SkMatrix on the C++ side.
- Renamed helpers_externs.js to externs.js and expanded it greatly.
This was necessitated by the code written in chaining.js
- Fixed a few bugs in previous tests (svg gold test race condition,
uncaught exception in svg reporting)
See also https://skia-review.googlesource.com/c/skia/+/147209 which
allows .moveTo .lineTo, etc to chain on the C++ SkPath.
Bug: skia:8216
Change-Id: I7450cd8b7b5377cf15c962b02d161677b62d7e15
Reviewed-on: https://skia-review.googlesource.com/147115
Reviewed-by: Mike Reed <reed@google.com>
2018-08-17 17:52:56 +00:00
|
|
|
|
2018-08-10 19:53:16 +00:00
|
|
|
function bits2float(str) {
|
|
|
|
return PathKit.SkBits2FloatUnsigned(parseInt(str))
|
|
|
|
}
|
|
|
|
|
[PathKit] Rework API to avoid extra copies unless explicitly called for.
Breaking Changes:
- All method calls that mutate a path now return the same JS path
object to allow chaining (moveTo, lineTo, trim, op, simplify, etc).
Pre-existing code likely will need to have some delete() methods
removed because the path will be deleted multiple times. See
chaining.js for this code (basically, we wrote our own binding code
since the default code wasn't quite flexible enough)
- GetCanvasFillType -> GetFillTypeString (Was in https://skia-review.googlesource.com/c/skia/+/147209)
Since Canvas and SVG use the same strings, it seemed logical to make
them share.
- stroke() now takes a single object instead of 3 params. This object
currently can have up to 4 params, cap, join, width, miter_limit.
This object can be expanded on in future versions as more configuration
options are added.
As per custom with v0 software, we bump the minor version to 0.2.X
to indicate breaking changes in a pre-release software package.
Other changes of note:
- Simple tests added for effects (see effects.specs.js) A follow up
CL will handle the Gold (correctness tests)
- Simple tests added for equals and copy constructors (from https://skia-review.googlesource.com/c/skia/+/147209)
- Added transform() to allow for arbitrary matrix transforms
- Added SimpleMatrix as a value_array, which means users can
provide a 9 element array which will be converted to SimpleMatrix
and then SkMatrix on the C++ side.
- Renamed helpers_externs.js to externs.js and expanded it greatly.
This was necessitated by the code written in chaining.js
- Fixed a few bugs in previous tests (svg gold test race condition,
uncaught exception in svg reporting)
See also https://skia-review.googlesource.com/c/skia/+/147209 which
allows .moveTo .lineTo, etc to chain on the C++ SkPath.
Bug: skia:8216
Change-Id: I7450cd8b7b5377cf15c962b02d161677b62d7e15
Reviewed-on: https://skia-review.googlesource.com/147115
Reviewed-by: Mike Reed <reed@google.com>
2018-08-17 17:52:56 +00:00
|
|
|
describe('bounds and rect', function(){
|
|
|
|
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,
|
|
|
|
bits2float("0x40333334"), // 2.8
|
|
|
|
bits2float("0x40155556"))); // 2.3333333
|
|
|
|
path.delete();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2018-08-09 17:58:04 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
[PathKit] Rework API to avoid extra copies unless explicitly called for.
Breaking Changes:
- All method calls that mutate a path now return the same JS path
object to allow chaining (moveTo, lineTo, trim, op, simplify, etc).
Pre-existing code likely will need to have some delete() methods
removed because the path will be deleted multiple times. See
chaining.js for this code (basically, we wrote our own binding code
since the default code wasn't quite flexible enough)
- GetCanvasFillType -> GetFillTypeString (Was in https://skia-review.googlesource.com/c/skia/+/147209)
Since Canvas and SVG use the same strings, it seemed logical to make
them share.
- stroke() now takes a single object instead of 3 params. This object
currently can have up to 4 params, cap, join, width, miter_limit.
This object can be expanded on in future versions as more configuration
options are added.
As per custom with v0 software, we bump the minor version to 0.2.X
to indicate breaking changes in a pre-release software package.
Other changes of note:
- Simple tests added for effects (see effects.specs.js) A follow up
CL will handle the Gold (correctness tests)
- Simple tests added for equals and copy constructors (from https://skia-review.googlesource.com/c/skia/+/147209)
- Added transform() to allow for arbitrary matrix transforms
- Added SimpleMatrix as a value_array, which means users can
provide a 9 element array which will be converted to SimpleMatrix
and then SkMatrix on the C++ side.
- Renamed helpers_externs.js to externs.js and expanded it greatly.
This was necessitated by the code written in chaining.js
- Fixed a few bugs in previous tests (svg gold test race condition,
uncaught exception in svg reporting)
See also https://skia-review.googlesource.com/c/skia/+/147209 which
allows .moveTo .lineTo, etc to chain on the C++ SkPath.
Bug: skia:8216
Change-Id: I7450cd8b7b5377cf15c962b02d161677b62d7e15
Reviewed-on: https://skia-review.googlesource.com/147115
Reviewed-by: Mike Reed <reed@google.com>
2018-08-17 17:52:56 +00:00
|
|
|
describe('Command arrays', function(){
|
|
|
|
it('does NOT approximates conics when dumping as toCmds', function(done){
|
|
|
|
LoadPathKit.then(() => {
|
|
|
|
let path = PathKit.NewPath();
|
|
|
|
path.moveTo(20, 120);
|
|
|
|
path.arc(20, 120, 18, 0, 1.75 * Math.PI);
|
|
|
|
path.lineTo(20, 120);
|
|
|
|
|
|
|
|
let expectedCmds = [
|
|
|
|
[PathKit.MOVE_VERB, 20, 120],
|
|
|
|
[PathKit.LINE_VERB, 38, 120],
|
|
|
|
[PathKit.CONIC_VERB, 38, 138, 20, 138, bits2float("0x3f3504f3)")], // 0.707107f
|
|
|
|
[PathKit.CONIC_VERB, 2, 138, 2, 120, bits2float("0x3f3504f3)")], // 0.707107f
|
|
|
|
[PathKit.CONIC_VERB, 2, 102, 20, 102, bits2float("0x3f3504f3)")], // 0.707107f
|
|
|
|
[PathKit.CONIC_VERB, bits2float("0x41dba58e"), 102, bits2float("0x4202e962"), bits2float("0x42d68b4d"), bits2float("0x3f6c8361")], // 27.4558, 102, 32.7279, 107.272, 0.92388
|
|
|
|
[PathKit.LINE_VERB, 20, 120],
|
|
|
|
];
|
|
|
|
let actual = path.toCmds();
|
|
|
|
expect(actual).toEqual(expectedCmds);
|
|
|
|
|
|
|
|
path.delete();
|
|
|
|
done();
|
|
|
|
});
|
2018-08-10 19:53:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-09 17:58:04 +00:00
|
|
|
});
|