is 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ is-*
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.2
4
+
5
+ * Added methods `#select` and `#first`
6
+
3
7
  ## 0.0.1
4
8
 
5
9
  * Init version
@@ -1,70 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gon (4.0.0)
5
- actionpack (>= 2.3.0)
6
- json
4
+ is (0.0.1)
7
5
 
8
6
  GEM
9
7
  remote: http://rubygems.org/
10
8
  specs:
11
- actionpack (3.2.3)
12
- activemodel (= 3.2.3)
13
- activesupport (= 3.2.3)
14
- builder (~> 3.0.0)
15
- erubis (~> 2.7.0)
16
- journey (~> 1.0.1)
17
- rack (~> 1.4.0)
18
- rack-cache (~> 1.2)
19
- rack-test (~> 0.6.1)
20
- sprockets (~> 2.1.2)
21
- activemodel (3.2.3)
22
- activesupport (= 3.2.3)
23
- builder (~> 3.0.0)
24
- activesupport (3.2.3)
25
- i18n (~> 0.6)
26
- multi_json (~> 1.0)
27
- blankslate (2.1.2.4)
28
- builder (3.0.0)
29
9
  diff-lcs (1.1.3)
30
- erubis (2.7.0)
31
- hike (1.2.1)
32
- i18n (0.6.0)
33
- jbuilder (0.4.0)
34
- activesupport (>= 3.0.0)
35
- blankslate (>= 2.1.2.4)
36
- journey (1.0.4)
37
- json (1.7.3)
38
- multi_json (1.2.0)
39
- rabl (0.6.9)
40
- activesupport (>= 2.3.14)
41
- multi_json (~> 1.0)
42
- rack (1.4.1)
43
- rack-cache (1.2)
44
- rack (>= 0.4)
45
- rack-test (0.6.1)
46
- rack (>= 1.0)
47
10
  rake (0.9.2.2)
48
- rspec (2.10.0)
49
- rspec-core (~> 2.10.0)
50
- rspec-expectations (~> 2.10.0)
51
- rspec-mocks (~> 2.10.0)
52
- rspec-core (2.10.1)
53
- rspec-expectations (2.10.0)
11
+ rspec (2.11.0)
12
+ rspec-core (~> 2.11.0)
13
+ rspec-expectations (~> 2.11.0)
14
+ rspec-mocks (~> 2.11.0)
15
+ rspec-core (2.11.1)
16
+ rspec-expectations (2.11.3)
54
17
  diff-lcs (~> 1.1.3)
55
- rspec-mocks (2.10.1)
56
- sprockets (2.1.3)
57
- hike (~> 1.2)
58
- rack (~> 1.0)
59
- tilt (~> 1.1, != 1.3.0)
60
- tilt (1.3.3)
18
+ rspec-mocks (2.11.3)
61
19
 
62
20
  PLATFORMS
63
21
  ruby
64
22
 
65
23
  DEPENDENCIES
66
- gon!
67
- jbuilder
68
- rabl
24
+ is!
69
25
  rake
70
26
  rspec
data/README.md CHANGED
@@ -21,6 +21,8 @@ Is.point(pt).in?(area) # => true
21
21
  Is.all_points(all_pts).in?(area) # => true
22
22
  Is.any_points(any_pts).in?(area) # => true
23
23
  Is.any_points(no_pts).in?(area) # => false
24
+ Is.select(any_pts).in(area) # => [[2, 2]]
25
+ Is.first(any_pts).in(area) # => [[2, 2]]
24
26
 
25
27
  # or
26
28
  Is.point_in_area?(pt, area) # => true
data/is.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_development_dependency "rspec"
23
+ s.add_development_dependency "rake"
23
24
  end
data/lib/is.rb CHANGED
@@ -10,11 +10,11 @@ class Is
10
10
  end
11
11
 
12
12
  def all_points(points)
13
- pts = points.map { |it| Point.new *it }
13
+ pts = points.clone
14
14
 
15
15
  pts.define_singleton_method :in?, ->(area) do
16
16
  area = Area.new area
17
- all? { |point| point.in? area }
17
+ all? { |point| Point.new(*point).in? area }
18
18
  end
19
19
 
20
20
  pts
@@ -22,11 +22,33 @@ class Is
22
22
  alias :points :all_points
23
23
 
24
24
  def any_points(points)
25
- pts = points.map { |it| Point.new *it }
25
+ pts = points.clone
26
26
 
27
27
  pts.define_singleton_method :in?, ->(area) do
28
28
  area = Area.new area
