Index: trunk/extensions/Maps/ParserHooks/Maps_GeoFunctions.php |
— | — | @@ -1,86 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -// The approximate radius of the earth in meters, according to http://en.wikipedia.org/wiki/Earth_radius. |
5 | | -define( 'Maps_EARTH_RADIUS', 6371000 ); |
6 | | - |
7 | | -/** |
8 | | - * Static class containing geographical functions. |
9 | | - * |
10 | | - * @since 0.6 |
11 | | - * |
12 | | - * @file Maps_GeoFunctions.php |
13 | | - * @ingroup Maps |
14 | | - * |
15 | | - * @author Jeroen De Dauw |
16 | | - * @author Pnelnik |
17 | | - * @author Matěj Grabovský |
18 | | - */ |
19 | | -final class MapsGeoFunctions { |
20 | | - |
21 | | - /** |
22 | | - * Returns the geographical distance between two coordinates. |
23 | | - * See http://en.wikipedia.org/wiki/Geographical_distance |
24 | | - * |
25 | | - * @since 0.6 |
26 | | - * |
27 | | - * @param array $start The first coordinates, as non-directional floats in an array with lat and lon keys. |
28 | | - * @param array $end The second coordinates, as non-directional floats in an array with lat and lon keys. |
29 | | - * |
30 | | - * @return float Distance in m. |
31 | | - */ |
32 | | - public static function calculateDistance( array $start, array $end ) { |
33 | | - $northRad1 = deg2rad( $start['lat'] ); |
34 | | - $eastRad1 = deg2rad( $start['lon'] ); |
35 | | - |
36 | | - $cosNorth1 = cos( $northRad1 ); |
37 | | - $cosEast1 = cos( $eastRad1 ); |
38 | | - |
39 | | - $sinNorth1 = sin( $northRad1 ); |
40 | | - $sinEast1 = sin( $eastRad1 ); |
41 | | - |
42 | | - $northRad2 = deg2rad( $end['lat'] ); |
43 | | - $eastRad2 = deg2rad( $end['lon'] ); |
44 | | - |
45 | | - $cosNorth2 = cos( $northRad2 ); |
46 | | - $cosEast2 = cos( $eastRad2 ); |
47 | | - |
48 | | - $sinNorth2 = sin( $northRad2 ); |
49 | | - $sinEast2 = sin( $eastRad2 ); |
50 | | - |
51 | | - $term1 = $cosNorth1 * $sinEast1 - $cosNorth2 * $sinEast2; |
52 | | - $term2 = $cosNorth1 * $cosEast1 - $cosNorth2 * $cosEast2; |
53 | | - $term3 = $sinNorth1 - $sinNorth2; |
54 | | - |
55 | | - $distThruSquared = $term1 * $term1 + $term2 * $term2 + $term3 * $term3; |
56 | | - |
57 | | - return 2 * Maps_EARTH_RADIUS * asin( sqrt( $distThruSquared ) / 2 ); |
58 | | - } |
59 | | - |
60 | | - /** |
61 | | - * Finds a destination given a starting location, bearing and distance. |
62 | | - * |
63 | | - * @since 0.6 |
64 | | - * |
65 | | - * @param array $startingCoordinates The starting coordinates, as non-directional floats in an array with lat and lon keys. |
66 | | - * @param float $bearing The initial bearing in degrees. |
67 | | - * @param float $distance The distance to travel in km. |
68 | | - * |
69 | | - * @return array The desitination coordinates, as non-directional floats in an array with lat and lon keys. |
70 | | - */ |
71 | | - public static function findDestination( array $startingCoordinates, $bearing, $distance ) { |
72 | | - $startingCoordinates['lat'] = deg2rad( (float)$startingCoordinates['lat'] ); |
73 | | - $startingCoordinates['lon'] = deg2rad( (float)$startingCoordinates['lon'] ); |
74 | | - |
75 | | - $radBearing = deg2rad ( (float)$bearing ); |
76 | | - $angularDistance = $distance / Maps_EARTH_RADIUS; |
77 | | - |
78 | | - $lat = asin (sin ( $startingCoordinates['lat'] ) * cos ( $angularDistance ) + cos ( $startingCoordinates['lat'] ) * sin ( $angularDistance ) * cos ( $radBearing ) ); |
79 | | - $lon = $startingCoordinates['lon'] + atan2 ( sin ( $radBearing ) * sin ( $angularDistance ) * cos ( $startingCoordinates['lat'] ), cos ( $angularDistance ) - sin ( $startingCoordinates['lat'] ) * sin ( $lat ) ); |
80 | | - |
81 | | - return array( |
82 | | - 'lat' => rad2deg( $lat ), |
83 | | - 'lon' => rad2deg( $lon ) |
84 | | - ); |
85 | | - } |
86 | | - |
87 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Maps/Includes/Maps_GeoFunctions.php |
— | — | @@ -0,0 +1,86 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +// The approximate radius of the earth in meters, according to http://en.wikipedia.org/wiki/Earth_radius. |
| 5 | +define( 'Maps_EARTH_RADIUS', 6371000 ); |
| 6 | + |
| 7 | +/** |
| 8 | + * Static class containing geographical functions. |
| 9 | + * |
| 10 | + * @since 0.6 |
| 11 | + * |
| 12 | + * @file Maps_GeoFunctions.php |
| 13 | + * @ingroup Maps |
| 14 | + * |
| 15 | + * @author Jeroen De Dauw |
| 16 | + * @author Pnelnik |
| 17 | + * @author Matěj Grabovský |
| 18 | + */ |
| 19 | +final class MapsGeoFunctions { |
| 20 | + |
| 21 | + /** |
| 22 | + * Returns the geographical distance between two coordinates. |
| 23 | + * See http://en.wikipedia.org/wiki/Geographical_distance |
| 24 | + * |
| 25 | + * @since 0.6 |
| 26 | + * |
| 27 | + * @param array $start The first coordinates, as non-directional floats in an array with lat and lon keys. |
| 28 | + * @param array $end The second coordinates, as non-directional floats in an array with lat and lon keys. |
| 29 | + * |
| 30 | + * @return float Distance in m. |
| 31 | + */ |
| 32 | + public static function calculateDistance( array $start, array $end ) { |
| 33 | + $northRad1 = deg2rad( $start['lat'] ); |
| 34 | + $eastRad1 = deg2rad( $start['lon'] ); |
| 35 | + |
| 36 | + $cosNorth1 = cos( $northRad1 ); |
| 37 | + $cosEast1 = cos( $eastRad1 ); |
| 38 | + |
| 39 | + $sinNorth1 = sin( $northRad1 ); |
| 40 | + $sinEast1 = sin( $eastRad1 ); |
| 41 | + |
| 42 | + $northRad2 = deg2rad( $end['lat'] ); |
| 43 | + $eastRad2 = deg2rad( $end['lon'] ); |
| 44 | + |
| 45 | + $cosNorth2 = cos( $northRad2 ); |
| 46 | + $cosEast2 = cos( $eastRad2 ); |
| 47 | + |
| 48 | + $sinNorth2 = sin( $northRad2 ); |
| 49 | + $sinEast2 = sin( $eastRad2 ); |
| 50 | + |
| 51 | + $term1 = $cosNorth1 * $sinEast1 - $cosNorth2 * $sinEast2; |
| 52 | + $term2 = $cosNorth1 * $cosEast1 - $cosNorth2 * $cosEast2; |
| 53 | + $term3 = $sinNorth1 - $sinNorth2; |
| 54 | + |
| 55 | + $distThruSquared = $term1 * $term1 + $term2 * $term2 + $term3 * $term3; |
| 56 | + |
| 57 | + return 2 * Maps_EARTH_RADIUS * asin( sqrt( $distThruSquared ) / 2 ); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Finds a destination given a starting location, bearing and distance. |
| 62 | + * |
| 63 | + * @since 0.6 |
| 64 | + * |
| 65 | + * @param array $startingCoordinates The starting coordinates, as non-directional floats in an array with lat and lon keys. |
| 66 | + * @param float $bearing The initial bearing in degrees. |
| 67 | + * @param float $distance The distance to travel in km. |
| 68 | + * |
| 69 | + * @return array The desitination coordinates, as non-directional floats in an array with lat and lon keys. |
| 70 | + */ |
| 71 | + public static function findDestination( array $startingCoordinates, $bearing, $distance ) { |
| 72 | + $startingCoordinates['lat'] = deg2rad( (float)$startingCoordinates['lat'] ); |
| 73 | + $startingCoordinates['lon'] = deg2rad( (float)$startingCoordinates['lon'] ); |
| 74 | + |
| 75 | + $radBearing = deg2rad ( (float)$bearing ); |
| 76 | + $angularDistance = $distance / Maps_EARTH_RADIUS; |
| 77 | + |
| 78 | + $lat = asin (sin ( $startingCoordinates['lat'] ) * cos ( $angularDistance ) + cos ( $startingCoordinates['lat'] ) * sin ( $angularDistance ) * cos ( $radBearing ) ); |
| 79 | + $lon = $startingCoordinates['lon'] + atan2 ( sin ( $radBearing ) * sin ( $angularDistance ) * cos ( $startingCoordinates['lat'] ), cos ( $angularDistance ) - sin ( $startingCoordinates['lat'] ) * sin ( $lat ) ); |
| 80 | + |
| 81 | + return array( |
| 82 | + 'lat' => rad2deg( $lat ), |
| 83 | + 'lon' => rad2deg( $lon ) |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/Includes/Maps_GeoFunctions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 88 | + native |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -93,6 +93,7 @@ |
94 | 94 | $wgAutoloadClasses['MapsMapper'] = $egMapsDir . 'Includes/Maps_Mapper.php'; |
95 | 95 | $wgAutoloadClasses['MapsCoordinateParser'] = $egMapsDir . 'Includes/Maps_CoordinateParser.php'; |
96 | 96 | $wgAutoloadClasses['MapsDistanceParser'] = $egMapsDir . 'Includes/Maps_DistanceParser.php'; |
| 97 | + $wgAutoloadClasses['MapsGeoFunctions'] = $egMapsDir . 'Includes/Maps_GeoFunctions.php'; |
97 | 98 | |
98 | 99 | // Autoload the "ParserHooks/" classes. |
99 | 100 | $wgAutoloadClasses['MapsCoordinates'] = $egMapsDir . 'ParserHooks/Maps_Coordinates.php'; |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -40,9 +40,6 @@ |
41 | 41 | # Geocoding parser functions: #geocode, #geocodelat, #geocodelon. |
42 | 42 | include_once $egMapsDir . 'ParserHooks/Maps_GeocodeFunctions.php'; |
43 | 43 | |
44 | | - # Geographic functions |
45 | | - include_once $egMapsDir . 'ParserHooks/Maps_GeoFunctions.php'; |
46 | | - |
47 | 44 | # Required for #coordinates. |
48 | 45 | $wgHooks['ParserFirstCallInit'][] = 'MapsCoordinates::staticInit'; |
49 | 46 | $wgHooks['LanguageGetMagic'][] = 'MapsCoordinates::staticMagic'; |