ruby-gr 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b317ddec0fec1377dc02ab3df429656bf7ae1a4056ed039b3814b344be362e59
4
- data.tar.gz: ed039b4fbac3b8e391039343924d8e8fdfe3cd2c72a8d5c6705d29170fc69809
3
+ metadata.gz: 51cba5fbff46f2beca8d4343580d583390daa5ae65308af59bc5353385c181ae
4
+ data.tar.gz: b7a9fed2d87f74dde366032c2589a71aeabafa142d1499cdaacf7b3ba0b150b0
5
5
  SHA512:
6
- metadata.gz: 40828455aaed63f0eea89ec1eebc31c7c4f2a1a49e3e3b874cc80b08336cda2da5fad15f02c475ab4187ea18c7b996e2d5fbcfcdad61cbc01d53e2704af4b3fe
7
- data.tar.gz: 8ebe911013ea044d6feca9e36dbf6a97d9d54e465b19659f06254c2b4e41414a398e5788770000301e03d0e06f6181e5d546cc582671816961a1ae3efc390f52
6
+ metadata.gz: 1a31d16e878229021a6f02403766b1d7be0d0c161261e92d5f1d2a19b5c4146bade5f17ef4f03784b6212845d0af089a21c41dc258fee194dedf1943fd649303
7
+ data.tar.gz: 741bb5fbfafd7a0422d5d0b528545112a9e84b2c20baa396d2ef51e6a0692083a0124db0e70cd82763e725e1169f18ce5a2dcc6ec1cec9deadecdff3042f023b
data/README.md CHANGED
@@ -37,6 +37,82 @@ GR.axes(tick, tick, 0, 0, 1, 1, -0.001)
37
37
  GR.updatews
