ruby-gr 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b2f6f44a5b2198487a5b2735ab2dcd33f1b7ce0176a2763ee50a2866273021a
4
- data.tar.gz: 0073dd18c710ad1107e73b5a365f55f03f746398f33a0cd59211194d940ddee2
3
+ metadata.gz: cbb0e07aec1fa9f4377df0a4c6c0765802f56ca299975970716b86d8aebf2273
4
+ data.tar.gz: 61a995043b20ba81623a96f45ca4689a9be49e8a5451497bc997cbbdee412361
5
5
  SHA512:
6
- metadata.gz: 205f75736354151eda828e200ff746e8bd69a8825476f9e7da02aafef6baf360904a8097edf27b12579b4e956821e142b83da9603d3d150b5b32b5f3e08e4214
7
- data.tar.gz: c7ddc7fd1949b22008f030ace9d3299ce38d6fa80553a27b5c3a3b74441d3376d1a15abc21b9753c5f38296f71981cd019373a2ab09fce5ab43eb413cb58107a
6
+ metadata.gz: 168285500cbd4c3a343001f3ad7649d03f37155da471546796569bf107018bd83d9c0b9af5c2a9c58b03b49163fc211f24156037abefc4f7bab459d4f1ed488a
7
+ data.tar.gz: da487fbc4d174d079b550e7fd2539defb66a4a9981c3af2b8d518e84f97dcc0bfecf52e83e9271817e2fe149252ef735b23132b33aa95a587009343951ad9d26
data/lib/gr.rb CHANGED
@@ -36,7 +36,7 @@
36
36
  # +------------------+
37
37
  #
38
38
  # The GR module works without Numo::Narrray.
39
-
39
+ #
40
40
  # This is a procedural interface to the GR plotting library,
41
41
  # https://github.com/sciapp/gr
42
42
  module GR
@@ -1850,7 +1850,7 @@ module GR
1850
1850
  end
1851
1851
  end
1852
1852
 
1853
- # Set the far and near clipping plane for perspective projection and the
1853
+ # Set the far and near clipping plane for perspective projection and the
1854
1854
  # vertical field ov view.
1855
1855
  # Switches projection type to perspective.
1856
1856
  # @param near_plane [Numeric] distance to near clipping plane
@@ -1886,7 +1886,7 @@ module GR
1886
1886
  end
1887
1887
  end
1888
1888
 
1889
- # Interface for interaction with the rotation of the model.
1889
+ # Interface for interaction with the rotation of the model.
1890
1890
  # For this a virtual Arcball is used.
1891
1891
  # @param start_mouse_pos_x [Numeric] x component of the start mouse position
1892
1892
  # @param start_mouse_pos_y [Numeric] y component of the start mouse position
@@ -3,7 +3,9 @@
3
3
  require 'fiddle/import'
4
4
 
5
5
  module GR
6
- # FFI Wrapper module for GR
6
+ # FFI Wrapper module for GR.
7
+ # The functions for GR are listed here.
8
+ # Add functions here when a new version of GR is released.
7
9
  module FFI
8
10
  extend Fiddle::Importer
9
11
 
@@ -16,8 +18,7 @@ module GR
16
18
  extend GRCommons::Extern
17
19
 
18
20
  # https://github.com/sciapp/gr/blob/master/lib/gr/gr.h
19
- # Order is important.
20
-
21
+ # keep same order
21
22
  try_extern 'void gr_initgr(void)'
22
23
  try_extern 'void gr_opengks(void)'
23
24
  try_extern 'void gr_closegks(void)'
@@ -8,7 +8,9 @@ autoload :GR3, 'gr3'
8
8
  require 'numo/narray'
9
9
 
10
10
  module GR
11
- class Plot # should be Figure ?
11
+ # This class offers a simple, matlab-style API built on top of the GR package.
12
+ # The class name Plot may be changed in the future.
13
+ class Plot
12
14
  # Why is the Plot class NOT object-oriented?
13
15
  #
14
16
  # Because the code here is mainly ported from GR.jl.
@@ -36,10 +38,10 @@ module GR
36
38
 
37
39
  # Keyword options conform to GR.jl.
