r67085 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67084‎ | r67085 | r67086 >
Date:16:04, 30 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Rounding bug fix
Modified paths:
  • /trunk/extensions/Maps/Maps_CoordinateParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps_CoordinateParser.php
@@ -203,14 +203,18 @@
204204 case Maps_COORDS_FLOAT:
205205 return $coordinate;
206206 case Maps_COORDS_DMS:
207 - $degrees = floor( $coordinate );
 207+ $isNegative = $coordinate < 0;
 208+
 209+ $degrees = $isNegative ? ceil( $coordinate ) : floor( $coordinate );
208210 $minutes = ( $coordinate - $degrees ) * 60;
209 - $seconds = ( $minutes - floor( $minutes ) ) * 60;
210 - return $degrees . Maps_GEO_DEG . ' ' . floor( $minutes ) . Maps_GEO_MIN . ' ' . round( $seconds ) . Maps_GEO_SEC;
 211+ $seconds = ( $minutes - ( $isNegative ? ceil( $minutes ) : floor( $minutes ) ) ) * 60;
 212+
 213+ return $degrees . Maps_GEO_DEG . ' ' . ( $isNegative ? ceil( $minutes ) : floor( $minutes ) ) . Maps_GEO_MIN . ' ' . round( $seconds ) . Maps_GEO_SEC;
211214 case Maps_COORDS_DD:
212215 return $coordinate . Maps_GEO_DEG;
213216 case Maps_COORDS_DM:
214 - return round( $coordinate ) . Maps_GEO_DEG . ' ' . ( $coordinate - floor( $coordinate ) ) * 60 . Maps_GEO_MIN;
 217+ $isNegative = $coordinate < 0;
 218+ return round( $coordinate ) . Maps_GEO_DEG . ' ' . ( $coordinate - ( $isNegative ? ceil( $coordinate ) : floor( $coordinate ) ) ) * 60 . Maps_GEO_MIN;
215219 default:
216220 throw new Exception( __METHOD__ . " does not support formatting of coordinates to the $targetFormat notation." );
217221 }
@@ -347,7 +351,7 @@
348352 // If there is no direction indicator, the coordinate is already non-directional and no work is required.
349353 if ( in_array( $lastChar, self::$mDirections ) ) {
350354 $coordinate = substr( $coordinate, 0, -1 );
351 - if ( ( $lastChar == "S" ) or ( $lastChar == "W" ) ) {
 355+ if ( ( $lastChar == 'S' ) or ( $lastChar == 'W' ) ) {
352356 $coordinate = '-' . trim( $coordinate );
353357 }
354358 }
@@ -384,7 +388,7 @@
385389 private static function setDirectionalAngle( $coordinate, $isLat ) {
386390 self::initializeDirectionLabels();
387391
388 - $isNegative = substr( $coordinate, 0, 1 ) == '-';
 392+ $isNegative = $coordinate{0} == '-';
389393 if ( $isNegative ) $coordinate = substr( $coordinate, 1 );
390394
391395 if ( $isLat ) {
@@ -406,7 +410,7 @@
407411 * FIXME: fix innacuracy
408412 */
409413 private static function parseDMSCoordinate( $coordinate ) {
410 - $isNegative = substr( $coordinate, 0, 1 ) == '-';
 414+ $isNegative = $coordinate{0} == '-';
411415 if ( $isNegative ) $coordinate = substr( $coordinate, 1 );
412416
413417 $degreePosition = strpos( $coordinate, Maps_GEO_DEG );
@@ -449,7 +453,7 @@
450454 * TODO: fix innacuracy
451455 */
452456 private static function parseDMCoordinate( $coordinate ) {
453 - $isNegative = substr( $coordinate, 0, 1 ) == '-';
 457+ $isNegative = $coordinate{0} == '-';
454458 if ( $isNegative ) $coordinate = substr( $coordinate, 1 );
455459
456460 list( $degrees, $minutes ) = explode( Maps_GEO_DEG, $coordinate );

Follow-up revisions

RevisionCommit summaryAuthorDate
r67088Follow up to r67085jeroendedauw16:58, 30 May 2010

Status & tagging log