triangular 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/build.yml +30 -0
  3. data/.gitignore +3 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +31 -0
  6. data/Gemfile +3 -1
  7. data/Gemfile.lock +51 -12
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +98 -0
  10. data/examples/slice_example.rb +6 -4
  11. data/lib/triangular/facet.rb +32 -42
  12. data/lib/triangular/line.rb +42 -16
  13. data/lib/triangular/point.rb +15 -15
  14. data/lib/triangular/polyline.rb +13 -12
  15. data/lib/triangular/ray.rb +41 -0
  16. data/lib/triangular/solid.rb +34 -36
  17. data/lib/triangular/units.rb +18 -14
  18. data/lib/triangular/vector.rb +8 -1
  19. data/lib/triangular/version.rb +3 -1
  20. data/lib/triangular/vertex.rb +17 -16
  21. data/lib/triangular.rb +4 -1
  22. data/spec/benchmark/benchmark_spec.rb +23 -0
  23. data/spec/profile/profile_spec.rb +20 -0
  24. data/spec/spec_helper.rb +17 -3
  25. data/spec/triangular/facet_spec.rb +235 -0
  26. data/spec/triangular/line_spec.rb +285 -0
  27. data/spec/triangular/point_spec.rb +108 -0
  28. data/spec/triangular/polyline_spec.rb +22 -0
  29. data/spec/triangular/ray_spec.rb +63 -0
  30. data/spec/{solid_spec.rb → triangular/solid_spec.rb} +71 -70
  31. data/spec/triangular/triangular_spec.rb +24 -0
  32. data/spec/triangular/units_spec.rb +77 -0
  33. data/spec/triangular/vector_spec.rb +23 -0
  34. data/spec/triangular/vertex_spec.rb +46 -0
  35. data/triangular.gemspec +22 -18
  36. metadata +114 -65
  37. data/README.rdoc +0 -64
  38. data/Rakefile +0 -11
  39. data/spec/facet_spec.rb +0 -233
  40. data/spec/line_spec.rb +0 -108
  41. data/spec/point_spec.rb +0 -88
  42. data/spec/polyline_spec.rb +0 -20
  43. data/spec/triangular_spec.rb +0 -22
  44. data/spec/units_spec.rb +0 -75
  45. data/spec/vertex_spec.rb +0 -44
