r67088 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67087‎ | r67088 | r67089 >
Date:16:58, 30 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r67085
Modified paths:
  • /trunk/extensions/Maps/Maps_CoordinateParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps_CoordinateParser.php
@@ -199,22 +199,32 @@
200200 */
201201 private static function formatCoordinate( $coordinate, $targetFormat ) {
202202 $coordinate = (float)$coordinate;
 203+
203204 switch ( $targetFormat ) {
204205 case Maps_COORDS_FLOAT:
205206 return $coordinate;
206207 case Maps_COORDS_DMS:
207208 $isNegative = $coordinate < 0;
 209+ $coordinate = abs( $coordinate );
208210
209 - $degrees = $isNegative ? ceil( $coordinate ) : floor( $coordinate );
 211+ $degrees = floor( $coordinate );
210212 $minutes = ( $coordinate - $degrees ) * 60;
211 - $seconds = ( $minutes - ( $isNegative ? ceil( $minutes ) : floor( $minutes ) ) ) * 60;
 213+ $seconds = ( $minutes - floor( $minutes ) ) * 60;
212214
213 - return $degrees . Maps_GEO_DEG . ' ' . ( $isNegative ? ceil( $minutes ) : floor( $minutes ) ) . Maps_GEO_MIN . ' ' . round( $seconds ) . Maps_GEO_SEC;
 215+ $result = $degrees . Maps_GEO_DEG . ' ' . floor( $minutes ) . Maps_GEO_MIN . ' ' . round( $seconds ) . Maps_GEO_SEC;
 216+ if ( $isNegative ) $result = '-' . $result;
 217+
 218+ return $result;
214219 case Maps_COORDS_DD:
215220 return $coordinate . Maps_GEO_DEG;
216221 case Maps_COORDS_DM:
217222 $isNegative = $coordinate < 0;
218 - return round( $coordinate ) . Maps_GEO_DEG . ' ' . ( $coordinate - ( $isNegative ? ceil( $coordinate ) : floor( $coordinate ) ) ) * 60 . Maps_GEO_MIN;
 223+ $coordinate = abs( $coordinate );
 224+
 225+ $result = round( $coordinate ) . Maps_GEO_DEG . ' ' . ( $coordinate - floor( $coordinate ) ) * 60 . Maps_GEO_MIN;
 226+ if ( $isNegative ) $result = '-' . $result;
 227+
 228+ return $result;
219229 default:
220230 throw new Exception( __METHOD__ . " does not support formatting of coordinates to the $targetFormat notation." );
221231 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r67085Rounding bug fixjeroendedauw16:04, 30 May 2010

Status & tagging log