triangular 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +25 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +11 -0
- data/examples/example_files/test_cube.stl +58 -0
- data/examples/example_files/y-axis-spacer.stl +310 -0
- data/examples/slice_example.rb +9 -0
- data/lib/triangular.rb +19 -0
- data/lib/triangular/facet.rb +81 -0
- data/lib/triangular/line.rb +38 -0
- data/lib/triangular/point.rb +33 -0
- data/lib/triangular/polyline.rb +24 -0
- data/lib/triangular/solid.rb +45 -0
- data/lib/triangular/vector.rb +4 -0
- data/lib/triangular/version.rb +3 -0
- data/lib/triangular/vertex.rb +44 -0
- data/spec/facet_spec.rb +257 -0
- data/spec/fixtures/test_cube.stl +58 -0
- data/spec/fixtures/y-axis-spacer.stl +310 -0
- data/spec/line_spec.rb +190 -0
- data/spec/point_spec.rb +67 -0
- data/spec/polyline_spec.rb +20 -0
- data/spec/solid_spec.rb +85 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/triangular_spec.rb +22 -0
- data/spec/vertex_spec.rb +44 -0
- data/triangular.gemspec +23 -0
- metadata +104 -0
data/spec/point_spec.rb
ADDED
@@ -0,0 +1,67 @@
|
|
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
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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 xmlns="http://www.w3.org/2000/svg" version="1.1">' + "\n"
|
12
|
+
expected_svg += ' <g transform="translate(2,2)">' + "\n"
|
13
|
+
expected_svg += " #{line.to_svg_path}\n"
|
14
|
+
expected_svg += ' </g>' + "\n"
|
15
|
+
expected_svg += '</svg>'
|
16
|
+
|
17
|
+
polyline.to_svg(2, 2).should == expected_svg
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/solid_spec.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Solid do
|
4
|
+
describe ".parse" do
|
5
|
+
context "with a correctly formatted solid" do
|
6
|
+
before do
|
7
|
+
@result = Solid.parse(<<-EOD)
|
8
|
+
solid y-axis-spacer
|
9
|
+
facet normal 0.0 0.0 -1.0
|
10
|
+
outer loop
|
11
|
+
vertex 16.5 0.0 -0.75
|
12
|
+
vertex 0.0 -9.5 -0.75
|
13
|
+
vertex 0.0 0.0 -0.75
|
14
|
+
endloop
|
15
|
+
endfacet
|
16
|
+
facet normal -0.0 1.0 0.0
|
17
|
+
outer loop
|
18
|
+
vertex 0.0 -1.87 0.0
|
19
|
+
vertex 16.5 -1.87 -0.13
|
20
|
+
vertex 0.0 -1.87 -0.13
|
21
|
+
endloop
|
22
|
+
endfacet
|
23
|
+
endsolid y-axis-spacer
|
24
|
+
|
25
|
+
EOD
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return a Solid" do
|
29
|
+
@result.should be_a Solid
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should correctly set the name parameter" do
|
33
|
+
@result.name.should == "y-axis-spacer"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should retun a Solid that has two Facets" do
|
37
|
+
@result.facets.length.should == 2
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return a Solid that has facets of type Facet" do
|
41
|
+
@result.facets.each do |facet|
|
42
|
+
facet.should be_a Facet
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#to_s" do
|
49
|
+
it "should output a string representation exactly the same as the input" do
|
50
|
+
input = "solid y-axis-spacer\n"
|
51
|
+
input += "facet normal 0.0 0.0 -1.0\n"
|
52
|
+
input += "outer loop\n"
|
53
|
+
input += "vertex 16.5 0.0 -0.75\n"
|
54
|
+
input += "vertex 0.0 -9.5 -0.75\n"
|
55
|
+
input += "vertex 0.0 0.0 -0.75\n"
|
56
|
+
input += "endloop\n"
|
57
|
+
input += "endfacet\n"
|
58
|
+
input += "facet normal -0.0 1.0 0.0\n"
|
59
|
+
input += "outer loop\n"
|
60
|
+
input += "vertex 0.0 -1.87 0.0\n"
|
61
|
+
input += "vertex 16.5 -1.87 -0.13\n"
|
62
|
+
input += "vertex 0.0 -1.87 -0.13\n"
|
63
|
+
input += "endloop\n"
|
64
|
+
input += "endfacet\n"
|
65
|
+
input += "endsolid y-axis-spacer\n"
|
66
|
+
|
67
|
+
solid = Solid.parse(input)
|
68
|
+
output = solid.to_s
|
69
|
+
|
70
|
+
output.should == input
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#slice_at_z" do
|
75
|
+
before do
|
76
|
+
@solid = Solid.parse(File.open("#{File.dirname(__FILE__)}/fixtures/test_cube.stl").read)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return a Polyline" do
|
80
|
+
@solid.slice_at_z(0).should be_a Polyline
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
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/vertex_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
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
|
data/triangular.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/triangular/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "triangular"
|
6
|
+
s.version = Triangular::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Aaron Gough"]
|
9
|
+
s.email = ["aaron@aarongough.com"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/triangular"
|
11
|
+
s.summary = "[ALPHA] A simple Ruby library for reading, writing, and manipulating Stereolithography (STL) files."
|
12
|
+
s.description = "Triangular is an easy-to-use Ruby library for reading, writing and manipulating Stereolithography (STL) files.\n\n The main purpose of Triangular is to enable its users to quickly create new software for Rapid Prototyping and Personal Manufacturing applications. "
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "triangular"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
+
s.add_development_dependency "rspec", "~> 2"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
22
|
+
s.require_path = 'lib'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: triangular
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aaron Gough
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-10-17 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "2"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
description: "Triangular is an easy-to-use Ruby library for reading, writing and manipulating Stereolithography (STL) files.\n\n The main purpose of Triangular is to enable its users to quickly create new software for Rapid Prototyping and Personal Manufacturing applications. "
|
38
|
+
email:
|
39
|
+
- aaron@aarongough.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- MIT-LICENSE
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- examples/example_files/test_cube.stl
|
54
|
+
- examples/example_files/y-axis-spacer.stl
|
55
|
+
- examples/slice_example.rb
|
56
|
+
- lib/triangular.rb
|
57
|
+
- lib/triangular/facet.rb
|
58
|
+
- lib/triangular/line.rb
|
59
|
+
- lib/triangular/point.rb
|
60
|
+
- lib/triangular/polyline.rb
|
61
|
+
- lib/triangular/solid.rb
|
62
|
+
- lib/triangular/vector.rb
|
63
|
+
- lib/triangular/version.rb
|
64
|
+
- lib/triangular/vertex.rb
|
65
|
+
- spec/facet_spec.rb
|
66
|
+
- spec/fixtures/test_cube.stl
|
67
|
+
- spec/fixtures/y-axis-spacer.stl
|
68
|
+
- spec/line_spec.rb
|
69
|
+
- spec/point_spec.rb
|
70
|
+
- spec/polyline_spec.rb
|
71
|
+
- spec/solid_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
- spec/triangular_spec.rb
|
74
|
+
- spec/vertex_spec.rb
|
75
|
+
- triangular.gemspec
|
76
|
+
homepage: http://rubygems.org/gems/triangular
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.3.6
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project: triangular
|
99
|
+
rubygems_version: 1.8.11
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: "[ALPHA] A simple Ruby library for reading, writing, and manipulating Stereolithography (STL) files."
|
103
|
+
test_files: []
|
104
|
+
|