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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4796455f861ca6470c2d70dc0df6ac3cbed39f56
4
- data.tar.gz: d7c4009ad2d103dd4df905fd1e0272ed223c2ebb
3
+ metadata.gz: a1d5db24047874cba578ee40d7b03c7ec2e204f5
4
+ data.tar.gz: 70c327e69d7a54897fa73436eb13b5d175a5711c
5
5
  SHA512:
6
- metadata.gz: fb8a84ca13e6a0b698f5b32ba78b059248fcdff3ef4a710fcb0efa10a50de352c7054104c1b0f8781ad95379d9e2417be3dd5e1bfa20678572a0f20caaa447a1
7
- data.tar.gz: 95350c86b4d5525324a7b33c8d56c608246b905b89e106c688a3499c969b39ef64f228b77522fab1516719f27bd77b831e3222276d77bd4e10bce2e4629a7f88
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 or by moving or lineing to the starting coordinates. 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.
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
 
@@ -1,3 +1,4 @@
1
+ require "bigdecimal"
1
2
  require "wicket/version"
2
3
  require "wicket/svg_path"
3
4
  require "wicket/subpath"
@@ -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*/,'').to_f } # remove whitespace and turn into a float
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
@@ -19,11 +19,7 @@ module Wicket
19
19
 
20
20
  def closed?
21
21
  return false if @commands.empty?
22
- if @commands.length > 1
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Wicket
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -114,13 +114,13 @@ module Wicket
114
114
  end
115
115
 
116
116
  context "the kitchen sink" do
117
- let(:path){ SVGPath.new("M749.208,402.3311l14.8604,23.8335l-3.6279,1.7236l-14.4775-23.1108L749.208,402.3311z M775.3047,457.8872l0.0293,33.5894 l-3.9326,0.0044l-0.0225-32.6997L775.3047,457.8872z M764.0645,426.1665l11.2402,31.7207l-3.9268,0.894l-10.9434-30.8901 L764.0645,426.1665z") }
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((227.1177 -371.5405,247.7852 -349.9634,250.373 -353.0425,230.2959 -374.0044,227.1177 -371.5405))")
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(((227.1177 -371.5405,247.7852 -349.9634,250.373 -353.0425,230.2959 -374.0044,227.1177 -371.5405)),((197.5977 -356.0957,227.0786 -325.3271,229.667 -328.4067,200.8188 -358.5156,197.5977 -356.0957)))")
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.1
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-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler