-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
import { IDrawable } from './drawable'; | ||
import { IDrawingWand } from './drawing-wand'; | ||
|
||
/** | ||
* Sets the width of the stroke used to draw object outlines. | ||
*/ | ||
export class DrawableStrokeWidth implements IDrawable { | ||
private readonly _width: number; | ||
|
||
/** | ||
* Initializes a new instance of the {@link DrawableStrokeWidth} class. | ||
* @param width - The width. | ||
*/ | ||
constructor(width: number) { | ||
this._width = width; | ||
} | ||
|
||
draw(wand: IDrawingWand): void { | ||
wand.strokeWidth(this._width); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
import { DrawableLine } from '@src/drawables/drawable-line'; | ||
import { DrawableStrokeColor } from '@src/drawables/drawable-stroke-color'; | ||
import { DrawableStrokeWidth } from '@src/drawables/drawable-stroke-width'; | ||
import { MagickColors } from '@src/magick-colors'; | ||
import { TestImages } from '@test/test-images'; | ||
|
||
describe('DrawableStrokeWidth', () => { | ||
it('should change the width of a line', () => { | ||
TestImages.empty150x150Canvas.use((image) => { | ||
const strokeColor = MagickColors.Green; | ||
|
||
image.draw([ | ||
new DrawableStrokeColor(strokeColor), | ||
new DrawableStrokeWidth(10), | ||
new DrawableLine(10, 10, 40, 50) | ||
]); | ||
|
||
expect(image).toHavePixelWithColor(9, 9, MagickColors.White); | ||
expect(image).toHavePixelWithColor(10, 10, strokeColor); | ||
expect(image).toHavePixelWithColor(6, 13, strokeColor); | ||
expect(image).toHavePixelWithColor(44, 47, strokeColor); | ||
expect(image).toHavePixelWithColor(40, 50, strokeColor); | ||
}); | ||
}); | ||
}); |