multiarray 0.9.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/multiarray/node.rb +4 -0
- data/lib/multiarray/operations.rb +21 -0
- data/test/tc_sequence.rb +5 -0
- metadata +4 -4
data/Rakefile
CHANGED
data/lib/multiarray/node.rb
CHANGED
@@ -252,6 +252,27 @@ module Hornetseye
|
|
252
252
|
min .. max
|
253
253
|
end
|
254
254
|
|
255
|
+
def normalise( range = 0 .. 0xFF )
|
256
|
+
if range.exclude_end?
|
257
|
+
raise "Normalisation does not support ranges with end value " +
|
258
|
+
"excluded (such as #{range})"
|
259
|
+
end
|
260
|
+
lower, upper = min, max
|
261
|
+
if lower.is_a? RGB or upper.is_a? RGB
|
262
|
+
current = [ lower.r, lower.g, lower.b ].min ..
|
263
|
+
[ upper.r, upper.g, upper.b ].max
|
264
|
+
else
|
265
|
+
current = min .. max
|
266
|
+
end
|
267
|
+
if current.last != current.first
|
268
|
+
factor =
|
269
|
+
( range.last - range.first ).to_f / ( current.last - current.first )
|
270
|
+
self * factor + ( range.first - current.first * factor )
|
271
|
+
else
|
272
|
+
self + ( range.first - current.first )
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
255
276
|
def fill!( value = typecode.default )
|
256
277
|
self[] = value
|
257
278
|
self
|
data/test/tc_sequence.rb
CHANGED
@@ -302,6 +302,11 @@ class TC_Sequence < Test::Unit::TestCase
|
|
302
302
|
assert_equal C( 3, 2, 3 ), S[ C( 1, 2, 3 ), C( 3, 2, 1 ) ].max
|
303
303
|
end
|
304
304
|
|
305
|
+
def test_normalise
|
306
|
+
assert_equal [ 0.0, 85.0, 255.0 ], S[ 1, 2, 4 ].normalise.to_a
|
307
|
+
assert_equal [ C( 0.0, 85.0, 255.0 ) ], S[ C( 1, 2, 4 ) ].normalise.to_a
|
308
|
+
end
|
309
|
+
|
305
310
|
def test_sum
|
306
311
|
[ S( O, 3 ), S( I, 3 ) ].each do |t|
|
307
312
|
assert_equal 9, t[ 4, 2, 3 ].sum
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 10
|
8
|
+
- 1
|
9
|
+
version: 0.10.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jan Wedekind
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-13 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|