@@ -32,10 +32,6 @@ class BroadBrushHelper {
3232 this . endCaps = [ ] ;
3333 // toggle wether we're using a square brush
3434 this . isSquareBrush = false ;
35- //test
36- this . mergeBatchSize = 20 ;
37- this . previewGroup = new paper . Group ( ) ;
38- this . pendingSquares = [ ] ;
3935 }
4036
4137 onBroadMouseDown ( event , tool , options ) {
@@ -44,7 +40,6 @@ class BroadBrushHelper {
4440 this . lastVec = null ;
4541 const size = options . brushSize / 2 ;
4642 if ( this . isSquareBrush ) {
47- this . pendingSquares = [ ] ;
4843 tool . minDistance = Math . max ( 1 , ( size / paper . view . zoom ) / 2 ) ;
4944 tool . maxDistance = options . brushSize ;
5045 } else {
@@ -83,45 +78,26 @@ class BroadBrushHelper {
8378 else this . roundHandler ( { point, delta } , tool , options ) ;
8479 }
8580 // square brush
86- squareHandler ( movement , tool , options ) {
87- const { point } = movement ;
81+ squareHandler ( movement , tool , options ) {
82+ // TODO this can technically handle other shapes, which we should add. However we need to implement some
83+ // cahce or flush system to make this less laggy when you have a large complex brush drawing (same goes for the segment brush)
84+ const { delta, point } = movement ;
8885 this . steps ++ ;
89- const size = options . brushSize / 2 ;
90- const square = new paper . Path . Rectangle (
91- new paper . Rectangle (
92- point . subtract ( new paper . Point ( size , size ) ) ,
93- point . add ( new paper . Point ( size , size ) )
94- )
95- ) ;
96- square . fillColor = options . fillColor ;
97- this . previewGroup . addChild ( square ) ;
98- this . pendingSquares . push ( square ) ;
99-
100- if ( this . pendingSquares . length >= this . mergeBatchSize ) {
101- this . flushPending ( ) ;
102- }
103- this . lastPoint = point ;
104- }
105-
106- flushPending ( ) {
107- if ( this . pendingSquares . length === 0 ) return ;
10886
109- // Merge preview shapes into finalPath
110- let merged = this . pendingSquares . shift ( ) ;
111- for ( const sq of this . pendingSquares ) {
112- merged = this . union ( merged , sq ) ;
113- }
114- this . pendingSquares . length = 0 ;
87+ const size = options . brushSize / 2 ;
88+ const square = new paper . Path . Rectangle ( new paper . Rectangle (
89+ new paper . Point ( point . x - size , point . y - size ) ,
90+ new paper . Point ( point . x + size , point . y + size )
91+ ) ) ;
11592
116- if ( ! this . finalPath ) {
117- this . finalPath = merged ;
118- } else {
119- this . finalPath = this . union ( this . finalPath , merged ) ;
93+ square . fillColor = options . fillColor ;
94+ this . lastPoint = point ;
95+ if ( ! this . finalPath ) this . finalPath = square ;
96+ else {
97+ const merged = this . union ( this . finalPath , square ) ;
98+ this . finalPath = merged ;
99+ }
120100 }
121-
122- // Clear preview layer
123- this . previewGroup . removeChildren ( ) ;
124- }
125101 // round brush
126102 roundHandler ( movement , tool , options ) {
127103 const { delta, point } = movement ;
@@ -277,7 +253,6 @@ class BroadBrushHelper {
277253
278254 // no need for normalization with the square brush
279255 if ( this . isSquareBrush ) {
280- this . flushPending ( ) ;
281256 if ( options . simplifySize > 0 && this . finalPath . segments ) this . simplify ( options . simplifySize ) ;
282257 return this . finalPath ;
283258 }
0 commit comments