proxbox 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/proxbox.rb +103 -103
- data/lib/proxbox/version.rb +3 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09c8581fac016b3d42629e9a1134d634c20bf45d
|
4
|
+
data.tar.gz: 5ba1565b43855f1348d0153cc66500a097708fe9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dccf659c1685bc9e1471c0775ad9d1832108edd9fd69fc741663c2cb604169fb89c26de4d4cc6c7b574c6f9e6b75d3afc148bee938eb9ab2884e6c5db32ce5d
|
7
|
+
data.tar.gz: 89a884488cb9a0d8e0f2c8c344e7f8902229c7463c1ca8d30caf669f3d0982e15eac15e0a513e84d9ec35d48c0e3e0e9985a3bd31c30525c8c2653edb25bcce1
|
data/lib/proxbox.rb
CHANGED
@@ -28,106 +28,106 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
class ProxBox
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
data/lib/proxbox/version.rb
CHANGED
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.
|
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:
|
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://
|
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.
|
42
|
+
rubygems_version: 2.5.0
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
45
|
summary: Proximity Box Detector
|