38
38
  ```
39
39
 
40
+ ## Examples
41
+ Have a look in the [`examples`](https://github.com/kojix2/GR.rb/tree/master/examples) directory for some simple examples.
42
+
43
+ griddata.rb
44
+
45
+ <p align="center">
46
+ <img src="https://user-images.githubusercontent.com/5798442/68080405-1b3e3580-fe3e-11e9-9f71-592ca2826bcb.png">
47
+ </p>
48
+
49
+ ```ruby
50
+ require 'gr'
51
+ require 'numo/narray'
52
+
53
+ DFloat = Numo::DFloat
54
+
55
+ xd = -2 + DFloat.new(100).rand * 4
56
+ yd = -2 + DFloat.new(100).rand * 4
57
+ zd = xd * Numo::NMath.exp(-xd * xd - yd * yd)
58
+
59
+ h = -0.5 + DFloat.new(20).seq / 19.0
60
+
61
+ GR.setviewport(0.1, 0.95, 0.1, 0.95)
62
+ GR.setwindow(-2.0, 2.0, -2.0, 2.0)
63
+ GR.setspace(-0.5, 0.5, 0, 90)
64
+ GR.setmarkersize(1.0)
65
+ GR.setmarkertype(-1)
66
+ GR.setcharheight(0.024)
67
+ GR.settextalign(2, 0)
68
+ GR.settextfontprec(3, 0)
69
+
70
+ x, y, z = GR.gridit(xd, yd, zd, 200, 200)
71
+ GR.surface(x, y, z, 5)
72
+ GR.contour(x, y, h, z, 0)
73
+ GR.polymarker(xd, yd)
74
+ GR.axes(0.25, 0.25, -2, -2, 2, 2, 0.01)
75
+
76
+ GR.updatews
77
+ ```
78
+
79
+ clifford_attractor.rb
80
+
81
+ <p align="center">
82
+ <img src="https://user-images.githubusercontent.com/5798442/68080387-baaef880-fe3d-11e9-9435-f998eaca79da.png">
83
+ </p>
84
+
85
+ ```ruby
86
+ require 'gr'
87
+
88
+ include Math
89
+
90
+ n = 100_000_000
91
+ x0 = 0
92
+ y0 = 0
93
+ a = -1.3
94
+ b = -1.3
95
+ c = -1.8
96
+ d = -1.9
97
+ dθ = 0.007
98
+
99
+ x = [x0]
100
+ y = [y0]
101
+ θ = 0.007
102
+
103
+ n.times do |i|
104
+ x << (sin(a * y[i]) + c * cos(a * x[i])) * cos(θ)
105
+ y << (sin(b * x[i]) + d * cos(b * y[i])) * cos(θ)
106
+ θ += dθ
107
+ end
108
+
109
+ GR.setviewport(0, 1, 0, 1)
110
+ GR.setwindow(-3, 3, -3, 3)
111
+ GR.setcolormap(8)
112
+ GR.shadepoints(x, y, dims: [480, 480], xform: 5)
113
+ GR.updatews
114
+ ```
115
+
40
116
  ## Contributing
41
117
 
42
- Bug reports and pull requests are welcome on GitHub at https://github.com/kojix2/GR.rb.
118
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kojix2/GR.rb.
data/lib/gr.rb CHANGED
@@ -1,5 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # OverView of GR.rb
4
+ #
5
+ # +--------------------+
6
+ # +-------------------+ | GR3 module |
7
+ # | GR module | | +----------------+ |
8
+ # | +---------------+ | | | GR3::FFI | |
9
+ # | | GR::FFI | | | | + libGR3.so | |
10
+ # | | + libGR.so | | | +----------------+ |
11
+ # | +---------------+ | | | define_method |
12
+ # | | define_method | | +----------------+ |
13
+ # | +---------------+ | | | | GR3::GR3Base | |
14
+ # | | | GR::GRBase | | | | v (Private) | |
15
+ # | | v (Private) | | | +++--------------+ |
16
+ # | +++-------------+ | | | Extend |
17
+ # | | Extend | | v +------+ |
18
+ # | v | | |Check | |
19
+ # | | | <--+Error | |
20
+ # +-------+-----------+ | +------+ |
21
+ # ^ +---------+----------+
22
+ # | +------------------+ ^
23
+ # Extend | | GRCommons module | | Extend
24
+ # | | +--------------+ | |
25
+ # +----+ CommonUtils +----+
26
+ # | | +--------------+ | |
27
+ # | | +--------------+ | |
28
+ # +----+ Version +----+
29
+ # | | +--------------+ |
30
+ # | | +--------------+ |
31
+ # +----+JupyterSupport| |
32
+ # | +--------------+ |
33
+ # +------------------+
34
+
3
35
  require 'ffi'
4
36
 
5
37
  module GR
@@ -30,11 +62,11 @@ module GR
30
62
  require_relative 'gr/grbase'
31
63
 
32
64
  extend GRCommons::JupyterSupport
33
- extend GRBase
34
65
 
35
66
  # `double` is the default type in GR
36
67
  # A Ruby array or NArray passed to GR method is automatically converted to
37
68
  # a FFI::MemoryPointer in the GRBase class.
69
+ extend GRBase
38
70
 
39
71
  class << self
40
72
  def initgr(*)
@@ -623,6 +655,7 @@ module GR
623
655
  # * Flip Y-axis
624
656
  # * 32 : OPTION_FLIP_Z
625
657
  # * Flip Z-axis
658
+ # @return [Integer]
626
659
  # `setscale` defines the current transformation according to the given scale
627
660
  # specification which may be or'ed together using any of the above options. GR uses
628
661
  # these options for all subsequent output primitives until another value is provided.
@@ -769,6 +802,7 @@ module GR
769
802
  # @param zmax [Numeric] Maximum value for the Z-axis.
770
803
  # @param rotation [Integer] Angle for the rotation of the X axis, in degrees.
771
804
  # @param tilt [integer] Viewing angle of the Z axis in degrees.
805
+ # @return [Integer]
772
806
  # `setspace` establishes the limits of an abstract Z-axis and defines the angles for
773
807
  # rotation and for the viewing angle (tilt) of a simulated three-dimensional graph,
774
808
  # used for mapping corresponding output primitives into the current window.
@@ -790,6 +824,7 @@ module GR
790
824
  # @param x [Numeric] The X coordinate of starting position of the text string
791
825
  # @param y [Numeric] The Y coordinate of starting position of the text string
792
826
  # @param string [String] The text to be drawn
827
+ # @return [Integer]
793
828
  #
794
829
  # The values for X and Y are in normalized device coordinates.
795
830
  # The attributes that control the appearance of text are text font and precision,
@@ -1082,6 +1117,7 @@ module GR
1082
1117
  super(npoints, x, y, z, nlevels, levels)
1083
1118
  end
1084
1119
 
1120
+ # @return [Integer]
1085
1121
  def hexbin(x, y, nbins)
1086
1122
  n = x.length
1087
1123
  super(n, x, y, nbins)
@@ -1117,6 +1153,7 @@ module GR
1117
1153
  end
1118
1154
  end
1119
1155
 
1156
+ # @return [Integer]
1120
1157
  def inqcolorfromrgb(*)
1121
1158
  super
1122
1159
  end
@@ -1127,20 +1164,30 @@ module GR
1127
1164
  end
1128
1165
  end
1129
1166
 
1167
+ # @return [Numeric]
1130
1168
  def tick(*)
1131
1169
  super
1132
1170
  end
1133
1171
 
1172
+ # @return [Integer]
1134
1173
  def validaterange(*)
1135
1174
  super
1136
1175
  end
1137
1176
 
1138
- def adjustlimits(*)
1139
- super
1177
+ def adjustlimits(amin, amax)
1178
+ inquiry %i[double double] do |pamin, pamax|
1179
+ pamin.write_double amin
1180
+ pamax.write_double amax
1181
+ super(pamin, pamax)
1182
+ end
1140
1183
  end
1141
1184
 
1142
- def adjustrange(*)
1143
- super
1185
+ def adjustrange(amin, amax)
1186
+ inquiry %i[double double] do |pamin, pamax|
1187
+ pamin.write_double amin
1188
+ pamax.write_double amax
1189
+ super(pamin, pamax)
1190
+ end
1144
1191
  end
1145
1192
 
1146
1193
  # Open and activate a print device.
@@ -1337,7 +1384,7 @@ module GR
1337
1384
  super
1338
1385
  end
1339
1386
 
1340
- # readimage
1387
+ # @return [Integer]
1341
1388
  def readimage(path)
1342
1389
  w, h, d = inquiry [:int, :int, :pointer] do |width, height, data|
1343
1390
  # data is a pointer of a pointer
@@ -1368,6 +1415,7 @@ module GR
1368
1415
  super(xmin, xmax, ymin, ymax, width, height, uint(data), model)
1369
1416
  end
1370
1417
 
1418
+ # @return [Integer]
1371
1419
  def importgraphics(*)
1372
1420
  super
1373
1421
  end
@@ -1414,10 +1462,12 @@ module GR
1414
1462
  super
1415
1463
  end
1416
1464
 
1465
+ # @return [String]
1417
1466
  def getgraphics(*)
1418
1467
  super
1419
1468
  end
1420
1469
 
1470
+ # @return [Integer]
1421
1471
  def drawgraphics(*)
1422
1472
  super
1423
1473
  end
@@ -1460,6 +1510,7 @@ module GR
1460
1510
  end
1461
1511
  end
1462
1512
 
1513
+ # @return [Numeric]
1463
1514
  def precision(*)
1464
1515
  super
1465
1516
  end
@@ -1468,6 +1519,7 @@ module GR
1468
1519
  super
1469
1520
  end
1470
1521
 
1522
+ # @return [Integer]
1471
1523
  def inqregenflags(*)
1472
1524
  super
1473
1525
  end
@@ -1488,6 +1540,7 @@ module GR
1488
1540
  super
1489
1541
  end
1490
1542
 
1543
+ # @return [Integer]
1491
1544
  def uselinespec(*)
1492
1545
  super
1493
1546
  end
@@ -1570,6 +1623,7 @@ module GR
1570
1623
  end
1571
1624
 
1572
1625
  # Returns the combined version strings of the GR runtime.
1626
+ # @return [String]
1573
1627
  def version
1574
1628
  super.read_string
1575
1629
  end
data/lib/gr/ffi.rb CHANGED
@@ -83,7 +83,7 @@ module GR
83
83
  attach_function :gr_closeseg, %i[], :void
84
84
  attach_function :gr_emergencyclosegks, %i[], :void
85
85
  attach_function :gr_updategks, %i[], :void
86
- attach_function :gr_setspace, %i[double double int int], :void
86
+ attach_function :gr_setspace, %i[double double int int], :int
87
87
  attach_function :gr_inqspace, %i[pointer pointer pointer pointer], :void
88
88
  attach_function :gr_textext, %i[double double string], :int
89
89
  attach_function :gr_inqtextext, %i[double double string pointer pointer], :void
@@ -144,14 +144,14 @@ module GR
144
144
  attach_function :gr_moveselection, %i[double double], :void
145
145
  attach_function :gr_resizeselection, %i[int double double], :void
146
146
  attach_function :gr_inqbbox, %i[pointer pointer pointer pointer], :void
147
- attach_function :gr_precision, %i[], :void
147
+ attach_function :gr_precision, %i[], :double
148
148
  attach_function :gr_setregenflags, %i[int], :void
149
- attach_function :gr_inqregenflags, %i[], :void
149
+ attach_function :gr_inqregenflags, %i[], :int
150
150
  attach_function :gr_savestate, %i[], :void
151
151
  attach_function :gr_restorestate, %i[], :void
152
152
  attach_function :gr_selectcontext, %i[int], :void
153
153
  attach_function :gr_destroycontext, %i[int], :void
154
- attach_function :gr_uselinespec, %i[string], :void
154
+ attach_function :gr_uselinespec, %i[string], :int
155
155
  # attach_function :gr_delaunay, %i[int pointer pointer pointer pointer], :void
156
156
  attach_function :gr_reducepoints, %i[int pointer pointer int pointer pointer], :void
157
157
  attach_function :gr_trisurface, %i[int pointer pointer pointer], :void
data/lib/gr3.rb CHANGED
@@ -1,5 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # OverView of GR.rb
4
+ #
5
+ # +--------------------+
6
+ # +-------------------+ | GR3 module |
7
+ # | GR module | | +----------------+ |
8
+ # | +---------------+ | | | GR3::FFI | |
9
+ # | | GR::FFI | | | | + libGR3.so | |
10
+ # | | + libGR.so | | | +----------------+ |
11
+ # | +---------------+ | | | define_method |
12
+ # | | define_method | | +----------------+ |
13
+ # | +---------------+ | | | | GR3::GR3Base | |
14
+ # | | | GR::GRBase | | | | v (Private) | |
15
+ # | | v (Private) | | | +++--------------+ |
16
+ # | +++-------------+ | | | Extend |
17
+ # | | Extend | | v +------+ |
18
+ # | v | | |Check | |
19
+ # | | | <--+Error | |
20
+ # +-------+-----------+ | +------+ |
21
+ # ^ +---------+----------+
22
+ # | +------------------+ ^
23
+ # Extend | | GRCommons module | | Extend
24
+ # | | +--------------+ | |
25
+ # +----+ CommonUtils +----+
26
+ # | | +--------------+ | |
27
+ # | | +--------------+ | |
28
+ # +----+ Version +----+
29
+ # | | +--------------+ |
30
+ # | | +--------------+ |
31
+ # +----+JupyterSupport| |
32
+ # | +--------------+ |
33
+ # +------------------+
34
+
3
35
  require 'ffi'
4
36
 
5
37
  module GR3
@@ -29,22 +61,35 @@ module GR3
29
61
  require_relative 'gr3/ffi'
30
62
  require_relative 'gr3/gr3base'
31
63
 
32
- extend GRCommons::JupyterSupport
33
- extend GR3Base
34
-
35
64
  # `float` is the default type in GR3
36
65
  # A Ruby array or NArray passed to GR3 method is automatically converted to
37
66
  # a FFI::MemoryPointer in the GR3Base class.
67
+ extend GR3Base
38
68
 
69
+ # This module is for adding error checking to all methods in GR3
39
70
  module CheckError
71
+ def geterror
72
+ line = ::FFI::MemoryPointer.new(:int)
73
+ file = ::FFI::MemoryPointer.new(:pointer)
74
+ e = super(1, line, file)
75
+ return [0, nil, nil] if e == 0
76
+
77
+ line = line.read_int
78
+ file = file.read_pointer.read_string
79
+ [e, line, file]
80
+ end
81
+
40
82
  FFI.ffi_methods.each do |method|
41
83
  method_name = method.to_s.sub(/^gr3_/, '')
42
84
  next if method_name == 'geterror'
43
85
 
44
86
  define_method(method_name) do |*args|
45
87
  values = super(*args)
46
- GR3Base.check_error
47
- values
88
+ e, line, file = geterror
89
+ if e != 0
90
+ mesg = FFI.gr3_geterrorstring(e)
91
+ raise "GR3 error #{file} #{line} #{mesg}"
92
+ end
48
93
  end
49
94
  end
50
95
  end
@@ -52,6 +97,7 @@ module GR3
52
97
 
53
98
  class << self
54
99
  # This method initializes the gr3 context.
100
+ # @return [Integer]
55
101
  def gr3_init(*)
56
102
  super
57
103
  end
@@ -65,10 +111,10 @@ module GR3
65
111
  super
66
112
  end
67
113
 
114
+ # @!method geterror
68
115
  # This function returns information on the most recent GR3 error.
69
- def geterror(*)
70
- super
71
- end
116
+ # @return [Integer]
117
+ # @note This method is defined in the CheckError module.
72
118
 
73
119
  # This function allows the user to find out how his commands are rendered.
74
120
  # If gr3 is initialized, a string in the format:
@@ -76,16 +122,19 @@ module GR3
76
122
  # For example `"gr3 - GLX - GL_ARB_framebuffer_object - 2.1 Mesa 7.10.2 - Software Rasterizer"`
77
123
  # might be returned on a Linux system (using GLX) with an available GL_ARB_framebuffer_object implementation.
78
124
  # If gr3 is not initialized `"Not initialized"` is returned.
125
+ # @return [String]
79
126
  def getrenderpathstring(*)
80
127
  super
81
128
  end
82
129
 
83
130
  # This function returns a string representation of a given error code.
131
+ # @return [String]
84
132
  def geterrorstring(*)
85
133
  super
86
134
  end
87
135
 
88
136
  # This function clears the draw list.
137
+ # @return [Integer]
89
138
  def clear(*)
90
139
  super
91
140
  end
@@ -104,11 +153,12 @@ module GR3
104
153
 
105
154
  # Set rendering quality
106
155
  # @param quality [] The quality to set
156
+ # @return [Integer]
107
157
  def setquality(*)
108
158
  super
109
159
  end
110
160
 
111
- # getimage
161
+ # @return [Integer]
112
162
  def getimage(width, height, use_alpha = true)
113
163
  bpp = use_alpha ? 4 : 3
114
164
  inquiry(uint8: width * height * bpp) do |bitmap|
@@ -116,15 +166,18 @@ module GR3
116
166
  end
117
167
  end
118
168
 
169
+ # @return [Integer]
119
170
  def export(*)
120
171
  super
121
172
  end
122
173
 
174
+ # @return [Integer]
123
175
  def drawimage(*)
124
176
  super
125
177
  end
126
178
 
127
179
  # createmesh_nocopy
180
+ # @return [Integer]
128
181
  def createmesh_nocopy(_n, vertices, normals, colors)
129
182
  inquiry_int do |mesh|
130
183
  super(mesh, vertices, normals, colors)
@@ -138,6 +191,7 @@ module GR3
138
191
  # @param normals [Array, NArray] the vertex normals
139
192
  # @param colors [Array, NArray] the vertex colors,
140
193
  # they should be white (1,1,1) if you want to change the color for each drawn mesh
194
+ # @return [Integer]
141
195
  def createmesh(n, vertices, normals, colors)
142
196
  inquiry_int do |mesh|
143
197
  super(mesh, n, vertices, normals, colors)
@@ -145,6 +199,7 @@ module GR3
145
199
  end
146
200
 
147
201
  # This function creates a mesh from vertex position, normal and color data.
202
+ # @return [Integer]
148
203
  def createindexedmesh_nocopy(num_vertices, vertices, normals, colors, num_indices, indices)
149
204
  inquiry_int do |mesh|
150
205
  super(mesh, num_vertices, vertices, normals, colors, num_indices, indices)
@@ -161,6 +216,7 @@ module GR3
161
216
  # they should be white (1,1,1) if you want to change the color for each drawn mesh
162
217
  # @param num_indices [Integer] the number of indices in the mesh (three times the number of triangles)
163
218
  # @param indices [Array, NArray] the index array (vertex indices for each triangle)
219
+ # @return [Integer]
164
220
  def createindexedmesh(num_vertices, vertices, normals, colors, num_indices, indices)
165
221
  inquiry_int do |mesh|
166
222
  super(mesh, num_vertices, vertices, normals, colors, num_indices, indices)
@@ -208,11 +264,13 @@ module GR3
208
264
  # It must be greater than 0 and less than 180.
209
265
  # @param zNear [Numeric] The distance to the near clipping plane.
210
266
  # @param zFar [Numeric] The distance to the far clipping plane.
267
+ # @return [Integer]
211
268
  def setcameraprojectionparameters(*)
212
269
  super
213
270
  end
214
271
 
215
272
  # Get the projection parameters.
273
+ # @return [Integer]
216
274
  def getcameraprojectionparameters(*)
217
275
  super
218
276
  end
@@ -231,6 +289,7 @@ module GR3
231
289
  super
232
290
  end
233
291
 
292
+ # @return [Integer]
234
293
  def createheightmapmesh(*)
235
294
  super
236
295
  end
@@ -262,6 +321,7 @@ module GR3
262
321
  super
263
322
  end
264
323
 
324
+ # @return [Integer]
265
325
  def selectid(*)
266
326
  super
267
327
  end
@@ -275,6 +335,7 @@ module GR3
275
335
  end
276
336
 
277
337
  # the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL
338
+ # @return [Integer]
278
339
  def getprojectiontype(*)
279
340
  super
280
341
  end
@@ -291,6 +352,7 @@ module GR3
291
352
  # @param step [Array] voxel sizes in each direction
292
353
  # @param offset [Array] coordinate origin in each direction
293
354
  # @param isolevel [Integer] isovalue at which the surface will be created
355
+ # @return [Integer]
294
356
  def createisosurfacemesh(grid, step, offset, isolevel)
295
357
  args = _preprocess_createslicemesh(grid, step, offset)
296
358
  grid = args.shift
@@ -320,6 +382,7 @@ module GR3
320
382
  # * color the surface according to the current gr colormap
321
383
  # * 16 : GR3_SURFACE_GRZSHADED
322
384
  # * like GR3_SURFACE_GRCOLOR, but use the z-value directly as color index
385
+ # @return [Integer]
323
386
  def createsurfacemesh(nx, ny, px, py, pz, option = 0)
324
387
  inquiry_int do |mesh|
325
388
  super(mesh, nx, ny, px, py, pz, option)
@@ -372,6 +435,7 @@ module GR3
372
435
  # @param num_steps [Integer] the number of steps between each point, allowing for a more smooth tube
373
436
  # @param num_segments [Integer] the number of segments each ring of the tube consists of,
374
437
  # e.g. 3 would yield a triangular tube
438
+ # @return [Integer]
375
439
  def drawtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20)
376
440
  super(n, points, colors, radii, num_steps, num_segments)
377
441
  end
@@ -385,6 +449,7 @@ module GR3
385
449
  # @param radii [Array, NArray] the desired tube radius at each point
386
450
  # @param num_steps [Integer] the number of steps between each point, allowing for a more smooth tube
387
451
  # @param num_segments [Integer] the number of segments each ring of the tube consists of, e.g. 3 would yield a triangular tube
452
+ # @return [Integer]
388
453
  def createtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20)
389
454
  inquiry_uint do |mesh| # mesh should be Int?
390
455
  super(mesh, n, points, colors, radii, num_steps, num_segments)
data/lib/gr3/ffi.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'ffi'
4
4
 
5
5
  module GR3
6
- # FFI Wrapper module for GR
6
+ # FFI Wrapper module for GR3
7
7
  module FFI
8
8
  extend ::FFI::Library
9
9
 
data/lib/gr3/gr3base.rb CHANGED
@@ -6,16 +6,6 @@ module GR3
6
6
  define_ffi_methods(FFI,
7
7
  prefix: 'gr3_',
8
8
  default_type: :float)
9
-
10
- def self.check_error
11
- line = ::FFI::MemoryPointer.new(:int)
12
- file = ::FFI::MemoryPointer.new(:string, 100)
13
- e = FFI.gr3_geterror(1, line, file)
14
- return if e == 0
15
-
16
- mesg = FFI.gr3_geterrorstring(e)
17
- raise "GR3 error #{file} #{line} #{mesg}"
18
- end
19
9
  end
20
10
  private_constant :GR3Base
21
11
 
@@ -48,10 +48,6 @@ module GRCommons
48
48
  pt.write_array_of_float data
49
49
  end
50
50
 
51
- def narray?(data)
52
- defined?(Numo::NArray) && data.is_a?(Numo::NArray)
53
- end
54
-
55
51
  def inquiry_int(&block)
56
52
  inquiry(:int, &block)
57
53
  end
@@ -100,6 +96,10 @@ module GRCommons
100
96
  pt.send("read_#{type}")
101
97
  end
102
98
  end
99
+
100
+ def narray?(data)
101
+ defined?(Numo::NArray) && data.is_a?(Numo::NArray)
102
+ end
103
103
  end
104
104
  end
105
105
 
@@ -4,24 +4,28 @@ module GRCommons
4
4
  # Jupyter Notebook and Jpyter Lab.
5
5
  module JupyterSupport
6
6
  if defined?(IRuby) && IRuby.respond_to?(:display)
7
+
8
+ # Sets the environment variable when the module is extended.
7
9
  def self.extended(_obj)
8
10
  require 'tmpdir'
9
11
  ENV['GKSwstype'] = 'svg'
10
- # May be extended to both GR3 and GR
11
12
  ENV['GKS_FILEPATH'] = Dir::Tmpname.create('plot-') {}
12
13
  end
13
14
 
15
+ # Display your plot in Jupyter Notebook / Lab
14
16
  def show
15
17
  emergencyclosegks
16
18
  sleep 0.5
17
- case ENV['GKSwstype']
19
+ type = ENV['GKSwstype']
20
+ case type
18
21
  when 'svg'
19
22
  data = File.read(ENV['GKS_FILEPATH'] + '.svg')
20
23
  IRuby.display(data, mime: 'image/svg+xml')
21
- when 'mov', 'mp4', 'webm'
24
+ when 'webm', 'ogg', 'mp4', 'mov'
22
25
  require 'base64'
23
- data = File.binread(ENV['GKS_FILEPATH'] + '.' + ENV['GKSwstype'])
24
- IRuby.display("<video controls autoplay type=\"video/mp4\" src=\"data:video/mp4;base64,#{Base64.encode64(data)}\">", mime: 'text/html')
26
+ data = File.binread(ENV['GKS_FILEPATH'] + '.' + type)
27
+ IRuby.display("<video controls autoplay type=\"video/#{type}\" src=\"data:video/#{type};base64,#{Base64.encode64(data)}\">",
28
+ mime: 'text/html')
25
29
  end
26
30
  nil
27
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-02 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi