Object
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 8 def initialize(angle) @original_angle = angle @angle = handle_keywords(angle) @angle = in_radians(@angle) % (2 * PI) @quadrant = (@angle * 2 / PI).to_i @angle = case @quadrant when 0 @angle when 1 PI - @angle when 2 @angle - PI when 3 2 * PI - @angle end end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 41 def handle_keywords(angle) if angle.is_a?(Sass::Script::Value::List) || angle.is_a?(Sass::Script::Value::String) direction = angle.to_sass is_end_point = !!/\bto\b/.match(direction) dir = 0 dir |= TOP if /\btop\b/.match(direction) dir |= BOTTOM if /\bbottom\b/.match(direction) dir |= RIGHT if /\bright\b/.match(direction) dir |= LEFT if /\bleft\b/.match(direction) if (r = DIR_KEYWORDS_TO_ANGLE[dir]) r += 180 unless is_end_point Sass::Script::Value::Number.new(r, %(deg), []) else raise Sass::SyntaxError, "Unknown direction: #{angle.to_sass}" end else angle end end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 61 def in_radians(angle) case angle.unit_str when "deg" angle.value * PI / 180.0 when "grad" angle.value * PI / 200.0 when "rad" angle.value when "turn" angle.value * PI * 2 else raise Sass::SyntaxError.new("#{angle.unit_str} is not an angle") end end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 141 def result(v) round6(scale(v)) end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 137 def round6(v) (v * 1_000_000).round / 1_000_000.0 end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 133 def scale(p) (p + 1) / 2.0 end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 76 def sin2(a) v = sin(a) v * v end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 81 def x @x ||= if @angle > 1.570621793869697 1.0 # avoid floating point rounding error at the asymptote else tan(@angle) + (1 - tan(@angle)) * sin2(@angle) end end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 97 def x1 result case @quadrant when 0, 1 -x when 2, 3 x end end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 115 def x2 result case @quadrant when 0, 1 x when 2, 3 -x end end
# File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 89 def y @y ||= if @angle < 0.0001 1.0 # the limit of the expression as we approach 0 is 1. else x / tan(@angle) end end
Generated with the Darkfish Rdoc Generator 2.