Class: Compass::Core::SassExtensions::Functions::GradientSupport::CSS3AngleToSVGConverter

### Home Classes Methods

### In Files

- lib/compass/core/sass_extensions/functions/gradient_support.rb

### Parent

Object

### Methods

- ::new
- #handle_keywords
- #in_radians
- #result
- #round6
- #scale
- #sin2
- #x
- #x1
- #x2
- #y
- #y1
- #y2

### Included Modules

- Compass::Core::SassExtensions::Functions::Math

### Class/Module Index

Quicksearch

- Compass
- Compass::BrowserSupport
- Compass::Configuration
- Compass::Configuration::Adapters
- Compass::Configuration::Data
- Compass::Configuration::Defaults
- Compass::Configuration::Inheritance
- Compass::Configuration::Inheritance::ClassMethods
- Compass::Configuration::Inheritance::ClassMethods::ArrayProxy
- Compass::Configuration::Inheritance::InstanceMethods
- Compass::Configuration::Paths
- Compass::Configuration::Watch
- Compass::Core
- Compass::Core::CanIUse
- Compass::Core::SassExtensions
- Compass::Core::SassExtensions::Functions
- Compass::Core::SassExtensions::Functions::Colors
- Compass::Core::SassExtensions::Functions::Configuration
- Compass::Core::SassExtensions::Functions::Constants
- Compass::Core::SassExtensions::Functions::CrossBrowserSupport
- Compass::Core::SassExtensions::Functions::CrossBrowserSupport::CSS2FallbackValue
- Compass::Core::SassExtensions::Functions::Display
- Compass::Core::SassExtensions::Functions::Enumerate
- Compass::Core::SassExtensions::Functions::Env
- Compass::Core::SassExtensions::Functions::Files
- Compass::Core::SassExtensions::Functions::FontFiles
- Compass::Core::SassExtensions::Functions::GradientSupport
- Compass::Core::SassExtensions::Functions::GradientSupport::Assertions
- Compass::Core::SassExtensions::Functions::GradientSupport::CSS3AngleToSVGConverter
- Compass::Core::SassExtensions::Functions::GradientSupport::ColorStop
- Compass::Core::SassExtensions::Functions::GradientSupport::Functions
- Compass::Core::SassExtensions::Functions::GradientSupport::Gradient
- Compass::Core::SassExtensions::Functions::GradientSupport::Gradient::ClassMethods
- Compass::Core::SassExtensions::Functions::GradientSupport::LinearGradient
- Compass::Core::SassExtensions::Functions::GradientSupport::RadialGradient
- Compass::Core::SassExtensions::Functions::ImageSize
- Compass::Core::SassExtensions::Functions::ImageSize::ImageProperties
- Compass::Core::SassExtensions::Functions::ImageSize::JPEG
- Compass::Core::SassExtensions::Functions::InlineImage
- Compass::Core::SassExtensions::Functions::Lists
- Compass::Core::SassExtensions::Functions::Math
- Compass::Core::SassExtensions::Functions::SassDeclarationHelper
- Compass::Core::SassExtensions::Functions::Selectors
- Compass::Core::SassExtensions::Functions::Urls
- Compass::Core::SassExtensions::Functions::Urls::FontUrl
- Compass::Core::SassExtensions::Functions::Urls::GeneratedImageUrl
- Compass::Core::SassExtensions::Functions::Urls::ImageUrl
- Compass::Core::SassExtensions::Functions::Urls::StylesheetUrl
- Compass::Error
- Compass::Frameworks
- Compass::Frameworks::Framework
- Compass::HasDeprecatedConstantsFromCore
- Compass::SassExtensions
- Compass::SassExtensions::Functions
- Compass::Util
- Sass
- Sass::Script
- Sass::Script::CrossBrowserFunctionCall
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::HasSimpleCrossBrowserFunctionSupport
- Sass::Script::List
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Tree
- Sass::Tree::Node

No matching classes.

# Compass::Core::SassExtensions::Functions::GradientSupport::CSS3AngleToSVGConverter

### Constants

BOTTOM
DIR_KEYWORDS_TO_ANGLE
LEFT
RIGHT
TOP

### Public Class Methods

new(angle) click to toggle source

    # 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

### Public Instance Methods

handle_keywords(angle) click to toggle source

    # 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

in_radians(angle) click to toggle source

    # 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

result(v) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 141
    def result(v)
      round6(scale(v))
    end

round6(v) click to toggle source

    # 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

scale(p) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 133
    def scale(p)
      (p + 1) / 2.0
    end

sin2(a) click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 76
    def sin2(a)
      v = sin(a)
      v * v
    end

x() click to toggle source

    # 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

x1() click to toggle source

    # 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

x2() click to toggle source

    # 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

y() click to toggle source

    # 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

y1() click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 106
    def y1
      result case @quadrant
             when 0, 3
               y
             when 1, 2
               -y
             end
    end

y2() click to toggle source

    # File lib/compass/core/sass_extensions/functions/gradient_support.rb, line 124
    def y2
      result case @quadrant
             when 0, 3
               -y
             when 1, 2
               y
             end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.