Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Sep 28, 2008
1 parent c9a2f10 commit 66ab6f9
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 77 deletions.
67 changes: 23 additions & 44 deletions .autotest
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
# #
# SMS AUTOTEST
#
#require 'autotest/growl'
#require 'autotest/html_report'
# require 'autotest/kdenotify'
require 'autotest/menu'
#require 'autotest/pretty'
require 'autotest/redgreen'
# require 'autotest/snarl'
require 'autotest/timestamp'

module Compile
def self.c; system "ruby ext/extconf.rb && cd ext && make"; end
end
class Autotest
Autotest.add_hook :initialize do |at|
%w{.svn .hg .git .DS_store}.each {|exception|at.add_exception(exception)}
end
# Autotest.add_hook :ran_command do
# Compile::c
# end
end

// def ellipsoidal_distance(point, a = 6378137.0, b = 6356752.3142)
// deg_to_rad = 0.0174532925199433
//
// f = (a-b) / a
// l = (point.lon - lon) * deg_to_rad
//
// u1 = Math.atan((1-f) * Math.tan(lat * deg_to_rad ))
// u2 = Math.atan((1-f) * Math.tan(point.lat * deg_to_rad))
// sinU1 = Math.sin(u1)
// cosU1 = Math.cos(u1)
// sinU2 = Math.sin(u2)
// cosU2 = Math.cos(u2)
//
// lambda = l
// lambdaP = 2 * Math::PI
// iterLimit = 20
//
// while (lambda-lambdaP).abs > 1e-12 && --iterLimit>0
// sinLambda = Math.sin(lambda)
// cosLambda = Math.cos(lambda)
// sinSigma = Math.sqrt((cosU2*sinLambda) * (cosU2*sinLambda) + (cosU1*sinU2-sinU1*cosU2*cosLambda) * (cosU1*sinU2-sinU1*cosU2*cosLambda))
//
// return 0 if sinSigma == 0 #coincident points
//
// cosSigma = sinU1*sinU2 + cosU1*cosU2*cosLambda
// sigma = Math.atan2(sinSigma, cosSigma)
// sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma
// cosSqAlpha = 1 - sinAlpha*sinAlpha
// cos2SigmaM = cosSigma - 2*sinU1*sinU2/cosSqAlpha
//
// cos2SigmaM = 0 if (cos2SigmaM.nan?) #equatorial line: cosSqAlpha=0
//
// c = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha))
// lambdaP = lambda
// lambda = l + (1-c) * f * sinAlpha * (sigma + c * sinSigma * (cos2SigmaM + c * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)))
// end
// return NaN if iterLimit==0 #formula failed to converge
//
// uSq = cosSqAlpha * (a*a - b*b) / (b*b)
// a_bis = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq)))
// b_bis = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq)))
// deltaSigma = b_bis * sinSigma*(cos2SigmaM + b_bis/4*(cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)- b_bis/6*cos2SigmaM*(-3+4*sinSigma*sinSigma)*(-3+4*cos2SigmaM*cos2SigmaM)))
//
// b*a_bis*(sigma-deltaSi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ mkmf.log
Makefile
coverage/*
doc/*
ext/*.bundle
ext/*.so
Binary file removed ext/geo.bundle
Binary file not shown.
10 changes: 5 additions & 5 deletions ext/geo.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ extern "C" {
rb_point_set = rb_define_class_under(rb_geo,
"PointSet",
rb_cObject);
rb_distance = rb_define_class_under(rb_geo,
"Distance",
rb_cObject);
// rb_distance = rb_define_class_under(rb_geo,
// "Distance",
// rb_cObject);

rb_define_alloc_func(rb_triangle_set, rb_triangle_set_alloc);
rb_define_method(rb_triangle_set, "<<", rb_triangle_set_insert, 1);
Expand Down Expand Up @@ -82,8 +82,8 @@ extern "C" {
rb_define_method(rb_triangle_set, "indexed=", rb_geo_set_set_indexed, 1);
rb_define_method(rb_triangle_set, "containers", rb_triangle_set_containers, 1);

rb_define_alloc_func(rb_distance, rb_distance_alloc);
rb_define_method(rb_distance, "haversine", rb_distance_insert, 1);
// rb_define_alloc_func(rb_distance, rb_distance_alloc);
// rb_define_method(rb_distance, "haversine", rb_distance_insert, 1);

rb_define_alloc_func(rb_point_set, rb_point_set_alloc);
rb_define_method(rb_point_set, "<<", rb_point_set_insert, 1);
Expand Down
5 changes: 1 addition & 4 deletions lib/georuby_c/base/geometry.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GeorubyC#:nodoc:
module Base
#arbitrary default SRID
#arbitrary default SRID
@@srid=4326

#Root of all geometric data classes.
Expand All @@ -27,9 +27,6 @@ def srid=(new_srid)
end
end
end

def deg2rad(d); (d/180.0) * Math::PI; end
def rad2deg(r); (r*180.0) / Math::PI; end

#to be implemented in subclasses
def bounding_box
Expand Down
40 changes: 21 additions & 19 deletions lib/georuby_c/base/point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ module GeorubyC
module Base
#Represents a point. It is in 3D if the Z coordinate is not +nil+.
class Point < Geometry

DEG2RAD = 0.0174532925199433

attr_accessor :x,:y,:z,:m
attr_accessor :r,:t # radium and theta - for polar cordinates

#if you prefer calling the coordinates lat and lon (or lng, for GeoKit compatibility)
alias :lon :x
alias :lng :x
alias :lat :y
alias :rad :r
alias :tet :t
alias :tetha :t

def initialize(srid=@@srid,with_z=false,with_m=false)
super(srid,with_z,with_m)
Expand Down Expand Up @@ -49,11 +55,10 @@ def euclidian_distance(point)
#Assumes x is the lon and y the lat, in degrees (Changed in version 1.1).
#The user has to make sure using this distance makes sense (ie she should be in latlon coordinates)
def spherical_distance(point,r=6370997.0)
deg_to_rad = 0.0174532925199433
radlat_from = lat * deg_to_rad
radlat_to = point.lat * deg_to_rad
dlat = (point.lat - lat) * deg_to_rad / 2
dlon = (point.lon - lon) * deg_to_rad / 2
radlat_from = lat * DEG2RAD
radlat_to = point.lat * DEG2RAD
dlat = (point.lat - lat) * DEG2RAD / 2
dlon = (point.lon - lon) * DEG2RAD / 2

a = Math.sin(dlat)**2 + Math.cos(radlat_from) * Math.cos(radlat_to) * Math.sin(dlon)**2
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
Expand All @@ -64,14 +69,12 @@ def spherical_distance(point,r=6370997.0)
#a is the semi-major axis (equatorial radius) of the ellipsoid
#b is the semi-minor axis (polar radius) of the ellipsoid
#Their values by default are set to the ones of the WGS84 ellipsoid
def ellipsoidal_distance(point, a = 6378137.0, b = 6356752.3142)
deg_to_rad = 0.0174532925199433

def ellipsoidal_distance(point, a = 6378137.0, b = 6356752.3142)
f = (a-b) / a
l = (point.lon - lon) * deg_to_rad
l = (point.lon - lon) * DEG2RAD

u1 = Math.atan((1-f) * Math.tan(lat * deg_to_rad ))
u2 = Math.atan((1-f) * Math.tan(point.lat * deg_to_rad))
u1 = Math.atan((1-f) * Math.tan(lat * DEG2RAD ))
u2 = Math.atan((1-f) * Math.tan(point.lat * DEG2RAD))
sinU1 = Math.sin(u1)
cosU1 = Math.cos(u1)
sinU2 = Math.sin(u2)
Expand Down Expand Up @@ -190,21 +193,20 @@ def kml_representation(options = {}) #:nodoc:

#Polar stuff
#http://www.engineeringtoolbox.com/converting-cartesian-polar-coordinates-d_1347.html
#http://rcoordinate.rubyforge.org/svn/point.rb

#http://rcoordinate.rubyforge.org/svn/point.rb
#polar distance
def r
Math.sqrt(x**2 + y**2)
end

#outputs theta in degrees
def t
if x == 0
if x.zero?
y < 0 ? 3 * Math::PI / 2 : Math::PI / 2
else
t = Math.atan(y/x)
t += 2 * Math::PI if t > 0
rad2deg(t)
t / DEG2RAD
end
end

Expand Down Expand Up @@ -266,9 +268,8 @@ def self.from_x_y_xl_yl(x,xl,y,yl,srid=@@srid)

#creates a point using polar coordinates
#r and theta(degrees)
def self.from_polar_r_t(r,t,srid=@@srid)
deg2rad = 0.0174532925199433
t *= deg2rad
def self.from_r_t(r,t,srid=@@srid)
t *= DEG2RAD
x = r * Math.cos(t)
y = r * Math.sin(t)
point= new(srid)
Expand All @@ -281,6 +282,7 @@ class << self
alias :from_lon_lat_z :from_x_y_z
alias :from_lon_lat_m :from_x_y_m
alias :from_lon_lat_z_m :from_x_y_z_m
alias :from_rad_tet :from_r_t
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/georuby_c/base/line_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
end




end
4 changes: 2 additions & 2 deletions spec/georuby_c/base/point_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
describe "Export Formats" do

before(:each) do
@point = Point.from_x_y(-11.2431,32.3141)
@point = Point.from_x_y( -11.2431, 32.3141 )
end

it "should print nicely" do
Expand Down Expand Up @@ -80,7 +80,7 @@
end

it "should instantiate a point from polar coordinates" do
@point = Point.from_polar_r_t(1.4142,45)
@point = Point.from_r_t(1.4142,45)
@point.y.should be_close(1, 0.00001)
@point.x.should be_close(1, 0.00001)
end
Expand Down
15 changes: 13 additions & 2 deletions spec/georuby_c_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
# http://rspec.info/
describe "Place your specs here" do

it "find this spec in spec directory" do
pending "Be sure to write your specs"
it "should instantiate Geometry" do
@geo = Geometry.new
@geo.class.should eql(Geometry)
end

it "should instantiate Point" do
@point = Point.new
@point.class.should eql(Point)
end

it "should instantiate Line" do
@point = LineString.new
@point.class.should eql(LineString)
end

end
5 changes: 4 additions & 1 deletion spec/spec.opts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
--colour
--colour
--format progress
--loadby mtime
--reverse

0 comments on commit 66ab6f9

Please sign in to comment.