Skip to content

Commit

Permalink
specs runs again
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Oct 28, 2008
1 parent 64f4f46 commit 2b0568b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 43 deletions.
34 changes: 0 additions & 34 deletions .autotest

This file was deleted.

41 changes: 37 additions & 4 deletions lib/georuby_c/base/envelope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module Base
#Contains the bounding box of a geometry
class Envelope
attr_accessor :lower_corner, :upper_corner
attr_accessor :srid, :with_z
attr_accessor :srid, :with_z, :zoom

#Creates a enw Envelope with +lower_corner+ as the first element of the corners array and +upper_corner+ as the second element
def initialize(srid = DEFAULT_SRID, with_z = false)
def initialize(srid = @@srid, with_z = false)
@srid = srid
@with_z = with_z
end
Expand All @@ -29,12 +29,44 @@ def extend(envelope)
e.extend!(envelope)
e
end
# def bounding_box(markers)
# max_lat, max_lon, min_lat, min_lon = -Float::MAX, -Float::MAX, Float::MAX, Float::MAX
# markers.each do |marker|
# coord = marker.point
# max_lat = coord.lat if coord.lat > max_lat
# min_lat = coord.lat if coord.lat < min_lat
# max_lon = coord.lng if coord.lng > max_lon
# min_lon = coord.lng if coord.lng < min_lon
# end
# min_point = Point.from_x_y(min_lat,min_lon)
# max_point = Point.from_x_y(max_lat,max_lon)

# end
# centrelat = (max_lat + min_lat)/2
# centrelng = (max_lon + min_lon)/2
# # logger.info("distance[#{distance}],zoom[#{zoom}]")
# #return GLatLngBounds.new(GLatLng.new(min_point),GLatLng.new(max_point)), [centrelat,centrelng], zoom
# return [centrelat,centrelng], zoom

#Sends back the center of the envelope
def center
Point.from_x_y((lower_corner.x + upper_corner.x)/2,(lower_corner.y + upper_corner.y)/2)
end

#Zoom level
def zoom
distance = lower_corner.spherical_distance(upper_corner)/10000
@zoom = case distance
when 150..9000 then 5
when 80..149 then 6
when 50..79 then 7
when 20..49 then 8
when 10..19 then 9
when 5..9 then 10
else 13
end
end

#Tests the equality of line strings
def ==(other_envelope)
if other_envelope.class != self.class
Expand Down Expand Up @@ -116,14 +148,15 @@ def kml_representation(options = {})#:nodoc:
end

#Creates a new envelope. Accept an array of 2 points as argument
def self.from_points(points,srid=DEFAULT_SRID,with_z=false)
def self.from_points(points,srid=@@srid,with_z=false)
raise "Not an array" unless points.class == Array
e = Envelope.new(srid,with_z)
e.lower_corner, e.upper_corner = points
e
end

#Creates a new envelope. Accept a sequence of point coordinates as argument : ((x,y),(x,y))
def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false)
def self.from_coordinates(points,srid=@@srid,with_z=false)
e = Envelope.new(srid,with_z)
e.lower_corner, e.upper_corner = points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z)}
e
Expand Down
4 changes: 4 additions & 0 deletions spec/famous_mocks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def mock_point(stubs={})
stubs = { :x => 10.100, :y => -20.200 }.merge!(stubs)
@mock_point ||= mock(Point, stubs)
end
27 changes: 22 additions & 5 deletions spec/georuby_c/base/envelope_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Envelope do
# before(:each) do
# @po = MultiPolygon.new
before(:each) do
@env = Envelope.from_points(
Point.from_x_y(10,20),Point.from_x_y(20,30))
end

it "should initialize" do
@env.should be_instance_of(Envelope)
end


# it "should have a lower corner" do
# @env.upper_corner.x.should eql('')
# end

#it "should f" do
# violated
#end

it "should have a center" do
@env.center.x.should eql(15)
@env.center.y.should eql(25)
end

it "should print a kml_representation" do
@env.as_kml.should eql("<LatLonAltBox>\n<north>30</north>\n<south>20</south>\n<east>20</east>\n<west>10</west>\n</LatLonAltBox>\n")
end

end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'georuby_c'
require File.expand_path(File.dirname(__FILE__) + "/famous_mocks")
include GeorubyC
include Base

0 comments on commit 2b0568b

Please sign in to comment.