gem_with_extension_example 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
|
|
1
|
+
require 'gem_with_extension_example/infinity_check_c'
|
1
2
|
require 'gem_with_extension_example/base'
|
2
3
|
require 'gem_with_extension_example/grid'
|
3
|
-
require 'gem_with_extension_example/timer'
|
4
|
-
require 'gem_with_extension_example/util'
|
4
|
+
require 'gem_with_extension_example/timer'
|
@@ -2,28 +2,28 @@ require 'complex'
|
|
2
2
|
|
3
3
|
class Grid
|
4
4
|
attr_reader :width, :height
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(width, height, default_value = nil)
|
7
7
|
@width = width
|
8
8
|
@height = height
|
9
9
|
@default_value = default_value
|
10
10
|
@grid = create(width, height, default_value)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def [](x,y)
|
14
14
|
if (x < 0 or x >= @width) or (y < 0 or y >= @height)
|
15
15
|
throw Error("Grid index out of bounds. [%d][%d] not in range ([0 through %d][0 through %d])" % [x, y, width - 1, height - 1])
|
16
16
|
end
|
17
17
|
@grid[x][y]
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def []=(x,y,a)
|
21
21
|
if (x < 0 or x >= @width) or (y < 0 or y >= @height)
|
22
22
|
throw Error("Grid index out of bounds. [%d][%d] not in range ([0 through %d][0 through %d])" % [x, y, width - 1, height - 1])
|
23
23
|
end
|
24
24
|
@grid[x][y] = a
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def clear(value=nil)
|
28
28
|
(0...@width).each do |xi|
|
29
29
|
(0...@height).each do |yi|
|
@@ -31,22 +31,22 @@ class Grid
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def to_s
|
36
36
|
s = ""
|
37
37
|
@grid.each{|c| s << c.to_s << "\n"}
|
38
38
|
return s
|
39
39
|
end
|
40
|
-
|
41
|
-
def each_col
|
42
|
-
@grid.each{|c| yield c.dup}
|
43
|
-
end
|
44
|
-
|
45
|
-
def each
|
46
|
-
@grid.each do |c|
|
47
|
-
c.each{|i| yield i}
|
48
|
-
end
|
49
|
-
end
|
40
|
+
|
41
|
+
def each_col
|
42
|
+
@grid.each{|c| yield c.dup}
|
43
|
+
end
|
44
|
+
|
45
|
+
def each
|
46
|
+
@grid.each do |c|
|
47
|
+
c.each{|i| yield i}
|
48
|
+
end
|
49
|
+
end
|
50
50
|
|
51
51
|
# Generate a two dimensional grid of float pairs, evenly
|
52
52
|
# distributed across width x height samples
|
@@ -57,11 +57,11 @@ class Grid
|
|
57
57
|
|
58
58
|
width_limit = Float(@width - 1)
|
59
59
|
height_limit = Float(@height - 1)
|
60
|
-
|
60
|
+
|
61
61
|
(0...@width).each do |xi|
|
62
62
|
x_unit = Float(xi) / width_limit
|
63
63
|
x = x0 + (x_unit * x_range)
|
64
|
-
|
64
|
+
|
65
65
|
(0...@height).each do |yi|
|
66
66
|
y_unit = Float(yi) / height_limit
|
67
67
|
y = y0 + (y_unit * y_range)
|
@@ -73,14 +73,14 @@ class Grid
|
|
73
73
|
|
74
74
|
def fill_test()
|
75
75
|
t = 0
|
76
|
-
@grid.each_with_index do |c, x|
|
77
|
-
c.each_with_index{|i, y| @grid[x][y] = t; t += 1}
|
78
|
-
end
|
76
|
+
@grid.each_with_index do |c, x|
|
77
|
+
c.each_with_index{|i, y| @grid[x][y] = t; t += 1}
|
78
|
+
end
|
79
79
|
end
|
80
80
|
|
81
81
|
#------------------------------------------
|
82
82
|
private
|
83
|
-
|
83
|
+
|
84
84
|
def create(width, height, default_value)
|
85
85
|
grid = Array.new(width){[]}
|
86
86
|
(0...width).each do |xi|
|
@@ -88,7 +88,7 @@ class Grid
|
|
88
88
|
end
|
89
89
|
return grid
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
end
|
93
93
|
|
94
94
|
RUN_TEST = false
|
@@ -103,7 +103,7 @@ if RUN_TEST
|
|
103
103
|
p grid[0,0]
|
104
104
|
p grid[1,1]
|
105
105
|
|
106
|
-
puts "-" * 9
|
106
|
+
puts "-" * 9
|
107
107
|
grid[0,0] = [5.0,2.0]
|
108
108
|
grid[1,1] = [7.0,9.0]
|
109
109
|
|
@@ -117,21 +117,21 @@ if RUN_TEST
|
|
117
117
|
grid.fill_complex(-2.0, -1.0, 1.0, 1.0)
|
118
118
|
puts "-" * 9
|
119
119
|
p grid
|
120
|
-
|
120
|
+
|
121
121
|
grid.clear(0)
|
122
122
|
puts "-" * 9
|
123
123
|
p grid
|
124
|
-
|
124
|
+
|
125
125
|
grid.fill_test
|
126
126
|
puts "-" * 9
|
127
127
|
p grid
|
128
|
-
|
128
|
+
|
129
129
|
puts "-" * 9
|
130
130
|
grid.each{|c| p c}
|
131
|
-
|
131
|
+
|
132
132
|
puts "-" * 9
|
133
133
|
grid.each_col{|c| p c}
|
134
|
-
|
134
|
+
|
135
135
|
puts "-" * 9
|
136
136
|
p grid
|
137
137
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_with_extension_example
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-10 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164571060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164571060
|
25
25
|
description: This gem is intended to function as a starting point for developing gems
|
26
26
|
that contain C optimizations.
|
27
27
|
email:
|
@@ -61,5 +61,5 @@ rubyforge_project: gem_with_extension_example
|
|
61
61
|
rubygems_version: 1.8.11
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
|
-
summary: An example gem with a C
|
64
|
+
summary: An example gem with a C extension.
|
65
65
|
test_files: []
|