-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added mask element and style property
- Loading branch information
Showing
7 changed files
with
127 additions
and
15 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
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,35 @@ | ||
import { Box2 } from '@daign/math'; | ||
import { GraphicNode } from '@daign/2d-pipeline'; | ||
|
||
import { StyledGraphicNode } from '../styledGraphicNode'; | ||
|
||
/** | ||
* Class for a mask element. | ||
*/ | ||
export class Mask extends StyledGraphicNode { | ||
// The id of the mask. | ||
public id: string = ''; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public constructor() { | ||
super(); | ||
|
||
this.baseClass = 'mask'; | ||
} | ||
|
||
/** | ||
* Get the bounding box of all child elements of the mask. | ||
* @returns The bounding box. | ||
*/ | ||
public getBox(): Box2 { | ||
const box = new Box2(); | ||
this.children.forEach( ( child: GraphicNode ): void => { | ||
if ( child instanceof StyledGraphicNode ) { | ||
box.expandByBox( child.getBoxTransformed() ); | ||
} | ||
} ); | ||
return box; | ||
} | ||
} |
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
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,56 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { Vector2 } from '@daign/math'; | ||
import { GraphicNode } from '@daign/2d-pipeline'; | ||
|
||
import { Mask, Line } from '../../lib'; | ||
|
||
describe( 'Mask', (): void => { | ||
describe( 'constructor', (): void => { | ||
it( 'should set the base class mask', (): void => { | ||
// Act | ||
const mask = new Mask(); | ||
|
||
// Assert | ||
expect( ( mask as any ).classNames.getByName( 'baseClass' ).value ).to.equal( 'mask' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'getBox', (): void => { | ||
it( 'should get the bounding box of the mask', (): void => { | ||
// Arrange | ||
const mask = new Mask(); | ||
|
||
const line1 = new Line(); | ||
line1.start = new Vector2( 7, 2 ); | ||
line1.end = new Vector2( 3, 8 ); | ||
mask.appendChild( line1 ); | ||
|
||
const line2 = new Line(); | ||
line2.start = new Vector2( 5, 6 ); | ||
line2.end = new Vector2( 1, 0 ); | ||
mask.appendChild( line2 ); | ||
|
||
// Act | ||
const box = mask.getBox(); | ||
|
||
// Assert | ||
expect( box.min.equals( new Vector2( 1, 0 ) ) ).to.be.true; | ||
expect( box.max.equals( new Vector2( 7, 8 ) ) ).to.be.true; | ||
} ); | ||
|
||
it( 'should ignore children that are not StyledGraphicNodes', (): void => { | ||
// Arrange | ||
const mask = new Mask(); | ||
|
||
const graphicNode = new GraphicNode(); | ||
mask.appendChild( graphicNode ); | ||
|
||
// Act | ||
const box = mask.getBox(); | ||
|
||
// Assert | ||
expect( box.isEmpty ).to.be.true; | ||
} ); | ||
} ); | ||
} ); |
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