geo_magic 0.2.1.1 → 0.2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -81,7 +81,27 @@ I have also just created a Geocode adapter for _Geocode_ and _Graticule_ (see: _
81
81
 
82
82
  h3. Create random points in Radius
83
83
 
84
- @create_points_in_square@ works, but @create_points_in_circle@ is currently broken. Please help fix this ASAP ;) Thanks!
84
+ * @create_points_in_square@
85
+ * @create_points_in_circle@
86
+
87
+ h3. Points within an area or distance
88
+
89
+ Within distance:
90
+
91
+ <pre>@points.as_map_points.within_distance 4.km, :from => @center_point</pre>
92
+
93
+ The closest n:
94
+
95
+ <pre>@points.as_map_points.the_closest 4, :from => @center_point</pre>
96
+
97
+ Within bounding rectangle:
98
+
99
+ <pre>rectangle = GeoMagic::Rectangle.new(GeoMagic::Point.new(-115, 50), GeoMagic::Point.new(-100, 20))
100
+ # or
101
+ # rect = GeoMagic::Rectangle.create_from_coords lat1, long1, lat2, long2
102
+ @points.as_map_points.within_rectangle rect, :from => @center_point
103
+
104
+ </pre>
85
105
 
86
106
  h2. Meta magic
87
107
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1.1
1
+ 0.2.1.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geo_magic}
8
- s.version = "0.2.1.1"
8
+ s.version = "0.2.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
@@ -6,6 +6,10 @@ module GeoMagic
6
6
  @top_left_point = GeoMagic::Point.new left_lat(point_a, point_b), bot_long(point_a, point_b)
7
7
  @bottom_right_point = GeoMagic::Point.new right_lat(point_a, point_b), top_long(point_a, point_b)
8
8
  end
9
+
10
+ def create_from_coords lat1, long1, lat2, long2
11
+ self.new GeoMagic::Point.new(lat1, long1), GeoMagic::Point.new(lat2, long2)
12
+ end
9
13
 
10
14
  def overlaps? point
11
15
  # puts "inside_top_left?: #{point} -> #{inside_top_left?(point)}"
@@ -39,7 +39,7 @@ module GeoMagic
39
39
  {:km => 6371, :miles => 3956, :feet => 20895592, :meters => 6371000}
40
40
  end
41
41
 
42
- def get_within dist_obj, options = {:precision => :lowest}
42
+ def within_distance dist_obj, options = {:precision => :lowest}
43
43
  calc_method = get_proc(options[:precision] || :normal)
44
44
  from_loc = get_location get_dist_obj(options[:from])
45
45
 
@@ -58,13 +58,13 @@ module GeoMagic
58
58
  res
59
59
  end
60
60
 
61
- def get_within_rect rectangle
61
+ def within_rectangle rectangle
62
62
  self.select do |point|
63
63
  rectangle.overlaps? point
64
64
  end
65
65
  end
66
66
 
67
- def get_closest number, options = {}
67
+ def the_closest number, options = {}
68
68
  calc_method = get_proc(options[:precision] || :normal)
69
69
  from_loc = get_location options[:from]
70
70
  populate_distance(calc_method, from_loc).sort_by_distance[0..number]
@@ -37,33 +37,44 @@ describe "GeoMagic closest" do
37
37
  @long1 = -104.88544
38
38
  @lat1 = 39.06546
39
39
 
40
- @center_point = GeoMagic::Point.new @long1, @lat1
40
+ @center_point = GeoMagic::Point.new @long1, @lat1
41
41
  @radius = @center_point.within(10.km)
42
42
  @points = @radius.create_points_in_square 10
43
+
44
+ @circle_points = @radius.create_points_in_square 4
43
45
  end
44
46
 
45
47
 
46
- # it "should select the closest 3 points" do
47
- # # puts "radius: #{@radius.inspect}"
48
- # # puts "points: #{@points.inspect}"
49
- # closest = @points.as_map_points.get_closest 3, :from => @center_point
50
- # puts "3 closest points: #{closest.inspect}"
51
- # end
52
- #
53
- it "should select all points within 4 km" do
48
+ it "should select the closest 3 points" do
49
+ # puts "radius: #{@radius.inspect}"
50
+ # puts "points: #{@points.inspect}"
51
+ closest = @points.as_map_points.the_closest 3, :from => @center_point
52
+ puts "3 closest points: #{closest.inspect}"
53
+ end
54
+
55
+ it "should select all points within 5 km" do
54
56
  # puts "radius: #{@radius.inspect}"
55
57
  # puts "points: #{@points.inspect}"
56
- closest = @points.as_map_points.get_within 4.km, :from => @center_point
58
+ closest = @points.as_map_points.within_distance 5.km, :from => @center_point
57
59
  puts "points within 4 km: #{closest.inspect}"
58
60
  end
59
61
 
62
+ it "should select all points within 4 km (circle points)" do
63
+ # puts "radius: #{@radius.inspect}"
64
+ # puts "points: #{@points.inspect}"
65
+ closest = @circle_points.as_map_points.within_distance 4.km, :from => @center_point
66
+ puts "circle_points: #{@circle_points}"
67
+ puts "points within 4 km: #{closest.inspect}"
68
+ end
69
+
70
+
60
71
  it "should select all points within 4 km" do
61
72
  points = @radius.create_points_in_square 4
62
73
  persons = Person.random_at points
63
74
 
64
75
  center_person = Person.new 'Man in the center', @center_point
65
76
 
66
- people_within = persons.as_map_points.get_within 5.km, :from => center_person
77
+ people_within = persons.as_map_points.within_distance 5.km, :from => center_person
67
78
  puts "Persons within 4 km of Man in the center: #{people_within.inspect}"
68
79
  end
69
80
  end
@@ -13,7 +13,7 @@ describe "GeoMagic within rectanlge" do
13
13
 
14
14
  it "should select all points in rectangle" do
15
15
  rectangle = GeoMagic::Rectangle.new(GeoMagic::Point.new(115, 50), GeoMagic::Point.new(100, 20))
16
- points_in_rectangle = @points.as_map_points.get_within_rect rectangle
16
+ points_in_rectangle = @points.as_map_points.within_rectangle rectangle
17
17
  puts "points: #{@points}"
18
18
 
19
19
  puts "---"
@@ -35,7 +35,7 @@ describe "GeoMagic within rectangle - negative longitude" do
35
35
 
36
36
  it "should select all points in rectangle" do
37
37
  rectangle = GeoMagic::Rectangle.new(GeoMagic::Point.new(-115, 50), GeoMagic::Point.new(-100, 20))
38
- points_in_rectangle = @points.as_map_points.get_within_rect rectangle
38
+ points_in_rectangle = @points.as_map_points.within_rectangle rectangle
39
39
  puts "points: #{@points}"
40
40
 
41
41
  puts "---"
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 2
8
8
  - 1
9
- - 1
10
- version: 0.2.1.1
9
+ - 2
10
+ version: 0.2.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kristian Mandrup
@@ -193,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
193
  requirements:
194
194
  - - ">="
195
195
  - !ruby/object:Gem::Version
196
- hash: -1898968996463192661
196
+ hash: -1865177309588779558
197
197
  segments:
198
198
  - 0
199
199
  version: "0"