@@ -483,27 +483,19 @@ private extension LayerTree.Gradient {
483483private extension LayerTree . Shape {
484484
485485 var gradientEndpoints : ( start: LayerTree . Point , end: LayerTree . Point ) ? {
486- switch self {
487- case . path( let p) :
488- return p. endpoints
489- case . ellipse( within: let rect) :
490- return rect. gradientEndpoints
491- case . rect( within: let rect, _) :
492- return rect. gradientEndpoints
493- case . polygon( between: let points) :
494- guard points. count > 1 else { return nil }
495- return ( points [ 0 ] , points [ points. count / 2 ] )
496- default :
497- return nil
498- }
486+ bounds? . gradientEndpoints
499487 }
500488
501489 var bounds : LayerTree . Rect ? {
502490 switch self {
503491 case . path( let p) :
504492 return p. bounds
505- default :
506- return nil
493+ case . rect( within: let rect, _) ,
494+ . ellipse( within: let rect) :
495+ return rect
496+ case . polygon( between: let points) ,
497+ . line( between: let points) :
498+ return . makeBounds( between: points)
507499 }
508500 }
509501}
@@ -524,4 +516,19 @@ private extension LayerTree.Rect {
524516 let end = LayerTree . Point ( midX, maxY)
525517 return ( start, end)
526518 }
519+
520+ static func makeBounds( between points: [ LayerTree . Point ] ) -> Self ? {
521+ var min = LayerTree . Point. maximum
522+ var max = LayerTree . Point. minimum
523+ for point in points {
524+ min = min. minimum ( combining: point)
525+ max = max. maximum ( combining: point)
526+ }
527+ return LayerTree . Rect (
528+ x: min. x,
529+ y: min. y,
530+ width: max. x - min. x,
531+ height: max. y - min. y
532+ )
533+ }
527534}
0 commit comments