straightedge 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +7 -0
  5. data/README.md +44 -2
  6. data/gemspec.yml +3 -0
  7. data/lib/straightedge.rb +33 -11
  8. data/lib/straightedge/aspects.rb +3 -0
  9. data/lib/straightedge/aspects/colorable.rb +8 -0
  10. data/lib/straightedge/aspects/figural.rb +12 -0
  11. data/lib/straightedge/aspects/positional.rb +10 -0
  12. data/lib/straightedge/colors.rb +72 -0
  13. data/lib/straightedge/config.rb +6 -0
  14. data/lib/straightedge/director.rb +39 -0
  15. data/lib/straightedge/extend/array.rb +2 -13
  16. data/lib/straightedge/figures.rb +8 -0
  17. data/lib/straightedge/{adapters.rb → figures/circle.rb} +0 -0
  18. data/lib/straightedge/figures/figure.rb +44 -0
  19. data/lib/straightedge/figures/grid.rb +65 -0
  20. data/lib/straightedge/figures/grid_cell.rb +0 -0
  21. data/lib/straightedge/figures/hexagon.rb +33 -0
  22. data/lib/straightedge/figures/label.rb +13 -0
  23. data/lib/straightedge/figures/line.rb +25 -0
  24. data/lib/straightedge/figures/mark.rb +23 -0
  25. data/lib/straightedge/figures/quadrilateral.rb +20 -0
  26. data/lib/straightedge/motor/adapter.rb +54 -0
  27. data/lib/straightedge/motor/engine.rb +16 -0
  28. data/lib/straightedge/origin.rb +3 -0
  29. data/lib/straightedge/presenter.rb +29 -0
  30. data/lib/straightedge/scene.rb +20 -0
  31. data/lib/straightedge/surface.rb +21 -0
  32. data/lib/straightedge/toolkit/compass.rb +19 -0
  33. data/lib/straightedge/toolkit/rose.rb +60 -0
  34. data/lib/straightedge/toolkit/ruler.rb +23 -0
  35. data/lib/straightedge/tools.rb +3 -0
  36. data/lib/straightedge/version.rb +1 -1
  37. data/spec/spec_helper.rb +4 -1
  38. data/spec/straightedge/adapter_spec.rb +14 -0
  39. data/spec/straightedge/director_spec.rb +10 -0
  40. data/spec/straightedge/extend/array_spec.rb +1 -6
  41. data/spec/straightedge/{figure_spec.rb → figures/figure_spec.rb} +0 -5
  42. data/spec/straightedge/figures/grid_spec.rb +31 -0
  43. data/spec/straightedge/figures/hexagon_spec.rb +7 -0
  44. data/spec/straightedge/motor/engine_spec.rb +11 -0
  45. data/spec/straightedge/scene_spec.rb +27 -0
  46. data/spec/straightedge/{compass_spec.rb → toolkit/compass_spec.rb} +0 -4
  47. data/spec/straightedge/{rose_spec.rb → toolkit/rose_spec.rb} +0 -5
  48. data/spec/straightedge/toolkit/ruler_spec.rb +14 -0
  49. data/spec/straightedge_spec.rb +35 -0
  50. metadata +54 -16
  51. data/.rvmrc +0 -1
  52. data/lib/straightedge/compass.rb +0 -17
  53. data/lib/straightedge/figure.rb +0 -28
  54. data/lib/straightedge/grid.rb +0 -34
  55. data/lib/straightedge/line.rb +0 -21
  56. data/lib/straightedge/mark.rb +0 -26
  57. data/lib/straightedge/rose.rb +0 -44
  58. data/lib/straightedge/ruler.rb +0 -21
  59. data/spec/straightedge/grid_spec.rb +0 -33
  60. data/spec/straightedge/ruler_spec.rb +0 -11
@@ -1,9 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'straightedge/extend/array'
3
- require 'straightedge/compass'
4
- require 'straightedge/rose'
5
- require 'straightedge/ruler'
6
- require 'straightedge/figure'
7
2
 
8
3
  describe Straightedge::Figure do
