From 243b3836c4d56ca418921e98fe25a63a54a27cf0 Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Thu, 11 Jun 2015 17:19:17 -0400 Subject: [PATCH] Refactor to remove instance_eval When you have a hammer... --- lib/squib/graphics/shapes.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/squib/graphics/shapes.rb b/lib/squib/graphics/shapes.rb index 4e9532b..47121ab 100644 --- a/lib/squib/graphics/shapes.rb +++ b/lib/squib/graphics/shapes.rb @@ -84,15 +84,13 @@ module Squib x, y, n = poly.x, poly.y, poly.n inner_radius, outer_radius = poly.inner_radius, poly.outer_radius use_cairo do |cc| - poly.instance_eval do - cc.rotate_about(x, y, trans.angle) - cc.move_to(x + outer_radius, y) #i = 0, so cos(0)=1 and sin(0)=0 - theta = Math::PI / n.to_f # i.e. (2*pi) / (2*n) - 0.upto(2 * n) do |i| - radius = i.even? ? outer_radius : inner_radius - cc.line_to(x + radius * Math::cos(i * theta), - y + radius * Math::sin(i * theta)) - end + cc.rotate_about(x, y, trans.angle) + cc.move_to(x + outer_radius, y) #i = 0, so cos(0)=1 and sin(0)=0 + theta = Math::PI / n.to_f # i.e. (2*pi) / (2*n) + 0.upto(2 * n) do |i| + radius = i.even? ? outer_radius : inner_radius + cc.line_to(x + radius * Math::cos(i * theta), + y + radius * Math::sin(i * theta)) end cc.close_path cc.fill_n_stroke(draw)