proxbox 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/proxbox.rb +103 -103
  3. data/lib/proxbox/version.rb +3 -1
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 603f1b5ab9c36a29c05331a25519ff9ad3b8d158
4
- data.tar.gz: ffd203e5f31c037b8352b36439a688bb73492cc0
3
+ metadata.gz: 09c8581fac016b3d42629e9a1134d634c20bf45d
4
+ data.tar.gz: 5ba1565b43855f1348d0153cc66500a097708fe9
5
5
  SHA512:
6
- metadata.gz: fb5ddf6112d29217b7c8dea166db860e16cfbe198d20e8b7952d1f3407f6b299164a2488e0d1da0dd07cc1c4a192dbe1f33795a74bfc60494c5a7c1dc2851c6d
7
- data.tar.gz: 3faaab4a3de8c0d71dfe016e8ad03c8e0ff8138440066801d00f1c219539acdccba895f47be960c6aeecb8346e840e1dc9a8320779a3e1ece96d54967f74ee10
6
+ metadata.gz: 5dccf659c1685bc9e1471c0775ad9d1832108edd9fd69fc741663c2cb604169fb89c26de4d4cc6c7b574c6f9e6b75d3afc148bee938eb9ab2884e6c5db32ce5d
7
+ data.tar.gz: 89a884488cb9a0d8e0f2c8c344e7f8902229c7463c1ca8d30caf669f3d0982e15eac15e0a513e84d9ec35d48c0e3e0e9985a3bd31c30525c8c2653edb25bcce1
@@ -28,106 +28,106 @@
28
28
 
29
29
 
30
30
  class ProxBox
