r64939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64938‎ | r64939 | r64940 >
Date:15:53, 11 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - added function to find a destination given starting point, bearing and distance (which will also be used by the SM distance query)
Modified paths:
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
@@ -43,8 +43,6 @@
4444
4545 final class MapsGeoFunctions {
4646
47 - // TODO: add support for smart geocoding
48 - // TODO: add coordinate validation
4947 function renderGeoDistance( Parser &$parser ) {
5048 $args = func_get_args();
5149
@@ -95,33 +93,7 @@
9694 }
9795
9896 if ( $start && $end ) {
99 - $northRad1 = deg2rad( $start['lat'] );
100 - $eastRad1 = deg2rad( $start['lon'] );
101 -
102 - $cosNorth1 = cos( $northRad1 );
103 - $cosEast1 = cos( $eastRad1 );
104 -
105 - $sinNorth1 = sin( $northRad1 );
106 - $sinEast1 = sin( $eastRad1 );
107 -
108 - $northRad2 = deg2rad( $end['lat'] );
109 - $eastRad2 = deg2rad( $end['lon'] );
110 -
111 - $cosNorth2 = cos( $northRad2 );
112 - $cosEast2 = cos( $eastRad2 );
113 -
114 - $sinNorth2 = sin( $northRad2 );
115 - $sinEast2 = sin( $eastRad2 );
116 -
117 - $term1 = $cosNorth1 * $sinEast1 - $cosNorth2 * $sinEast2;
118 - $term2 = $cosNorth1 * $cosEast1 - $cosNorth2 * $cosEast2;
119 - $term3 = $sinNorth1 - $sinNorth2;
120 -
121 - $distThruSquared = $term1 * $term1 + $term2 * $term2 + $term3 * $term3;
122 -
123 - $surfaceDistance = 2 * Maps_EARTH_RADIUS * asin( sqrt( $distThruSquared ) / 2 );
124 -
125 - $output = $surfaceDistance . ' km';
 97+ $output = self::calculateDistance( $start, $end ) . ' km';
12698 $errorList = $manager->getErrorList();
12799
128100 if ( $errorList != '' ) {
@@ -152,7 +124,65 @@
153125 return array( $output, 'noparse' => true, 'isHTML' => true );
154126 }
155127
 128+ public static function renderFindDestination() {
 129+ // TODO
 130+ }
 131+
156132 /**
 133+ *
 134+ * @param unknown_type $start
 135+ * @param unknown_type $end
 136+ */
 137+ public static function calculateDistance( $start, $end ) {
 138+ $northRad1 = deg2rad( $start['lat'] );
 139+ $eastRad1 = deg2rad( $start['lon'] );
 140+
 141+ $cosNorth1 = cos( $northRad1 );
 142+ $cosEast1 = cos( $eastRad1 );
 143+
 144+ $sinNorth1 = sin( $northRad1 );
 145+ $sinEast1 = sin( $eastRad1 );
 146+
 147+ $northRad2 = deg2rad( $end['lat'] );
 148+ $eastRad2 = deg2rad( $end['lon'] );
 149+
 150+ $cosNorth2 = cos( $northRad2 );
 151+ $cosEast2 = cos( $eastRad2 );
 152+
 153+ $sinNorth2 = sin( $northRad2 );
 154+ $sinEast2 = sin( $eastRad2 );
 155+
 156+ $term1 = $cosNorth1 * $sinEast1 - $cosNorth2 * $sinEast2;
 157+ $term2 = $cosNorth1 * $cosEast1 - $cosNorth2 * $cosEast2;
 158+ $term3 = $sinNorth1 - $sinNorth2;
 159+
 160+ $distThruSquared = $term1 * $term1 + $term2 * $term2 + $term3 * $term3;
 161+
 162+ return 2 * Maps_EARTH_RADIUS * asin( sqrt( $distThruSquared ) / 2 );
 163+ }
 164+
 165+ /**
 166+ *
 167+ * @param unknown_type $startingCoordinates
 168+ * @param unknown_type $bearing
 169+ * @param unknown_type $distance
 170+ */
 171+ public static function findDestination( $startingCoordinates, $bearing, $distance ) {
 172+ $angularDistance = $distance / Maps_EARTH_RADIUS;
 173+ $lat = asin(
 174+ sin( $startingCoordinates['lat'] ) * cos( $angularDistance ) +
 175+ cos( $startingCoordinates['lat'] ) * sin( $angularDistance ) * cos( $bearing )
 176+ );
 177+ return array(
 178+ 'lat' => $lat,
 179+ 'lon' => $startingCoordinates['lon'] + atan2(
 180+ sin( $bearing ) * sin( $angularDistance ) * cos( $startingCoordinates['lat'] ),
 181+ cos( $angularDistance ) - sin( $startingCoordinates['lat'] ) * sin( $lat )
 182+ )
 183+ );
 184+ }
 185+
 186+ /**
157187 * Returns a boolean indicating if MapsGeocoder is available.
158188 */
159189 private static function geocoderIsAvailable() {
Index: trunk/extensions/Maps/Maps.php
@@ -33,7 +33,7 @@
3434 echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.';
3535 }
3636 else {
37 - define( 'Maps_VERSION', '0.6 a11' );
 37+ define( 'Maps_VERSION', '0.6 a12' );
3838
3939 // The different coordinate notations.
4040 define( 'Maps_COORDS_FLOAT', 'float' );

Status & tagging log