savage-transform 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/LICENSE +20 -0
- data/README.rdoc +108 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/lib/savage.rb +3 -0
- data/lib/savage/direction.rb +56 -0
- data/lib/savage/direction_proxy.rb +19 -0
- data/lib/savage/directions/arc_to.rb +30 -0
- data/lib/savage/directions/close_path.rb +22 -0
- data/lib/savage/directions/coordinate_target.rb +21 -0
- data/lib/savage/directions/cubic_curve_to.rb +47 -0
- data/lib/savage/directions/horizontal_to.rb +31 -0
- data/lib/savage/directions/line_to.rb +15 -0
- data/lib/savage/directions/move_to.rb +15 -0
- data/lib/savage/directions/point_target.rb +22 -0
- data/lib/savage/directions/quadratic_curve_to.rb +44 -0
- data/lib/savage/directions/vertical_to.rb +31 -0
- data/lib/savage/parser.rb +108 -0
- data/lib/savage/path.rb +66 -0
- data/lib/savage/sub_path.rb +78 -0
- data/lib/savage/transformable.rb +59 -0
- data/lib/savage/utils.rb +7 -0
- data/savage-transform.gemspec +26 -0
- data/spec/savage/directions/arc_to_spec.rb +97 -0
- data/spec/savage/directions/close_path_spec.rb +30 -0
- data/spec/savage/directions/cubic_curve_to_spec.rb +146 -0
- data/spec/savage/directions/horizontal_to_spec.rb +10 -0
- data/spec/savage/directions/line_to_spec.rb +14 -0
- data/spec/savage/directions/move_to_spec.rb +10 -0
- data/spec/savage/directions/point_spec.rb +12 -0
- data/spec/savage/directions/quadratic_curve_spec.rb +123 -0
- data/spec/savage/directions/vertical_to_spec.rb +10 -0
- data/spec/savage/parser_spec.rb +250 -0
- data/spec/savage/path_spec.rb +105 -0
- data/spec/savage/sub_path_spec.rb +195 -0
- data/spec/savage/transformable_spec.rb +99 -0
- data/spec/savage_spec.rb +5 -0
- data/spec/shared/command.rb +13 -0
- data/spec/shared/coordinate_target.rb +36 -0
- data/spec/shared/direction.rb +29 -0
- data/spec/shared/point_target.rb +45 -0
- data/spec/spec_helper.rb +36 -0
- metadata +153 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
include Savage
|
4
|
+
|
5
|
+
describe Transformable do
|
6
|
+
it 'should apply to Path, SubPath and Direction' do
|
7
|
+
[Path, SubPath, Direction, Directions::LineTo].each do |cls|
|
8
|
+
expect(cls.ancestors).to include(Transformable)
|
9
|
+
expect(cls.public_instance_methods).to include(:transform)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'fully transformable paths' do
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Path do
|
17
|
+
it 'can transform' do
|
18
|
+
path = Parser.parse %Q{C211.003,239.997,253.003,197.997,304.003,197.997}
|
19
|
+
path.scale( 0.5, -0.5 )
|
20
|
+
path.translate( 0, 100 )
|
21
|
+
path.to_command.should == "C105.5015-19.9985 126.5015 1.0015 152.0015 1.0015"
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should transform subpaths recursively' do
|
25
|
+
path = Parser.parse('M 0 100 L 100 200 L 200 200 H 30 M 0 100 Z')
|
26
|
+
path.translate( 100, -135 )
|
27
|
+
path.subpaths.first.to_command.should == "M100-35 200 65 300 65 130 65"
|
28
|
+
path.subpaths[1].to_command.should == "M100-35Z"
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be not fully transformable with H/V directions' do
|
32
|
+
path = Parser.parse('M 0 100 L 100 200 L 200 200 H 30 M 0 100 Z')
|
33
|
+
path.fully_transformable?.should be_false
|
34
|
+
path.to_transformable_commands!
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can transform relative Horizontal and Vertical subpaths' do
|
38
|
+
path = Parser.parse('m 50 50 h 100 v 100 h -100 v -100')
|
39
|
+
path.rotate( 90, 100, 100 )
|
40
|
+
path.to_command.should == "M-250 50l0 100-100 0 0-100 100 0"
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'can transform absolute Horizontal and Vertical subpaths' do
|
44
|
+
path = Parser.parse('M 50 50 H 150 V 150 H 50 V 50')
|
45
|
+
path.rotate( 90, 100, 100 )
|
46
|
+
path.to_command.should == "M-250 50-250 150-350 150-350 50-250 50"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe SubPath do
|
51
|
+
it 'should transfrom subpaths recursively' do
|
52
|
+
path = Parser.parse('M 0 100 L 100 200 L 200 200 H 30 M 0 100 Z')
|
53
|
+
subpath = path.subpaths.first
|
54
|
+
subpath.translate( 10, 15 )
|
55
|
+
subpath.directions.first.to_command.should == "M10 115"
|
56
|
+
subpath.directions[1].to_command.should == "L110 215"
|
57
|
+
subpath.directions[2].to_command.should == "L210 215"
|
58
|
+
subpath.directions[3].to_command.should == "H40"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'can turn to fully transformable directions' do
|
62
|
+
subpath = Parser.parse('m 50 50 h 100 v 100 h -100 v -100').subpaths.first
|
63
|
+
subpath.fully_transformable?.should be_false
|
64
|
+
|
65
|
+
subpath.to_transformable_commands!
|
66
|
+
subpath.to_command.should == 'M50 50l100 0 0 100-100 0 0-100'
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe Directions::LineTo do
|
72
|
+
it 'could be translate' do
|
73
|
+
x, y = 50, 80
|
74
|
+
dir = Directions::LineTo.new(x, y)
|
75
|
+
dir.translate( 130, 601 )
|
76
|
+
dir.target.x.should == 180
|
77
|
+
dir.target.y.should == 681
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should ignore translating if relative' do
|
81
|
+
x, y = 50, 80
|
82
|
+
dir = Directions::LineTo.new(x, y, false)
|
83
|
+
dir.translate( 130, 601 )
|
84
|
+
# notice: not changed
|
85
|
+
dir.target.x.should == 50
|
86
|
+
dir.target.y.should == 80
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'could be rotated' do
|
90
|
+
x, y = 50, 80
|
91
|
+
dir = Directions::LineTo.new(x, y)
|
92
|
+
dir.rotate(90)
|
93
|
+
dir.target.x.should == -80
|
94
|
+
dir.target.y.round.should == 50
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
data/spec/savage_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Command
|
2
|
+
def extract_coordinates(command_string)
|
3
|
+
coordinates = []
|
4
|
+
command_string.scan /-?\d+(\.\d+)?/ do |match_group|
|
5
|
+
coordinates << $&.to_f
|
6
|
+
end
|
7
|
+
coordinates
|
8
|
+
end
|
9
|
+
|
10
|
+
def extract_command(command_string)
|
11
|
+
command_string[0,1]
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_examples 'CoordinateTarget' do
|
2
|
+
before :each do
|
3
|
+
@dir = dir_class.new(100)
|
4
|
+
end
|
5
|
+
include Command
|
6
|
+
it_behaves_like 'Direction'
|
7
|
+
it 'should have an accessible target, based on the constructor argument' do
|
8
|
+
@dir.respond_to?(:target).should == true
|
9
|
+
@dir.target.should == 100
|
10
|
+
end
|
11
|
+
it 'should be constructed with at least a target parameter' do
|
12
|
+
lambda { dir_class.new }.should raise_error
|
13
|
+
lambda { dir_class.new 45 }.should_not raise_error
|
14
|
+
lambda { dir_class.new 45, true }.should_not raise_error
|
15
|
+
end
|
16
|
+
it 'should be relative if constructed with a false third parameter' do
|
17
|
+
direction = dir_class.new(45, false)
|
18
|
+
direction.absolute?.should == false
|
19
|
+
end
|
20
|
+
it 'should be absolute if constructed with a true third parameter' do
|
21
|
+
direction = dir_class.new(45, true)
|
22
|
+
direction.absolute?.should == true
|
23
|
+
end
|
24
|
+
it 'should be absolute if constructed with only two parameters' do
|
25
|
+
direction = dir_class.new(45)
|
26
|
+
direction.absolute?.should == true
|
27
|
+
end
|
28
|
+
describe '#to_command' do
|
29
|
+
it 'should have exactly 1 numerical parameter' do
|
30
|
+
extract_coordinates(@dir.to_command).length.should == 1
|
31
|
+
end
|
32
|
+
it 'should show the provided X value as the next parameter' do
|
33
|
+
extract_coordinates(@dir.to_command)[0].should == 100
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
shared_examples "Direction" do
|
2
|
+
include Command
|
3
|
+
it 'should have a to_command method' do
|
4
|
+
@dir.respond_to?(:to_command).should == true
|
5
|
+
end
|
6
|
+
it 'should have an absolute? method' do
|
7
|
+
@dir.respond_to?(:absolute?).should == true
|
8
|
+
end
|
9
|
+
it 'should have a command_code method' do
|
10
|
+
@dir.respond_to?(:command_code).should == true
|
11
|
+
end
|
12
|
+
describe '#to_command' do
|
13
|
+
it "should start with the command\'s command code" do
|
14
|
+
@dir.to_command[0,1].should == @dir.command_code
|
15
|
+
end
|
16
|
+
it 'should only have one alphabetical command code' do
|
17
|
+
@dir.to_command.match(/[A-Za-z]/).size.should == 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
describe '#command_code' do
|
21
|
+
it 'should start with a lower-case letter when not absolute' do
|
22
|
+
rel_dir = create_relative
|
23
|
+
rel_dir.command_code.should == command_code.downcase
|
24
|
+
end
|
25
|
+
it 'should start with a capital letter when absolute' do
|
26
|
+
@dir.command_code.should == command_code.upcase
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
shared_examples_for 'PointTarget' do
|
2
|
+
before :each do
|
3
|
+
@dir = dir_class.new(100,200)
|
4
|
+
end
|
5
|
+
include Command
|
6
|
+
it_behaves_like 'Direction'
|
7
|
+
it 'should have a target' do
|
8
|
+
@dir.respond_to?(:target).should == true
|
9
|
+
@dir.target.class.should == Point
|
10
|
+
end
|
11
|
+
it 'should have an accessible target x, based on the constructor argument' do
|
12
|
+
@dir.target.x.should == 100
|
13
|
+
end
|
14
|
+
it 'should have an accessible target y, based on the constructor argument' do
|
15
|
+
@dir.target.y.should == 200
|
16
|
+
end
|
17
|
+
it 'should be constructed with at least an x and y parameter' do
|
18
|
+
lambda { dir_class.new }.should raise_error
|
19
|
+
lambda { dir_class.new 45 }.should raise_error
|
20
|
+
lambda { dir_class.new 45, 50 }.should_not raise_error
|
21
|
+
end
|
22
|
+
it 'should be relative if constructed with a false third parameter' do
|
23
|
+
direction = dir_class.new(45, 50, false)
|
24
|
+
direction.absolute?.should == false
|
25
|
+
end
|
26
|
+
it 'should be absolute if constructed with a true third parameter' do
|
27
|
+
direction = dir_class.new(45, 50, true)
|
28
|
+
direction.absolute?.should == true
|
29
|
+
end
|
30
|
+
it 'should be absolute if constructed with only two parameters' do
|
31
|
+
direction = dir_class.new(45, 45)
|
32
|
+
direction.absolute?.should == true
|
33
|
+
end
|
34
|
+
describe '#to_command' do
|
35
|
+
it 'should have exactly 2 numerical parameters' do
|
36
|
+
extract_coordinates(@dir.to_command).length.should == 2
|
37
|
+
end
|
38
|
+
it 'should show the provided X value as the next parameter' do
|
39
|
+
extract_coordinates(@dir.to_command)[0].should == 100
|
40
|
+
end
|
41
|
+
it 'should show the provided Y value as the final parameter' do
|
42
|
+
extract_coordinates(@dir.to_command)[1].should == 200
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spork'
|
3
|
+
|
4
|
+
Spork.prefork do
|
5
|
+
# Loading more in this block will cause your tests to run faster. However,
|
6
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
7
|
+
# need to restart spork for it take effect.
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
10
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'shared'))
|
11
|
+
|
12
|
+
require 'savage'
|
13
|
+
require 'rspec'
|
14
|
+
require 'rspec/autorun'
|
15
|
+
RSpec.configure do |config|
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
Dir[File.join(File.dirname(__FILE__) << '/shared', "*.rb")].each {|file| require File.basename(file) }
|
20
|
+
end
|
21
|
+
|
22
|
+
Spork.each_run do
|
23
|
+
# This code will be run each time you run your specs.
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
# --- Instructions ---
|
28
|
+
# - Sort through your spec_helper file. Place as much environment loading
|
29
|
+
# code that you don't normally modify during development in the
|
30
|
+
# Spork.prefork block.
|
31
|
+
# - Place the rest under Spork.each_run block
|
32
|
+
# - Any code that is left outside of the blocks will be ran during preforking
|
33
|
+
# and during each_run!
|
34
|
+
# - These instructions should self-destruct in 10 seconds. If they don't,
|
35
|
+
# feel free to delete them.
|
36
|
+
#
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: savage-transform
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- qhwa
|
8
|
+
- Jeremy Holland
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.5'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.5'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
56
|
+
description: extract color information from images
|
57
|
+
email:
|
58
|
+
- qhwa@163.com
|
59
|
+
- jeremy@jeremypholland.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".document"
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
67
|
+
- LICENSE
|
68
|
+
- README.rdoc
|
69
|
+
- Rakefile
|
70
|
+
- VERSION
|
71
|
+
- lib/savage.rb
|
72
|
+
- lib/savage/direction.rb
|
73
|
+
- lib/savage/direction_proxy.rb
|
74
|
+
- lib/savage/directions/arc_to.rb
|
75
|
+
- lib/savage/directions/close_path.rb
|
76
|
+
- lib/savage/directions/coordinate_target.rb
|
77
|
+
- lib/savage/directions/cubic_curve_to.rb
|
78
|
+
- lib/savage/directions/horizontal_to.rb
|
79
|
+
- lib/savage/directions/line_to.rb
|
80
|
+
- lib/savage/directions/move_to.rb
|
81
|
+
- lib/savage/directions/point_target.rb
|
82
|
+
- lib/savage/directions/quadratic_curve_to.rb
|
83
|
+
- lib/savage/directions/vertical_to.rb
|
84
|
+
- lib/savage/parser.rb
|
85
|
+
- lib/savage/path.rb
|
86
|
+
- lib/savage/sub_path.rb
|
87
|
+
- lib/savage/transformable.rb
|
88
|
+
- lib/savage/utils.rb
|
89
|
+
- savage-transform.gemspec
|
90
|
+
- spec/savage/directions/arc_to_spec.rb
|
91
|
+
- spec/savage/directions/close_path_spec.rb
|
92
|
+
- spec/savage/directions/cubic_curve_to_spec.rb
|
93
|
+
- spec/savage/directions/horizontal_to_spec.rb
|
94
|
+
- spec/savage/directions/line_to_spec.rb
|
95
|
+
- spec/savage/directions/move_to_spec.rb
|
96
|
+
- spec/savage/directions/point_spec.rb
|
97
|
+
- spec/savage/directions/quadratic_curve_spec.rb
|
98
|
+
- spec/savage/directions/vertical_to_spec.rb
|
99
|
+
- spec/savage/parser_spec.rb
|
100
|
+
- spec/savage/path_spec.rb
|
101
|
+
- spec/savage/sub_path_spec.rb
|
102
|
+
- spec/savage/transformable_spec.rb
|
103
|
+
- spec/savage_spec.rb
|
104
|
+
- spec/shared/command.rb
|
105
|
+
- spec/shared/coordinate_target.rb
|
106
|
+
- spec/shared/direction.rb
|
107
|
+
- spec/shared/point_target.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
homepage: https://github.com/qhwa/color_extract
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.2.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: extract color information from images
|
133
|
+
test_files:
|
134
|
+
- spec/savage/directions/arc_to_spec.rb
|
135
|
+
- spec/savage/directions/close_path_spec.rb
|
136
|
+
- spec/savage/directions/cubic_curve_to_spec.rb
|
137
|
+
- spec/savage/directions/horizontal_to_spec.rb
|
138
|
+
- spec/savage/directions/line_to_spec.rb
|
139
|
+
- spec/savage/directions/move_to_spec.rb
|
140
|
+
- spec/savage/directions/point_spec.rb
|
141
|
+
- spec/savage/directions/quadratic_curve_spec.rb
|
142
|
+
- spec/savage/directions/vertical_to_spec.rb
|
143
|
+
- spec/savage/parser_spec.rb
|
144
|
+
- spec/savage/path_spec.rb
|
145
|
+
- spec/savage/sub_path_spec.rb
|
146
|
+
- spec/savage/transformable_spec.rb
|
147
|
+
- spec/savage_spec.rb
|
148
|
+
- spec/shared/command.rb
|
149
|
+
- spec/shared/coordinate_target.rb
|
150
|
+
- spec/shared/direction.rb
|
151
|
+
- spec/shared/point_target.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
has_rdoc:
|