straightedge 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +7 -0
- data/README.md +44 -2
- data/gemspec.yml +3 -0
- data/lib/straightedge.rb +33 -11
- data/lib/straightedge/aspects.rb +3 -0
- data/lib/straightedge/aspects/colorable.rb +8 -0
- data/lib/straightedge/aspects/figural.rb +12 -0
- data/lib/straightedge/aspects/positional.rb +10 -0
- data/lib/straightedge/colors.rb +72 -0
- data/lib/straightedge/config.rb +6 -0
- data/lib/straightedge/director.rb +39 -0
- data/lib/straightedge/extend/array.rb +2 -13
- data/lib/straightedge/figures.rb +8 -0
- data/lib/straightedge/{adapters.rb → figures/circle.rb} +0 -0
- data/lib/straightedge/figures/figure.rb +44 -0
- data/lib/straightedge/figures/grid.rb +65 -0
- data/lib/straightedge/figures/grid_cell.rb +0 -0
- data/lib/straightedge/figures/hexagon.rb +33 -0
- data/lib/straightedge/figures/label.rb +13 -0
- data/lib/straightedge/figures/line.rb +25 -0
- data/lib/straightedge/figures/mark.rb +23 -0
- data/lib/straightedge/figures/quadrilateral.rb +20 -0
- data/lib/straightedge/motor/adapter.rb +54 -0
- data/lib/straightedge/motor/engine.rb +16 -0
- data/lib/straightedge/origin.rb +3 -0
- data/lib/straightedge/presenter.rb +29 -0
- data/lib/straightedge/scene.rb +20 -0
- data/lib/straightedge/surface.rb +21 -0
- data/lib/straightedge/toolkit/compass.rb +19 -0
- data/lib/straightedge/toolkit/rose.rb +60 -0
- data/lib/straightedge/toolkit/ruler.rb +23 -0
- data/lib/straightedge/tools.rb +3 -0
- data/lib/straightedge/version.rb +1 -1
- data/spec/spec_helper.rb +4 -1
- data/spec/straightedge/adapter_spec.rb +14 -0
- data/spec/straightedge/director_spec.rb +10 -0
- data/spec/straightedge/extend/array_spec.rb +1 -6
- data/spec/straightedge/{figure_spec.rb → figures/figure_spec.rb} +0 -5
- data/spec/straightedge/figures/grid_spec.rb +31 -0
- data/spec/straightedge/figures/hexagon_spec.rb +7 -0
- data/spec/straightedge/motor/engine_spec.rb +11 -0
- data/spec/straightedge/scene_spec.rb +27 -0
- data/spec/straightedge/{compass_spec.rb → toolkit/compass_spec.rb} +0 -4
- data/spec/straightedge/{rose_spec.rb → toolkit/rose_spec.rb} +0 -5
- data/spec/straightedge/toolkit/ruler_spec.rb +14 -0
- data/spec/straightedge_spec.rb +35 -0
- metadata +54 -16
- data/.rvmrc +0 -1
- data/lib/straightedge/compass.rb +0 -17
- data/lib/straightedge/figure.rb +0 -28
- data/lib/straightedge/grid.rb +0 -34
- data/lib/straightedge/line.rb +0 -21
- data/lib/straightedge/mark.rb +0 -26
- data/lib/straightedge/rose.rb +0 -44
- data/lib/straightedge/ruler.rb +0 -21
- data/spec/straightedge/grid_spec.rb +0 -33
- 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,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
|
data/spec/straightedge_spec.rb
CHANGED
@@ -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.
|
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-
|
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
|
-
- ".
|
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/
|
111
|
-
- lib/straightedge/
|
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/
|
114
|
-
- lib/straightedge/
|
115
|
-
- lib/straightedge/
|
116
|
-
- lib/straightedge/
|
117
|
-
- lib/straightedge/
|
118
|
-
- lib/straightedge/
|
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/
|
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/
|
126
|
-
- spec/straightedge/
|
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
|
data/lib/straightedge/compass.rb
DELETED
@@ -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
|
data/lib/straightedge/figure.rb
DELETED
@@ -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
|
data/lib/straightedge/grid.rb
DELETED
@@ -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
|
data/lib/straightedge/line.rb
DELETED
@@ -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
|
data/lib/straightedge/mark.rb
DELETED
@@ -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
|
data/lib/straightedge/rose.rb
DELETED
@@ -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
|