curvature 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 214d89e901a59866ff938955e86e0b1f57d3f1c4
4
+ data.tar.gz: 34ba277ce2b8879d9af917ebbb9473f058af5c1f
5
+ SHA512:
6
+ metadata.gz: e6ee528b3627590114268532d6b389d0e0aed895e7010f631b25164fda2d6b1784f82774f76c673ab7db5477ebe8218e96475c9782ed87a7b2f8794e0302e9f6
7
+ data.tar.gz: 622297f4ce778485e23d4861fd720774acd48379490961b6e6dfc02e3367f77f44f55a168ba78b1165dc095c9f5d068b577db1b0b680f1454f5b4cbe6abe8a63
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mill.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 jslabovitz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,3 @@
1
+ # Curvature
2
+
3
+ Curvature helps in acquiring samples, generating curves to fit those samples, and charting the results.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'curvature'
3
+ s.version = '0.1'
4
+ s.summary = 'Acquires samples, generates curves to fit those samples, and charts the results.'
5
+ s.author = 'John Labovitz'
6
+ s.email = 'johnl@johnlabovitz.com'
7
+ s.description = %q{
8
+ Curvature helps in acquiring samples, generating curves to fit those samples, and charting the results.
9
+ }
10
+ s.homepage = 'http://github.com/jslabovitz/curvature'
11
+ s.license = 'MIT'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_path = 'lib'
16
+
17
+ s.add_dependency 'spliner'
18
+ s.add_dependency 'builder'
19
+
20
+ s.add_development_dependency 'bundler'
21
+ s.add_development_dependency 'rake'
22
+ end
@@ -0,0 +1,6 @@
1
+ require 'builder'
2
+ require 'spliner'
3
+
4
+ require 'curvature/sample'
5
+ require 'curvature/curve'
6
+ require 'curvature/chart'
@@ -0,0 +1,56 @@
1
+ module Curvature
2
+
3
+ class Chart
4
+
5
+ attr_accessor :name
6
+ attr_accessor :width
7
+ attr_accessor :height
8
+ attr_accessor :x_range
9
+ attr_accessor :y_range
10
+ attr_accessor :curves
11
+
12
+ def initialize(params={})
13
+ @curves = []
14
+ {
15
+ width: 500,
16
+ height: 500,
17
+ }.merge(params).each { |k, v| send("#{k}=", v) }
18
+ end
19
+
20
+ def <<(curve)
21
+ curve.chart = self
22
+ @curves << curve
23
+ end
24
+
25
+ def scaled_point(x, y)
26
+ [
27
+ @width * ((x - @x_range.min) / (@x_range.max - @x_range.min)),
28
+ @height * ((y - @y_range.min) / (@y_range.max - @y_range.min)),
29
+ ]
30
+ end
31
+
32
+ def to_html
33
+ xml = Builder::XmlMarkup.new(indent: 2)
34
+ xml.div(class: 'chart') do
35
+ xml.h2(@name) if @name
36
+ xml.svg(xmlns: 'http://www.w3.org/2000/svg', version: '1.1', width: @width, height: @height) do
37
+ xml.g(width: @width, height: @height, transform: "translate(0,#{@height}) scale(1,-1)") do
38
+ # draw border
39
+ xml.rect(x: 0, y: 0, width: @width, height: @height, fill: 'none', :'stroke-width' => 1, stroke: 'blue')
40
+
41
+ # draw linear line
42
+ xml.line(x1: 0, y1: 0, x2: @width, y2: @height, :'stroke-width' => 0.5, stroke: 'blue')
43
+
44
+ # draw curves
45
+ @curves.each do |curve|
46
+ xml << curve.to_html
47
+ end
48
+ end
49
+ end
50
+ end
51
+ xml.target!
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,70 @@
1
+ module Curvature
2
+
3
+ class Curve
4
+
5
+ attr_accessor :name
6
+ attr_accessor :samples
7
+ attr_accessor :chart
8
+
9
+ def initialize(params={})
10
+ @samples = []
11
+ {
12
+ }.merge(params).each { |k, v| send("#{k}=", v) }
13
+ end
14
+
15
+ def <<(sample)
16
+ @samples << sample
17
+ end
18
+
19
+ def value_for(input)
20
+ unless @spliner
21
+ @spliner = Spliner::Spliner.new(
22
+ @samples.map(&:input),
23
+ @samples.map(&:output),
24
+ )
25
+ end
26
+ @spliner[input] or raise "Can't find output for input #{input.inspect} on curve #{@name.inspect}"
27
+ end
28
+
29
+ def print
30
+ puts @name
31
+ @samples.each do |sample|
32
+ puts "\t%2s: %2.2f => %2.2f" % [sample.label, sample.input, sample.output]
33
+ end
34
+ puts
35
+ end
36
+
37
+ DefaultSampleAttributes = {
38
+ stroke: 'none',
39
+ fill: 'black',
40
+ }
41
+
42
+ def to_html
43
+ xml = Builder::XmlMarkup.new(indent: 2)
44
+
45
+ # draw interpolated curve
46
+ xml.g(fill: 'none', stroke: 'green', :'stroke-width' => 0.5) do
47
+ points = @chart.x_range.step(1.0 / @chart.width).map do |input|
48
+ @chart.scaled_point(input, value_for(input))
49
+ end
50
+ xml.polyline(points: points.map { |pt| pt.join(',') }.join(' '))
51
+ end
52
+
53
+ # draw individual samples
54
+ @samples.each do |sample|
55
+ cx, cy = @chart.scaled_point(sample.input, sample.output)
56
+ attributes = DefaultSampleAttributes.merge(
57
+ title: sample.label,
58
+ cx: cx,
59
+ cy: cy,
60
+ r: 3,
61
+ ).merge(sample.attributes || {})
62
+ xml.circle(attributes)
63
+ end
64
+
65
+ xml.target!
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,17 @@
1
+ module Curvature
2
+
3
+ class Sample
4
+
5
+ attr_accessor :label
6
+ attr_accessor :input
7
+ attr_accessor :output
8
+ attr_accessor :attributes
9
+
10
+ def initialize(params={})
11
+ {
12
+ }.merge(params).each { |k, v| send("#{k}=", v) }
13
+ end
14
+
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: curvature
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - John Labovitz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spliner
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: builder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |2
70
+
71
+ Curvature helps in acquiring samples, generating curves to fit those samples, and charting the results.
72
+ email: johnl@johnlabovitz.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - curvature.gemspec
83
+ - lib/curvature.rb
84
+ - lib/curvature/chart.rb
85
+ - lib/curvature/curve.rb
86
+ - lib/curvature/sample.rb
87
+ homepage: http://github.com/jslabovitz/curvature
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Acquires samples, generates curves to fit those samples, and charts the results.
111
+ test_files: []