38
40
  KW_ARGS = %i[accelerate algorithm alpha backgroundcolor barwidth baseline
39
- clabels color colormap figsize isovalue label labels levels
40
- location nbins rotation size tilt title where xflip xform xlabel
41
- xlim xlog yflip ylabel ylim ylog zflip zlabel zlim zlog clim
42
- subplot].freeze
41
+ clabels color colormap figsize horizontal isovalue label labels
42
+ levels location nbins rotation size tilt title where xflip
43
+ xform xlabel xlim xlog yflip ylabel ylim ylog zflip zlabel zlim
44
+ zlog clim subplot].freeze
43
45
 
44
46
  @@last_plot = nil
45
47
  def self.last_plot
@@ -397,11 +399,9 @@ module GR
397
399
  end
398
400
 
399
401
  def plot_polar(θ, ρ)
400
- ρ = Numo::DFloat.cast(ρ) if ρ.is_a? Array
401
402
  window = kvs[:window]
402
- rmin = window[2]
403
- rmax = window[3]
404
- ρ = (ρ - rmin) / (rmax - rmin)
403
+ rmax = window[3].to_f
404
+ ρ = ρ.map { |i| i / rmax }
405
405
  n = ρ.length
406
406
  x = []
407
407
  y = []
@@ -664,21 +664,18 @@ module GR
664
664
  GR.fillrect(x[i], x[i + 1], ymin, y[i])
665
665
  end
666
666
 
667
- # when :polarhist
668
- # xmin, xmax = x.minmax
669
- # ymax = kvs[:window][3]
670
- # ρ = y.map { |i| 2 * (i.to_f / ymax - 0.5) }
671
- # θ = x.map { |i| 2 * Math::PI * (i.to_f - xmin) / (xmax - xmin) }
672
- # ρ.length.times do |i|
673
- # GR.setfillcolorind(989)
674
- # GR.setfillintstyle(GR::INTSTYLE_SOLID)
675
- # GR.fillarea([0, ρ[i] * Math.cos(θ[i]), ρ[i] * Math.cos(θ[i + 1])],
676
- # [0, ρ[i] * Math.sin(θ[i]), ρ[i] * Math.sin(θ[i + 1])])
677
- # GR.setfillcolorind(1)
678
- # GR.setfillintstyle(GR::INTSTYLE_HOLLOW)
679
- # GR.fillarea([0, ρ[i] * Math.cos(θ[i]), ρ[i] * Math.cos(θ[i + 1])],
680
- # [0, ρ[i] * Math.sin(θ[i]), ρ[i] * Math.sin(θ[i + 1])])
681
- # end
667
+ when :polarhist
668
+ ymax = kvs[:window][3].to_f
669
+ ρ = y.map { |i| i / ymax }
670
+ θ = x.map { |i| i * 180 / Math::PI }
671
+ (1...ρ.length).each do |i|
672
+ GR.setfillcolorind(989)
673
+ GR.setfillintstyle(GR::INTSTYLE_SOLID)
674
+ GR.fillarc(-ρ[i], ρ[i], -ρ[i], ρ[i], θ[i - 1], θ[i])
675
+ GR.setfillcolorind(1)
676
+ GR.setfillintstyle(GR::INTSTYLE_HOLLOW)
677
+ GR.fillarc(-ρ[i], ρ[i], -ρ[i], ρ[i], θ[i - 1], θ[i])
678
+ end
682
679
 
683
680
  when :polarheatmap
684
681
  w, h = z.shape
@@ -1163,14 +1160,14 @@ module GR
1163
1160
  create_plot(:stem, *args)
1164
1161
  end
1165
1162
 
1166
- # def polarhistogram(x, kv = {})
1167
- # plt = GR::Plot.new(x, kv)
1168
- # plt.kvs[:kind] = :polarhist
1169
- # nbins = plt.kvs[:nbins] || 0
1170
- # x, y = hist(x, nbins)
1171
- # plt.args = [[x, y, nil, nil, '']]
1172
- # plt.plot_data
1173
- # end
1163
+ def polarhistogram(x, kv = {})
1164
+ plt = GR::Plot.new(x, kv)
1165
+ plt.kvs[:kind] = :polarhist
1166
+ nbins = plt.kvs[:nbins] || 0
1167
+ x, y = hist(x, nbins)
1168
+ plt.args = [[x, y, nil, nil, '']]
1169
+ plt.plot_data
1170
+ end
1174
1171
 