31
- attr_accessor :pbox
32
-
33
- def initialize( params = {} )
34
- @pbox = params.fetch(:pbox, nil)
35
- if !!@pbox
36
- raise "Invalid list of layout details!" unless @pbox.all? { |grid, obj|
37
- grid.all? { |layout|
38
- layout.is_a?(Fixnum)
39
- } && grid.length == 4
40
- }
41
- @pbox = pop_relationships(@pbox)
42
- end
43
- end
44
-
45
- def pop_relationships(everything)
46
- raise "Incorrect Array length(s)! Each must be 2 in length!" unless everything.all? {|i| i.length == 2}
47
- everything.each_with_index { |item, index|
48
- everything.each_with_index { |sectem, secdex|
49
- unless index == secdex
50
- everything[index][2] = Array(everything[index][2]) << overall_relationship(item[0],sectem[0])
51
- else
52
- everything[index][2] = Array(everything[index][2]) << nil
53
- end
54
- }
55
- }
56
- everything
57
- end
58
-
59
- def euclidean_distance(a,b)
60
- raise "Array's required!" unless a.is_a?(Array) && b.is_a?(Array)
61
- raise "Array's must contain Integers!" unless [a,b].all? {|h| h.all? {|i| i.is_a?(Fixnum)} }
62
- Math.sqrt(a.zip(b).map { |x| (x[1] - x[0])**2 }.reduce(:+))
63
- end
64
-
65
- def two_dimension_compare(a,b)
66
- tdep = two_dimension_edge_points(a,b)
67
- {
68
- # :horizontal => [1<->2, 2<->1, 3<->4, 4<->3]
69
- :horizontal => [
70
- euclidean_distance( *tdep[:horizontal][0] ),
71
- euclidean_distance( *tdep[:horizontal][1] ),
72
- euclidean_distance( *tdep[:horizontal][2] ),
73
- euclidean_distance( *tdep[:horizontal][3] )
74
- ],
75
-
76
- # :vertical => [1<->3, 2<->4, 3<->1, 4<->2]
77
- :vertical => [
78
- euclidean_distance( *tdep[:vertical][0] ),
79
- euclidean_distance( *tdep[:vertical][1] ),
80
- euclidean_distance( *tdep[:vertical][2] ),
81
- euclidean_distance( *tdep[:vertical][3] )
82
- ]
83
- }
84
- end
85
-
86
- def two_dimension_edge_points(a,b)
87
- a = Array four_points(*a)
88
- b = Array four_points(*b)
89
- {
90
- # :horizontal => [1<->2, 2<->1, 3<->4, 4<->3]
91
- :horizontal => [
92
- [ a[0..1], [b[2],b[1]] ],
93
- [ [a[2],a[1]], b[0..1] ],
94
- [ [a[0],a[3]], b[2..3] ],
95
- [ a[2..3], [b[0],b[3]] ]
96
- ],
97
-
98
- # :vertical => [1<->3, 2<->4, 3<->1, 4<->2]
99
- :vertical => [
100
- [ a[0..1], [b[0],b[3]] ],
101
- [ [a[2],a[1]], b[2..3] ],
102
- [ [a[0],a[3]], b[0..1] ],
103
- [ a[2..3], [b[2],b[1]] ]
104
- ]
105
- }
106
- end
107
-
108
- def strongest_relationship(arr)
109
- closest_by_value(arr)
110
- end
111
-
112
- def four_points(x,y,width,height)
113
- Array( [x,y,x+width,y+height] )
114
- end
115
-
116
- def closest_by_value(array_points, value = 0)
117
- array_points.min_by { |x| (x.to_f - value).abs }
118
- end
119
-
120
- def closest_by_index(array_points, value = 0)
121
- array_points.index (
122
- closest_by_value(array_points, value)
123
- )
124
- end
125
-
126
- def overall_relationship(a,b)
127
- hash = two_dimension_compare(a,b)
128
- closest_by_value(
129
- [ closest_by_value( hash[ :vertical ] ),
130
- closest_by_value( hash[ :horizontal ] ) ]
131
- )
132
- end
133
- end
31
+ attr_accessor :pbox
32
+
33
+ def initialize( params = {} )
34
+ @pbox = params.fetch(:pbox, nil)
35
+ if !!@pbox
36
+ raise "Invalid list of layout details!" unless @pbox.all? { |grid, obj|
37
+ grid.all? { |layout|
38
+ layout.is_a?(Fixnum)
39
+ } && grid.length == 4
40
+ }
41
+ @pbox = pop_relationships(@pbox)
42
+ end
43
+ end
44
+
45
+ def pop_relationships(everything)
46
+ raise "Incorrect Array length(s)! Each must be 2 in length!" unless everything.all? {|i| i.length == 2}
47
+ everything.each_with_index { |item, index|
48
+ everything.each_with_index { |sectem, secdex|
49
+ unless index == secdex
50
+ everything[index][2] = Array(everything[index][2]) << overall_relationship(item[0],sectem[0])
51
+ else
52
+ everything[index][2] = Array(everything[index][2]) << nil
53
+ end
54
+ }
55
+ }
56
+ everything
57
+ end
58
+
59
+ def euclidean_distance(a,b)
60
+ raise "Array's required!" unless a.is_a?(Array) && b.is_a?(Array)
61
+ raise "Array's must contain Integers!" unless [a,b].all? {|h| h.all? {|i| i.is_a?(Fixnum)} }
62
+ Math.sqrt(a.zip(b).map { |x| (x[1] - x[0])**2 }.reduce(:+))
63
+ end
64
+
65
+ def two_dimension_compare(a,b)
66
+ tdep = two_dimension_edge_points(a,b)
67
+ {
68
+ # :horizontal => [1<->2, 2<->1, 3<->4, 4<->3]
69
+ :horizontal => [
70
+ euclidean_distance( *tdep[:horizontal][0] ),
71
+ euclidean_distance( *tdep[:horizontal][1] ),
72
+ euclidean_distance( *tdep[:horizontal][2] ),
73
+ euclidean_distance( *tdep[:horizontal][3] )
74
+ ],
75
+
76
+ # :vertical => [1<->3, 2<->4, 3<->1, 4<->2]
77
+ :vertical => [
78
+ euclidean_distance( *tdep[:vertical][0] ),
79
+ euclidean_distance( *tdep[:vertical][1] ),
80
+ euclidean_distance( *tdep[:vertical][2] ),
81
+ euclidean_distance( *tdep[:vertical][3] )
82
+ ]
83
+ }
84
+ end
85
+
86
+ def two_dimension_edge_points(a,b)
87
+ a = Array four_points(*a)
88
+ b = Array four_points(*b)
89
+ {
90
+ # :horizontal => [1<->2, 2<->1, 3<->4, 4<->3]
91
+ :horizontal => [
92
+ [ a[0..1], [b[2],b[1]] ],
93
+ [ [a[2],a[1]], b[0..1] ],
94
+ [ [a[0],a[3]], b[2..3] ],
95
+ [ a[2..3], [b[0],b[3]] ]
96
+ ],
97
+
98
+ # :vertical => [1<->3, 2<->4, 3<->1, 4<->2]
99
+ :vertical => [
100
+ [ a[0..1], [b[0],b[3]] ],
101
+ [ [a[2],a[1]], b[2..3] ],
102
+ [ [a[0],a[3]], b[0..1] ],
103
+ [ a[2..3], [b[2],b[1]] ]
104
+ ]
105
+ }
106
+ end
107
+
108
+ def strongest_relationship(arr)
109
+ closest_by_value(arr)
110
+ end
111
+
112
+ def four_points(x,y,width,height)
113
+ Array( [x,y,x+width,y+height] )
114
+ end
115
+
116
+ def closest_by_value(array_points, value = 0)
117
+ array_points.min_by { |x| (x.to_f - value).abs }
118
+ end
119
+
120
+ def closest_by_index(array_points, value = 0)
121
+ array_points.index (
122
+ closest_by_value(array_points, value)
123
+ )
124
+ end
125
+
126
+ def overall_relationship(a,b)
127
+ hash = two_dimension_compare(a,b)
128
+ closest_by_value(
129
+ [ closest_by_value( hash[ :vertical ] ),
130
+ closest_by_value( hash[ :horizontal ] ) ]
131
+ )
132
+ end
133
+ end
@@ -1,7 +1,9 @@
1
1
  class ProxBox
2
2
  #:nodoc:
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
 
6
+ # Version 0.0.2
7
+ # * Source Release
6
8
  # Version 0.0.1
7
9
  # * First Release
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark / 6ftDan(TM)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-30 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Proximity Box Detector. Relationship by closeness.
14
14
  email: webmaster@6ftdan.com
@@ -19,7 +19,7 @@ files:
19
19
  - LICENSE
20
20
  - lib/proxbox.rb
21
21
  - lib/proxbox/version.rb
22
- homepage: https://rubygems.org/gems/proxbox
22
+ homepage: https://bitbucket.org/danielpclark/proxbox
23
23
  licenses:
24
24
  - Attribution-NonCommercial-NoDerivatives 4.0 International
25
25
  metadata: {}
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  version: '0'
40
40
  requirements: []
41
41
  rubyforge_project:
42
- rubygems_version: 2.3.0
42
+ rubygems_version: 2.5.0
43
43
  signing_key:
44
44
  specification_version: 4
45
45
  summary: Proximity Box Detector