rubypost 0.0.1 → 0.0.2
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.
- data/doc/created.rid +1 -0
- data/doc/fr_class_index.html +77 -0
- data/doc/fr_file_index.html +35 -0
- data/doc/fr_method_index.html +142 -0
- data/doc/index.html +24 -0
- data/lib/draw.rb +115 -0
- data/lib/drawable.rb +153 -185
- data/lib/graph.rb +222 -211
- data/lib/objects.rb +132 -98
- data/lib/options.rb +127 -127
- data/lib/revert_float_to_s.rb +6 -6
- data/lib/rubypost.rb +1 -0
- data/tests/{test_cricle.rb → test_circle.rb} +4 -5
- data/tests/test_graph.rb +13 -10
- data/tests/test_pair.rb +2 -4
- data/tests/test_path.rb +46 -62
- data/tests/test_picture.rb +26 -0
- data/tests/test_square.rb +15 -15
- metadata +13 -4
data/tests/test_path.rb
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
#require 'rubygems'
|
|
2
|
-
#gem 'rubypost'
|
|
3
1
|
#require 'rubypost'
|
|
4
2
|
|
|
5
|
-
#load the rest of rubypost
|
|
6
3
|
require '../lib/objects'
|
|
7
4
|
require '../lib/drawable'
|
|
5
|
+
require '../lib/draw'
|
|
8
6
|
require '../lib/options'
|
|
7
|
+
require '../lib/graph'
|
|
9
8
|
|
|
10
9
|
include RubyPost
|
|
11
10
|
|
|
@@ -13,103 +12,88 @@ include RubyPost
|
|
|
13
12
|
#to use File#view. tex mproof breaks
|
|
14
13
|
file = RubyPost::File.new('testpath')
|
|
15
14
|
|
|
16
|
-
#
|
|
17
|
-
fig1 = Figure.new
|
|
18
|
-
file.add_figure(fig1)
|
|
15
|
+
#create a curved path
|
|
19
16
|
path = Path.new
|
|
20
17
|
path.curved
|
|
21
18
|
8.times{ |i| path.add_pair(Pair.new(i.cm, ((i/4.0)**2).cm)) }
|
|
22
|
-
|
|
19
|
+
|
|
20
|
+
#draw a curved path
|
|
21
|
+
fig1 = Figure.new
|
|
22
|
+
file.add_figure(fig1)
|
|
23
|
+
fig1.add_drawable(Draw.new(path))
|
|
23
24
|
|
|
24
25
|
#draw the same path but with an arrow at the end
|
|
25
26
|
fig2 = Figure.new
|
|
26
27
|
file.add_figure(fig2)
|
|
27
|
-
|
|
28
|
-
arrow.curved
|
|
29
|
-
8.times{ |i| arrow.add_pair(Pair.new(i.cm, ((i/4.0)**2).cm)) }
|
|
30
|
-
fig2.add_drawable(arrow)
|
|
28
|
+
fig2.add_drawable(Arrow.new(path))
|
|
31
29
|
|
|
32
30
|
#draw the same path but with an arrow on both ends
|
|
33
31
|
fig3 = Figure.new
|
|
34
32
|
file.add_figure(fig3)
|
|
35
|
-
|
|
36
|
-
arrow2 = arrow.clone
|
|
37
|
-
arrow2.dblarrow
|
|
38
|
-
fig3.add_drawable(arrow2)
|
|
33
|
+
fig3.add_drawable(DoubleArrow.new(path))
|
|
39
34
|
|
|
40
35
|
#draw the same path but with an arrow at the start
|
|
41
36
|
#this is achieved by reversing the path
|
|
42
37
|
fig4 = Figure.new
|
|
43
38
|
file.add_figure(fig4)
|
|
44
39
|
#see the ruby reference for clone symatics
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
fig4.add_drawable(
|
|
40
|
+
revpath = path.clone
|
|
41
|
+
revpath.reverse
|
|
42
|
+
fig4.add_drawable(Arrow.new(revpath))
|
|
48
43
|
|
|
49
|
-
#draw the
|
|
44
|
+
#draw the path but scale it by 0.5 and make it dashed
|
|
50
45
|
fig5 = Figure.new
|
|
51
46
|
file.add_figure(fig5)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
8.times{ |i| arrow4.add_pair(Pair.new(i.cm, ((i/4.0)**2).cm)) }
|
|
56
|
-
fig5.add_drawable(arrow4)
|
|
47
|
+
draw_command = Arrow.new.add_option(Scale.new(0.5)).add_option(Dashed.new)
|
|
48
|
+
draw_command.set_drawable(path)
|
|
49
|
+
fig5.add_drawable(draw_command)
|
|
57
50
|
|
|
58
51
|
#draw the same arrow but scale it by 0.5 and rotate 140 degrees
|
|
59
52
|
#and make it red
|
|
60
53
|
fig6 = Figure.new
|
|
61
54
|
file.add_figure(fig6)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
fig6.add_drawable(
|
|
68
|
-
|
|
69
|
-
#draw
|
|
70
|
-
#
|
|
71
|
-
#
|
|
55
|
+
draw_command = Arrow.new
|
|
56
|
+
draw_command.add_option(Rotate.new(140))
|
|
57
|
+
draw_command.add_option(Scale.new(0.5))
|
|
58
|
+
draw_command.add_option(Colour.new(1.0,0.0,0.0))
|
|
59
|
+
draw_command.set_drawable(path)
|
|
60
|
+
fig6.add_drawable(draw_command)
|
|
61
|
+
|
|
62
|
+
#draw the previous arrow again again and draw
|
|
63
|
+
#another arrow but translate right by 5cm. <br>
|
|
64
|
+
#Note the order of translation and rotation is important.
|
|
65
|
+
#Also make the colour blue and use a square pen that is
|
|
72
66
|
#thickened by a factor of 2
|
|
73
67
|
fig7 = Figure.new
|
|
74
68
|
file.add_figure(fig7)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
fig7.add_drawable(
|
|
83
|
-
fig7.add_drawable(
|
|
84
|
-
|
|
85
|
-
#draw
|
|
69
|
+
draw_command2 = Arrow.new
|
|
70
|
+
draw_command2.add_option(Rotate.new(140))
|
|
71
|
+
draw_command2.add_option(Scale.new(0.5))
|
|
72
|
+
draw_command2.add_option(Translate.new(Pair.new(5.0.cm,0.0)))
|
|
73
|
+
draw_command2.add_option(Colour.new(0.0,0.0,1.0))
|
|
74
|
+
draw_command2.add_option(Pen.new('pensquare', 2.0))
|
|
75
|
+
draw_command2.set_drawable(path)
|
|
76
|
+
fig7.add_drawable(draw_command)
|
|
77
|
+
fig7.add_drawable(draw_command2)
|
|
78
|
+
|
|
79
|
+
#draw same path, make it cycle and make it use straight lines
|
|
86
80
|
fig8 = Figure.new
|
|
87
81
|
file.add_figure(fig8)
|
|
88
|
-
cycled_path =
|
|
89
|
-
8.times{ |i| cycled_path.add_pair(Pair.new(i.cm, ((i/3.0)**2).cm)) }
|
|
82
|
+
cycled_path = path.clone
|
|
90
83
|
cycled_path.add_pair('cycle')
|
|
91
|
-
|
|
84
|
+
cycled_path.straight
|
|
85
|
+
fig8.add_drawable(Draw.new(cycled_path))
|
|
92
86
|
|
|
93
|
-
#draw the path, make it cycle and filled with
|
|
87
|
+
#draw the path, make it cycle and filled with black
|
|
94
88
|
fig9 = Figure.new
|
|
95
89
|
file.add_figure(fig9)
|
|
96
|
-
|
|
97
|
-
8.times{ |i| filled_path.add_pair(Pair.new(i.cm, ((i/3.0)**2).cm)) }
|
|
98
|
-
filled_path.add_pair('cycle')
|
|
99
|
-
fig9.add_drawable(filled_path)
|
|
90
|
+
fig9.add_drawable(Fill.new(cycled_path))
|
|
100
91
|
|
|
101
92
|
#draw the path, make it cycle and filled with colour
|
|
102
93
|
fig10 = Figure.new
|
|
103
94
|
file.add_figure(fig10)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
test_center.add_pair(Pair.new(0.0,3.0.cm))
|
|
107
|
-
test_center.add_pair(Pair.new(3.0.cm,3.0.cm))
|
|
108
|
-
test_center.add_pair(Pair.new(3.0.cm,0.0))
|
|
109
|
-
test_center.add_pair(Pair.new('cycle'))
|
|
110
|
-
|
|
111
|
-
filled_path.add_pair('cycle')
|
|
112
|
-
fig10.add_drawable(filled_path)
|
|
95
|
+
fig10.add_drawable(Fill.new(cycled_path).colour(1,0,0))
|
|
96
|
+
|
|
113
97
|
|
|
114
98
|
puts file.compile_to_string
|
|
115
99
|
file.compile
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#require 'rubypost'
|
|
2
|
+
|
|
3
|
+
require '../lib/objects'
|
|
4
|
+
require '../lib/drawable'
|
|
5
|
+
require '../lib/draw'
|
|
6
|
+
require '../lib/options'
|
|
7
|
+
require '../lib/graph'
|
|
8
|
+
|
|
9
|
+
include RubyPost
|
|
10
|
+
|
|
11
|
+
file = RubyPost::File.new('testpicture')
|
|
12
|
+
fig = Figure.new
|
|
13
|
+
|
|
14
|
+
pic = Picture.new('testpic')
|
|
15
|
+
fig.add_drawable(Draw.new(pic))
|
|
16
|
+
file.add_figure(fig)
|
|
17
|
+
|
|
18
|
+
pic.add_drawable(Draw.new(Square.new).scale(1.cm))
|
|
19
|
+
pic.add_drawable(Draw.new(Circle.new).scale(1.cm))
|
|
20
|
+
|
|
21
|
+
fig.add_drawable(Draw.new(pic).rotate(45).translate(0,-5.cm).colour(0,0,1))
|
|
22
|
+
|
|
23
|
+
puts file.compile_to_string
|
|
24
|
+
file.compile
|
|
25
|
+
file.view
|
|
26
|
+
|
data/tests/test_square.rb
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
#require 'rubygems'
|
|
2
|
-
#gem 'rubypost'
|
|
3
1
|
#require 'rubypost'
|
|
4
2
|
|
|
5
|
-
#load the rest of rubypost
|
|
6
3
|
require '../lib/objects'
|
|
7
4
|
require '../lib/drawable'
|
|
5
|
+
require '../lib/draw'
|
|
8
6
|
require '../lib/options'
|
|
7
|
+
require '../lib/graph'
|
|
9
8
|
|
|
10
9
|
include RubyPost
|
|
11
10
|
|
|
@@ -16,27 +15,28 @@ file = RubyPost::File.new('testsquare')
|
|
|
16
15
|
#draw a square
|
|
17
16
|
fig1 = Figure.new
|
|
18
17
|
file.add_figure(fig1)
|
|
19
|
-
square1 = RubyPost::Square.new
|
|
20
|
-
fig1.add_drawable(square1)
|
|
18
|
+
square1 = RubyPost::Square.new
|
|
19
|
+
fig1.add_drawable(Draw.new(square1).scale(1.cm))
|
|
21
20
|
|
|
22
|
-
#draw a
|
|
21
|
+
#draw a square with a circular and thickened pen. Also
|
|
22
|
+
#rotate and change scale and colour
|
|
23
23
|
fig2 = Figure.new
|
|
24
24
|
file.add_figure(fig2)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
fig2.add_drawable(
|
|
25
|
+
square_drawer = Draw.new
|
|
26
|
+
square_drawer.add_option(Rotate.new(45))
|
|
27
|
+
square_drawer.add_option(Scale.new(2.cm))
|
|
28
|
+
square_drawer.add_option(Colour.new(1.0,0.0,1.0))
|
|
29
|
+
square_drawer.add_option(Dashed.new)
|
|
30
|
+
square_drawer.add_option(Pen.new('pencircle', 2.0))
|
|
31
|
+
fig2.add_drawable(square_drawer.set_drawable(square1))
|
|
32
32
|
|
|
33
33
|
#draw a green filled square
|
|
34
34
|
#we are using the colour method for Drawable. It actually just
|
|
35
35
|
#calls add_option(Colour.new(r,g,b))
|
|
36
36
|
fig3 = Figure.new
|
|
37
37
|
file.add_figure(fig3)
|
|
38
|
-
|
|
39
|
-
fig3.add_drawable(
|
|
38
|
+
square_drawer = Fill.new.scale(1.cm).colour(0.0,1.0,0.0).set_drawable(square1)
|
|
39
|
+
fig3.add_drawable(square_drawer)
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
puts file.compile_to_string
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
|
-
rubygems_version: 0.9.
|
|
2
|
+
rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: rubypost
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 0.0.
|
|
7
|
-
date: 2008-01-
|
|
6
|
+
version: 0.0.2
|
|
7
|
+
date: 2008-01-27 00:00:00 +10:00
|
|
8
8
|
summary: Ruby wrapper for the MetaPost drawing language
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|
|
@@ -29,11 +29,13 @@ post_install_message:
|
|
|
29
29
|
authors:
|
|
30
30
|
- Robby McKilliam
|
|
31
31
|
files:
|
|
32
|
-
- tests/
|
|
32
|
+
- tests/test_circle.rb
|
|
33
33
|
- tests/test_graph.rb
|
|
34
34
|
- tests/test_pair.rb
|
|
35
35
|
- tests/test_path.rb
|
|
36
|
+
- tests/test_picture.rb
|
|
36
37
|
- tests/test_square.rb
|
|
38
|
+
- lib/draw.rb
|
|
37
39
|
- lib/drawable.rb
|
|
38
40
|
- lib/graph.rb
|
|
39
41
|
- lib/objects.rb
|
|
@@ -41,6 +43,13 @@ files:
|
|
|
41
43
|
- lib/redefine_float_to_s_for_metapost.rb
|
|
42
44
|
- lib/revert_float_to_s.rb
|
|
43
45
|
- lib/rubypost.rb
|
|
46
|
+
- doc/classes
|
|
47
|
+
- doc/created.rid
|
|
48
|
+
- doc/files
|
|
49
|
+
- doc/fr_class_index.html
|
|
50
|
+
- doc/fr_file_index.html
|
|
51
|
+
- doc/fr_method_index.html
|
|
52
|
+
- doc/index.html
|
|
44
53
|
- README
|
|
45
54
|
test_files:
|
|
46
55
|
- tests/test_path.rb
|