1175
1172
  # Draw a heatmap.
1176
1173
  def heatmap(*args)
data/lib/gr3.rb CHANGED
@@ -81,7 +81,7 @@ module GR3
81
81
  # a FFI::MemoryPointer in the GR3Base class.
82
82
  extend GR3Base
83
83
 
84
- # This module is for adding error checking to all methods in GR3
84
+ # This module is for adding error checking to all methods in GR3.
85
85
  module CheckError
86
86
  def geterror
87
87
  line = GRCommons::Fiddley::MemoryPointer.new(:int)
@@ -3,7 +3,9 @@
3
3
  require 'fiddle/import'
4
4
 
5
5
  module GR3
6
- # FFI Wrapper module for GR3
6
+ # FFI Wrapper module for GR3.
7
+ # The functions for GR3 are listed here.
8
+ # Add functions here when a new version of GR is released.
7
9
  module FFI
8
10
  extend Fiddle::Importer
9
11
 
@@ -16,8 +18,7 @@ module GR3
16
18
  extend GRCommons::Extern
17
19
 
18
20
  # https://github.com/sciapp/gr/blob/master/lib/gr3/gr3.h
19
- # Order is important.
20
-
21
+ # keep same order
21
22
  try_extern 'int gr3_init(int *attrib_list)'
22
23
  try_extern 'void gr3_free(void *pointer)'
23
24
  try_extern 'void gr3_terminate(void)'
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- # This module adds methods to the GRBase and GR3Base modules.
4
+ # This module provides a way to add FFI methods to the GRBase and GR3Base modules.
5
5
  module DefineMethods
6
6
  private
7
7
 
8
8
  def define_ffi_methods(ffi_class, prefix: '', default_type: :double)
9
9
  ffi_class.ffi_methods.each do |method|
10
- # delete_prefix (Ruby >= 2.5)
10
+ # Use delete_prefix (Ruby >= 2.5)
11
11
  method_name = method.to_s.sub(/^#{prefix}/, '')
12
12
 
13
13
  # FIXME: Refactoring required
@@ -5,9 +5,10 @@ module GRCommons
5
5
  module Extern
6
6
  attr_reader :ffi_methods
7
7
 
8
+ # Improved extern method.
8
9
  # 1. Ignore functions that cannot be attached.
9
- # For compatiblity with older versions of GR.
10
10
  # 2. Available function (names) are stored in @ffi_methods.
11
+ # For compatiblity with older versions of GR.
11
12
  def try_extern(signature, *opts)
12
13
  @ffi_methods ||= []
13
14
  begin
@@ -1,18 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Fiddley v0.0.8
4
- # https://github.com/unak/fiddley
5
- #
6
- # Copyright (c) 2017 NAKAMURA Usaku usa@garbagecollect.jp
7
- #
8
- # Released under the 2-Clause BSD License.
9
-
10
- # NOTE: kojix2 added, removed, and modified several methods.
11
-
12
3
  require 'fiddle/import'
13
4
 
14
5
  module GRCommons
15
- # Ruby-FFI compatible API layer for Fiddle.
6
+ # Fiddley v0.0.8
7
+ # https://github.com/unak/fiddley
8
+ #
9
+ # Copyright (c) 2017 NAKAMURA Usaku usa@garbagecollect.jp
10
+ #
11
+ # Released under the 2-Clause BSD License.
12
+ #
13
+ # NOTE: This module is only part of the original code.
14
+ # kojix2 adds, deletes, and modifies several methods.
16
15
  module Fiddley
17
16
  # NOTE: GR.rb supports 2.4 +. Unpack 1 does not work under 2.3.
18
17
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Module with common code for GR, GR3
3
+ # Module with common code for GR, GR3.
4
4
  module GRCommons
5
5
  end
6
6
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.13'
4
+ VERSION = '0.0.14'
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.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-01 00:00:00.000000000 Z
11
+ date: 2020-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler