rubypost 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/draw.rb +39 -39
- data/lib/drawable.rb +198 -208
- data/lib/graph.rb +311 -311
- data/lib/label.rb +0 -0
- data/lib/objects.rb +203 -217
- data/lib/options.rb +176 -176
- data/lib/redefine_float_to_s_for_metapost.rb +20 -11
- data/lib/revert_float_to_s.rb +13 -6
- data/lib/rubypost.rb +7 -8
- data/lib/simpleplot.rb +0 -0
- data/tests/mproof.dvi +0 -0
- data/tests/mproof.log +28 -0
- data/tests/test_circle.rb +0 -0
- data/tests/test_clip.rb +0 -0
- data/tests/test_graph.rb +1 -0
- data/tests/test_label.rb +0 -0
- data/tests/test_pair.rb +0 -0
- data/tests/test_path.rb +2 -1
- data/tests/test_picture.rb +1 -0
- data/tests/test_simpleplot.rb +0 -0
- data/tests/test_square.rb +1 -0
- data/tests/testsquare.1 +36 -0
- data/tests/testsquare.2 +42 -0
- data/tests/testsquare.3 +30 -0
- data/tests/testsquare.log +6 -0
- data/tests/testsquare.mp +20 -0
- metadata +44 -50
- data/doc/created.rid +0 -1
- data/doc/fr_class_index.html +0 -87
- data/doc/fr_file_index.html +0 -37
- data/doc/fr_method_index.html +0 -203
- data/doc/index.html +0 -24
data/README
CHANGED
data/lib/draw.rb
CHANGED
@@ -106,45 +106,45 @@ module RubyPost
|
|
106
106
|
|
107
107
|
#alias DoubleArrow, implements the metapost drawdblarrow command
|
108
108
|
class DblArrow < DoubleArrow
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
#This wraps the metapost clipping command. This needs
|
113
|
-
#to be used with a little care. It will clip everything that
|
114
|
-
#has been previously added to the picture when you add it.
|
115
|
-
#Anything that gets drawn after clipping, wont be clipped.
|
116
|
-
#This is in keeping with the way that metapost works,
|
117
|
-
#however most other objects in rubypost the order inwhich
|
118
|
-
#they are added has no effect (other than overlay).
|
119
|
-
# <\br>
|
120
|
-
#Clip only kind of fits as a draw command. It's doesn't need colours
|
121
|
-
#and stuff. This is the best place to put it at the moment, but it
|
122
|
-
#probably should inheret something else.
|
123
|
-
class Clip < BaseDrawCommand
|
124
|
-
|
125
|
-
attr_writer :path, :picture
|
126
|
-
|
127
|
-
def initialize(path=nil, pic='currentpicture')
|
128
|
-
super()
|
129
|
-
@picture = pic
|
130
|
-
@path = path
|
131
|
-
end
|
132
|
-
|
133
|
-
#set the clipping path
|
134
|
-
def set_path(p)
|
135
|
-
@path = p
|
136
|
-
end
|
137
|
-
|
138
|
-
#set the picture to clip. Defaults to 'currentpicture' see a metapost guide
|
139
|
-
def set_picture(p='currentpicture')
|
140
|
-
@picture = p
|
141
|
-
end
|
142
|
-
|
143
|
-
def compile
|
144
|
-
"clip " + @picture.compile + " to " + @path.compile + ' ' + compile_options + ";\n"
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
#This wraps the metapost clipping command. This needs
|
113
|
+
#to be used with a little care. It will clip everything that
|
114
|
+
#has been previously added to the picture when you add it.
|
115
|
+
#Anything that gets drawn after clipping, wont be clipped.
|
116
|
+
#This is in keeping with the way that metapost works,
|
117
|
+
#however most other objects in rubypost the order inwhich
|
118
|
+
#they are added has no effect (other than overlay).
|
119
|
+
# <\br>
|
120
|
+
#Clip only kind of fits as a draw command. It's doesn't need colours
|
121
|
+
#and stuff. This is the best place to put it at the moment, but it
|
122
|
+
#probably should inheret something else.
|
123
|
+
class Clip < BaseDrawCommand
|
124
|
+
|
125
|
+
attr_writer :path, :picture
|
126
|
+
|
127
|
+
def initialize(path=nil, pic='currentpicture')
|
128
|
+
super()
|
129
|
+
@picture = pic
|
130
|
+
@path = path
|
131
|
+
end
|
132
|
+
|
133
|
+
#set the clipping path
|
134
|
+
def set_path(p)
|
135
|
+
@path = p
|
136
|
+
end
|
137
|
+
|
138
|
+
#set the picture to clip. Defaults to 'currentpicture' see a metapost guide
|
139
|
+
def set_picture(p='currentpicture')
|
140
|
+
@picture = p
|
141
|
+
end
|
142
|
+
|
143
|
+
def compile
|
144
|
+
"clip " + @picture.compile + " to " + @path.compile + ' ' + compile_options + ";\n"
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
148
|
|
149
149
|
|
150
150
|
end
|
data/lib/drawable.rb
CHANGED
@@ -1,209 +1,199 @@
|
|
1
|
-
require 'matrix'
|
2
|
-
#require 'vector'
|
3
|
-
|
4
|
-
|
5
|
-
module RubyPost
|
6
|
-
|
7
|
-
#rubypost drawable
|
8
|
-
#base class for anything that actually gets drawn on a figure
|
9
|
-
class Drawable < Object
|
10
|
-
end
|
11
|
-
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
@x
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
def
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
#returns the
|
94
|
-
def
|
95
|
-
Pair.new(@x
|
96
|
-
end
|
97
|
-
|
98
|
-
#returns the
|
99
|
-
def
|
100
|
-
Pair.new(@x
|
101
|
-
end
|
102
|
-
|
103
|
-
#returns
|
104
|
-
def
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
#
|
137
|
-
#of
|
138
|
-
def
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
def initialize
|
200
|
-
super()
|
201
|
-
end
|
202
|
-
|
203
|
-
def compile
|
204
|
-
'fullcircle'
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
208
|
-
|
1
|
+
require 'matrix'
|
2
|
+
#require 'vector'
|
3
|
+
|
4
|
+
|
5
|
+
module RubyPost
|
6
|
+
|
7
|
+
#rubypost drawable
|
8
|
+
#base class for anything that actually gets drawn on a figure
|
9
|
+
class Drawable < Object
|
10
|
+
end
|
11
|
+
|
12
|
+
#wrapper for the metapost picture
|
13
|
+
#pictures are collection of drawables
|
14
|
+
class Picture < Drawable
|
15
|
+
|
16
|
+
attr_writer :name
|
17
|
+
|
18
|
+
#store a unique picture name unless incase it was not specified.
|
19
|
+
@@default_name = 0
|
20
|
+
|
21
|
+
#intialise a picture with it's name, use a string!
|
22
|
+
def initialize(name="picture_number" + @@default_name.to_s)
|
23
|
+
super()
|
24
|
+
@name = name
|
25
|
+
@draw_commands = Array.new
|
26
|
+
@@default_name = @@default_name + 1
|
27
|
+
@@picture_precompiler.add_picture(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_drawable(d)
|
31
|
+
@draw_commands.push(d)
|
32
|
+
end
|
33
|
+
|
34
|
+
#creates the definition of the picture that goes
|
35
|
+
#at the start of the file
|
36
|
+
def precompile
|
37
|
+
str = "picture " + @name + ";\n"
|
38
|
+
@draw_commands.each do |d|
|
39
|
+
str = str + d.compile + "\n"
|
40
|
+
end
|
41
|
+
str = str + @name + " := currentpicture; currentpicture := " + @@org_picture + ";\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
def compile
|
45
|
+
@name.compile
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
#A custom drawable. Send it a metapost string
|
51
|
+
class CustomDrawable < Drawable
|
52
|
+
|
53
|
+
attr_writer :command
|
54
|
+
|
55
|
+
def initialize(c=String.new)
|
56
|
+
super()
|
57
|
+
@command = c
|
58
|
+
end
|
59
|
+
|
60
|
+
def compile
|
61
|
+
@command.compile
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
#Cartesion point.
|
67
|
+
class Pair < Drawable
|
68
|
+
|
69
|
+
attr :x
|
70
|
+
attr :y
|
71
|
+
|
72
|
+
#Can set the value and individual scales of the x and y point
|
73
|
+
def initialize(x=0,y=0)
|
74
|
+
super()
|
75
|
+
@x = x
|
76
|
+
@y = y
|
77
|
+
end
|
78
|
+
|
79
|
+
def compile
|
80
|
+
'(' + @x.compile + ', ' + @y.compile + ')'
|
81
|
+
end
|
82
|
+
|
83
|
+
#returns the addition of the pairs
|
84
|
+
def +(p)
|
85
|
+
Pair.new(@x + p.x, @y + p.y)
|
86
|
+
end
|
87
|
+
|
88
|
+
#returns the subtraction of the pairs
|
89
|
+
def -(p)
|
90
|
+
Pair.new(@x - p.x, @y - p.y)
|
91
|
+
end
|
92
|
+
|
93
|
+
#returns the pair multiplied by a scalar
|
94
|
+
def *(n)
|
95
|
+
Pair.new(@x*n, @y*n)
|
96
|
+
end
|
97
|
+
|
98
|
+
#returns the pair divided by a scalar
|
99
|
+
def /(n)
|
100
|
+
Pair.new(@x/n, @y/n)
|
101
|
+
end
|
102
|
+
|
103
|
+
#returns true if the pairs are equal
|
104
|
+
def ==(p)
|
105
|
+
@x == p.x && @y == p.y
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
#sequence of pairs connected as a metapost path
|
111
|
+
class Path < Drawable
|
112
|
+
|
113
|
+
attr_writer :line_type
|
114
|
+
|
115
|
+
def initialize
|
116
|
+
super()
|
117
|
+
@p = Array.new
|
118
|
+
straight
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_pair(p)
|
122
|
+
@p.push(p)
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
#returns a pair that is the centroid of the pairs
|
127
|
+
#of this path
|
128
|
+
def center(p)
|
129
|
+
ret = Pair.new
|
130
|
+
@p.each { |p| ret = ret + p }
|
131
|
+
return ret/p.length
|
132
|
+
end
|
133
|
+
|
134
|
+
#reverse the path. <br>
|
135
|
+
#Note, this reverses the pairs that have so far
|
136
|
+
#been added. Anything added after calling reverse
|
137
|
+
#will be appended to the end of the array as usual
|
138
|
+
def reverse
|
139
|
+
@p = @p.reverse
|
140
|
+
self
|
141
|
+
end
|
142
|
+
|
143
|
+
#set the path to have straight line segments
|
144
|
+
def straight
|
145
|
+
@line_type = '--'
|
146
|
+
self
|
147
|
+
end
|
148
|
+
|
149
|
+
#set the path to have curved line segments
|
150
|
+
def curved
|
151
|
+
@line_type = '..'
|
152
|
+
self
|
153
|
+
end
|
154
|
+
|
155
|
+
def compile
|
156
|
+
str = '('
|
157
|
+
(@p.length-1).times do |i|
|
158
|
+
str = str + @p[i].compile + @line_type
|
159
|
+
end
|
160
|
+
str + @p[-1].compile + ')'
|
161
|
+
end
|
162
|
+
|
163
|
+
def clone
|
164
|
+
c = Path.new
|
165
|
+
@p.each{ |i| c.add_pair(i) }
|
166
|
+
c.line_type = @line_type
|
167
|
+
c
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
#Wraps teh metapost unitsquare command
|
173
|
+
class Square < Path
|
174
|
+
|
175
|
+
def initialize
|
176
|
+
super()
|
177
|
+
@p.push(Pair.new(-0.5,-0.5))
|
178
|
+
@p.push(Pair.new(-0.5,0.5))
|
179
|
+
@p.push(Pair.new(0.5,0.5))
|
180
|
+
@p.push(Pair.new(0.5,-0.5))
|
181
|
+
@p.push('cycle')
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
#Wraps the metapost fullcircle command
|
187
|
+
class Circle < Drawable
|
188
|
+
|
189
|
+
def initialize
|
190
|
+
super()
|
191
|
+
end
|
192
|
+
|
193
|
+
def compile
|
194
|
+
'fullcircle'
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
209
199
|
end
|