9
4
  it 'should compute adjacent positions' do
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Grid do
4
+ context "when given width and height" do
5
+ let(:width) { 10 }
6
+ let(:height) { 10 }
7
+ subject { Grid.new([width,height]) }
8
+ it 'should reflect given width and height' do
9
+ expect(subject.width).to eql(width)
10
+ expect(subject.height).to eql(height)
11
+ end
12
+ end
13
+
14
+ describe ".elements" do
15
+ subject { Grid.new([2,2]) }
16
+
17
+ it 'should iterate over the grid' do
18
+ expect(subject.to_a).to eql([[0, 0], [0, 1], [1, 0], [1, 1]])
19
+ end
20
+ end
21
+
22
+ describe "#first" do
23
+ subject { Grid.new([1,1]) }
24
+ its(:first) { should eql([0,0]) }
25
+ end
26
+
27
+ describe "#sample" do
28
+ subject { Grid.new([2,2]) }
29
+ its(:sample) { should be_an Array } # eql([1,1])}
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hexagon do
4
+ #it 'should have a left triagnle' do
5
+ # expect(subject.left_triangle).to eql([ ])
6
+ #end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Engine do
4
+ subject { Engine.new }
5
+ let(:plane) { subject.surface }
6
+
7
+ it 'should render the surface' do
8
+ expect(plane).to receive(:display) #.with(plane)
9
+ subject.boot
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ #require 'straightedge/extend/array'
4
+ #require 'straightedge/ruler'
5
+ #require 'straightedge/mark'
6
+ #require 'straightedge/rose'
7
+ #require 'straightedge/compass'
8
+ #require 'straightedge/figure'
9
+ #require 'straightedge/grid'
10
+ #require 'straightedge/scene'
11
+
12
+ #describe Straightedge::Scene do
13
+ # let(:figures) do
14
+ # [ Figure.new([[0,0]]) ]
15
+ # end
16
+ #
17
+ # let(:grid) do
18
+ # Grid.new([10,10])
19
+ # end
20
+ #
21
+ # subject { Scene.new(grid: grid, figures: figures) }
22
+ # it 'should write figures to an adapter' do
23
+ # adapter = double
24
+ # expect(adapter).to receive(:draw).with(figures.first)
25
+ # subject.render(adapter)
26
+ # end
27
+ #end
@@ -1,8 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'straightedge/extend/array'
3
- require 'straightedge/mark'
4
- require 'straightedge/rose'
5
- require 'straightedge/compass'
6
2
 
7
3
  describe Compass do
8
4
  let(:origin) { [0,0] }
@@ -1,9 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'straightedge/extend/array'
3
- require 'straightedge/rose'
4
- require 'straightedge/ruler'
5
-
6
- # TODO separate into own spec?
7
2
  describe Straightedge::Rose do
8
3
  context "roses" do
9
4
  it 'should construct a simple rose' do
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ruler do
4
+ let(:a) { [0,3] }
5
+ let(:b) { [4,0] }
6
+
7
+ it 'should have a unit' do
8
+ expect(subject.unit).to eql(1)
9
+ end
10
+
11
+ it 'should measure distance' do
12
+ expect(Ruler.distance(a,b)).to eql(5.0)
13
+ end
14
+ end
@@ -5,4 +5,39 @@ describe Straightedge do
5
5
  it "should have a VERSION constant" do
6
6
  subject.const_get('VERSION').should_not be_empty
7
7
  end
8
+
9
+ context "contracts" do
10
+
11
+ context "example scene" do
12
+ let(:scene) { Director.new.current_scene }
13
+ it "should be constructed without issues" do
14
+ expect { scene.render }.not_to raise_error
15
+ end
16
+
17
+ end
18
+
19
+ context "classical constructions" do
20
+ =begin
21
+ the classical straightedge and compass constructions:
22
+
23
+ - Creating the line through two existing points
24
+ - Creating the circle through one point with centre another point
25
+ - Creating the point which is the intersection of two existing, non-parallel lines
26
+ - Creating the one or two points in the intersection of a line and a circle (if they intersect)
27
+ - Creating the one or two points in the intersection of two circles (if they intersect).
28
+ =end
29
+
30
+ describe "creating a line between two points" do
31
+ let(:a) { [0,4] }
32
+ let(:b) { [3,0] }
33
+
34
+ let(:line) { Line.new([a,b]) }
35
+
36
+ it 'should have length 5' do
37
+ expect(line.length).to eql(5.0)
38
+ end
39
+ end
40
+ end
41
+ end
8
42
  end
