libpuzzle 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: de07b8f796b345b3b285a59bb81915cbcc15babb
4
- data.tar.gz: 1430d9c7072d2f10201e5c0d7c0c542cf1e4ff67
3
+ metadata.gz: 61fff184af161b5377a6694aabd10ac0ba055d8e
4
+ data.tar.gz: d9b307424e770443fc1e3bc2d6489f53494146cf
5
5
  SHA512:
6
- metadata.gz: 86381650ff903e1c93143c666c480dda691c57359f518f2da21349cbee7ecc83407631d3a486e1f262dbf9891615880e7979fe655a5674af6ede9f5a4effb613
7
- data.tar.gz: af2ea94a849e346d2ce75e4e12ede2337f8d29244a029a40f9ab3f121bb0f73f5c77b0adb6960b48a55b9ba7dfe6b235b1a135ab92669e27bea4214d7494bd96
6
+ metadata.gz: f3f9271ab2cc92f18fbbef4bf72c5cd01d3437b7a47210f3bdd63d9a808e77167690249a5014833327a661f6adc8c09841fd3c028629f7e6b08a66419a516ad6
7
+ data.tar.gz: a832703673a611fc3fe1ffb900d9b8b54c1a2fe50a99fbb6ec06763aca6d63a777e22e8cac5b4a188ec7d6e840721202afa516859f651dcbd302cbd307b03adb
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mkmf'
2
3
  have_library('puzzle')
3
4
  have_header('puzzle.h')
@@ -42,8 +42,22 @@ static VALUE distance(VALUE p1, VALUE p2){
42
42
  return rb_float_new(_distance(p1, p2));
43
43
  }
44
44
 
45
- static VALUE equal(VALUE p1, VALUE p2){
46
- return _distance(p1, p2) < 0.6 ? Qtrue : Qfalse;
45
+ static VALUE similar(int argc, VALUE *argv, VALUE self){
46
+ VALUE puzzle, opt;
47
+ double threshold = 0.6;
48
+
49
+ rb_scan_args(argc, argv, "1:", &puzzle, &opt);
50
+
51
+ if (!NIL_P(opt)) {
52
+ VALUE rb_threshold = rb_hash_aref(opt, ID2SYM(rb_intern("threshold")));
53
+ if(RB_FLOAT_TYPE_P(rb_threshold)) threshold = NUM2DBL(rb_threshold);
54
+ }
55
+ return _distance(self, puzzle) < threshold ? Qtrue : Qfalse;
56
+ }
57
+
58
+ static VALUE equal(int argc, VALUE *argv, VALUE str){
59
+ rb_warn("Puzzle#== is deprecated; use #similar? instead");
60
+ return similar(argc, argv, str);
47
61
  }
48
62
 
49
63
  static VALUE compress(VALUE self){
@@ -83,6 +97,7 @@ void Init_puzzle_ext(void){
83
97
  rb_define_singleton_method(rb_cPuzzle, "new", new, 1);
84
98
  rb_define_singleton_method(rb_cPuzzle, "uncompress", uncompress, 1);
85
99
  rb_define_method(rb_cPuzzle, "distance", distance, 1);
86
- rb_define_method(rb_cPuzzle, "==", equal, 1);
100
+ rb_define_method(rb_cPuzzle, "==", equal, -1);
101
+ rb_define_method(rb_cPuzzle, "similar?", similar, -1);
87
102
  rb_define_method(rb_cPuzzle, "compress", compress, 0);
88
- }
103
+ }
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  require 'puzzle_ext'
2
- require 'puzzle/version'
3
+ require 'puzzle/version'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Puzzle
2
- VERSION = '1.0.3'
3
- end
3
+ VERSION = '1.0.4'
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libpuzzle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jian Weihang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.4.6
101
+ rubygems_version: 2.6.4
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: A library to find similar pictures with libpuzzle