Skip to content

Commit 98eb2f6

Browse files
committed
Refactor draw_path method
1 parent 970d85d commit 98eb2f6

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/uing/area/area/draw/context.cr

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,20 @@ module UIng
104104
fill_brush : Brush? = nil,
105105
stroke_brush : Brush? = nil,
106106
stroke_params : StrokeParams? = nil, &)
107-
if fill && fill_brush.nil?
108-
raise ArgumentError.new("fill=true requires fill_brush")
109-
end
110-
if stroke && (stroke_brush.nil? || stroke_params.nil?)
111-
raise ArgumentError.new("stroke=true requires stroke_brush and stroke_params")
112-
end
113-
114107
Path.open(mode) do |path|
115108
yield path
116109
path.end_path
117-
self.draw_fill(path, fill_brush.not_nil!) if fill
118-
self.draw_stroke(path, stroke_brush.not_nil!, stroke_params.not_nil!) if stroke
110+
111+
if fill
112+
brush = fill_brush || raise ArgumentError.new("fill=true requires fill_brush")
113+
draw_fill(path, brush)
114+
end
115+
116+
if stroke
117+
brush = stroke_brush || raise ArgumentError.new("stroke=true requires stroke_brush and stroke_params")
118+
params = stroke_params || raise ArgumentError.new("stroke=true requires stroke_brush and stroke_params")
119+
draw_stroke(path, brush, params)
120+
end
119121
end
120122
end
121123

0 commit comments

Comments
 (0)