43
+
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: straightedge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-24 00:00:00.000000000 Z
11
+ date: 2014-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini-config
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.3
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +107,7 @@ files:
93
107
  - ".document"
94
108
  - ".gitignore"
95
109
  - ".rspec"
96
- - ".rvmrc"
110
+ - ".ruby-version"
97
111
  - ".yardopts"
98
112
  - ChangeLog.md
99
113
  - Gemfile
@@ -107,23 +121,47 @@ files:
107
121
  - features/straightedge.feature
108
122
  - gemspec.yml
109
123
  - lib/straightedge.rb
110
- - lib/straightedge/adapters.rb
111
- - lib/straightedge/compass.rb
124
+ - lib/straightedge/aspects.rb
125
+ - lib/straightedge/aspects/colorable.rb
126
+ - lib/straightedge/aspects/figural.rb
127
+ - lib/straightedge/aspects/positional.rb
128
+ - lib/straightedge/colors.rb
129
+ - lib/straightedge/config.rb
130
+ - lib/straightedge/director.rb
112
131
  - lib/straightedge/extend/array.rb
113
- - lib/straightedge/figure.rb
114
- - lib/straightedge/grid.rb
115
- - lib/straightedge/line.rb
116
- - lib/straightedge/mark.rb
117
- - lib/straightedge/rose.rb
118
- - lib/straightedge/ruler.rb
132
+ - lib/straightedge/figures.rb
133
+ - lib/straightedge/figures/circle.rb
134
+ - lib/straightedge/figures/figure.rb
135
+ - lib/straightedge/figures/grid.rb
136
+ - lib/straightedge/figures/grid_cell.rb
137
+ - lib/straightedge/figures/hexagon.rb
138
+ - lib/straightedge/figures/label.rb
139
+ - lib/straightedge/figures/line.rb
140
+ - lib/straightedge/figures/mark.rb
141
+ - lib/straightedge/figures/quadrilateral.rb
142
+ - lib/straightedge/motor/adapter.rb
143
+ - lib/straightedge/motor/engine.rb
144
+ - lib/straightedge/origin.rb
145
+ - lib/straightedge/presenter.rb
146
+ - lib/straightedge/scene.rb
147
+ - lib/straightedge/surface.rb
148
+ - lib/straightedge/toolkit/compass.rb
149
+ - lib/straightedge/toolkit/rose.rb
150
+ - lib/straightedge/toolkit/ruler.rb
151
+ - lib/straightedge/tools.rb
119
152
  - lib/straightedge/version.rb
120
153
  - spec/spec_helper.rb
121
- - spec/straightedge/compass_spec.rb
154
+ - spec/straightedge/adapter_spec.rb
155
+ - spec/straightedge/director_spec.rb
122
156
  - spec/straightedge/extend/array_spec.rb
123
- - spec/straightedge/figure_spec.rb
124
- - spec/straightedge/grid_spec.rb
125
- - spec/straightedge/rose_spec.rb
126
- - spec/straightedge/ruler_spec.rb
157
+ - spec/straightedge/figures/figure_spec.rb
158
+ - spec/straightedge/figures/grid_spec.rb
159
+ - spec/straightedge/figures/hexagon_spec.rb
160
+ - spec/straightedge/motor/engine_spec.rb
161
+ - spec/straightedge/scene_spec.rb
162
+ - spec/straightedge/toolkit/compass_spec.rb
163
+ - spec/straightedge/toolkit/rose_spec.rb
164
+ - spec/straightedge/toolkit/ruler_spec.rb
127
165
  - spec/straightedge_spec.rb
128
166
  - straightedge.gemspec