data/README.rdoc DELETED
@@ -1,64 +0,0 @@
1
- = Triangular
2
-
3
- Triangular is an easy-to-use Ruby library for reading, writing and manipulating Stereolithography (STL) files.
4
-
5
- The main purpose of Triangular is to enable its users to quickly create new software for Rapid Prototyping and Personal Manufacturing applications. Triangular has many of the core functions needed in order to generate toolpaths for 3D printers and CNC Mills/Routers.
6
-
7
- Please note that Triangular requires Ruby 1.9+. Triangular is currently in the Alpha stage of development which means that the API can and will change, and that new features will be added often!
8
-
9
- === A Quick Example
10
-
11
- require "rubygems"
12
- require "triangular"
13
-
14
- # Open and parse an STL file
15
- solid = Triangular.parse_file("test.stl")
16
-
17
- # Set the units of measurement for the resulting solid to inches
18
- solid.units = :inches
19
-
20
- # Move the solid so that all of it's coordinates are in positive space (ie: greater than 0)
21
- solid.align_to_origin!
22
-
23
- # Get the bounding box of the solid
24
- bounds = solid.get_bounds
25
-
26
- # Create a section plane ('slice') through the solid on the XY plane at a Z height of 0.7
27
- slice = solid.slice_at_z(0.7)
28
-
29
- # Open a file for SVG output
30
- File.open("slice.svg", "w+") do |file|
31
-
32
- # Output the slice as an SVG document (correctly scaled according to the solid's units)
33
- file.puts slice.to_svg(bounds[1].x, bounds[1].y, solid.units)
34
- end
35
-
36
- === Installation
37
-
38
- For ease of use the Triangular is packaged as a RubyGem. Providing you already have Ruby and RubyGems installing Triangular is as easy as entering the following command in a terminal:
39
-
40
- gem install triangular
41
-
42
- === Performance
43
-
44
- At the moment Triangular has not been optimized at all. The parser is a relatively naive one that was designed to be easy to read rather than performant. Once the feature-set of Triangular has stabilized I will be doing a pass over it in order to make it fast enough for production use. Right now it could definitely be improved.
45
-
46
- For example here is some information about run-times when processing a 51Mb STL file:
47
-
48
- solid = Triangular.parse("big_file.stl")
49
- # 65 seconds
50
-
51
- solid.align_to_origin!
52
- # 8 seconds
53
-
54
- solid.slice_at_z(1.0)
55
- # 2 seconds
56
-
57
- === Author & Credits
58
-
59
- Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
60
-
61
- Special thanks go out to {Alkas Baybas}[https://github.com/abaybas] for lending me his massive brain!
62
-
63
- Copyright (c) 2011 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
64
-
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rspec/core/rake_task'
5
-
6
- desc "Run the specs for Triangular"
7
- RSpec::Core::RakeTask.new do |t|
8
- t.rspec_opts = "-c"
9
- t.fail_on_error = false
10
- t.verbose = false
11
- end
data/spec/facet_spec.rb DELETED
@@ -1,233 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Facet do
4
- describe ".parse" do
5
- context "with a correctly formatted facet" do
6
- before do
7
- @result = Facet.parse(<<-EOD)
8
- facet normal 0.0 0.0 -1.0
9
- outer loop
10
- vertex 16.5 0.0 -0.75
11
- vertex 0.0 -9.5 -0.75
12
- vertex 0.0 0.0 -0.75
13
- endloop
14
- endfacet
15
- EOD
16
- end
17
-
18
- it "should return a facet object" do
19
- @result.should be_a Facet
20
- end
21
-
22
- it "should return a facet with 3 vertices" do
23
- @result.vertices.length.should == 3
24
- end
25
-
26
- it "should return a facet with vertices of type Vertex" do
27
- @result.vertices.each do |vertex|
28
- vertex.should be_a Vertex
29
- end
30
- end
31
-
32
- it "should return a facet with a normal of type Vector" do
33
- @result.normal.should be_a Vector
34
- end
35
-
36
- it "should correctly set the normal values" do
37
- @result.normal.x.should == 0
38
- @result.normal.y.should == 0
39
- @result.normal.z.should == -1
40
- end
41
-
42
- it "should correctly set the values for the first vertex" do
43
- @result.vertices[0].x.should == 16.5
44
- @result.vertices[0].y.should == 0
45
- @result.vertices[0].z.should == -0.75
46
- end
47
-
48
- it "should correctly set the values for the second vertex" do
49
- @result.vertices[1].x.should == 0
50
- @result.vertices[1].y.should == -9.5
51
- @result.vertices[1].z.should == -0.75
52
- end
53
-
54
- it "should correctly set the values for the third vertex" do
55
- @result.vertices[2].x.should == 0
56
- @result.vertices[2].y.should == 0
57
- @result.vertices[2].z.should == -0.75
58
- end
59
- end
60
-
61
- context "when passed multiple facets" do
62
- before do
63
- @result = Facet.parse(<<-EOD)
64
- facet normal 0.0 0.0 -1.0
65
- outer loop
66
- vertex 16.5 0.0 -0.75
67
- vertex 0.0 -9.5 -0.75
68
- vertex 0.0 0.0 -0.75
69
- endloop
70
- endfacet
71
- facet normal 0.0 0.0 -1.0
72
- outer loop
73
- vertex 16.5 0.0 -0.75
74
- vertex 0.0 -9.5 -0.75
75
- vertex 0.0 0.0 -0.75
76
- endloop
77
- endfacet
78
- EOD
79
- end
80
-
81
- it "should return multiple facet objects" do
82
- @result.should be_a Array
83
- @result.each do |item|
84
- item.should be_a Facet
85
- end
86
- end
87
- end
88
- end
89
-
90
- describe "#to_s" do
91
- it "should return the string representation for a facet" do
92
- facet = Facet.new
93
- facet.normal = Vector.new(0, 0, 1)
94
- facet.vertices << Point.new(1, 2, 3)
95
- facet.vertices << Point.new(1, 2, 3)
96
- facet.vertices << Point.new(1, 2, 3)
97
-
98
- expected_string = "facet normal 0.0 0.0 1.0\n"
99
- expected_string += "outer loop\n"
100
- expected_string += facet.vertices[0].to_s + "\n"
101
- expected_string += facet.vertices[1].to_s + "\n"
102
- expected_string += facet.vertices[2].to_s + "\n"
103
- expected_string += "endloop\n"
104
- expected_string += "endfacet\n"
105
-
106
- facet.to_s.should == expected_string
107
- end
108
- end
109
-
110
- describe "#intersection_at_z" do
111
- context "for a facet that intersects the target Z plane" do
112
- before do
113
- vertex1 = Vertex.new(0.0, 0.0, 0.0)
114
- vertex2 = Vertex.new(0.0, 0.0, 6.0)
115
- vertex3 = Vertex.new(6.0, 0.0, 6.0)
116
-
117
- @facet = Facet.new(nil, vertex1, vertex2, vertex3)
118
- end
119
-
120
- context "when the target Z plane is 3.0" do
121
- it "should return a line object" do
122
- @facet.intersection_at_z(3.0).should be_a Line
123
- end
124
-
125
- it "should return a line with the correct start value" do
126
- @facet.intersection_at_z(3.0).start.x.should == 0.0
127
- @facet.intersection_at_z(3.0).start.y.should == 0.0
128
- @facet.intersection_at_z(3.0).start.z.should == 3.0
129
- end
130
-
131
- it "should return a line with the correct end value" do
132
- @facet.intersection_at_z(3.0).end.x.should == 3.0
133
- @facet.intersection_at_z(3.0).end.y.should == 0.0
134
- @facet.intersection_at_z(3.0).end.z.should == 3.0
135
- end
136
- end
137
-
138
- context "when the target Z plane is 6.0" do
139
- it "should return a line object" do
140
- @facet.intersection_at_z(6.0).should be_a Line
141
- end
142
-
143
- it "should return a line with the correct start value" do
144
- @facet.intersection_at_z(6.0).start.x.should == 0.0
145
- @facet.intersection_at_z(6.0).start.y.should == 0.0
146
- @facet.intersection_at_z(6.0).start.z.should == 6.0
147
- end
148
-
149
- it "should return a line with the correct end value" do
150
- @facet.intersection_at_z(6.0).end.x.should == 6.0
151
- @facet.intersection_at_z(6.0).end.y.should == 0.0
152
- @facet.intersection_at_z(6.0).end.z.should == 6.0
153
- end
154
- end
155
- end
156
-
157
- context "with vertices in both positive and negative space" do
158
- before do
159
- @facet = Facet.parse(<<-EOD)
160
- facet normal -0.0 1.0 -0.0
161
- outer loop
162
- vertex -1.0 1.0 1.0
163
- vertex 1.0 1.0 -1.0
164
- vertex -1.0 1.0 -1.0
165
- endloop
166
- endfacet
167
- EOD
168
- end
169
-
170
- it "should return a line with the correct start value" do
171
- @facet.intersection_at_z(0.0).start.x.should == 0.0
172
- @facet.intersection_at_z(0.0).start.y.should == 1.0
173
- @facet.intersection_at_z(0.0).start.z.should == 0.0
174
- end
175
-
176
- it "should return a line with the correct end value" do
177
- @facet.intersection_at_z(0.0).end.x.should == -1.0
178
- @facet.intersection_at_z(0.0).end.y.should == 1.0
179
- @facet.intersection_at_z(0.0).end.z.should == 0.0
180
- end
181
- end
182
-
183
- context "for a facet that lies on the target Z plane" do
184
- before do
185
- vertex1 = Vertex.new(0.0, 0.0, 1.0)
186
- vertex2 = Vertex.new(2.0, 0.0, 1.0)
187
- vertex3 = Vertex.new(2.0, 2.0, 1.0)
188
-
189
- @facet = Facet.new(nil, vertex1, vertex2, vertex3)
190
- end
191
-
192
- it "should return nil" do
193
- @facet.intersection_at_z(1.0).should == nil
194
- end
195
- end
196
-
197
- context "for a facet that does not intersect the target Z plane" do
198
- before do
199
- vertex1 = Vertex.new(0.0, 0.0, 0.0)
200
- vertex2 = Vertex.new(2.0, 0.0, 0.0)
201
- vertex3 = Vertex.new(2.0, 2.0, 0.0)
202
-
203
- @facet = Facet.new(nil, vertex1, vertex2, vertex3)
204
- end
205
-
206
- it "should return nil" do
207
- @facet.intersection_at_z(1.0).should == nil
208
- end
209
- end
210
- end
211
-
212
- describe "#translate!" do
213
- before do
214
- @facet = Facet.parse(<<-EOD)
215
- facet normal 0.0 0.0 -1.0
216
- outer loop
217
- vertex -16.5 0.0 -0.75
218
- vertex 0.0 -9.5 -0.75
219
- vertex 0.0 0.0 -0.75
220
- endloop
221
- endfacet
222
- EOD
223
- end
224
-
225
- it "should call translate on each of it's Vertices" do
226
- @facet.vertices[0].should_receive(:translate!).with(16.5, 9.5, 0.75)
227
- @facet.vertices[1].should_receive(:translate!).with(16.5, 9.5, 0.75)
228
- @facet.vertices[2].should_receive(:translate!).with(16.5, 9.5, 0.75)
229
-
230
- @facet.translate!(16.5, 9.5, 0.75)
231
- end
232
- end
233
- end
data/spec/line_spec.rb DELETED
@@ -1,108 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Line do
4
- describe "#intersects_z?" do
5
- context "for a line that intersects the target Z plane" do
6
- context "with a positive Z vector" do
7
- before do
8
- @line = Line.new(Vertex.new(0.0, 0.0, 0.0), Vertex.new(0.0, 0.0, 6.0))
9
- end
10
-
11
- it "should return true" do
12
- @line.intersects_z?(3.0).should be_true
13
- end
14
- end
15
-
16
- context "with a negative Z vector" do
17
- before do
18
- @line = Line.new(Vertex.new(0.0, 0.0, 6.0), Vertex.new(0.0, 0.0, 0.0))
19
- end
20
-
21
- it "should return true" do
22
- @line.intersects_z?(3.0).should be_true
23
- end
24
- end
25
- end
26
-
27
- context "for a line that does not intersect the target Z plane" do
28
- before do
29
- @line = Line.new(Vertex.new(0.0, 0.0, 4.0), Vertex.new(0.0, 0.0, 6.0))
30
- end
31
-
32
- it "should return false" do
33
- @line.intersects_z?(3.0).should be_false
34
- end
35
- end
36
- end
37
-
38
- describe "#intersection_at_z" do
39
- context "for a line that intersects the target Z plane" do
40
- context "and spans both positive and negative space" do
41
- context "with a positive Z vector" do
42
- before do
43
- @line = Line.new(Vertex.new(-1.0, 1.0, 1.0), Vertex.new(1.0, 1.0, -1.0))
44
- end
45
-
46
- it "should return a Point representing the intersection" do
47
- @line.intersection_at_z(0).x.should == 0.0
48
- @line.intersection_at_z(0).y.should == 1.0
49
- @line.intersection_at_z(0).z.should == 0.0
50
- end
51
- end
52
-
53
- context "with a negative Z vector" do
54
- before do
55
- @line = Line.new(Vertex.new(1.0, 1.0, 1.0), Vertex.new(-1.0, -1.0, -1.0))
56
- end
57
-
58
- it "should return a Point representing the intersection" do
59
- @line.intersection_at_z(0).x.should == 0
60
- @line.intersection_at_z(0).y.should == 0
61
- @line.intersection_at_z(0).z.should == 0
62
- end
63
- end
64
- end
65
- end
66
-
67
- context "for a line that lies on the target Z plane" do
68
- before do
69
- @line = Line.new(Vertex.new(0.0, 0.0, 3.0), Vertex.new(0.0, 6.0, 3.0))
70
- end
71
-
72
- it "should raise an error" do
73
- lambda{
74
- @line.intersection_at_z(3.0)
75
- }.should raise_error
76
- end
77
- end
78
-
79
- context "for a line that does not intersect the target Z plane" do
80
- before do
81
- @line = Line.new(Vertex.new(0.0, 0.0, 4.0), Vertex.new(0.0, 0.0, 6.0))
82
- end
83
-
84
- it "should return nil" do
85
- @line.intersection_at_z(3.0).should be_nil
86
- end
87
- end
88
- end
89
-
90
- describe "==" do
91
- it "should return true when the two lines are identical" do
92
- (Line.new(Vertex.new(-1.0, -1.0, -1.0), Vertex.new(1.0, 1.0, 1.0)) == Line.new(Vertex.new(-1.0, -1.0, -1.0), Vertex.new(1.0, 1.0, 1.0))).should be_true
93
- end
94
-
95
- it "should not return true when the lines are not identical" do
96
- (Line.new(Vertex.new(-1.0, -1.0, -1.1), Vertex.new(1.0, 1.0, 1.0)) == Line.new(Vertex.new(-1.0, -1.0, -1.0), Vertex.new(1.0, 1.0, 1.0))).should be_false
97
- end
98
- end
99
-
100
- describe "#to_svg_path" do
101
- it "should return a string containing an SVG path" do
102
- line = Line.new(Vertex.new(0.0, 0.0, 0.0), Vertex.new(1.0, 1.0, 1.0))
103
- expected_output = '<path d="M 0.0 0.0 L 1.0 1.0" fill="none" stroke="black" stroke-width="0.005" />'
104
-
105
- line.to_svg_path(:inches).should == expected_output
106
- end
107
- end
108
- end
data/spec/point_spec.rb DELETED
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Point do
4
- describe ".parse" do
5
- context "with a correctly formatted point" do
6
- before do
7
- @result = Point.parse(" 16.5 0.0 -0.75 ")
8
- end
9
-
10
- it "should return a point object" do
11
- @result.should be_a Point
12
- end
13
-
14
- it "should correctly set the X value" do
15
- @result.x.should == 16.5
16
- end
17
-
18
- it "should correctly set the Y value" do
19
- @result.y.should == 0
20
- end
21
-
22
- it "should correctly set the Z value" do
23
- @result.z.should == -0.75
24
- end
25
- end
26
-
27
- context "with a point that contains exponential notation" do
28
- before do
29
- @result = Point.parse(" -5.23431439438796e-32 0.0 5.23431439438796e32 ")
30
- end
31
-
32
- it "should correctly set the X value" do
33
- @result.x.should == -5.23431439438796e-32
34
- end
35
-
36
- it "should correctly set the Y value" do
37
- @result.y.should == 0.0
38
- end
39
-
40
- it "should correctly set the Z value" do
41
- @result.z.should == 5.23431439438796e32
42
- end
43
- end
44
- end
45
-
46
- describe "#to_s" do
47
- it "should return the XYZ components separated by spaces" do
48
- point = Point.new(1.0, 2.0, -3.1)
49
- point.to_s.should == "1.0 2.0 -3.1"
50
- end
51
-
52
- it "should convert integers into floats for output" do
53
- point = Point.new(1, 2, 3)
54
- point.to_s.should == "1.0 2.0 3.0"
55
- end
56
- end
57
-
58
- describe "#==" do
59
- it "should return true when the points have identical values" do
60
- (Point.new(1.0, 2.0, -3.1) == Point.new(1.0, 2.0, -3.1)).should be_true
61
- end
62
-
63
- it "should return false when the points do not have identical values" do
64
- (Point.new(1.0, 2.0, -3.1) == Point.new(1.0, 2.0, -3.2)).should be_false
65
- end
66
- end
67
-
68
- describe "#translate!" do
69
- before do
70
- @point = Point.new(1.0, 1.0, 1.0)
71
- end
72
-
73
- it "should add the supplied value to X" do
74
- @point.translate!(16.5, 9.5, 0.75)
75
- @point.x.should == 17.5
76
- end
77
-
78
- it "should add the supplied value to Y" do
79
- @point.translate!(16.5, 9.5, 0.75)
80
- @point.y.should == 10.5
81
- end
82
-
83
- it "should add the supplied value to Z" do
84
- @point.translate!(16.5, 9.5, 0.75)
85
- @point.z.should == 1.75
86
- end
87
- end
88
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Polyline do
4
- describe "#to_svg" do
5
- it "should output an SVG document as a string" do
6
- line = Line.new(Vertex.new(0.0, 0.0, 0.0), Vertex.new(1.0, 1.0, 1.0))
7
- polyline = Polyline.new([line])
8
-
9
- expected_svg = '<?xml version="1.0" standalone="no"?>' + "\n"
10
- expected_svg += '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' + "\n"
11
- expected_svg += '<svg x="0" y="0" width="20in" height="30in" viewBox="0 0 20 30" xmlns="http://www.w3.org/2000/svg" version="1.1">' + "\n"
12
- expected_svg += ' <g transform="translate(1in,2in)">' + "\n"
13
- expected_svg += " #{line.to_svg_path(:inches)}\n"
14
- expected_svg += ' </g>' + "\n"
15
- expected_svg += '</svg>'
16
-
17
- polyline.to_svg(20, 30, :inches, 1, 2).should == expected_svg
18
- end
19
- end
20
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Triangular do
4
- describe ".parse" do
5
- it "should return a Solid" do
6
- stl_string = File.open("#{File.dirname(__FILE__)}/fixtures/y-axis-spacer.stl").read
7
- result = Triangular.parse(stl_string)
8
-
9
- result.should be_a Solid
10
- end
11
- end
12
-
13
- describe ".parse_file" do
14
- it "should return a Solid" do
15
- input = File.open(File.expand_path("#{File.dirname(__FILE__)}/fixtures/y-axis-spacer.stl")).read
16
- result = Triangular.parse_file(File.expand_path("#{File.dirname(__FILE__)}/fixtures/y-axis-spacer.stl"))
17
- result.should be_a Solid
18
-
19
- result.to_s.should == input
20
- end
21
- end
22
- end
data/spec/units_spec.rb DELETED
@@ -1,75 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Units do
4
- describe ".name" do
5
- it "should return 'inches' for :inches" do
6
- Units.name(:inches).should == 'inches'
7
- end
8
-
9
- it "should return 'centimeters' for :centimeters" do
10
- Units.name(:centimeters).should == 'centimeters'
11
- end
12
-
13
- it "should return 'millimeters' for :millimeters" do
14
- Units.name(:millimeters).should == 'millimeters'
15
- end
16
-
17
- it "should return 'none' for :none" do
18
- Units.name(:none).should == 'none'
19
- end
20
-
21
- it "should raise an exception if called with an unknown unit" do
22
- lambda {
23
- Units.name(:error)
24
- }.should raise_error
25
- end
26
- end
27
-
28
- describe ".svg_name" do
29
- it "should return 'in' for :inches" do
30
- Units.svg_name(:inches).should == 'in'
31
- end
32
-
33
- it "should return 'cm' for :centimeters" do
34
- Units.svg_name(:centimeters).should == 'cm'
35
- end
36
-
37
- it "should return 'mm' for :millimeters" do
38
- Units.svg_name(:millimeters).should == 'mm'
39
- end
40
-
41
- it "should return '' for :none" do
42
- Units.svg_name(:none).should == ''
43
- end
44
-
45
- it "should raise an exception if called with an unknown unit" do
46
- lambda {
47
- Units.svg_name(:error)
48
- }.should raise_error
49
- end
50
- end
51
-
52
- describe ".stroke_width" do
53
- it "should return 'in' for :inches" do
54
- Units.stroke_width(:inches).should == 0.005
55
- end
56
-
57
- it "should return 'cm' for :centimeters" do
58
- Units.stroke_width(:centimeters).should == 0.01
59
- end
60
-
61
- it "should return 'mm' for :millimeters" do
62
- Units.stroke_width(:millimeters).should == 0.1
63
- end
64
-
65
- it "should return '' for :none" do
66
- Units.stroke_width(:none).should == 0.1
67
- end
68
-
69
- it "should raise an exception if called with an unknown unit" do
70
- lambda {
71
- Units.stroke_width(:error)
72
- }.should raise_error
73
- end
74
- end
75
- end
data/spec/vertex_spec.rb DELETED
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Vertex do
4
- describe ".parse" do
5
- context "with a correctly formatted vertex" do
6
- before do
7
- @result = Vertex.parse(" vertex 16.5 0.0 -0.75\n")
8
- end
9
-
10
- it "should return a vertex object" do
11
- @result.should be_a Vertex
12
- end
13
-
14
- it "should correctly set the X value" do
15
- @result.x.should == 16.5
16
- end
17
-
18
- it "should correctly set the Y value" do
19
- @result.y.should == 0
20
- end
21
-
22
- it "should correctly set the Z value" do
23
- @result.z.should == -0.75
24
- end
25
- end
26
- end
27
-
28
- describe "#to_s" do
29
- it "should return the keyword 'vertex' followed by the XYZ coordinates" do
30
- vertex = Vertex.new(1.0, 2.0, -3.0)
31
- vertex.to_s.should == "vertex 1.0 2.0 -3.0"
32
- end
33
- end
34
-
35
- describe "#==" do
36
- it "should return true when the vertices have identical values" do
37
- (Vertex.new(1.0, 2.0, -3.1) == Vertex.new(1.0, 2.0, -3.1)).should be_true
38
- end
39
-
40
- it "should return false when the vertices do not have identical values" do
41
- (Vertex.new(1.0, 2.0, -3.1) == Vertex.new(1.0, 2.0, -3.2)).should be_false
42
- end
43
- end
44
- end