sketch-in-ruby 0.0.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.
@@ -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,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sketch-in-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Fosdick
9
+ - Meseker Yohannes
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-03-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: geometry-in-ruby
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ description: Sketches used in the creation of mechanical designs
32
+ email:
33
+ - meseker.yohannes@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - README.markdown
41
+ - Rakefile
42
+ - lib/geometry/dsl/polyline.rb
43
+ - lib/geometry/dsl/turtle.rb
44
+ - lib/sketch.rb
45
+ - lib/sketch/builder.rb
46
+ - lib/sketch/builder/path.rb
47
+ - lib/sketch/builder/polygon.rb
48
+ - lib/sketch/builder/polyline.rb
49
+ - lib/sketch/dsl.rb
50
+ - lib/sketch/group.rb
51
+ - lib/sketch/layout.rb
52
+ - lib/sketch/point.rb
53
+ - sketch-in-ruby.gemspec
54
+ - test/geometry/dsl/polyline.rb
55
+ - test/sketch.rb
56
+ - test/sketch/builder.rb
57
+ - test/sketch/builder/path.rb
58
+ - test/sketch/builder/polygon.rb
59
+ - test/sketch/builder/polyline.rb
60
+ - test/sketch/dsl.rb
61
+ - test/sketch/group.rb
62
+ - test/sketch/layout.rb
63
+ - test/sketch/point.rb
64
+ - test/sketch/polygon.rb
65
+ homepage: http://github.com/meseker/sketch
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project: sketch
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: 2D mechanical sketches
89
+ test_files:
90
+ - test/geometry/dsl/polyline.rb
91
+ - test/sketch.rb
92
+ - test/sketch/builder.rb
93
+ - test/sketch/builder/path.rb
94
+ - test/sketch/builder/polygon.rb
95
+ - test/sketch/builder/polyline.rb
96
+ - test/sketch/dsl.rb
97
+ - test/sketch/group.rb
98
+ - test/sketch/layout.rb
99
+ - test/sketch/point.rb
100
+ - test/sketch/polygon.rb