129
167
  homepage: https://rubygems.org/gems/straightedge
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use --create @straightedge
@@ -1,17 +0,0 @@
1
- module Straightedge
2
- class Compass
3
- extend Forwardable
4
- attr_accessor :rose
5
- def_delegator :rose, :project
6
-
7
- def initialize(rose=Rose.extended)
8
- @rose = rose
9
- end
10
-
11
- class << self
12
- def default
13
- @default_compass ||= new
14
- end
15
- end
16
- end
17
- end
@@ -1,28 +0,0 @@
1
- module Straightedge
2
- # TODO the idea is that a figure is a collection of lines and marks
3
- class Figure
4
- extend Forwardable
5
- def_delegators :marks, :each, :sample, :flatten, :to_a, :include?
6
- def_delegator :compass, :project
7
- attr_reader :lines, :marks
8
- attr_reader :compass
9
-
10
- def initialize(marks=[], lines: [], compass: Compass.default)
11
- @marks = marks
12
- @lines = lines
13
- @compass = compass
14
- end
15
-
16
- def adjacent
17
- @marks.map(&method(:project)).flatten(1).uniq.reject(&method(:include?))
18
- end
19
-
20
- def center
21
- [@marks.map(&:x).mean, @marks.map(&:y).mean]
22
- end
23
-
24
- def distance_from_center(xy)
25
- Ruler.distance(xy,center)
26
- end
27
- end
28
- end
@@ -1,34 +0,0 @@
1
- module Straightedge
2
- # TODO extend, make into just an arbitrary tiling Figure
3
- # so we can do sexy hexagons!
4
- #
5
- class Grid < Figure
6
- extend Forwardable
7
- include Enumerable
8
-
9
- def_delegator :lines, :x, :width
10
- def_delegator :lines, :y, :height
11
-
12
- DEFAULT_SIZE = 1_000
13
-
14
- def initialize(axes=[DEFAULT_SIZE,DEFAULT_SIZE])
15
- super([], lines: axes)
16
- @marks = Array.new(width) do |x|
17
- Array.new(height) do |y|
18
- [x,y]
19
- end
20
- end.flatten(1)
21
- end
22
-
23
- def each
24
- @marks.each { |p| yield(p) }
25
- end
26
-
27
- def clip(xys=[])
28
- xys.reject do |xy|
29
- x,y = *xy
30
- x < 0 || y < 0 || x >= width || y >= height
31
- end
32
- end
33
- end
34
- end
@@ -1,21 +0,0 @@
1
- module Straightedge
2
- class Line
3
- attr_reader :color, :alpha, :beta
4
- def initialize(a,b,color=:black)
5
- @alpha, @beta = a, b
6
- @color = color
7
- end
8
-
9
- def dx
10
- @alpha.x - @beta.x
11
- end
12
-
13
- def dy
14
- @alpha.y - @beta.y
15
- end
16
-
17
- def length
18
- Math.sqrt(dx*dx + dy*dy)
19
- end
20
- end
21
- end
@@ -1,26 +0,0 @@
1
- module Straightedge
2
- #
3
- # a mark is an "indicated" point with an optional color
4
- # the idea is for it to be a thin wrapper around the
5
- # vector arrays that are going to be so common
6
- #
7
- # so calling .to_point on an array will give you a mark
8
- # and hence #x/#y accessors (equivalently #width/#height)
9
- # on simple vectors
10
- #
11
- # where you could instantiate a mark, try to just use
12
- # a vector and push the calculation as far west as
13
- # possible
14
- #
15
- class Mark
16
- attr_reader :color, :x, :y
17
-
18
- alias :width :x
19
- alias :height :y
20
-
21
- def initialize(*args,color: :black)
22
- @x, @y = *args # x, y
23
- @color = color
24
- end
25
- end
26
- end
@@ -1,44 +0,0 @@
1
- module Straightedge
2
- class Rose
3
- attr_reader :directions
4
- def initialize(directions:{})
5
- @directions = directions
6
- end
7
-
8
- def project(point)
9
- @directions.values.collect do |delta|
10
- Ruler.translate(point, delta)
11
- end
12
- end
13
-
14
- class << self
15
- def simple
16
- return @simple_rose unless @simple_rose.nil?
17
- @simple_rose = new directions: {
18
- :north => [0, -1],
19
- :south => [0, 1],
20
- :east => [1, 0],
21
- :west => [-1, 0]
22
- }
23
- end
24
-
25
- def extended
26
- return @extended_rose unless @extended_rose.nil?
27
- simple_rose_axes = [[:east,:west],[:north, :south]]
28
- extended_directions = permute(simple, simple_rose_axes)
29
- all_directions = simple.directions.merge(extended_directions)
30
- @extended_rose = new directions: all_directions
31
- end
32
-
33
- def permute(rose, axes)
34
- combinations = axes.x.map do |x|
35
- axes.y.map do |y|
36
- ["#{y}#{x}".to_sym, Ruler.translate(rose.directions[x], rose.directions[y])]
37
- end
38
- end
39
-
40
- Hash[combinations.flatten(1)]
41
- end
42
- end
43
- end
44
- end