wicket 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +11 -1
- data/lib/wicket.rb +1 -0
- data/lib/wicket/command.rb +11 -5
- data/lib/wicket/subpath.rb +1 -5
- data/lib/wicket/svg_path.rb +0 -10
- data/lib/wicket/version.rb +1 -1
- data/spec/svg_path_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1d5db24047874cba578ee40d7b03c7ec2e204f5
|
4
|
+
data.tar.gz: 70c327e69d7a54897fa73436eb13b5d175a5711c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00f66f02b83314f43d2567e7c2324223dd0d769036c27bf9571896330ea485703724a0c3a5d155ed66cab9757c8c7f567cc1f490dcfb474cd9af0739769e8243
|
7
|
+
data.tar.gz: 65885c4b9f665eee96d41cf70ecf1e6587befb6fe64612849df94a281d12198804d6f966a669569a545b45871dbc632a625adefe900fe03057a9f6fdbcd4a047
|
data/README.md
CHANGED
@@ -8,6 +8,7 @@ Notable features include:
|
|
8
8
|
- Translating line paths into WKT Polygons or Multipolygons
|
9
9
|
- Accepting absolute or relative path commands
|
10
10
|
- Inversing Y axis measurements (SVG y coordinates decrease as you go up)
|
11
|
+
- Decimal math for increased accuracy
|
11
12
|
|
12
13
|
Future possible features could include:
|
13
14
|
- Translating curved paths
|
@@ -36,18 +37,27 @@ Or install it yourself as:
|
|
36
37
|
## Usage
|
37
38
|
|
38
39
|
```ruby
|
40
|
+
# one subpath
|
39
41
|
path = Wicket::SVGPath.new("M10 10H20l10 10H10z")
|
40
42
|
path.to_polygon
|
41
43
|
# => "POLYGON((10.0 -10.0,20.0 -10.0,30.0 -20.0,10.0 -20.0,10.0 -10.0))"
|
42
44
|
path.to_multipolygon
|
43
45
|
# => "MULTIPOLYGON(((10.0 -10.0,30.0 -10.0,40.0 -10.0,50.0 -20.0,40.0 -20.0,10.0 -10.0)))"
|
46
|
+
|
47
|
+
# two subpaths
|
48
|
+
path = Wicket::SVGPath.new("M10 10H20l10 10H10z M100 100h10v10h-10z")
|
49
|
+
path.to_polygon # ONLY THE FIRST SUBPATH!
|
50
|
+
# => "POLYGON((10.0 -10.0,20.0 -10.0,30.0 -20.0,10.0 -20.0,10.0 -10.0))"
|
51
|
+
path.to_multipolygon # both subpaths
|
52
|
+
# => "MULTIPOLYGON(((10.0 -10.0,30.0 -10.0,40.0 -10.0,50.0 -20.0,40.0 -20.0,10.0 -10.0)),((100 -100,110 -100,110 -110,100 -110,100 -100)))
|
53
|
+
|
44
54
|
```
|
45
55
|
|
46
56
|
## Gotchas
|
47
57
|
|
48
58
|
- Wicket assumes that a move command (M or m) is part of the polygon edge. It just so happened that a lot of the data I was working with when creating this project was formatted that way. Eventually I believe this should not be the case and should be able to be toggled on as an option.
|
49
59
|
- Polygons are assumed to have no holes, thus everything inside the path is part of the polygon.
|
50
|
-
- Each polygon is represented by a subpath. A subpath continues until it is closed by a Z command
|
60
|
+
- Each polygon is represented by a subpath. A subpath continues until it is closed by a Z command. Multiple subpaths are represented as individual elements in `#to_multipolygon`, whereas only the first subpath is represented in `#to_polygon`. Make sure your data does not include multiple subpaths if using the `#to_polygon` method.
|
51
61
|
|
52
62
|
## Contributing
|
53
63
|
|
data/lib/wicket.rb
CHANGED
data/lib/wicket/command.rb
CHANGED
@@ -9,14 +9,20 @@ module Wicket
|
|
9
9
|
cursor_start = subpath.cursor_end # get the current position of the cursor
|
10
10
|
args = arg_string.to_s.scan(/(?:\-\s*)?\d+(?:\.\d+)?/).flatten # parse out the numerical arguments
|
11
11
|
if !args.empty?
|
12
|
+
generate_commands(args,command_class,absolute,cursor_start)
|
13
|
+
else # Must be a Z command
|
14
|
+
[command_class.new(absolute,cursor_start)]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def generate_commands(args,command_class,absolute,cursor_start)
|
12
21
|
args.each_slice(command_class.arg_count).map do |slice| # slice them according to the number the code takes
|
13
|
-
slice.map!{|arg| arg.gsub(/\s*/,'')
|
22
|
+
slice.map!{|arg| BigDecimal.new(arg.gsub(/\s*/,'')) } # remove whitespace and turn into a decimal
|
14
23
|
command_class.new(absolute,cursor_start,*slice)
|
15
24
|
end
|
16
|
-
else
|
17
|
-
[command_class.new(absolute,cursor_start)]
|
18
25
|
end
|
19
|
-
end
|
20
26
|
end
|
21
27
|
|
22
28
|
def subpath=(subpath)
|
@@ -33,7 +39,7 @@ module Wicket
|
|
33
39
|
|
34
40
|
private
|
35
41
|
def inverse_values
|
36
|
-
[cursor_end[:x], cursor_end[:y] * -1]
|
42
|
+
[cursor_end[:x].to_s("F"), (cursor_end[:y] * -1).to_s("F")]
|
37
43
|
end
|
38
44
|
end
|
39
45
|
end
|
data/lib/wicket/subpath.rb
CHANGED
@@ -19,11 +19,7 @@ module Wicket
|
|
19
19
|
|
20
20
|
def closed?
|
21
21
|
return false if @commands.empty?
|
22
|
-
|
23
|
-
first_command.cursor_end == last_command.cursor_end
|
24
|
-
else
|
25
|
-
first_command.cursor_start == first_command.cursor_end
|
26
|
-
end
|
22
|
+
@commands.last.class == Commands::Z
|
27
23
|
end
|
28
24
|
|
29
25
|
def to_polygon
|
data/lib/wicket/svg_path.rb
CHANGED
@@ -32,15 +32,5 @@ module Wicket
|
|
32
32
|
def new_subpath
|
33
33
|
Subpath.new.tap {|s| @subpaths << s }
|
34
34
|
end
|
35
|
-
|
36
|
-
def group_by_subpath(parsed_result)
|
37
|
-
parsed_result.each_with_object([]) do
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def parse_arg_string(arg_string)
|
42
|
-
matches = arg_string.scan(/(?:\-\s*)?\d+(?:\.\d+)?/)
|
43
|
-
matches.flatten.map!{|arg| arg.gsub(/\s*/,'').to_f }
|
44
|
-
end
|
45
35
|
end
|
46
36
|
end
|
data/lib/wicket/version.rb
CHANGED
data/spec/svg_path_spec.rb
CHANGED
@@ -114,13 +114,13 @@ module Wicket
|
|
114
114
|
end
|
115
115
|
|
116
116
|
context "the kitchen sink" do
|
117
|
-
let(:path){ SVGPath.new("
|
117
|
+
let(:path){ SVGPath.new("M293.9214,533.9287l-6.3857-18.1475l3.9316-0.8857l6.0811,17.29L293.9214,533.9287z M287.5356,515.7813V496.5h3.9316v18.3955 L287.5356,515.7813z") }
|
118
118
|
it "parses the first subpath to polygon" do
|
119
|
-
expect(path.to_polygon).to eq("POLYGON((
|
119
|
+
expect(path.to_polygon).to eq("POLYGON((293.9214 -533.9287,287.5357 -515.7812,291.4673 -514.8955,297.5484 -532.1855,293.9214 -533.9287,293.9214 -533.9287))")
|
120
120
|
end
|
121
121
|
|
122
122
|
it "parses both to a multipolygon" do
|
123
|
-
expect(path.to_multipolygon).to eq("MULTIPOLYGON(((
|
123
|
+
expect(path.to_multipolygon).to eq("MULTIPOLYGON(((293.9214 -533.9287,287.5357 -515.7812,291.4673 -514.8955,297.5484 -532.1855,293.9214 -533.9287,293.9214 -533.9287)),((287.5356 -515.7813,287.5356 -496.5,291.4672 -496.5,291.4672 -514.8955,287.5356 -515.7813,287.5356 -515.7813)))")
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wicket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Urabe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|