husler 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ coverage/
@@ -0,0 +1,11 @@
1
+ script: "rspec spec"
2
+ language: ruby
3
+ bundler_args: --without coverage
4
+ rvm:
5
+ - 1.8.7
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - jruby-18mode
9
+ - jruby-19mode
10
+ - rbx-18mode
11
+ - rbx-19mode
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
- source 'https://rubygems.org'
1
+ source :rubygems
2
2
 
3
3
  # Specify your gem's dependencies in husler.gemspec
4
4
  gemspec
5
+
6
+ group :coverage do
7
+ gem 'simplecov'
8
+ end
data/README.md CHANGED
@@ -1,10 +1,14 @@
1
- # Husler
1
+ # Husler [![Build Status](https://secure.travis-ci.org/soulcutter/husler.png)](http://travis-ci.org/soulcutter/husler)
2
2
 
3
3
  A ruby implementation of [HUSL, a human-friendly color space](http://boronine.com/husl/).
4
4
 
5
5
  ## Usage
6
6
 
7
- TODO
7
+ ```ruby
8
+ Husler.rgb_to_husl(r, g, b) # rgb values must be between 0 and 1
9
+
10
+ Husler.husl_to_rgb(h, s, l) # h(ue) is between 0-360 and s(aturation) and l(ightness) between 0-100
11
+ ```
8
12
 
9
13
  ## Credit
10
14
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -16,4 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec', '>= 2.11.0'
19
21
  end
@@ -1,5 +1,3 @@
1
- require 'mathn'
2
-
3
1
  require "husler/version"
4
2
  require 'husler/constants'
5
3
 
@@ -34,7 +32,7 @@ module Husler
34
32
  sub1 = ((l + 16) ** 3) / 1560896.0
35
33
  sub2 = sub1 > 0.008856 ? sub1 : (l / 903.3);
36
34
 
37
- result = Float::INFINITY
35
+ result = INFINITY
38
36
 
39
37
  M.each do |m1, m2, m3|
40
38
  top = ((0.99915 * m1 + 1.05122 * m2 + 1.14460 * m3) * sub2);
@@ -89,8 +87,9 @@ module Husler
89
87
  end
90
88
 
91
89
  def xyz_rgb(tuple)
90
+ dup_tuple = tuple.dup
92
91
  (0...3).each do |i|
93
- tuple[i] = from_linear(dot_product(M[i], tuple))
92
+ tuple[i] = from_linear(dot_product(M[i], dup_tuple))
94
93
  end
95
94
  tuple
96
95
  end
@@ -1,6 +1,7 @@
1
1
  module Husler
2
2
  PI = Math::PI
3
3
  #PI = 3.1415926535897932384626433832795
4
+ INFINITY = +1.0/0 # positive infinity technically
4
5
 
5
6
  ONE_THIRD = (1.0 / 3.0)
6
7
 
@@ -1,3 +1,3 @@
1
1
  module Husler
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Husler do
4
+ context "#rgb_to_husl" do
5
+ it "matches the expected output from the canonical coffeescript implementation" do
6
+ # jQuery.husl.fromRGB(0.75, 0.5, 0.25);
7
+ Husler.rgb_to_husl(0.75, 0.5, 0.25).should == [41.92580295066964, 78.60025347503503, 58.774191389329374]
8
+ end
9
+ end
10
+
11
+ context "#husl_to_rgb" do
12
+ it "matches the expected output from the canonical coffeescript implementation" do
13
+ # jQuery.husl.toRGB(41.92580295066964, 78.60025347503503, 58.774191389329374)
14
+ Husler.husl_to_rgb(41.92580295066964, 78.60025347503503, 58.774191389329374).should ==
15
+ [0.7499979858220194, 0.5000211204153698, 0.25000732006691057]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "spec/"
5
+ end
6
+ end
7
+
8
+ require 'husler'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: husler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-07 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.11.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.11.0
14
30
  description: A ruby implementation of HUSL, a human-friendly color space
15
31
  email:
16
32
  - bradley.schaefer@gmail.com
@@ -19,6 +35,7 @@ extensions: []
19
35
  extra_rdoc_files: []
20
36
  files:
21
37
  - .gitignore
38
+ - .travis.yml
22
39
  - Gemfile
23
40
  - LICENSE.txt
24
41
  - README.md
@@ -27,6 +44,8 @@ files:
27
44
  - lib/husler.rb
28
45
  - lib/husler/constants.rb
29
46
  - lib/husler/version.rb
47
+ - spec/lib/husler_spec.rb
48
+ - spec/spec_helper.rb
30
49
  homepage: ''
31
50
  licenses: []
32
51
  post_install_message:
@@ -51,4 +70,6 @@ rubygems_version: 1.8.24
51
70
  signing_key:
52
71
  specification_version: 3
53
72
  summary: A ruby implementation of HUSL, a human-friendly color space
54
- test_files: []
73
+ test_files:
74
+ - spec/lib/husler_spec.rb
75
+ - spec/spec_helper.rb