straightedge 0.1.0
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 +7 -0
- data/.document +3 -0
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +4 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +20 -0
- data/README.md +31 -0
- data/Rakefile +40 -0
- data/bin/straightedge +14 -0
- data/features/.gitkeep +0 -0
- data/features/step_definitions/.gitkeep +0 -0
- data/features/step_definitions/straightedge_steps.rb +1 -0
- data/features/straightedge.feature +1 -0
- data/gemspec.yml +14 -0
- data/lib/straightedge/adapters.rb +0 -0
- data/lib/straightedge/compass.rb +17 -0
- data/lib/straightedge/extend/array.rb +23 -0
- data/lib/straightedge/figure.rb +28 -0
- data/lib/straightedge/grid.rb +34 -0
- data/lib/straightedge/line.rb +21 -0
- data/lib/straightedge/mark.rb +26 -0
- data/lib/straightedge/rose.rb +44 -0
- data/lib/straightedge/ruler.rb +21 -0
- data/lib/straightedge/version.rb +4 -0
- data/lib/straightedge.rb +17 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/straightedge/compass_spec.rb +30 -0
- data/spec/straightedge/extend/array_spec.rb +45 -0
- data/spec/straightedge/figure_spec.rb +16 -0
- data/spec/straightedge/grid_spec.rb +33 -0
- data/spec/straightedge/rose_spec.rb +28 -0
- data/spec/straightedge/ruler_spec.rb +11 -0
- data/spec/straightedge_spec.rb +8 -0
- data/straightedge.gemspec +60 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a4391ab9503098a88e8fcdc920ac529b241afe5
|
4
|
+
data.tar.gz: 5dcff1efdb2e6a442648b381aa124640c72de1f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c5a50dc8f32b28f4a07659b29c4a73a6731230bedf5f99b38b93b4d98961ae2602b8d962d195b307ca4d50d35e770be94a58a19ff999fd0706fe53296235ae7
|
7
|
+
data.tar.gz: 33cceb0569dd5753bc4fd886839f180be98aac6ab87b281053b1626fe0dc0e1177c0f4a69d5a955643398894e7e09180d8990e297251dfa77aeef649b02d49c1
|
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create @straightedge
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title "straightedge Documentation" --protected
|
data/ChangeLog.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Joseph Weissman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# straightedge
|
2
|
+
|
3
|
+
* [Homepage](https://rubygems.org/gems/straightedge)
|
4
|
+
* [Documentation](http://rubydoc.info/gems/straightedge/frames)
|
5
|
+
* [Email](mailto:jweissman1986 at gmail.com)
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
One idea is for this to house the reusable geometry logic in Ruby
|
10
|
+
|
11
|
+
## Features
|
12
|
+
|
13
|
+
## Examples
|
14
|
+
|
15
|
+
require 'straightedge'
|
16
|
+
|
17
|
+
## Requirements
|
18
|
+
|
19
|
+
## Install
|
20
|
+
|
21
|
+
$ gem install straightedge
|
22
|
+
|
23
|
+
## Synopsis
|
24
|
+
|
25
|
+
$ straightedge
|
26
|
+
|
27
|
+
## Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2014 Joseph Weissman
|
30
|
+
|
31
|
+
See {file:LICENSE.txt} for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler'
|
7
|
+
rescue LoadError => e
|
8
|
+
warn e.message
|
9
|
+
warn "Run `gem install bundler` to install Bundler."
|
10
|
+
exit -1
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
Bundler.setup(:development)
|
15
|
+
rescue Bundler::BundlerError => e
|
16
|
+
warn e.message
|
17
|
+
warn "Run `bundle install` to install missing gems."
|
18
|
+
exit e.status_code
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake'
|
22
|
+
|
23
|
+
require 'rubygems/tasks'
|
24
|
+
Gem::Tasks.new
|
25
|
+
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
RSpec::Core::RakeTask.new
|
28
|
+
|
29
|
+
task :test => :spec
|
30
|
+
task :default => :spec
|
31
|
+
|
32
|
+
require 'yard'
|
33
|
+
YARD::Rake::YardocTask.new
|
34
|
+
task :doc => :yard
|
35
|
+
|
36
|
+
require 'cucumber/rake/task'
|
37
|
+
|
38
|
+
Cucumber::Rake::Task.new do |t|
|
39
|
+
t.cucumber_opts = %w[--format pretty]
|
40
|
+
end
|
data/bin/straightedge
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
root = File.expand_path(File.join(File.dirname(__FILE__),'..'))
|
4
|
+
if File.directory?(File.join(root,'.git'))
|
5
|
+
Dir.chdir(root) do
|
6
|
+
begin
|
7
|
+
require 'bundler/setup'
|
8
|
+
rescue LoadError => e
|
9
|
+
warn e.message
|
10
|
+
warn "Run `gem install bundler` to install Bundler"
|
11
|
+
exit -1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/features/.gitkeep
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
@wip
|
@@ -0,0 +1 @@
|
|
1
|
+
Feature: Blah blah blah
|
data/gemspec.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
name: straightedge
|
2
|
+
summary: geometry concepts for ruby
|
3
|
+
description: give me a compass and straightedge and i will conquer the world
|
4
|
+
license: MIT
|
5
|
+
authors: Joseph Weissman
|
6
|
+
email: jweissman1986@gmail.com
|
7
|
+
homepage: https://rubygems.org/gems/straightedge
|
8
|
+
|
9
|
+
development_dependencies:
|
10
|
+
bundler: ~> 1.0
|
11
|
+
rake: ~> 0.8
|
12
|
+
rspec: ~> 2.4
|
13
|
+
rubygems-tasks: ~> 0.2
|
14
|
+
yard: ~> 0.8
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Array
|
2
|
+
extend Forwardable
|
3
|
+
|
4
|
+
def sum
|
5
|
+
inject(&:+)
|
6
|
+
end
|
7
|
+
|
8
|
+
def mean
|
9
|
+
sum / size
|
10
|
+
end
|
11
|
+
|
12
|
+
# consider the array as a vector in n-space (where n is the self.length)
|
13
|
+
def to_point
|
14
|
+
Straightedge::Mark.new(*self)
|
15
|
+
end
|
16
|
+
def_delegators :to_point, :x, :y
|
17
|
+
|
18
|
+
# consider the array as an array of points
|
19
|
+
def to_points
|
20
|
+
Straightedge::Figure.new(self)
|
21
|
+
end
|
22
|
+
def_delegators :to_points, :adjacent, :center
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -0,0 +1,34 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,44 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Straightedge
|
2
|
+
class Ruler
|
3
|
+
def initialize(unit=1)
|
4
|
+
@unit = unit
|
5
|
+
end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def default; @default ||= new end
|
9
|
+
|
10
|
+
def translate(xy, dxy)
|
11
|
+
xy.zip(dxy).map { |x,y| x+y }
|
12
|
+
end
|
13
|
+
|
14
|
+
def distance(alpha,beta)
|
15
|
+
Line.new(alpha,beta).length
|
16
|
+
#dx, dy = alpha.x - beta.x, alpha.y - beta.y
|
17
|
+
#Math.sqrt(dx*dx + dy*dy)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/straightedge.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'straightedge/version'
|
2
|
+
|
3
|
+
require 'straightedge/compass'
|
4
|
+
require 'straightedge/rose'
|
5
|
+
require 'straightedge/ruler'
|
6
|
+
|
7
|
+
require 'straightedge/mark'
|
8
|
+
require 'straightedge/line'
|
9
|
+
require 'straightedge/figure'
|
10
|
+
|
11
|
+
# really a grid should be a tiling figure...!
|
12
|
+
require 'straightedge/grid'
|
13
|
+
|
14
|
+
require 'straightedge/extend/array'
|
15
|
+
|
16
|
+
module Straightedge
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'straightedge/extend/array'
|
3
|
+
require 'straightedge/mark'
|
4
|
+
require 'straightedge/rose'
|
5
|
+
require 'straightedge/compass'
|
6
|
+
|
7
|
+
describe Compass do
|
8
|
+
let(:origin) { [0,0] }
|
9
|
+
|
10
|
+
context "roses" do
|
11
|
+
it 'should construct a simple rose' do
|
12
|
+
%i[ north south east west ].each do |d|
|
13
|
+
expect(Rose.simple.directions.keys).to include(d)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should construct an extended rose' do
|
18
|
+
expect(Rose.extended.directions).to eql({
|
19
|
+
:east => [1, 0],
|
20
|
+
:north => [0, -1],
|
21
|
+
:northeast => [1, -1],
|
22
|
+
:northwest => [-1, -1],
|
23
|
+
:south => [0, 1],
|
24
|
+
:southeast => [1, 1],
|
25
|
+
:southwest => [-1, 1],
|
26
|
+
:west => [-1, 0]
|
27
|
+
})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'straightedge/mark'
|
3
|
+
require 'straightedge/figure'
|
4
|
+
require 'straightedge/compass'
|
5
|
+
require 'straightedge/rose'
|
6
|
+
require 'straightedge/extend/array'
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
describe Array do
|
10
|
+
describe ".to_point" do
|
11
|
+
subject do
|
12
|
+
[1,2]
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'should decode straightforwardly as a geometric coordinate' do
|
16
|
+
it 'should have an x-coordinate' do
|
17
|
+
expect(subject.x).to eql(1)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have a y-coordinate' do
|
21
|
+
expect(subject.y).to eql(2)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".to_points" do
|
27
|
+
subject do
|
28
|
+
[[1,2],[3,2]]
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'should decode as a set of points' do
|
32
|
+
it 'should have a center' do
|
33
|
+
expect(subject.center).to eql([2,2])
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:expected_adjacent) do
|
37
|
+
[[1, 1], [1, 3], [2, 2], [0, 2], [2, 1], [2, 3], [0, 1], [0, 3], [3, 1], [3, 3], [4, 2], [4, 1], [4, 3]]
|
38
|
+
end
|
39
|
+
it 'should have adjacent coordinates' do
|
40
|
+
expect(subject.adjacent).to eql(expected_adjacent)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,16 @@
|
|
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
|
+
|
8
|
+
describe Straightedge::Figure do
|
9
|
+
it 'should compute adjacent positions' do
|
10
|
+
expect([[0,0]].adjacent).to eql([[0, -1], [0, 1], [1, 0], [-1, 0], [1, -1], [1, 1], [-1, -1], [-1, 1]]) #[0,1])
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should compute centroid' do
|
14
|
+
expect([[0,0],[2,2]].center).to eql([1,1])
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'straightedge/extend/array'
|
4
|
+
require 'straightedge/mark'
|
5
|
+
require 'straightedge/rose'
|
6
|
+
|
7
|
+
require 'straightedge/compass'
|
8
|
+
require 'straightedge/figure'
|
9
|
+
require 'straightedge/grid'
|
10
|
+
|
11
|
+
describe Straightedge::Grid do
|
12
|
+
it "should have width and height" do
|
13
|
+
expect(subject.width).to eql(Straightedge::Grid::DEFAULT_SIZE)
|
14
|
+
expect(subject.height).to eql(Straightedge::Grid::DEFAULT_SIZE)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should express this geometry as an array called dimensions' do
|
18
|
+
expect(subject.lines).to eql([subject.width, subject.height])
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".elements" do
|
22
|
+
subject { Straightedge::Grid.new([2,2]) }
|
23
|
+
|
24
|
+
it 'should iterate over the grid' do
|
25
|
+
expect(subject.marks).to eql([[0, 0], [0, 1], [1, 0], [1, 1]])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#first" do
|
30
|
+
subject { Straightedge::Grid.new }
|
31
|
+
its(:first) { should eql([0,0]) }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
describe Straightedge::Rose do
|
8
|
+
context "roses" do
|
9
|
+
it 'should construct a simple rose' do
|
10
|
+
%i[ north south east west ].each do |d|
|
11
|
+
expect(Rose.simple.directions.keys).to include(d)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should construct an extended rose' do
|
16
|
+
expect(Rose.extended.directions).to eql({
|
17
|
+
:east => [1, 0],
|
18
|
+
:north => [0, -1],
|
19
|
+
:northeast => [1, -1],
|
20
|
+
:northwest => [-1, -1],
|
21
|
+
:south => [0, 1],
|
22
|
+
:southeast => [1, 1],
|
23
|
+
:southwest => [-1, 1],
|
24
|
+
:west => [-1, 0]
|
25
|
+
})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'straightedge/extend/array'
|
3
|
+
require 'straightedge/ruler'
|
4
|
+
|
5
|
+
describe Straightedge::Ruler do
|
6
|
+
let(:a) { [0,3] }
|
7
|
+
let(:b) { [4,0] }
|
8
|
+
it 'should measure distance' do
|
9
|
+
expect(Straightedge::Ruler.distance(a,b)).to eql(5.0)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
7
|
+
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
12
|
+
|
13
|
+
require 'straightedge/version'
|
14
|
+
Straightedge::VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
23
|
+
|
24
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
25
|
+
|
26
|
+
gem.files = `git ls-files`.split($/)
|
27
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
28
|
+
|
29
|
+
gem.executables = gemspec.fetch('executables') do
|
30
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
31
|
+
end
|
32
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
33
|
+
|
34
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
35
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
36
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
37
|
+
|
38
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
39
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
40
|
+
})
|
41
|
+
|
42
|
+
gem.requirements = gemspec['requirements']
|
43
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
44
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
45
|
+
gem.post_install_message = gemspec['post_install_message']
|
46
|
+
|
47
|
+
split = lambda { |string| string.split(/,\s*/) }
|
48
|
+
|
49
|
+
if gemspec['dependencies']
|
50
|
+
gemspec['dependencies'].each do |name,versions|
|
51
|
+
gem.add_dependency(name,split[versions])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if gemspec['development_dependencies']
|
56
|
+
gemspec['development_dependencies'].each do |name,versions|
|
57
|
+
gem.add_development_dependency(name,split[versions])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: straightedge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joseph Weissman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubygems-tasks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
description: give me a compass and straightedge and i will conquer the world
|
84
|
+
email: jweissman1986@gmail.com
|
85
|
+
executables:
|
86
|
+
- straightedge
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files:
|
89
|
+
- ChangeLog.md
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.md
|
92
|
+
files:
|
93
|
+
- ".document"
|
94
|
+
- ".gitignore"
|
95
|
+
- ".rspec"
|
96
|
+
- ".rvmrc"
|
97
|
+
- ".yardopts"
|
98
|
+
- ChangeLog.md
|
99
|
+
- Gemfile
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
- Rakefile
|
103
|
+
- bin/straightedge
|
104
|
+
- features/.gitkeep
|
105
|
+
- features/step_definitions/.gitkeep
|
106
|
+
- features/step_definitions/straightedge_steps.rb
|
107
|
+
- features/straightedge.feature
|
108
|
+
- gemspec.yml
|
109
|
+
- lib/straightedge.rb
|
110
|
+
- lib/straightedge/adapters.rb
|
111
|
+
- lib/straightedge/compass.rb
|
112
|
+
- 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
|
119
|
+
- lib/straightedge/version.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/straightedge/compass_spec.rb
|
122
|
+
- 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
|
127
|
+
- spec/straightedge_spec.rb
|
128
|
+
- straightedge.gemspec
|
129
|
+
homepage: https://rubygems.org/gems/straightedge
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.3
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: geometry concepts for ruby
|
153
|
+
test_files: []
|