aurora-sketch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +7 -0
- data/README.markdown +86 -0
- data/Rakefile +28 -0
- data/aurora-sketch.gemspec +21 -0
- data/lib/geometry/dsl/polyline.rb +107 -0
- data/lib/geometry/dsl/turtle.rb +64 -0
- data/lib/sketch.rb +180 -0
- data/lib/sketch/builder.rb +100 -0
- data/lib/sketch/builder/path.rb +16 -0
- data/lib/sketch/builder/polygon.rb +15 -0
- data/lib/sketch/builder/polyline.rb +51 -0
- data/lib/sketch/dsl.rb +56 -0
- data/lib/sketch/group.rb +38 -0
- data/lib/sketch/layout.rb +118 -0
- data/lib/sketch/point.rb +7 -0
- data/test/geometry/dsl/polyline.rb +81 -0
- data/test/sketch.rb +189 -0
- data/test/sketch/builder.rb +167 -0
- data/test/sketch/builder/path.rb +13 -0
- data/test/sketch/builder/polygon.rb +12 -0
- data/test/sketch/builder/polyline.rb +12 -0
- data/test/sketch/dsl.rb +104 -0
- data/test/sketch/group.rb +23 -0
- data/test/sketch/layout.rb +167 -0
- data/test/sketch/point.rb +44 -0
- data/test/sketch/polygon.rb +42 -0
- metadata +96 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'sketch/group'
|
3
|
+
|
4
|
+
describe Sketch::Group do
|
5
|
+
describe "when constructed" do
|
6
|
+
describe "with no arguments" do
|
7
|
+
subject { Sketch::Group.new }
|
8
|
+
|
9
|
+
it "must have an identity transformation" do
|
10
|
+
subject.transformation.identity?.must_equal true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "must be empty" do
|
14
|
+
subject.elements.size.must_equal 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must accept valid Transformation arguments" do
|
19
|
+
group = Sketch::Group.new origin:[1,2,3]
|
20
|
+
group.transformation.translation.must_equal Point[1,2,3]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'sketch/layout'
|
3
|
+
|
4
|
+
describe Sketch::Layout do
|
5
|
+
Group = Sketch::Group
|
6
|
+
|
7
|
+
describe "when constructed" do
|
8
|
+
describe "with no arguments" do
|
9
|
+
subject { Sketch::Layout.new }
|
10
|
+
|
11
|
+
it "must have an identity transformation" do
|
12
|
+
subject.transformation.identity?.must_equal true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "must be empty" do
|
16
|
+
subject.elements.size.must_equal 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "with a transformation" do
|
21
|
+
subject { Sketch::Layout.new origin:[1,2] }
|
22
|
+
|
23
|
+
it "must set the transformation property" do
|
24
|
+
subject.transformation.must_equal Geometry::Transformation.new(origin:Point[1,2])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "when horizontal" do
|
30
|
+
subject { Sketch::Layout.new :horizontal }
|
31
|
+
|
32
|
+
it "must layout primitive objects" do
|
33
|
+
subject.push Geometry::Rectangle.new from:[0,0], to:[5,5]
|
34
|
+
subject.push Geometry::Rectangle.new from:[0,0], to:[6,6]
|
35
|
+
|
36
|
+
subject.first.must_be_kind_of Geometry::Rectangle
|
37
|
+
subject.last.must_be_kind_of Sketch::Group
|
38
|
+
|
39
|
+
subject.last.transformation.translation.must_equal Point[5,0]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "must layout groups" do
|
43
|
+
group = Group.new
|
44
|
+
group.push Geometry::Rectangle.new from:[0,0], to:[5,5]
|
45
|
+
subject.push group
|
46
|
+
|
47
|
+
group = Group.new
|
48
|
+
group.push Geometry::Rectangle.new from:[0,0], to:[6,6]
|
49
|
+
subject.push group
|
50
|
+
|
51
|
+
subject.elements.count.must_equal 2
|
52
|
+
|
53
|
+
subject.first.transformation.translation.must_be_nil
|
54
|
+
subject.last.transformation.translation.must_equal Point[5,0]
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "with spacing" do
|
58
|
+
subject { Sketch::Layout.new :horizontal, spacing:1 }
|
59
|
+
|
60
|
+
it "must add space between the elements" do
|
61
|
+
group = Group.new.push Geometry::Rectangle.new from:[0,0], to:[5,5]
|
62
|
+
subject.push group
|
63
|
+
|
64
|
+
group = Group.new.push Geometry::Rectangle.new from:[0,0], to:[6,6]
|
65
|
+
subject.push group
|
66
|
+
|
67
|
+
subject.first.transformation.translation.must_be_nil
|
68
|
+
subject.last.transformation.translation.must_equal Point[6,0]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "when bottom aligned" do
|
73
|
+
subject { Sketch::Layout.new :horizontal, align: :bottom }
|
74
|
+
|
75
|
+
it "must bottom align the elements" do
|
76
|
+
subject.push Group.new.push Geometry::Rectangle.new from:[0,-1], to:[5,5]
|
77
|
+
subject.push Group.new.push Geometry::Rectangle.new from:[0,-1], to:[6,6]
|
78
|
+
|
79
|
+
subject.first.transformation.translation.must_equal Point[0,1]
|
80
|
+
subject.last.transformation.translation.must_equal Point[5,1]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "when top aligned" do
|
85
|
+
subject { Sketch::Layout.new :horizontal, align: :top }
|
86
|
+
|
87
|
+
it "must top align the elements" do
|
88
|
+
subject.push Group.new.push Geometry::Rectangle.new from:[0,0], to:[5,5]
|
89
|
+
subject.push Group.new.push Geometry::Rectangle.new from:[0,0], to:[6,6]
|
90
|
+
|
91
|
+
subject.elements.count.must_equal 2
|
92
|
+
|
93
|
+
subject.first.transformation.translation.must_equal Point[0,1]
|
94
|
+
subject.last.transformation.translation.must_equal Point[5,0]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "when vertical" do
|
100
|
+
subject { Sketch::Layout.new :vertical }
|
101
|
+
|
102
|
+
it "must layout groups" do
|
103
|
+
group = Group.new
|
104
|
+
group.push Geometry::Rectangle.new from:[0,0], to:[5,5]
|
105
|
+
subject.push group
|
106
|
+
|
107
|
+
group = Group.new
|
108
|
+
group.push Geometry::Rectangle.new from:[0,0], to:[6,6]
|
109
|
+
subject.push group
|
110
|
+
|
111
|
+
subject.first.transformation.translation.must_be_nil
|
112
|
+
subject.last.transformation.translation.must_equal Point[0,5]
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "with spacing" do
|
116
|
+
subject { Sketch::Layout.new :vertical, spacing:1 }
|
117
|
+
|
118
|
+
it "must add space between the elements" do
|
119
|
+
group = Group.new.push Geometry::Rectangle.new from:[0,0], to:[5,5]
|
120
|
+
subject.push group
|
121
|
+
|
122
|
+
group = Group.new.push Geometry::Rectangle.new from:[0,0], to:[6,6]
|
123
|
+
subject.push group
|
124
|
+
|
125
|
+
subject.first.transformation.translation.must_be_nil
|
126
|
+
subject.last.transformation.translation.must_equal Point[0,6]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "when left aligned" do
|
131
|
+
subject { Sketch::Layout.new :vertical, align: :left }
|
132
|
+
|
133
|
+
it "must left align the elements" do
|
134
|
+
subject.push Group.new.push Geometry::Rectangle.new from:[-1,0], to:[5,5]
|
135
|
+
subject.push Group.new.push Geometry::Rectangle.new from:[-1,0], to:[6,6]
|
136
|
+
|
137
|
+
subject.first.transformation.translation.must_equal Point[1,0]
|
138
|
+
subject.last.transformation.translation.must_equal Point[1,5]
|
139
|
+
end
|
140
|
+
|
141
|
+
it "must left align primitive objects" do
|
142
|
+
subject.push Geometry::Rectangle.new from:[-1,-1], to:[5,5]
|
143
|
+
subject.push Geometry::Rectangle.new from:[0,0], to:[6,6]
|
144
|
+
|
145
|
+
subject.first.must_be_kind_of Sketch::Group
|
146
|
+
subject.last.must_be_kind_of Sketch::Group
|
147
|
+
|
148
|
+
subject.first.transformation.translation.must_equal Point[1,1]
|
149
|
+
subject.last.transformation.translation.must_equal Point[0,6]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "when right aligned" do
|
154
|
+
subject { Sketch::Layout.new :vertical, align: :right }
|
155
|
+
|
156
|
+
it "must right align the elements" do
|
157
|
+
subject.push Group.new.push Geometry::Rectangle.new from:[0,0], to:[5,5]
|
158
|
+
subject.push Group.new.push Geometry::Rectangle.new from:[0,0], to:[6,6]
|
159
|
+
|
160
|
+
subject.elements.count.must_equal 2
|
161
|
+
|
162
|
+
subject.first.transformation.translation.must_equal Point[1,0]
|
163
|
+
subject.last.transformation.translation.must_equal Point[0,5]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'sketch/point'
|
3
|
+
|
4
|
+
describe Sketch::Point do
|
5
|
+
it "create a Point object" do
|
6
|
+
point = Sketch::Point[2, 1]
|
7
|
+
assert_kind_of(Sketch::Point, point)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "create a Point object using list syntax" do
|
11
|
+
point = Sketch::Point[2,1]
|
12
|
+
assert_equal(2, point.size)
|
13
|
+
assert_equal(2, point.x)
|
14
|
+
assert_equal(1, point.y)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "create a Point object from an array" do
|
18
|
+
point = Sketch::Point[3,4]
|
19
|
+
assert_equal(2, point.size)
|
20
|
+
assert_equal(3, point.x)
|
21
|
+
assert_equal(4, point.y)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "create a Point object from a Vector" do
|
25
|
+
point = Sketch::Point[Vector[3,4]]
|
26
|
+
assert_equal(2, point.size)
|
27
|
+
assert_equal(3, point.x)
|
28
|
+
assert_equal(4, point.y)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "create a Point object from a Vector using list syntax" do
|
32
|
+
point = Sketch::Point[Vector[3,4]]
|
33
|
+
assert_equal(2, point.size)
|
34
|
+
assert_equal(3, point.x)
|
35
|
+
assert_equal(4, point.y)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "allow indexed element access" do
|
39
|
+
point = Sketch::Point[5,6]
|
40
|
+
assert_equal(2, point.size)
|
41
|
+
assert_equal(5, point[0])
|
42
|
+
assert_equal(6, point[1])
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'sketch'
|
3
|
+
|
4
|
+
describe Sketch do
|
5
|
+
let(:sketch) { Sketch.new }
|
6
|
+
|
7
|
+
it "should make a square polygon using turtle-like commands" do
|
8
|
+
skip
|
9
|
+
polygon = sketch.add_polygon do
|
10
|
+
start_at [0,0]
|
11
|
+
move_to [1,0]
|
12
|
+
turn_left 90
|
13
|
+
move 1
|
14
|
+
turn_left 90
|
15
|
+
forward 1
|
16
|
+
end
|
17
|
+
assert_kind_of(Sketch::Polygon, polygon)
|
18
|
+
assert_equal(1, sketch.elements.size)
|
19
|
+
assert_equal(4, polygon.vertices.size)
|
20
|
+
assert_equal(Point[0,0], polygon.vertices[0])
|
21
|
+
assert_equal(Point[1,0], polygon.vertices[1])
|
22
|
+
assert_equal(Point[1,1], polygon.vertices[2])
|
23
|
+
# assert_equal(Point[0,1], polygon.vertices[3])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should make another square polygon using turtle-like commands" do
|
27
|
+
skip
|
28
|
+
polygon = sketch.add_polygon do
|
29
|
+
start_at [0,0]
|
30
|
+
move [1,0]
|
31
|
+
move [0,1]
|
32
|
+
move [-1,0]
|
33
|
+
end
|
34
|
+
assert_kind_of(Sketch::Polygon, polygon)
|
35
|
+
assert_equal(1, sketch.elements.size)
|
36
|
+
assert_equal(4, polygon.vertices.size)
|
37
|
+
assert_equal(Point[0,0], polygon.vertices[0])
|
38
|
+
assert_equal(Point[1,0], polygon.vertices[1])
|
39
|
+
assert_equal(Point[1,1], polygon.vertices[2])
|
40
|
+
assert_equal(Point[0,1], polygon.vertices[3])
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aurora-sketch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brandon Fosdick
|
8
|
+
- Meseker Yohannes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: aurora-geometry
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.0.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.0.1
|
28
|
+
description: Sketches used in the creation of mechanical designs
|
29
|
+
email:
|
30
|
+
- bfoz@bfoz.net
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- README.markdown
|
38
|
+
- Rakefile
|
39
|
+
- aurora-sketch.gemspec
|
40
|
+
- lib/geometry/dsl/polyline.rb
|
41
|
+
- lib/geometry/dsl/turtle.rb
|
42
|
+
- lib/sketch.rb
|
43
|
+
- lib/sketch/builder.rb
|
44
|
+
- lib/sketch/builder/path.rb
|
45
|
+
- lib/sketch/builder/polygon.rb
|
46
|
+
- lib/sketch/builder/polyline.rb
|
47
|
+
- lib/sketch/dsl.rb
|
48
|
+
- lib/sketch/group.rb
|
49
|
+
- lib/sketch/layout.rb
|
50
|
+
- lib/sketch/point.rb
|
51
|
+
- test/geometry/dsl/polyline.rb
|
52
|
+
- test/sketch.rb
|
53
|
+
- test/sketch/builder.rb
|
54
|
+
- test/sketch/builder/path.rb
|
55
|
+
- test/sketch/builder/polygon.rb
|
56
|
+
- test/sketch/builder/polyline.rb
|
57
|
+
- test/sketch/dsl.rb
|
58
|
+
- test/sketch/group.rb
|
59
|
+
- test/sketch/layout.rb
|
60
|
+
- test/sketch/point.rb
|
61
|
+
- test/sketch/polygon.rb
|
62
|
+
homepage: http://github.com/bfoz/sketch
|
63
|
+
licenses: []
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project: sketch
|
81
|
+
rubygems_version: 2.0.3
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: 2D mechanical sketches
|
85
|
+
test_files:
|
86
|
+
- test/geometry/dsl/polyline.rb
|
87
|
+
- test/sketch.rb
|
88
|
+
- test/sketch/builder.rb
|
89
|
+
- test/sketch/builder/path.rb
|
90
|
+
- test/sketch/builder/polygon.rb
|
91
|
+
- test/sketch/builder/polyline.rb
|
92
|
+
- test/sketch/dsl.rb
|
93
|
+
- test/sketch/group.rb
|
94
|
+
- test/sketch/layout.rb
|
95
|
+
- test/sketch/point.rb
|
96
|
+
- test/sketch/polygon.rb
|