29
- any? { |point| point.in? area }
29
+ any? { |point| Point.new(*point).in? area }
30
+ end
31
+
32
+ pts
33
+ end
34
+
35
+ def select(points)
36
+ pts = points.clone
37
+
38
+ pts.define_singleton_method :in, ->(area) do
39
+ area = Area.new area
40
+ select { |point| Point.new(*point).in? area }
41
+ end
42
+
43
+ pts
44
+ end
45
+
46
+ def first(points)
47
+ pts = points.clone
48
+
49
+ pts.define_singleton_method :in, ->(area) do
50
+ area = Area.new area
51
+ find { |point| Point.new(*point).in? area }
30
52
  end
31
53
 
32
54
  pts
@@ -44,6 +66,14 @@ class Is
44
66
  any_points(points).in?(area)
45
67
  end
46
68
 
69
+ def select_points_in_area(points, area)
70
+ select(points).in(area)
71
+ end
72
+
73
+ def first_point_in_area(points, area)
74
+ first(points).in(area)
75
+ end
76
+
47
77
  end
48
78
 
49
79
  end
@@ -51,21 +51,21 @@ class Is
51
51
 
52
52
  def bounding_box
53
53
  {
54
- 'left' => area.min{|a, b| a.longitude <=> b.longitude}.longitude,
55
- 'right' => area.max{|a, b| a.longitude <=> b.longitude}.longitude,
56
- 'top' => area.max{|a, b| a.latitude <=> b.latitude}.latitude,
54
+ 'left' => area.min{|a, b| a.longitude <=> b.longitude}.longitude,
55
+ 'right' => area.max{|a, b| a.longitude <=> b.longitude}.longitude,
56
+ 'top' => area.max{|a, b| a.latitude <=> b.latitude}.latitude,
57
57
  'bottom' => area.min{|a, b| a.latitude <=> b.latitude}.latitude
58
58
  }
59
59
  end
60
60
 
61
61
  def outside_box?(point)
62
- if point.nil? || point.longitude.nil? || point.latitude.nil?
62
+ if point.nil? or point.longitude.nil? or point.latitude.nil?
63
63
  true
64
64
  else
65
65
  box = bounding_box
66
- point.longitude < box['left'] ||
67
- point.longitude > box['right'] ||
68
- point.latitude < box['bottom'] ||
66
+ point.longitude < box['left'] or
67
+ point.longitude > box['right'] or
68
+ point.latitude < box['bottom'] or
69
69
  point.latitude > box['top']
70
70
  end
71
71
  end
@@ -1,5 +1,5 @@
1
1
  class Is
2
2
 
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
 
5
5
  end
@@ -52,6 +52,42 @@ describe Is do
52
52
 
53
53
  end
54
54
 
55
+ describe '#select' do
56
+
57
+ it 'points in area' do
58
+ points = [[2, 0], [2, 2.5], [2.5, 2.25]]
59
+ Is.select(points).in(AREA).should == [[2, 2.5], [2.5, 2.25]]
60
+ end
61
+
62
+ end
63
+
64
+ describe '#first' do
65
+
66
+ it 'point in area' do
67
+ points = [[2, 0], [2, 2.5], [2.5, 2.25]]
68
+ Is.first(points).in(AREA).should == [2, 2.5]
69
+ end
70
+
71
+ end
72
+
73
+ describe '#select_points_in_area' do
74
+
75
+ it 'points in area' do
76
+ points = [[2, 0], [2, 2.5], [2.5, 2.25]]
77
+ Is.select_points_in_area(points, AREA).should == [[2, 2.5], [2.5, 2.25]]
78
+ end
79
+
80
+ end
81
+
82
+ describe '#first_point_in_area' do
83
+
84
+ it 'point in area' do
85
+ points = [[2, 0], [2, 2.5], [2.5, 2.25]]
86
+ Is.first_point_in_area(points, AREA).should == [2, 2.5]
87
+ end
88
+
89
+ end
90
+
55
91
  describe '#point_in_area?' do
56
92
 
57
93
  it 'is inside area' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: is
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-04 00:00:00.000000000 Z
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Simple small tool for finding points in polygon
31
47
  email:
32
48
  - alex.gaziev@gmail.com
@@ -34,6 +50,8 @@ executables: []
34
50
  extensions: []
35
51
  extra_rdoc_files: []
36
52
  files:
53
+ - .gitignore
54
+ - .travis.yml
37
55
  - CHANGELOG.md
38
56
  - Gemfile
39
57
  - Gemfile.lock