fixed trig functions closes #498
This commit is contained in:
parent
289c452d64
commit
acfd1e43a2
@ -19,9 +19,10 @@ module Compass::SassExtensions::Functions::Trig
|
||||
private
|
||||
def trig(operation, number)
|
||||
if number.numerator_units == ["deg"] && number.denominator_units == []
|
||||
Sass::Script::Number.new(Math.send(operation, Math::PI * number.value / 360))
|
||||
Sass::Script::Number.new(Math.send(operation, (number.value * Math::PI / 180)))
|
||||
else
|
||||
Sass::Script::Number.new(Math.send(operation, number.value), number.numerator_units, number.denominator_units)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -65,18 +65,21 @@ class SassExtensionsTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_trig_functions
|
||||
assert_equal "0.841", evaluate("sin(1)")
|
||||
assert_equal "0.841px", evaluate("sin(1px)")
|
||||
assert_equal "0.0", evaluate("sin(pi())")
|
||||
assert_equal "1", evaluate("sin(pi() / 2)")
|
||||
assert_equal "1", evaluate("sin(180deg)")
|
||||
assert_equal "0.0", evaluate("sin(180deg)")
|
||||
assert_equal "-1", evaluate("sin(3* pi() / 2)")
|
||||
assert_equal "-1", evaluate("cos(pi())")
|
||||
assert_equal "-1", evaluate("cos(360deg)")
|
||||
assert_equal "1", evaluate("cos(360deg)")
|
||||
assert_equal "-0.176", evaluate("sin(270)")
|
||||
assert_equal "1", evaluate("cos(2*pi())")
|
||||
assert_equal "0.0", evaluate("cos(pi() / 2)")
|
||||
assert_equal "0.0", evaluate("cos(3* pi() / 2)")
|
||||
assert_equal "0.0", evaluate("tan(pi())")
|
||||
assert_equal "0.0", evaluate("tan(360deg)")
|
||||
assert_equal "0.959", evaluate("sin(360)")
|
||||
assert evaluate("tan(pi()/2 - 0.0001)").to_f > 1000, evaluate("tan(pi()/2 - 0.0001)")
|
||||
assert evaluate("tan(pi()/2 + 0.0001)").to_f < -1000, evaluate("tan(pi()/2 - 0.0001)")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user