Skip to content

Commit

Permalink
feat: add getFillTypeString() for PathKit
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Apr 20, 2021
1 parent 6d40b2a commit 44719de
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class Path2D {
op(path: Path2D, operation: PathOp): Path2D
toSVGString(): string
getFillType(): FillType
getFillTypeString(): string
setFillType(type: FillType): void
simplify(): Path2D
asWinding(): Path2D
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class Path2D {
op(path: Path2D, operation: PathOp): Path2D
toSVGString(): string
getFillType(): FillType
getFillTypeString(): string
setFillType(type: FillType): void
simplify(): Path2D
asWinding(): Path2D
Expand Down
13 changes: 13 additions & 0 deletions __test__/pathkit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ test('FillType must be Winding after conversion by AsWinding()', (t) => {
t.is(path.asWinding().getFillType(), FillType.Winding)
})

test('getFillTypeString()', (t) => {
const path = new Path2D()
path.rect(1, 2, 3, 4)
t.is(path.getFillTypeString(), 'nonzero')
})

test('getFillTypeString() and setFillType()', (t) => {
const path = new Path2D()
path.rect(1, 2, 3, 4)
path.setFillType(FillType.EvenOdd)
t.is(path.getFillTypeString(), 'evenodd')
})

test('Path FillType must be converted from nonzero to evenodd', (t) => {
const pathCircle = new Path2D(
'M50 87.5776C70.7536 87.5776 87.5776 70.7536 87.5776 50C87.5776 29.2464 70.7536 12.4224 50 12.4224C29.2464 12.4224 12.4224 29.2464 12.4224 50C12.4224 70.7536 29.2464 87.5776 50 87.5776ZM50 100C77.6142 100 100 77.6142 100 50C100 22.3858 77.6142 0 50 0C22.3858 0 0 22.3858 0 50C0 77.6142 22.3858 100 50 100Z',
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export class Path2D {
op(path: Path2D, operation: PathOp): Path2D
toSVGString(): string
getFillType(): FillType
getFillTypeString(): string
setFillType(type: FillType): void
simplify(): Path2D
asWinding(): Path2D
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ Path2D.prototype.stroke = function stroke(strokeOptions = {}) {
return this._stroke(width, miterLimit, join, cap)
}

Path2D.prototype.getFillTypeString = function getFillTypeString() {
const fillType = this.getFillType()

if (fillType === FillType.Winding) {
return 'nonzero'
} else if (fillType === FillType.EvenOdd) {
return 'evenodd'
} else {
return 'nonzero' // default
}
}

function createCanvas(width, height) {
const canvasElement = new CanvasElement(width, height)
const ctx = new CanvasRenderingContext2D(width, height)
Expand Down

1 comment on commit 44719de

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 44719de Previous: 6d40b2a Ratio
Draw house#@napi-rs/skia 20 ops/sec (±0.97%) 21.4 ops/sec (±1.22%) 1.07
Draw house#node-canvas 17 ops/sec (±1.17%) 20.9 ops/sec (±1.09%) 1.23
Draw gradient#@napi-rs/skia 20 ops/sec (±0.73%) 20.37 ops/sec (±0.9%) 1.02
Draw gradient#node-canvas 16 ops/sec (±1.4%) 20.41 ops/sec (±1.3%) 1.28

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.