@@ -22,6 +22,9 @@ public class Path {
22
22
23
23
uint _pathKey = 0 ;
24
24
25
+ bool _isRRect = false ;
26
+ public bool isRRect => this . _isRRect ;
27
+
25
28
public uint pathKey {
26
29
get {
27
30
return this . _pathKey ;
@@ -35,6 +38,39 @@ public Path(int capacity = 128) {
35
38
36
39
public List < float > commands => this . _commands ;
37
40
41
+ void _updateRRectFlag ( bool isRRect ) {
42
+ if ( this . _commands . Count > 0 && ! this . _isRRect ) {
43
+ return ;
44
+ }
45
+ this . _isRRect = isRRect && this . _hasOnlyMoveTos ( ) ;
46
+ }
47
+
48
+ bool _hasOnlyMoveTos ( ) {
49
+ var i = 0 ;
50
+ while ( i < this . _commands . Count ) {
51
+ var cmd = ( PathCommand ) this . _commands [ i ] ;
52
+ switch ( cmd ) {
53
+ case PathCommand . moveTo :
54
+ i += 3 ;
55
+ break ;
56
+ case PathCommand . lineTo :
57
+ return false ;
58
+ case PathCommand . bezierTo :
59
+ return false ;
60
+ case PathCommand . close :
61
+ i ++ ;
62
+ break ;
63
+ case PathCommand . winding :
64
+ i += 2 ;
65
+ break ;
66
+ default :
67
+ return false ;
68
+ }
69
+ }
70
+
71
+ return true ;
72
+ }
73
+
38
74
public override string ToString ( ) {
39
75
var sb = new StringBuilder ( "Path: count = " + this . _commands . Count ) ;
40
76
@@ -88,6 +124,7 @@ void _reset() {
88
124
89
125
this . _pathKey = pathGlobalKey ++ ;
90
126
this . _cache = null ;
127
+ this . _isRRect = false ;
91
128
}
92
129
93
130
internal PathCache flatten ( float scale ) {
@@ -238,22 +275,25 @@ public void moveTo(float x, float y) {
238
275
public void relativeLineTo ( float x , float y ) {
239
276
var x0 = this . _commandx ;
240
277
var y0 = this . _commandy ;
241
-
278
+
279
+ this . _updateRRectFlag ( false ) ;
242
280
this . _appendLineTo ( x + x0 , y + y0 ) ;
243
281
}
244
282
245
283
public void lineTo ( float x , float y ) {
284
+ this . _updateRRectFlag ( false ) ;
246
285
this . _appendLineTo ( x , y ) ;
247
286
}
248
287
249
288
public void cubicTo ( float c1x , float c1y , float c2x , float c2y , float x , float y ) {
289
+ this . _updateRRectFlag ( false ) ;
250
290
this . _appendBezierTo ( c1x , c1y , c2x , c2y , x , y ) ;
251
291
}
252
292
253
293
public void relativeCubicTo ( float c1x , float c1y , float c2x , float c2y , float x , float y ) {
254
294
var x0 = this . _commandx ;
255
295
var y0 = this . _commandy ;
256
-
296
+ this . _updateRRectFlag ( false ) ;
257
297
this . cubicTo ( x0 + c1x , y0 + c1y , x0 + c2x , y0 + c2y , x0 + x , y0 + y ) ;
258
298
}
259
299
@@ -262,6 +302,7 @@ public void quadraticBezierTo(float cx, float cy, float x, float y) {
262
302
var y0 = this . _commandy ;
263
303
264
304
const float twoThird = 2.0f / 3.0f ;
305
+ this . _updateRRectFlag ( false ) ;
265
306
this . _appendBezierTo (
266
307
x0 + twoThird * ( cx - x0 ) , y0 + twoThird * ( cy - y0 ) ,
267
308
x + twoThird * ( cx - x ) , y + twoThird * ( cy - y ) ,
@@ -272,10 +313,12 @@ public void relativeQuadraticBezierTo(float cx, float cy, float x, float y) {
272
313
var x0 = this . _commandx ;
273
314
var y0 = this . _commandy ;
274
315
316
+ this . _updateRRectFlag ( false ) ;
275
317
this . quadraticBezierTo ( x0 + cx , y0 + cy , x0 + x , y0 + y ) ;
276
318
}
277
319
278
320
public void conicTo ( float x1 , float y1 , float x2 , float y2 , float w ) {
321
+ this . _updateRRectFlag ( false ) ;
279
322
if ( ! ( w > 0 ) ) {
280
323
this . lineTo ( x2 , y2 ) ;
281
324
return ;
@@ -313,7 +356,7 @@ public void conicTo(float x1, float y1, float x2, float y2, float w) {
313
356
public void relativeConicTo ( float x1 , float y1 , float x2 , float y2 , float w ) {
314
357
var x0 = this . _commandx ;
315
358
var y0 = this . _commandy ;
316
-
359
+ this . _updateRRectFlag ( false ) ;
317
360
this . conicTo ( x0 + x1 , y0 + y1 , x0 + x2 , y0 + y2 , w ) ;
318
361
}
319
362
@@ -324,7 +367,7 @@ public void arcToPoint(Offset arcEnd,
324
367
bool largeArc = false ,
325
368
bool clockwise = false ) {
326
369
radius = radius ?? Radius . zero ;
327
-
370
+ this . _updateRRectFlag ( false ) ;
328
371
D . assert ( PaintingUtils . _offsetIsValid ( arcEnd ) ) ;
329
372
D . assert ( PaintingUtils . _radiusIsValid ( radius ) ) ;
330
373
@@ -458,6 +501,7 @@ public void winding(PathWinding dir) {
458
501
}
459
502
460
503
public void addRect ( Rect rect ) {
504
+ this . _updateRRectFlag ( true ) ;
461
505
this . _appendMoveTo ( rect . left , rect . top ) ;
462
506
this . _appendLineTo ( rect . left , rect . bottom ) ;
463
507
this . _appendLineTo ( rect . right , rect . bottom ) ;
@@ -466,6 +510,7 @@ public void addRect(Rect rect) {
466
510
}
467
511
468
512
public void addRRect ( RRect rrect ) {
513
+ this . _updateRRectFlag ( true ) ;
469
514
float w = rrect . width ;
470
515
float h = rrect . height ;
471
516
float halfw = Mathf . Abs ( w ) * 0.5f ;
@@ -501,6 +546,7 @@ public void addRRect(RRect rrect) {
501
546
}
502
547
503
548
public void addEllipse ( float cx , float cy , float rx , float ry ) {
549
+ this . _updateRRectFlag ( true ) ;
504
550
this . _appendMoveTo ( cx - rx , cy ) ;
505
551
this . _appendBezierTo ( cx - rx , cy + ry * _KAPPA90 ,
506
552
cx - rx * _KAPPA90 , cy + ry , cx , cy + ry ) ;
@@ -514,16 +560,19 @@ public void addEllipse(float cx, float cy, float rx, float ry) {
514
560
}
515
561
516
562
public void addCircle ( float cx , float cy , float r ) {
563
+ this . _updateRRectFlag ( true ) ;
517
564
this . addEllipse ( cx , cy , r , r ) ;
518
565
}
519
566
520
567
public void addOval ( Rect oval ) {
521
568
D . assert ( oval != null ) ;
569
+ this . _updateRRectFlag ( true ) ;
522
570
var center = oval . center ;
523
571
this . addEllipse ( center . dx , center . dy , oval . width / 2 , oval . height / 2 ) ;
524
572
}
525
573
526
574
public void arcTo ( float x1 , float y1 , float x2 , float y2 , float radius ) {
575
+ this . _updateRRectFlag ( false ) ;
527
576
var x0 = this . _commandx ;
528
577
var y0 = this . _commandy ;
529
578
@@ -563,6 +612,7 @@ public void arcTo(float x1, float y1, float x2, float y2, float radius) {
563
612
}
564
613
565
614
public void arcTo ( Rect rect , float startAngle , float sweepAngle , bool forceMoveTo = true ) {
615
+ this . _updateRRectFlag ( false ) ;
566
616
var mat = Matrix3 . makeScale ( rect . width / 2 , rect . height / 2 ) ;
567
617
var center = rect . center ;
568
618
mat . postTranslate ( center . dx , center . dy ) ;
@@ -572,6 +622,7 @@ public void arcTo(Rect rect, float startAngle, float sweepAngle, bool forceMoveT
572
622
}
573
623
574
624
public void addArc ( Rect rect , float startAngle , float sweepAngle ) {
625
+ this . _updateRRectFlag ( false ) ;
575
626
this . arcTo ( rect , startAngle , sweepAngle , true ) ;
576
627
}
577
628
@@ -659,10 +710,12 @@ void _addArcCommands(
659
710
}
660
711
661
712
public void addArc ( float cx , float cy , float r , float a0 , float a1 , PathWinding dir , bool forceMoveTo = true ) {
713
+ this . _updateRRectFlag ( false ) ;
662
714
this . _addArcCommands ( cx , cy , r , a0 , a1 , dir , forceMoveTo ) ;
663
715
}
664
716
665
717
public void addPolygon ( IList < Offset > points , bool close ) {
718
+ this . _updateRRectFlag ( false ) ;
666
719
D . assert ( points != null ) ;
667
720
if ( points . Count == 0 ) {
668
721
return ;
@@ -705,7 +758,8 @@ public void addPath(Path path, Offset offset) {
705
758
706
759
public void addPath ( Path path , Matrix3 transform = null ) {
707
760
D . assert ( path != null ) ;
708
-
761
+
762
+ this . _updateRRectFlag ( path . isRRect ) ;
709
763
var i = 0 ;
710
764
while ( i < path . _commands . Count ) {
711
765
var cmd = ( PathCommand ) path . _commands [ i ] ;
0 commit comments