diff options
| author | mo khan <mo@mokhan.ca> | 2015-04-08 15:28:37 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-04-08 15:28:37 -0600 |
| commit | c7363e63f3d6d60debe3721cecf3354d1904405d (patch) | |
| tree | ea4fb9824bb13bda0db2ed544fb18879a9cbae7f | |
| parent | 208d393e2a282ceceee463e8d887bd2bfce4ce6e (diff) | |
add relative movements.
| -rw-r--r-- | lib/scale/shapes/path.rb | 8 | ||||
| -rw-r--r-- | spec/shapes/path_spec.rb | 25 |
2 files changed, 27 insertions, 6 deletions
diff --git a/lib/scale/shapes/path.rb b/lib/scale/shapes/path.rb index 1b8af99..a495852 100644 --- a/lib/scale/shapes/path.rb +++ b/lib/scale/shapes/path.rb @@ -11,12 +11,12 @@ module Scale command("L #{x} #{y}") end - def horizontal(n) - command("H #{n}") + def horizontal(n, relative: false) + command("#{relative ? "h" : "H"} #{n}") end - def vertical(n) - command("V #{n}") + def vertical(n, relative: false) + command("#{relative ? "v" : "V"} #{n}") end def close_path diff --git a/spec/shapes/path_spec.rb b/spec/shapes/path_spec.rb index 646acfa..f6df8c0 100644 --- a/spec/shapes/path_spec.rb +++ b/spec/shapes/path_spec.rb @@ -32,11 +32,24 @@ describe Scale::Path do XML expect(subject.to_xml).to eql(expected) end + + it 'moves horizontally using relative position' do + subject.move_to(x: 10, y: 10) + subject.horizontal(90, relative: true) + expected = <<-XML +<?xml version="1.0"?> +<path d="M10 10 h 90"/> + XML + expect(subject.to_xml).to eql(expected) + end end describe "#vertial" do - it 'draws a horizontal line' do + before :each do subject.move_to(x: 10, y: 10) + end + + it 'draws a vertical line' do subject.vertical(90) expected = <<-XML <?xml version="1.0"?> @@ -44,6 +57,15 @@ describe Scale::Path do XML expect(subject.to_xml).to eql(expected) end + + it 'draws a vertical line relative to the current position' do + subject.vertical(90, relative: true) + expected = <<-XML +<?xml version="1.0"?> +<path d="M10 10 v 90"/> + XML + expect(subject.to_xml).to eql(expected) + end end describe "#close_path" do @@ -74,5 +96,4 @@ describe Scale::Path do expect(subject.to_xml).to eql(expected) end end - end |
