From 7c95d28947a9ed8f003bfaef147f2fb72dc4b6ab Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 2 Nov 2014 11:07:28 +0100 Subject: rename package The package not only contains the GeoPoint definition, but other location related classes, too. --- main/src/cgeo/calendar/CalendarAddon.java | 2 +- .../cgeo/geocaching/AbstractDialogFragment.java | 4 +- main/src/cgeo/geocaching/CacheCache.java | 2 +- main/src/cgeo/geocaching/CacheDetailActivity.java | 2 +- main/src/cgeo/geocaching/CacheListActivity.java | 2 +- main/src/cgeo/geocaching/CachePopupFragment.java | 2 +- main/src/cgeo/geocaching/CompassActivity.java | 4 +- main/src/cgeo/geocaching/DataStore.java | 4 +- main/src/cgeo/geocaching/Destination.java | 2 +- main/src/cgeo/geocaching/EditWaypointActivity.java | 6 +- main/src/cgeo/geocaching/Geocache.java | 2 +- main/src/cgeo/geocaching/ICoordinates.java | 2 +- main/src/cgeo/geocaching/MainActivity.java | 4 +- .../cgeo/geocaching/NavigateAnyPointActivity.java | 6 +- main/src/cgeo/geocaching/SearchActivity.java | 4 +- main/src/cgeo/geocaching/StaticMapsProvider.java | 2 +- main/src/cgeo/geocaching/TrackableActivity.java | 2 +- main/src/cgeo/geocaching/Waypoint.java | 2 +- .../src/cgeo/geocaching/WaypointPopupFragment.java | 4 +- .../cache/navi/AbstractPointNavigationApp.java | 2 +- .../apps/cache/navi/AbstractRadarApp.java | 2 +- .../geocaching/apps/cache/navi/AndroidWearApp.java | 2 +- .../geocaching/apps/cache/navi/CompassApp.java | 2 +- .../apps/cache/navi/GeopointNavigationApp.java | 2 +- .../geocaching/apps/cache/navi/GoogleMapsApp.java | 6 +- .../apps/cache/navi/GoogleMapsDirectionApp.java | 2 +- .../apps/cache/navi/GoogleNavigationApp.java | 2 +- .../geocaching/apps/cache/navi/InternalMap.java | 2 +- .../geocaching/apps/cache/navi/MapsWithMeApp.java | 2 +- .../apps/cache/navi/NavigationAppFactory.java | 2 +- .../geocaching/apps/cache/navi/NavigonApp.java | 2 +- .../geocaching/apps/cache/navi/OruxMapsApp.java | 2 +- .../cgeo/geocaching/apps/cache/navi/PebbleApp.java | 2 +- .../cgeo/geocaching/apps/cache/navi/RMapsApp.java | 4 +- .../cgeo/geocaching/apps/cache/navi/RadarApp.java | 2 +- .../geocaching/apps/cache/navi/StreetviewApp.java | 2 +- .../apps/cache/navi/SygicNavigationApp.java | 2 +- .../geocaching/connector/AbstractConnector.java | 3 +- .../geocaching/connector/ConnectorFactory.java | 2 +- main/src/cgeo/geocaching/connector/IConnector.java | 2 +- .../connector/capability/ISearchByCenter.java | 2 +- .../connector/capability/ISearchByViewPort.java | 2 +- main/src/cgeo/geocaching/connector/ec/ECApi.java | 4 +- .../cgeo/geocaching/connector/ec/ECConnector.java | 4 +- .../cgeo/geocaching/connector/gc/GCConnector.java | 4 +- main/src/cgeo/geocaching/connector/gc/GCMap.java | 8 +- .../src/cgeo/geocaching/connector/gc/GCParser.java | 4 +- main/src/cgeo/geocaching/connector/gc/Tile.java | 4 +- .../connector/oc/OCApiLiveConnector.java | 4 +- .../cgeo/geocaching/connector/oc/OkapiClient.java | 6 +- .../cgeo/geocaching/connector/ox/OXConnector.java | 4 +- .../geocaching/connector/ox/OpenCachingApi.java | 6 +- main/src/cgeo/geocaching/export/GpxSerializer.java | 2 +- main/src/cgeo/geocaching/files/GPXParser.java | 2 +- main/src/cgeo/geocaching/files/LocParser.java | 2 +- .../src/cgeo/geocaching/filter/DistanceFilter.java | 2 +- .../cgeo/geocaching/geopoint/DistanceParser.java | 51 -- main/src/cgeo/geocaching/geopoint/Geopoint.java | 601 --------------------- .../geocaching/geopoint/GeopointFormatter.java | 116 ---- .../cgeo/geocaching/geopoint/GeopointParser.java | 163 ------ main/src/cgeo/geocaching/geopoint/IConversion.java | 13 - main/src/cgeo/geocaching/geopoint/Units.java | 62 --- main/src/cgeo/geocaching/geopoint/Viewport.java | 192 ------- .../loaders/CoordsGeocacheListLoader.java | 3 +- .../loaders/HistoryGeocacheListLoader.java | 2 +- .../loaders/OfflineGeocacheListLoader.java | 2 +- .../cgeo/geocaching/location/DistanceParser.java | 51 ++ main/src/cgeo/geocaching/location/Geopoint.java | 601 +++++++++++++++++++++ .../geocaching/location/GeopointFormatter.java | 116 ++++ .../cgeo/geocaching/location/GeopointParser.java | 163 ++++++ main/src/cgeo/geocaching/location/IConversion.java | 13 + main/src/cgeo/geocaching/location/Units.java | 62 +++ main/src/cgeo/geocaching/location/Viewport.java | 192 +++++++ main/src/cgeo/geocaching/maps/CGeoMap.java | 4 +- main/src/cgeo/geocaching/maps/CachesOverlay.java | 2 +- main/src/cgeo/geocaching/maps/PositionDrawer.java | 2 +- main/src/cgeo/geocaching/maps/ScaleDrawer.java | 4 +- .../geocaching/maps/google/v1/GoogleGeoPoint.java | 2 +- .../maps/google/v1/GoogleMapItemFactory.java | 2 +- .../geocaching/maps/google/v1/GoogleMapView.java | 2 +- .../geocaching/maps/interfaces/MapItemFactory.java | 2 +- .../geocaching/maps/interfaces/MapViewImpl.java | 2 +- .../maps/mapsforge/MapsforgeGeoPoint.java | 2 +- .../maps/mapsforge/MapsforgeMapItemFactory.java | 2 +- .../maps/mapsforge/MapsforgeMapView.java | 2 +- .../maps/mapsforge/v024/MapsforgeGeoPoint.java | 2 +- .../mapsforge/v024/MapsforgeMapItemFactory024.java | 2 +- .../maps/mapsforge/v024/MapsforgeMapView024.java | 2 +- main/src/cgeo/geocaching/sensors/GeoData.java | 2 +- main/src/cgeo/geocaching/sensors/IGeoData.java | 2 +- main/src/cgeo/geocaching/settings/Settings.java | 2 +- .../geocaching/sorting/DistanceComparator.java | 2 +- main/src/cgeo/geocaching/speech/SpeechService.java | 2 +- main/src/cgeo/geocaching/speech/TextFactory.java | 4 +- main/src/cgeo/geocaching/twitter/Twitter.java | 4 +- .../src/cgeo/geocaching/ui/AddressListAdapter.java | 4 +- .../cgeo/geocaching/ui/CacheDetailsCreator.java | 2 +- main/src/cgeo/geocaching/ui/CacheListAdapter.java | 2 +- main/src/cgeo/geocaching/ui/CompassMiniView.java | 2 +- .../geocaching/ui/CoordinatesFormatSwitcher.java | 4 +- main/src/cgeo/geocaching/ui/DistanceView.java | 4 +- .../ui/dialog/CoordinatesInputDialog.java | 6 +- tests/src/cgeo/geocaching/CgeoApplicationTest.java | 4 +- tests/src/cgeo/geocaching/DataStoreTest.java | 4 +- tests/src/cgeo/geocaching/DestinationTest.java | 2 +- tests/src/cgeo/geocaching/GeocacheTest.java | 2 +- .../cgeo/geocaching/StaticMapsProviderTest.java | 2 +- tests/src/cgeo/geocaching/WaypointTest.java | 2 +- .../cgeo/geocaching/connector/gc/AutoZoomTest.java | 4 +- .../geocaching/connector/gc/GCConnectorTest.java | 4 +- .../cgeo/geocaching/connector/gc/GCParserTest.java | 2 +- tests/src/cgeo/geocaching/export/ExportTest.java | 2 +- tests/src/cgeo/geocaching/files/GPXParserTest.java | 2 +- tests/src/cgeo/geocaching/files/LocParserTest.java | 2 +- .../geocaching/geopoint/DistanceParserTest.java | 30 - .../geocaching/geopoint/GeoPointFormatterTest.java | 33 -- .../geocaching/geopoint/GeoPointParserTest.java | 119 ---- .../src/cgeo/geocaching/geopoint/GeopointTest.java | 306 ----------- tests/src/cgeo/geocaching/geopoint/UnitsTest.java | 73 --- .../src/cgeo/geocaching/geopoint/ViewportTest.java | 107 ---- .../geocaching/location/DistanceParserTest.java | 32 ++ .../geocaching/location/GeoPointFormatterTest.java | 35 ++ .../geocaching/location/GeoPointParserTest.java | 121 +++++ .../src/cgeo/geocaching/location/GeopointTest.java | 308 +++++++++++ tests/src/cgeo/geocaching/location/UnitsTest.java | 74 +++ .../src/cgeo/geocaching/location/ViewportTest.java | 109 ++++ .../geocaching/sorting/DistanceComparatorTest.java | 2 +- .../cgeo/geocaching/speech/TextFactoryTest.java | 2 +- tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java | 2 +- tests/src/cgeo/geocaching/test/mock/GC2CJPF.java | 2 +- tests/src/cgeo/geocaching/test/mock/GC2JVEH.java | 2 +- tests/src/cgeo/geocaching/test/mock/GC3XX5J.java | 2 +- .../src/cgeo/geocaching/test/mock/MockedCache.java | 2 +- 133 files changed, 2026 insertions(+), 2013 deletions(-) delete mode 100644 main/src/cgeo/geocaching/geopoint/DistanceParser.java delete mode 100644 main/src/cgeo/geocaching/geopoint/Geopoint.java delete mode 100644 main/src/cgeo/geocaching/geopoint/GeopointFormatter.java delete mode 100644 main/src/cgeo/geocaching/geopoint/GeopointParser.java delete mode 100644 main/src/cgeo/geocaching/geopoint/IConversion.java delete mode 100644 main/src/cgeo/geocaching/geopoint/Units.java delete mode 100644 main/src/cgeo/geocaching/geopoint/Viewport.java create mode 100644 main/src/cgeo/geocaching/location/DistanceParser.java create mode 100644 main/src/cgeo/geocaching/location/Geopoint.java create mode 100644 main/src/cgeo/geocaching/location/GeopointFormatter.java create mode 100644 main/src/cgeo/geocaching/location/GeopointParser.java create mode 100644 main/src/cgeo/geocaching/location/IConversion.java create mode 100644 main/src/cgeo/geocaching/location/Units.java create mode 100644 main/src/cgeo/geocaching/location/Viewport.java delete mode 100644 tests/src/cgeo/geocaching/geopoint/DistanceParserTest.java delete mode 100644 tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java delete mode 100644 tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java delete mode 100644 tests/src/cgeo/geocaching/geopoint/GeopointTest.java delete mode 100644 tests/src/cgeo/geocaching/geopoint/UnitsTest.java delete mode 100644 tests/src/cgeo/geocaching/geopoint/ViewportTest.java create mode 100644 tests/src/cgeo/geocaching/location/DistanceParserTest.java create mode 100644 tests/src/cgeo/geocaching/location/GeoPointFormatterTest.java create mode 100644 tests/src/cgeo/geocaching/location/GeoPointParserTest.java create mode 100644 tests/src/cgeo/geocaching/location/GeopointTest.java create mode 100644 tests/src/cgeo/geocaching/location/UnitsTest.java create mode 100644 tests/src/cgeo/geocaching/location/ViewportTest.java diff --git a/main/src/cgeo/calendar/CalendarAddon.java b/main/src/cgeo/calendar/CalendarAddon.java index 4a672fa..8737447 100644 --- a/main/src/cgeo/calendar/CalendarAddon.java +++ b/main/src/cgeo/calendar/CalendarAddon.java @@ -2,7 +2,7 @@ package cgeo.calendar; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.GeopointFormatter; +import cgeo.geocaching.location.GeopointFormatter; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.utils.ProcessUtils; diff --git a/main/src/cgeo/geocaching/AbstractDialogFragment.java b/main/src/cgeo/geocaching/AbstractDialogFragment.java index 343d97c..3deb701 100644 --- a/main/src/cgeo/geocaching/AbstractDialogFragment.java +++ b/main/src/cgeo/geocaching/AbstractDialogFragment.java @@ -7,8 +7,8 @@ import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.gcvote.GCVote; import cgeo.geocaching.gcvote.GCVoteRating; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java index 1913d3c..74e22b5 100644 --- a/main/src/cgeo/geocaching/CacheCache.java +++ b/main/src/cgeo/geocaching/CacheCache.java @@ -3,7 +3,7 @@ package cgeo.geocaching; import cgeo.geocaching.DataStore.StorageLocation; import cgeo.geocaching.connector.gc.Tile; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.utils.LeastRecentlyUsedMap; import cgeo.geocaching.utils.LeastRecentlyUsedMap.RemoveHandler; import cgeo.geocaching.utils.Log; diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 7ca6525..16f5cef 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -21,8 +21,8 @@ import cgeo.geocaching.enumerations.CacheAttribute; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Units; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Units; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.network.Network; import cgeo.geocaching.sensors.GeoDirHandler; diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java index 7ef59dd..c501f89 100644 --- a/main/src/cgeo/geocaching/CacheListActivity.java +++ b/main/src/cgeo/geocaching/CacheListActivity.java @@ -21,7 +21,6 @@ import cgeo.geocaching.export.GpxExport; import cgeo.geocaching.files.GPXImporter; import cgeo.geocaching.filter.FilterUserInterface; import cgeo.geocaching.filter.IFilter; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.AbstractList; import cgeo.geocaching.list.ListNameMemento; import cgeo.geocaching.list.PseudoList; @@ -37,6 +36,7 @@ import cgeo.geocaching.loaders.NextPageGeocacheListLoader; import cgeo.geocaching.loaders.OfflineGeocacheListLoader; import cgeo.geocaching.loaders.OwnerGeocacheListLoader; import cgeo.geocaching.loaders.PocketGeocacheListLoader; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.CGeoMap; import cgeo.geocaching.network.Cookies; import cgeo.geocaching.network.Network; diff --git a/main/src/cgeo/geocaching/CachePopupFragment.java b/main/src/cgeo/geocaching/CachePopupFragment.java index 4db74ef..068663f 100644 --- a/main/src/cgeo/geocaching/CachePopupFragment.java +++ b/main/src/cgeo/geocaching/CachePopupFragment.java @@ -2,8 +2,8 @@ package cgeo.geocaching; import cgeo.geocaching.activity.Progress; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.network.Network; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.CacheDetailsCreator; diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java index 4196ee2..6d45911 100644 --- a/main/src/cgeo/geocaching/CompassActivity.java +++ b/main/src/cgeo/geocaching/CompassActivity.java @@ -5,8 +5,8 @@ import butterknife.InjectView; import cgeo.geocaching.activity.AbstractActionBarActivity; import cgeo.geocaching.enumerations.LoadFlags; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; import cgeo.geocaching.maps.CGeoMap; import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.GpsStatusProvider.Status; diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java index 1aba760..632e13e 100644 --- a/main/src/cgeo/geocaching/DataStore.java +++ b/main/src/cgeo/geocaching/DataStore.java @@ -11,11 +11,11 @@ import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.files.LocalStorage; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.list.AbstractList; import cgeo.geocaching.list.PseudoList; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.search.SearchSuggestionCursor; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.dialog.Dialogs; diff --git a/main/src/cgeo/geocaching/Destination.java b/main/src/cgeo/geocaching/Destination.java index 10d51be..1990d5d 100644 --- a/main/src/cgeo/geocaching/Destination.java +++ b/main/src/cgeo/geocaching/Destination.java @@ -1,6 +1,6 @@ package cgeo.geocaching; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; public final class Destination implements ICoordinates { diff --git a/main/src/cgeo/geocaching/EditWaypointActivity.java b/main/src/cgeo/geocaching/EditWaypointActivity.java index d3ee5d0..a091ff7 100644 --- a/main/src/cgeo/geocaching/EditWaypointActivity.java +++ b/main/src/cgeo/geocaching/EditWaypointActivity.java @@ -7,9 +7,9 @@ import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.DistanceParser; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter; +import cgeo.geocaching.location.DistanceParser; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 76c3b13..e4fba34 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -20,8 +20,8 @@ import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.files.GPXParser; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.CancellableHandler; diff --git a/main/src/cgeo/geocaching/ICoordinates.java b/main/src/cgeo/geocaching/ICoordinates.java index b70e4ac..8f78e00 100644 --- a/main/src/cgeo/geocaching/ICoordinates.java +++ b/main/src/cgeo/geocaching/ICoordinates.java @@ -1,6 +1,6 @@ package cgeo.geocaching; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; public interface ICoordinates { diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java index 40504fb..d6f9c73 100644 --- a/main/src/cgeo/geocaching/MainActivity.java +++ b/main/src/cgeo/geocaching/MainActivity.java @@ -9,10 +9,10 @@ import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.capability.ILogin; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.StatusCode; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Units; import cgeo.geocaching.list.PseudoList; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; import cgeo.geocaching.maps.CGeoMap; import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.GpsStatusProvider; diff --git a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java index e9568ad..5093293 100644 --- a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java +++ b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java @@ -7,9 +7,9 @@ import butterknife.Optional; import cgeo.geocaching.activity.AbstractActionBarActivity; import cgeo.geocaching.activity.INavigationSource; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; -import cgeo.geocaching.geopoint.DistanceParser; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter; +import cgeo.geocaching.location.DistanceParser; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/SearchActivity.java b/main/src/cgeo/geocaching/SearchActivity.java index edd611a..4f21a63 100644 --- a/main/src/cgeo/geocaching/SearchActivity.java +++ b/main/src/cgeo/geocaching/SearchActivity.java @@ -9,8 +9,8 @@ import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.connector.capability.ISearchByGeocode; import cgeo.geocaching.connector.trackable.TrackableConnector; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; import cgeo.geocaching.search.AutoCompleteAdapter; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index 030c379..fc950c1 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -2,7 +2,7 @@ package cgeo.geocaching; import cgeo.geocaching.compatibility.Compatibility; import cgeo.geocaching.files.LocalStorage; -import cgeo.geocaching.geopoint.GeopointFormatter.Format; +import cgeo.geocaching.location.GeopointFormatter.Format; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java index 1f48165..3ec81fa 100644 --- a/main/src/cgeo/geocaching/TrackableActivity.java +++ b/main/src/cgeo/geocaching/TrackableActivity.java @@ -10,7 +10,7 @@ import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.trackable.TrackableConnector; import cgeo.geocaching.connector.trackable.TravelBugConnector; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Units; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.ui.AbstractCachingPageViewCreator; import cgeo.geocaching.ui.AnchorAwareLinkMovementMethod; diff --git a/main/src/cgeo/geocaching/Waypoint.java b/main/src/cgeo/geocaching/Waypoint.java index 43b24f3..5cfeb29 100644 --- a/main/src/cgeo/geocaching/Waypoint.java +++ b/main/src/cgeo/geocaching/Waypoint.java @@ -2,7 +2,7 @@ package cgeo.geocaching; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.MatcherWrapper; import org.apache.commons.lang3.StringUtils; diff --git a/main/src/cgeo/geocaching/WaypointPopupFragment.java b/main/src/cgeo/geocaching/WaypointPopupFragment.java index 03d95e5..00c7986 100644 --- a/main/src/cgeo/geocaching/WaypointPopupFragment.java +++ b/main/src/cgeo/geocaching/WaypointPopupFragment.java @@ -4,8 +4,8 @@ import butterknife.ButterKnife; import butterknife.InjectView; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.ui.CacheDetailsCreator; import cgeo.geocaching.utils.Log; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java index ec9705c..5e7a5cc 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java @@ -5,7 +5,7 @@ import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.apps.AbstractApp; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.app.Activity; import android.content.Intent; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AbstractRadarApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AbstractRadarApp.java index f31d175..2394be0 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/AbstractRadarApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/AbstractRadarApp.java @@ -2,7 +2,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.Geocache; import cgeo.geocaching.Waypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.app.Activity; import android.content.Intent; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AndroidWearApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AndroidWearApp.java index f083a26..391462b 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/AndroidWearApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/AndroidWearApp.java @@ -4,7 +4,7 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.Intents; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.ProcessUtils; import android.app.Activity; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java b/main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java index c79dfad..8e1e4cf 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java @@ -4,7 +4,7 @@ import cgeo.geocaching.CompassActivity; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.app.Activity; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GeopointNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GeopointNavigationApp.java index fe4fd5d..194b229 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/GeopointNavigationApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/GeopointNavigationApp.java @@ -1,6 +1,6 @@ package cgeo.geocaching.apps.cache.navi; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.app.Activity; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java index b14ba35..80609ce 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java @@ -4,9 +4,9 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter; -import cgeo.geocaching.geopoint.GeopointFormatter.Format; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; +import cgeo.geocaching.location.GeopointFormatter.Format; import cgeo.geocaching.utils.Log; import android.app.Activity; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java index f5ccef4..3102101 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java @@ -2,7 +2,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.MapProviderFactory; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.utils.Log; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java index 902eebf..1979fba 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java @@ -1,7 +1,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.Log; import android.app.Activity; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java b/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java index 540b025..2355d9d 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java @@ -4,7 +4,7 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.CGeoMap; import android.app.Activity; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java b/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java index ea5aebb..f1a504f 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java @@ -3,7 +3,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import com.mapswithme.maps.api.MapsWithMeApi; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index efc988b..db68129 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -11,7 +11,7 @@ import cgeo.geocaching.apps.cache.WhereYouGoApp; import cgeo.geocaching.apps.cache.navi.GoogleNavigationApp.GoogleNavigationBikeApp; import cgeo.geocaching.apps.cache.navi.GoogleNavigationApp.GoogleNavigationDrivingApp; import cgeo.geocaching.apps.cache.navi.GoogleNavigationApp.GoogleNavigationWalkingApp; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.settings.Settings; import org.eclipse.jdt.annotation.Nullable; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java index 024bf37..9f64070 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java @@ -1,7 +1,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.app.Activity; import android.content.Intent; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/OruxMapsApp.java b/main/src/cgeo/geocaching/apps/cache/navi/OruxMapsApp.java index 4dbfadd..f710333 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/OruxMapsApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/OruxMapsApp.java @@ -1,7 +1,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.app.Activity; import android.content.Intent; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java b/main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java index a12a38e..f384192 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java @@ -1,7 +1,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.content.Intent; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java b/main/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java index 4dbb46c..b78caab 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java @@ -3,8 +3,8 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter.Format; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter.Format; import android.app.Activity; import android.content.Intent; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java b/main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java index 0ee512b..a26edc4 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java @@ -1,7 +1,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.content.Intent; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java b/main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java index 4c797a1..584cca9 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java @@ -3,7 +3,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.R; import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.ProcessUtils; import android.app.Activity; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/SygicNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/SygicNavigationApp.java index 76b7f0e..00a09e3 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/SygicNavigationApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/SygicNavigationApp.java @@ -1,7 +1,7 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.app.Activity; import android.content.Intent; diff --git a/main/src/cgeo/geocaching/connector/AbstractConnector.java b/main/src/cgeo/geocaching/connector/AbstractConnector.java index a5d0407..834167a 100644 --- a/main/src/cgeo/geocaching/connector/AbstractConnector.java +++ b/main/src/cgeo/geocaching/connector/AbstractConnector.java @@ -15,10 +15,11 @@ import cgeo.geocaching.connector.capability.ISearchByOwner; import cgeo.geocaching.connector.capability.ISearchByViewPort; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; + import rx.functions.Action1; import java.util.ArrayList; diff --git a/main/src/cgeo/geocaching/connector/ConnectorFactory.java b/main/src/cgeo/geocaching/connector/ConnectorFactory.java index e6ef829..6bbfae0 100644 --- a/main/src/cgeo/geocaching/connector/ConnectorFactory.java +++ b/main/src/cgeo/geocaching/connector/ConnectorFactory.java @@ -21,7 +21,7 @@ import cgeo.geocaching.connector.trackable.GeokretyConnector; import cgeo.geocaching.connector.trackable.TrackableConnector; import cgeo.geocaching.connector.trackable.TravelBugConnector; import cgeo.geocaching.connector.trackable.UnknownTrackableConnector; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; diff --git a/main/src/cgeo/geocaching/connector/IConnector.java b/main/src/cgeo/geocaching/connector/IConnector.java index e6b6674..c235df4 100644 --- a/main/src/cgeo/geocaching/connector/IConnector.java +++ b/main/src/cgeo/geocaching/connector/IConnector.java @@ -4,7 +4,7 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.ICache; import cgeo.geocaching.LogCacheActivity; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import org.eclipse.jdt.annotation.NonNull; diff --git a/main/src/cgeo/geocaching/connector/capability/ISearchByCenter.java b/main/src/cgeo/geocaching/connector/capability/ISearchByCenter.java index adc36c7..576220d 100644 --- a/main/src/cgeo/geocaching/connector/capability/ISearchByCenter.java +++ b/main/src/cgeo/geocaching/connector/capability/ISearchByCenter.java @@ -2,8 +2,8 @@ package cgeo.geocaching.connector.capability; import cgeo.geocaching.SearchResult; import cgeo.geocaching.connector.IConnector; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.loaders.RecaptchaReceiver; +import cgeo.geocaching.location.Geopoint; import org.eclipse.jdt.annotation.NonNull; diff --git a/main/src/cgeo/geocaching/connector/capability/ISearchByViewPort.java b/main/src/cgeo/geocaching/connector/capability/ISearchByViewPort.java index 7981ba8..ef81c4c 100644 --- a/main/src/cgeo/geocaching/connector/capability/ISearchByViewPort.java +++ b/main/src/cgeo/geocaching/connector/capability/ISearchByViewPort.java @@ -3,7 +3,7 @@ package cgeo.geocaching.connector.capability; import cgeo.geocaching.SearchResult; import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.connector.gc.MapTokens; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import org.eclipse.jdt.annotation.NonNull; diff --git a/main/src/cgeo/geocaching/connector/ec/ECApi.java b/main/src/cgeo/geocaching/connector/ec/ECApi.java index 3e7472e..64177af 100644 --- a/main/src/cgeo/geocaching/connector/ec/ECApi.java +++ b/main/src/cgeo/geocaching/connector/ec/ECApi.java @@ -9,9 +9,9 @@ import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.files.GPX10Parser; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.utils.JsonUtils; diff --git a/main/src/cgeo/geocaching/connector/ec/ECConnector.java b/main/src/cgeo/geocaching/connector/ec/ECConnector.java index a266eee..27b5b54 100644 --- a/main/src/cgeo/geocaching/connector/ec/ECConnector.java +++ b/main/src/cgeo/geocaching/connector/ec/ECConnector.java @@ -16,9 +16,9 @@ import cgeo.geocaching.connector.capability.ISearchByViewPort; import cgeo.geocaching.connector.gc.MapTokens; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.StatusCode; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.loaders.RecaptchaReceiver; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.SettingsActivity; import cgeo.geocaching.utils.CancellableHandler; diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java index 6a96d04..8b714c7 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java @@ -21,9 +21,9 @@ import cgeo.geocaching.connector.capability.ISearchByKeyword; import cgeo.geocaching.connector.capability.ISearchByOwner; import cgeo.geocaching.connector.capability.ISearchByViewPort; import cgeo.geocaching.enumerations.StatusCode; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.loaders.RecaptchaReceiver; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java index 63c42ff..ccb2f0c 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCMap.java +++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java @@ -10,10 +10,10 @@ import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LiveMapStrategy.StrategyFlag; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.files.ParserException; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter.Format; -import cgeo.geocaching.geopoint.Units; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; +import cgeo.geocaching.location.Viewport; +import cgeo.geocaching.location.GeopointFormatter.Format; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.Formatter; diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java index c33fedd..b0f8b8e 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCParser.java +++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java @@ -22,9 +22,9 @@ import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.files.LocParser; import cgeo.geocaching.gcvote.GCVote; import cgeo.geocaching.gcvote.GCVoteRating; -import cgeo.geocaching.geopoint.DistanceParser; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.loaders.RecaptchaReceiver; +import cgeo.geocaching.location.DistanceParser; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/connector/gc/Tile.java b/main/src/cgeo/geocaching/connector/gc/Tile.java index ff13fe3..17d129e 100644 --- a/main/src/cgeo/geocaching/connector/gc/Tile.java +++ b/main/src/cgeo/geocaching/connector/gc/Tile.java @@ -1,8 +1,8 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.ICoordinates; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.utils.LeastRecentlyUsedSet; diff --git a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java index dd25c5e..b56055a 100644 --- a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java +++ b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java @@ -15,9 +15,9 @@ import cgeo.geocaching.connector.capability.ISearchByOwner; import cgeo.geocaching.connector.capability.ISearchByViewPort; import cgeo.geocaching.connector.gc.MapTokens; import cgeo.geocaching.connector.oc.UserInfo.UserInfoStatus; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.loaders.RecaptchaReceiver; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.CryptUtils; diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java index f665a1a..b3f2f39 100644 --- a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java @@ -22,9 +22,9 @@ import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.OAuth; import cgeo.geocaching.network.OAuthTokens; diff --git a/main/src/cgeo/geocaching/connector/ox/OXConnector.java b/main/src/cgeo/geocaching/connector/ox/OXConnector.java index 7d4cf7f..6bb5bce 100644 --- a/main/src/cgeo/geocaching/connector/ox/OXConnector.java +++ b/main/src/cgeo/geocaching/connector/ox/OXConnector.java @@ -9,9 +9,9 @@ import cgeo.geocaching.connector.capability.ISearchByGeocode; import cgeo.geocaching.connector.capability.ISearchByKeyword; import cgeo.geocaching.connector.capability.ISearchByViewPort; import cgeo.geocaching.connector.gc.MapTokens; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.loaders.RecaptchaReceiver; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.CancellableHandler; diff --git a/main/src/cgeo/geocaching/connector/ox/OpenCachingApi.java b/main/src/cgeo/geocaching/connector/ox/OpenCachingApi.java index 21207ec..c232ef5 100644 --- a/main/src/cgeo/geocaching/connector/ox/OpenCachingApi.java +++ b/main/src/cgeo/geocaching/connector/ox/OpenCachingApi.java @@ -2,10 +2,10 @@ package cgeo.geocaching.connector.ox; import cgeo.geocaching.Geocache; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/export/GpxSerializer.java b/main/src/cgeo/geocaching/export/GpxSerializer.java index d3e8887..08c6ef5 100644 --- a/main/src/cgeo/geocaching/export/GpxSerializer.java +++ b/main/src/cgeo/geocaching/export/GpxSerializer.java @@ -7,7 +7,7 @@ import cgeo.geocaching.Trackable; import cgeo.geocaching.Waypoint; import cgeo.geocaching.enumerations.CacheAttribute; import cgeo.geocaching.enumerations.LoadFlags; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.SynchronizedDateFormat; import cgeo.geocaching.utils.TextUtils; diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index bedee43..cd99ae9 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -18,8 +18,8 @@ import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.CancellableHandler; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.MatcherWrapper; diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java index 6fcd2c3..1cc0c63 100644 --- a/main/src/cgeo/geocaching/files/LocParser.java +++ b/main/src/cgeo/geocaching/files/LocParser.java @@ -4,7 +4,7 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.SearchResult; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.CancellableHandler; import cgeo.geocaching.utils.Log; diff --git a/main/src/cgeo/geocaching/filter/DistanceFilter.java b/main/src/cgeo/geocaching/filter/DistanceFilter.java index 3328c72..923f46a 100644 --- a/main/src/cgeo/geocaching/filter/DistanceFilter.java +++ b/main/src/cgeo/geocaching/filter/DistanceFilter.java @@ -4,7 +4,7 @@ import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.Geocache; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import java.util.ArrayList; import java.util.List; diff --git a/main/src/cgeo/geocaching/geopoint/DistanceParser.java b/main/src/cgeo/geocaching/geopoint/DistanceParser.java deleted file mode 100644 index e3a7482..0000000 --- a/main/src/cgeo/geocaching/geopoint/DistanceParser.java +++ /dev/null @@ -1,51 +0,0 @@ -package cgeo.geocaching.geopoint; - -import cgeo.geocaching.utils.MatcherWrapper; - -import org.apache.commons.lang3.StringUtils; - -import java.util.Locale; -import java.util.regex.Pattern; - -public final class DistanceParser { - - private static final Pattern pattern = Pattern.compile("^([0-9.,]+)[ ]*(m|km|ft|yd|mi|)?$", Pattern.CASE_INSENSITIVE); - - /** - * Parse a distance string composed by a number and an optional suffix - * (such as "1.2km"). - * - * @param distanceText - * the string to analyze - * @return the distance in kilometers - * - * @throws NumberFormatException - * if the given number is invalid - */ - public static float parseDistance(String distanceText, final boolean metricUnit) - throws NumberFormatException { - final MatcherWrapper matcher = new MatcherWrapper(pattern, distanceText); - - if (!matcher.find()) { - throw new NumberFormatException(distanceText); - } - - final float value = Float.parseFloat(matcher.group(1).replace(',', '.')); - final String unit = matcher.group(2).toLowerCase(Locale.US); - - if (unit.equals("m") || (StringUtils.isEmpty(unit) && metricUnit)) { - return value / 1000; - } - if (unit.equals("km")) { - return value; - } - if (unit.equals("yd")) { - return value * IConversion.YARDS_TO_KILOMETER; - } - if (unit.equals("mi")) { - return value * IConversion.MILES_TO_KILOMETER; - } - return value * IConversion.FEET_TO_KILOMETER; - } - -} diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java deleted file mode 100644 index aa7c929..0000000 --- a/main/src/cgeo/geocaching/geopoint/Geopoint.java +++ /dev/null @@ -1,601 +0,0 @@ -package cgeo.geocaching.geopoint; - -import cgeo.geocaching.ICoordinates; -import cgeo.geocaching.R; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.annotation.NonNull; - -import android.location.Location; -import android.os.Build; -import android.os.Parcel; -import android.os.Parcelable; - -/** - * Abstraction of geographic point. This class is immutable. - */ -public final class Geopoint implements ICoordinates, Parcelable { - /** - * Reusable default object - */ - public static final @NonNull Geopoint ZERO = new Geopoint(0.0, 0.0); - - private static final double DEG_TO_RAD = Math.PI / 180; - private static final double RAD_TO_DEG = 180 / Math.PI; - private static final float EARTH_RADIUS = 6371.0f; - /** - * JIT bug in Android 4.2.1 - */ - private static final boolean DISTANCE_BROKEN = Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1; - - private final double latitude; - private final double longitude; - - /** - * Creates new Geopoint with given latitude and longitude (both degree). - * - * @param lat - * latitude - * @param lon - * longitude - */ - public Geopoint(final double lat, final double lon) { - latitude = lat; - longitude = lon; - } - - /** - * Creates new Geopoint with latitude and longitude parsed from string. - * - * @param text - * string to parse - * @throws Geopoint.ParseException - * if the string cannot be parsed - * @see GeopointParser#parse(String) - */ - public Geopoint(@NonNull final String text) { - final Geopoint parsed = GeopointParser.parse(text); - latitude = parsed.latitude; - longitude = parsed.longitude; - } - - /** - * Creates new Geopoint with latitude and longitude parsed from strings. - * - * @param latText - * latitude string to parse - * @param lonText - * longitude string to parse - * @throws Geopoint.ParseException - * if any argument string cannot be parsed - */ - public Geopoint(final String latText, final String lonText) { - this(GeopointParser.parseLatitude(latText), GeopointParser.parseLongitude(lonText)); - } - - /** - * Creates new Geopoint with given Location. - * - * @param loc - * the Location to clone - */ - public Geopoint(final Location loc) { - this(loc.getLatitude(), loc.getLongitude()); - } - - /** - * Create new Geopoint from Parcel. - * - * @param in - * a Parcel to read the saved data from - */ - public Geopoint(final Parcel in) { - latitude = in.readDouble(); - longitude = in.readDouble(); - } - - /** - * Create new Geopoint from individual textual components. - * - * @param latDir - * @param latDeg - * @param latDegFrac - * @param lonDir - * @param lonDeg - * @param lonDegFrac - */ - public Geopoint(final String latDir, final String latDeg, final String latDegFrac, - final String lonDir, final String lonDeg, final String lonDegFrac) { - this(getLatSign(latDir) + latDeg + "." + addZeros(latDegFrac, 5), - getLonSign(lonDir) + lonDeg + "." + addZeros(lonDegFrac, 5)); - } - - /** - * Create new Geopoint from individual textual components. - * - * @param latDir - * @param latDeg - * @param latMin - * @param latMinFrac - * @param lonDir - * @param lonDeg - * @param lonMin - * @param lonMinFrac - */ - public Geopoint(final String latDir, final String latDeg, final String latMin, final String latMinFrac, - final String lonDir, final String lonDeg, final String lonMin, final String lonMinFrac) { - this(latDir + " " + latDeg + " " + latMin + "." + addZeros(latMinFrac, 3), - lonDir + " " + lonDeg + " " + lonMin + "." + addZeros(lonMinFrac, 3)); - } - - /** - * Create new Geopoint from individual textual components. - * - * @param latDir - * @param latDeg - * @param latMin - * @param latSec - * @param latSecFrac - * @param lonDir - * @param lonDeg - * @param lonMin - * @param lonSec - * @param lonSecFrac - */ - public Geopoint(final String latDir, final String latDeg, final String latMin, final String latSec, final String latSecFrac, - final String lonDir, final String lonDeg, final String lonMin, final String lonSec, final String lonSecFrac) { - this(latDir + " " + latDeg + " " + latMin + " " + latSec + "." + addZeros(latSecFrac, 3), - lonDir + " " + lonDeg + " " + lonMin + " " + lonSec + "." + addZeros(lonSecFrac, 3)); - } - - /** - * Get latitude in degree. - * - * @return latitude - */ - public double getLatitude() { - return latitude; - } - - /** - * Get latitude in microdegree. - * - * @return latitude - */ - public int getLatitudeE6() { - return (int) Math.round(latitude * 1E6); - } - - /** - * Get longitude in degree. - * - * @return longitude - */ - public double getLongitude() { - return longitude; - } - - /* - * Return a waypoint which is the copy of this one rounded to the given limit. - * For example, to get a waypoint adapter to a display with 3 digits after the - * seconds decimal point, a rounding factor of 3600*1000 would be appropriate. - */ - Geopoint roundedAt(final long factor) { - return new Geopoint(((double) Math.round(latitude * factor)) / factor, - ((double) Math.round(longitude * factor)) / factor); - } - - /** - * Get longitude in microdegree. - * - * @return longitude - */ - public int getLongitudeE6() { - return (int) Math.round(longitude * 1E6); - } - - /** - * Get distance and bearing from the current point to a target. - * - * @param target - * The target - * @return An array of floats: the distance in meters, then the bearing in degrees - */ - private float[] pathTo(final Geopoint target) { - float[] results = new float[2]; - android.location.Location.distanceBetween(latitude, longitude, target.latitude, target.longitude, results); - return results; - } - - /** - * Calculates distance to given Geopoint in km. - * - * @param point - * target - * @return distance in km - * @throws GeopointException - * if there is an error in distance calculation - */ - public float distanceTo(@NonNull final ICoordinates point) { - final Geopoint otherCoords = point.getCoords(); - if (DISTANCE_BROKEN) { - return (float) (getDistance(latitude, longitude, otherCoords.latitude, otherCoords.longitude) / 1000); - } - return pathTo(otherCoords)[0] / 1000; - } - - /** - * Calculates bearing to given Geopoint in degree. - * - * @param point - * target - * @return bearing in degree, in the [0,360[ range - */ - public float bearingTo(final ICoordinates point) { - // Android library returns a bearing in the [-180;180] range - final float bearing = pathTo(point.getCoords())[1]; - return bearing < 0 ? bearing + 360 : bearing; - } - - /** - * Calculates geopoint from given bearing and distance. - * - * @param bearing - * bearing in degree - * @param distance - * distance in km - * @return the projected geopoint - */ - public Geopoint project(final double bearing, final double distance) { - final double rlat1 = latitude * DEG_TO_RAD; - final double rlon1 = longitude * DEG_TO_RAD; - final double rbearing = bearing * DEG_TO_RAD; - final double rdistance = distance / EARTH_RADIUS; - - final double rlat = Math.asin(Math.sin(rlat1) * Math.cos(rdistance) + Math.cos(rlat1) * Math.sin(rdistance) * Math.cos(rbearing)); - final double rlon = rlon1 + Math.atan2(Math.sin(rbearing) * Math.sin(rdistance) * Math.cos(rlat1), Math.cos(rdistance) - Math.sin(rlat1) * Math.sin(rlat)); - - return new Geopoint(rlat * RAD_TO_DEG, rlon * RAD_TO_DEG); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof Geopoint)) { - return false; - } - final Geopoint gp = (Geopoint) obj; - return getLatitudeE6() == gp.getLatitudeE6() && getLongitudeE6() == gp.getLongitudeE6(); - } - - @Override - public int hashCode() { - return getLatitudeE6() ^ getLongitudeE6(); - } - - /** - * Returns formatted coordinates. - * - * @param format - * the desired format - * @see GeopointFormatter - * @return formatted coordinates - */ - public String format(GeopointFormatter.Format format) { - return GeopointFormatter.format(format, this); - } - - /** - * Returns formatted coordinates with default format. - * Default format is decimalminutes, e.g. N 52° 36.123 E 010° 03.456 - * - * @return formatted coordinates - */ - @Override - public String toString() { - return format(GeopointFormatter.Format.LAT_LON_DECMINUTE); - } - - abstract public static class GeopointException extends NumberFormatException { - private static final long serialVersionUID = 1L; - - protected GeopointException(String msg) { - super(msg); - } - } - - public static class ParseException extends GeopointException { - private static final long serialVersionUID = 1L; - public final int resource; - - public ParseException(final String msg, final GeopointParser.LatLon faulty) { - super(msg); - resource = faulty == GeopointParser.LatLon.LAT ? R.string.err_parse_lat : R.string.err_parse_lon; - } - } - - @Override - public Geopoint getCoords() { - return this; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(final Parcel dest, final int flags) { - dest.writeDouble(latitude); - dest.writeDouble(longitude); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public Geopoint createFromParcel(final Parcel in) { - return new Geopoint(in); - } - - @Override - public Geopoint[] newArray(final int size) { - return new Geopoint[size]; - } - }; - - /** - * Get latitude character (N or S). - * - * @return - */ - public char getLatDir() { - return latitude >= 0 ? 'N' : 'S'; - } - - /** - * Get longitude character (E or W). - * - * @return - */ - public char getLonDir() { - return longitude >= 0 ? 'E' : 'W'; - } - - /** - * Get the integral non-negative latitude degrees. - * - * @return - */ - public int getLatDeg() { - return getDeg(latitude); - } - - /** - * Get the integral non-negative longitude degrees. - * - * @return - */ - public int getLonDeg() { - return getDeg(longitude); - } - - private static int getDeg(final double deg) { - return (int) Math.abs(deg); - } - - /** - * Get the fractional part of the latitude degrees scaled up by 10^5. - * - * @return - */ - public int getLatDegFrac() { - return getDegFrac(latitude); - } - - /** - * Get the fractional part of the longitude degrees scaled up by 10^5. - * - * @return - */ - public int getLonDegFrac() { - return getDegFrac(longitude); - } - - private static int getDegFrac(final double deg) { - return (int) (Math.round(Math.abs(deg) * 100000) % 100000); - } - - /** - * Get the integral latitude minutes. - * - * @return - */ - public int getLatMin() { - return getMin(latitude); - } - - /** - * Get the integral longitude minutes. - * - * @return - */ - public int getLonMin() { - return getMin(longitude); - } - - private static int getMin(final double deg) { - return ((int) Math.abs(deg * 60)) % 60; - } - - /** - * Get the fractional part of the latitude minutes scaled up by 1000. - * - * @return - */ - public int getLatMinFrac() { - return getMinFrac(latitude); - } - - /** - * Get the fractional part of the longitude minutes scaled up by 1000. - * - * @return - */ - public int getLonMinFrac() { - return getMinFrac(longitude); - } - - private static int getMinFrac(final double deg) { - return (int) (Math.round(Math.abs(deg) * 60000) % 1000); - } - - /** - * Get the latitude minutes. - * - * @return - */ - public double getLatMinRaw() { - return getMinRaw(latitude); - } - - /** - * Get the longitude minutes. - * - * @return - */ - public double getLonMinRaw() { - return getMinRaw(longitude); - } - - private static double getMinRaw(final double deg) { - return (Math.abs(deg) * 60) % 60; - } - - /** - * Get the integral part of the latitude seconds. - * - * @return - */ - public int getLatSec() { - return getSec(latitude); - } - - /** - * Get the integral part of the longitude seconds. - * - * @return - */ - public int getLonSec() { - return getSec(longitude); - } - - private static int getSec(final double deg) { - return ((int) Math.abs(deg * 3600)) % 60; - } - - /** - * Get the fractional part of the latitude seconds scaled up by 1000. - * - * @return - */ - - public int getLatSecFrac() { - return getSecFrac(latitude); - } - - /** - * Get the fractional part of the longitude seconds scaled up by 1000. - * - * @return - */ - - public int getLonSecFrac() { - return getSecFrac(longitude); - } - - private static int getSecFrac(final double deg) { - return (int) (Math.round(Math.abs(deg) * 3600000) % 1000); - } - - /** - * Get the latitude seconds. - * - * @return - */ - public double getLatSecRaw() { - return getSecRaw(latitude); - } - - /** - * Get the longitude seconds. - * - * @return - */ - public double getLonSecRaw() { - return getSecRaw(longitude); - } - - private static double getSecRaw(final double deg) { - return (Math.abs(deg) * 3600) % 60; - } - - private static String addZeros(final String value, final int len) { - return StringUtils.leftPad(value.trim(), len, '0'); - } - - private static String getLonSign(final String lonDir) { - return "W".equalsIgnoreCase(lonDir) ? "-" : ""; - } - - private static String getLatSign(final String latDir) { - return "S".equalsIgnoreCase(latDir) ? "-" : ""; - } - - /** - * Gets distance in meters (workaround for 4.2.1 JIT bug). - */ - public static double getDistance(double lat1, double lon1, double lat2, double lon2) { - // for haversine use R = 6372.8 km instead of 6371 km - double earthRadius = 6372.8; - double dLat = toRadians(lat2 - lat1); - double dLon = toRadians(lon2 - lon1); - double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + - Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) * - Math.sin(dLon / 2) * Math.sin(dLon / 2); - // simplify haversine - return (2 * earthRadius * 1000 * Math.asin(Math.sqrt(a))); - } - - private static double toRadians(double angdeg) { - return angdeg * DEG_TO_RAD; - } - - /** - * Check whether a latitude built from user supplied data is valid. We accept both N90/S90. - * - * @return true if the latitude looks valid, false otherwise - */ - public static boolean isValidLatitude(final double latitude) { - return latitude >= -90 && latitude <= 90; - } - - /** - * Check whether a longitude from user supplied data is valid. We accept both E180/W180. - * - * @return true if the longitude looks valid, false otherwise - */ - public static boolean isValidLongitude(final double longitude) { - return longitude >= -180 && longitude <= 180; - } - - /** - * Check whether a geopoint built from user supplied data is valid. We accept both N90/S90 and E180/W180. - * - * @return true if the geopoint looks valid, false otherwise - */ - public boolean isValid() { - return isValidLatitude(latitude) && isValidLongitude(longitude); - } - -} diff --git a/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java b/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java deleted file mode 100644 index a6965f9..0000000 --- a/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java +++ /dev/null @@ -1,116 +0,0 @@ -package cgeo.geocaching.geopoint; - -import java.util.Locale; - -/** - * Formatting of Geopoint. - */ -public class GeopointFormatter { - /** - * Predefined formats. - */ - public enum Format { - /** Example: "10,123456 -0,123456" */ - LAT_LON_DECDEGREE, - - /** Example: "10.123456,-0.123456" (unlocalized) */ - LAT_LON_DECDEGREE_COMMA, - - /** Example: "N 10° 12,345 · W 5° 12,345" */ - LAT_LON_DECMINUTE, - - /** Example: "N 10° 12.345 W 5° 12.345" */ - LAT_LON_DECMINUTE_RAW, - - /** Example: "N 10° 12' 34" W 5° 12' 34" */ - LAT_LON_DECSECOND, - - /** Example: "-0.123456" (unlocalized latitude) */ - LAT_DECDEGREE_RAW, - - /** Example: "N 10° 12,345" */ - LAT_DECMINUTE, - - /** Example: "N 10 12,345" */ - LAT_DECMINUTE_RAW, - - /** Example: "-0.123456" (unlocalized longitude) */ - LON_DECDEGREE_RAW, - - /** Example: "W 5° 12,345" */ - LON_DECMINUTE, - - /** Example: "W 5 12,345" */ - LON_DECMINUTE_RAW; - } - - /** - * Formats a Geopoint. - * - * @param gp - * the Geopoint to format - * @param format - * one of the predefined formats - * @return the formatted coordinates - */ - public static String format(final Format format, final Geopoint gp) { - final double latSigned = gp.getLatitude(); - final double lonSigned = gp.getLongitude(); - - switch (format) { - case LAT_LON_DECDEGREE: - return String.format(Locale.getDefault(), "%.6f %.6f", latSigned, lonSigned); - - case LAT_LON_DECDEGREE_COMMA: - return String.format((Locale) null, "%.6f,%.6f", latSigned, lonSigned); - - case LAT_LON_DECMINUTE: { - final Geopoint rgp = gp.roundedAt(60 * 1000); - return String.format(Locale.getDefault(), "%c %02d° %06.3f · %c %03d° %06.3f", - rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw(), rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); - } - - case LAT_LON_DECMINUTE_RAW: { - final Geopoint rgp = gp.roundedAt(60 * 1000); - return String.format((Locale) null, "%c %02d° %06.3f %c %03d° %06.3f", - rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw(), rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); - } - - case LAT_LON_DECSECOND: { - final Geopoint rgp = gp.roundedAt(3600 * 1000); - return String.format(Locale.getDefault(), "%c %02d° %02d' %06.3f\" · %c %03d° %02d' %06.3f\"", - rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMin(), rgp.getLatSecRaw(), - rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMin(), rgp.getLonSecRaw()); - } - - case LAT_DECDEGREE_RAW: - return String.format((Locale) null, "%.6f", latSigned); - - case LAT_DECMINUTE: { - final Geopoint rgp = gp.roundedAt(60 * 1000); - return String.format(Locale.getDefault(), "%c %02d° %06.3f", rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw()); - } - - case LAT_DECMINUTE_RAW: { - final Geopoint rgp = gp.roundedAt(60 * 1000); - return String.format(Locale.getDefault(), "%c %02d %06.3f", rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw()); - } - - case LON_DECDEGREE_RAW: - return String.format((Locale) null, "%.6f", lonSigned); - - case LON_DECMINUTE: { - final Geopoint rgp = gp.roundedAt(60 * 1000); - return String.format(Locale.getDefault(), "%c %03d° %06.3f", rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); - } - - case LON_DECMINUTE_RAW: { - final Geopoint rgp = gp.roundedAt(60 * 1000); - return String.format(Locale.getDefault(), "%c %03d %06.3f", rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); - } - - } - throw new IllegalStateException(); // cannot happen, if switch case is enum complete - } - -} diff --git a/main/src/cgeo/geocaching/geopoint/GeopointParser.java b/main/src/cgeo/geocaching/geopoint/GeopointParser.java deleted file mode 100644 index 62d43da..0000000 --- a/main/src/cgeo/geocaching/geopoint/GeopointParser.java +++ /dev/null @@ -1,163 +0,0 @@ -package cgeo.geocaching.geopoint; - -import cgeo.geocaching.utils.MatcherWrapper; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.annotation.NonNull; - -import java.util.regex.Pattern; - -/** - * Parse coordinates. - */ -class GeopointParser { - - private static class ResultWrapper { - final double result; - final int matcherPos; - final int matcherLength; - - public ResultWrapper(final double result, int matcherPos, int stringLength) { - this.result = result; - this.matcherPos = matcherPos; - this.matcherLength = stringLength; - } - } - - // ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 ) - private static final Pattern PATTERN_LAT = Pattern.compile("\\b([NS]|)\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE); - private static final Pattern PATTERN_LON = Pattern.compile("\\b([WE]|)\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE); - - private static final Pattern PATTERN_BAD_BLANK = Pattern.compile("(\\d)[,.] (\\d{2,})"); - - enum LatLon { - LAT, - LON - } - - /** - * Parses a pair of coordinates (latitude and longitude) out of a String. - * Accepts following formats and combinations of it: - * X DD - * X DD° - * X DD° MM - * X DD° MM.MMM - * X DD° MM SS - * - * as well as: - * DD.DDDDDDD - * - * Both . and , are accepted, also variable count of spaces (also 0) - * - * @param text - * the string to parse - * @return an Geopoint with parsed latitude and longitude - * @throws Geopoint.ParseException - * if lat or lon could not be parsed - */ - public static Geopoint parse(@NonNull final String text) { - final ResultWrapper latitudeWrapper = parseHelper(text, LatLon.LAT); - // cut away the latitude part when parsing the longitude - final ResultWrapper longitudeWrapper = parseHelper(text.substring(latitudeWrapper.matcherPos + latitudeWrapper.matcherLength), LatLon.LON); - - if (longitudeWrapper.matcherPos - (latitudeWrapper.matcherPos + latitudeWrapper.matcherLength) >= 10) { - throw new Geopoint.ParseException("Distance between latitude and longitude text is to large.", LatLon.LON); - } - - final double lat = latitudeWrapper.result; - final double lon = longitudeWrapper.result; - if (!Geopoint.isValidLatitude(lat)) { - throw new Geopoint.ParseException(text, LatLon.LAT); - } - if (!Geopoint.isValidLongitude(lon)) { - throw new Geopoint.ParseException(text, LatLon.LON); - } - return new Geopoint(lat, lon); - } - - /** - * Helper for coordinates-parsing - * - * @param text - * @param latlon - * @return - */ - private static ResultWrapper parseHelper(final String text, final LatLon latlon) { - - MatcherWrapper matcher = new MatcherWrapper(PATTERN_BAD_BLANK, text); - String replaceSpaceAfterComma = matcher.replaceAll("$1.$2"); - - final Pattern pattern = LatLon.LAT == latlon ? PATTERN_LAT : PATTERN_LON; - matcher = new MatcherWrapper(pattern, replaceSpaceAfterComma); - - try { - return new ResultWrapper(Double.valueOf(replaceSpaceAfterComma), 0, text.length()); - } catch (NumberFormatException ignored) { - // fall through to advanced parsing - } - - if (matcher.find()) { - final double sign = matcher.group(1).equalsIgnoreCase("S") || matcher.group(1).equalsIgnoreCase("W") ? -1.0 : 1.0; - final double degree = Integer.valueOf(matcher.group(2)).doubleValue(); - - double minutes = 0.0; - double seconds = 0.0; - - if (null != matcher.group(3)) { - minutes = Integer.valueOf(matcher.group(3)).doubleValue(); - - if (null != matcher.group(4)) { - seconds = Double.parseDouble("0." + matcher.group(4)) * 60.0; - } else if (null != matcher.group(5)) { - seconds = Double.parseDouble(matcher.group(5).replace(",", ".")); - } - } - - return new ResultWrapper(sign * (degree + minutes / 60.0 + seconds / 3600.0), matcher.start(), matcher.group().length()); - - } - - // Nothing found with "N 52...", try to match string as decimal degree parts (i.e. multiple doubles) - try { - final String[] items = StringUtils.split(text.trim()); - if (items.length > 0 && items.length <= 2) { - final int index = (latlon == LatLon.LON ? items.length - 1 : 0); - final String textPart = items[index]; - final int pos = (latlon == LatLon.LON ? text.lastIndexOf(textPart) : text.indexOf(textPart)); - return new ResultWrapper(Double.parseDouble(textPart), pos, textPart.length()); - } - } catch (NumberFormatException ignored) { - // The right exception will be raised below. - } - - throw new Geopoint.ParseException("Could not parse coordinates as " + latlon + ": \"" + text + "\"", latlon); - } - - /** - * Parses latitude out of a given string. - * - * @see #parse(String) - * @param text - * the string to be parsed - * @return the latitude as decimal degree - * @throws Geopoint.ParseException - * if latitude could not be parsed - */ - public static double parseLatitude(final String text) { - return parseHelper(text, LatLon.LAT).result; - } - - /** - * Parses longitude out of a given string. - * - * @see #parse(String) - * @param text - * the string to be parsed - * @return the longitude as decimal degree - * @throws Geopoint.ParseException - * if longitude could not be parsed - */ - public static double parseLongitude(final String text) { - return parseHelper(text, LatLon.LON).result; - } -} diff --git a/main/src/cgeo/geocaching/geopoint/IConversion.java b/main/src/cgeo/geocaching/geopoint/IConversion.java deleted file mode 100644 index b1cbffd..0000000 --- a/main/src/cgeo/geocaching/geopoint/IConversion.java +++ /dev/null @@ -1,13 +0,0 @@ -package cgeo.geocaching.geopoint; - -public interface IConversion { - public static final float MILES_TO_KILOMETER = 1.609344f; - public static final float FEET_TO_KILOMETER = 0.0003048f; - public static final float YARDS_TO_KILOMETER = 0.0009144f; - /** - * Factor used to calculate distance from meters to foot; - *

- * ft = m * METERS_TO_FEET; - */ - public static final double METERS_TO_FEET = 3.2808399d; -} diff --git a/main/src/cgeo/geocaching/geopoint/Units.java b/main/src/cgeo/geocaching/geopoint/Units.java deleted file mode 100644 index c657ede..0000000 --- a/main/src/cgeo/geocaching/geopoint/Units.java +++ /dev/null @@ -1,62 +0,0 @@ -package cgeo.geocaching.geopoint; - -import cgeo.geocaching.settings.Settings; - -import org.apache.commons.lang3.tuple.ImmutablePair; - -import java.util.Locale; - -public class Units { - - public static ImmutablePair scaleDistance(final double distanceKilometers) { - double distance; - String units; - if (Settings.useImperialUnits()) { - distance = distanceKilometers / IConversion.MILES_TO_KILOMETER; - if (distance >= 0.1) { - units = "mi"; - } else { - distance *= 5280; - units = "ft"; - } - } else { - if (distanceKilometers >= 1) { - distance = distanceKilometers; - units = "km"; - } else { - distance = distanceKilometers * 1000; - units = "m"; - } - } - return new ImmutablePair<>(distance, units); - } - - public static String getDistanceFromKilometers(final Float distanceKilometers) { - if (distanceKilometers == null) { - return "?"; - } - - final ImmutablePair scaled = scaleDistance(distanceKilometers); - String formatString; - if (scaled.left >= 100) { - formatString = "%.0f"; - } else if (scaled.left >= 10) { - formatString = "%.1f"; - } else { - formatString = "%.2f"; - } - - return String.format(formatString + " %s", scaled.left, scaled.right); - } - - public static String getDistanceFromMeters(float meters) { - return getDistanceFromKilometers(meters / 1000f); - } - - public static String getSpeed(final float kilometersPerHour) { - if (Settings.useImperialUnits()) { - return String.format(Locale.US, "%.0f mph", kilometersPerHour / IConversion.MILES_TO_KILOMETER); - } - return String.format(Locale.US, "%.0f km/h", kilometersPerHour); - } -} diff --git a/main/src/cgeo/geocaching/geopoint/Viewport.java b/main/src/cgeo/geocaching/geopoint/Viewport.java deleted file mode 100644 index a48b0a1..0000000 --- a/main/src/cgeo/geocaching/geopoint/Viewport.java +++ /dev/null @@ -1,192 +0,0 @@ -package cgeo.geocaching.geopoint; - -import cgeo.geocaching.ICoordinates; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; - -import java.util.Collection; - -public final class Viewport { - - public final @NonNull Geopoint center; - public final @NonNull Geopoint bottomLeft; - public final @NonNull Geopoint topRight; - - public Viewport(final @NonNull ICoordinates point1, final @NonNull ICoordinates point2) { - final Geopoint gp1 = point1.getCoords(); - final Geopoint gp2 = point2.getCoords(); - this.bottomLeft = new Geopoint(Math.min(gp1.getLatitude(), gp2.getLatitude()), - Math.min(gp1.getLongitude(), gp2.getLongitude())); - this.topRight = new Geopoint(Math.max(gp1.getLatitude(), gp2.getLatitude()), - Math.max(gp1.getLongitude(), gp2.getLongitude())); - this.center = new Geopoint((gp1.getLatitude() + gp2.getLatitude()) / 2, - (gp1.getLongitude() + gp2.getLongitude()) / 2); - } - - public Viewport(final @NonNull ICoordinates center, final double latSpan, final double lonSpan) { - this.center = center.getCoords(); - final double centerLat = this.center.getLatitude(); - final double centerLon = this.center.getLongitude(); - final double latHalfSpan = Math.abs(latSpan) / 2; - final double lonHalfSpan = Math.abs(lonSpan) / 2; - bottomLeft = new Geopoint(centerLat - latHalfSpan, centerLon - lonHalfSpan); - topRight = new Geopoint(centerLat + latHalfSpan, centerLon + lonHalfSpan); - } - - public double getLatitudeMin() { - return bottomLeft.getLatitude(); - } - - public double getLatitudeMax() { - return topRight.getLatitude(); - } - - public double getLongitudeMin() { - return bottomLeft.getLongitude(); - } - - public double getLongitudeMax() { - return topRight.getLongitude(); - } - - public @NonNull - Geopoint getCenter() { - return center; - } - - public double getLatitudeSpan() { - return getLatitudeMax() - getLatitudeMin(); - } - - public double getLongitudeSpan() { - return getLongitudeMax() - getLongitudeMin(); - } - - /** - * Check whether a point is contained in this viewport. - * - * @param point - * the coordinates to check - * @return true if the point is contained in this viewport, false otherwise or if the point contains no coordinates - */ - public boolean contains(final @NonNull ICoordinates point) { - final Geopoint coords = point.getCoords(); - return coords != null - && coords.getLongitudeE6() >= bottomLeft.getLongitudeE6() - && coords.getLongitudeE6() <= topRight.getLongitudeE6() - && coords.getLatitudeE6() >= bottomLeft.getLatitudeE6() - && coords.getLatitudeE6() <= topRight.getLatitudeE6(); - } - - /** - * Count the number of points present in the viewport. - * - * @param points a collection of (possibly null) points - * @return the number of non-null points in the viewport - */ - public int count(final @NonNull Collection points) { - int total = 0; - for (ICoordinates point: points) { - if (point != null && contains(point)) { - total += 1; - } - } - return total; - } - - @Override - public String toString() { - return "(" + bottomLeft.toString() + "," + topRight.toString() + ")"; - } - - /** - * Check whether another viewport is fully included into the current one. - * - * @param vp - * the other viewport - * @return true if the viewport is fully included into this one, false otherwise - */ - public boolean includes(final @NonNull Viewport vp) { - return contains(vp.bottomLeft) && contains(vp.topRight); - } - - /** - * Return the "where" part of the string appropriate for a SQL query. - * - * @param dbTable - * the database table to use as prefix, or null if no prefix is required - * @return the string without the "where" keyword - */ - public StringBuilder sqlWhere(@Nullable final String dbTable) { - final String prefix = dbTable == null ? "" : (dbTable + "."); - return new StringBuilder(prefix).append("latitude >= ").append(getLatitudeMin()).append(" and ") - .append(prefix).append("latitude <= ").append(getLatitudeMax()).append(" and ") - .append(prefix).append("longitude >= ").append(getLongitudeMin()).append(" and ") - .append(prefix).append("longitude <= ").append(getLongitudeMax()); - } - - /** - * Return a widened or shrunk viewport. - * - * @param factor - * multiplicative factor for the latitude and longitude span (> 1 to widen, < 1 to shrink) - * @return a widened or shrunk viewport - */ - public @NonNull - Viewport resize(final double factor) { - return new Viewport(getCenter(), getLatitudeSpan() * factor, getLongitudeSpan() * factor); - } - - /** - * Return the smallest viewport containing all the given points. - * - * @param points - * a set of points. Point with null coordinates (or null themselves) will be ignored - * @return the smallest viewport containing the non-null coordinates, or null if no coordinates are non-null - */ - static public @Nullable - Viewport containing(final Collection points) { - boolean valid = false; - double latMin = Double.MAX_VALUE; - double latMax = -Double.MAX_VALUE; - double lonMin = Double.MAX_VALUE; - double lonMax = -Double.MAX_VALUE; - for (final ICoordinates point : points) { - if (point != null) { - final Geopoint coords = point.getCoords(); - if (coords != null) { - valid = true; - final double latitude = coords.getLatitude(); - final double longitude = coords.getLongitude(); - latMin = Math.min(latMin, latitude); - latMax = Math.max(latMax, latitude); - lonMin = Math.min(lonMin, longitude); - lonMax = Math.max(lonMax, longitude); - } - } - } - if (!valid) { - return null; - } - return new Viewport(new Geopoint(latMin, lonMin), new Geopoint(latMax, lonMax)); - } - - @Override - public boolean equals(final Object other) { - if (this == other) { - return true; - } - if (!(other instanceof Viewport)) { - return false; - } - final Viewport vp = (Viewport) other; - return bottomLeft.equals(vp.bottomLeft) && topRight.equals(vp.topRight); - } - - @Override - public int hashCode() { - return bottomLeft.hashCode() ^ topRight.hashCode(); - } - -} diff --git a/main/src/cgeo/geocaching/loaders/CoordsGeocacheListLoader.java b/main/src/cgeo/geocaching/loaders/CoordsGeocacheListLoader.java index c2d92bf..2549b7b 100644 --- a/main/src/cgeo/geocaching/loaders/CoordsGeocacheListLoader.java +++ b/main/src/cgeo/geocaching/loaders/CoordsGeocacheListLoader.java @@ -3,9 +3,10 @@ package cgeo.geocaching.loaders; import cgeo.geocaching.SearchResult; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.capability.ISearchByCenter; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import org.eclipse.jdt.annotation.NonNull; + import rx.functions.Func1; import android.content.Context; diff --git a/main/src/cgeo/geocaching/loaders/HistoryGeocacheListLoader.java b/main/src/cgeo/geocaching/loaders/HistoryGeocacheListLoader.java index fdb35f2..74d5e8a 100644 --- a/main/src/cgeo/geocaching/loaders/HistoryGeocacheListLoader.java +++ b/main/src/cgeo/geocaching/loaders/HistoryGeocacheListLoader.java @@ -3,7 +3,7 @@ package cgeo.geocaching.loaders; import cgeo.geocaching.DataStore; import cgeo.geocaching.SearchResult; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.settings.Settings; import android.content.Context; diff --git a/main/src/cgeo/geocaching/loaders/OfflineGeocacheListLoader.java b/main/src/cgeo/geocaching/loaders/OfflineGeocacheListLoader.java index 0d5af6a..04d720e 100644 --- a/main/src/cgeo/geocaching/loaders/OfflineGeocacheListLoader.java +++ b/main/src/cgeo/geocaching/loaders/OfflineGeocacheListLoader.java @@ -3,7 +3,7 @@ package cgeo.geocaching.loaders; import cgeo.geocaching.DataStore; import cgeo.geocaching.Intents; import cgeo.geocaching.SearchResult; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.settings.Settings; import android.content.Context; diff --git a/main/src/cgeo/geocaching/location/DistanceParser.java b/main/src/cgeo/geocaching/location/DistanceParser.java new file mode 100644 index 0000000..1fb8fc7 --- /dev/null +++ b/main/src/cgeo/geocaching/location/DistanceParser.java @@ -0,0 +1,51 @@ +package cgeo.geocaching.location; + +import cgeo.geocaching.utils.MatcherWrapper; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Locale; +import java.util.regex.Pattern; + +public final class DistanceParser { + + private static final Pattern pattern = Pattern.compile("^([0-9.,]+)[ ]*(m|km|ft|yd|mi|)?$", Pattern.CASE_INSENSITIVE); + + /** + * Parse a distance string composed by a number and an optional suffix + * (such as "1.2km"). + * + * @param distanceText + * the string to analyze + * @return the distance in kilometers + * + * @throws NumberFormatException + * if the given number is invalid + */ + public static float parseDistance(String distanceText, final boolean metricUnit) + throws NumberFormatException { + final MatcherWrapper matcher = new MatcherWrapper(pattern, distanceText); + + if (!matcher.find()) { + throw new NumberFormatException(distanceText); + } + + final float value = Float.parseFloat(matcher.group(1).replace(',', '.')); + final String unit = matcher.group(2).toLowerCase(Locale.US); + + if (unit.equals("m") || (StringUtils.isEmpty(unit) && metricUnit)) { + return value / 1000; + } + if (unit.equals("km")) { + return value; + } + if (unit.equals("yd")) { + return value * IConversion.YARDS_TO_KILOMETER; + } + if (unit.equals("mi")) { + return value * IConversion.MILES_TO_KILOMETER; + } + return value * IConversion.FEET_TO_KILOMETER; + } + +} diff --git a/main/src/cgeo/geocaching/location/Geopoint.java b/main/src/cgeo/geocaching/location/Geopoint.java new file mode 100644 index 0000000..ad693ca --- /dev/null +++ b/main/src/cgeo/geocaching/location/Geopoint.java @@ -0,0 +1,601 @@ +package cgeo.geocaching.location; + +import cgeo.geocaching.ICoordinates; +import cgeo.geocaching.R; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.annotation.NonNull; + +import android.location.Location; +import android.os.Build; +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Abstraction of geographic point. This class is immutable. + */ +public final class Geopoint implements ICoordinates, Parcelable { + /** + * Reusable default object + */ + public static final @NonNull Geopoint ZERO = new Geopoint(0.0, 0.0); + + private static final double DEG_TO_RAD = Math.PI / 180; + private static final double RAD_TO_DEG = 180 / Math.PI; + private static final float EARTH_RADIUS = 6371.0f; + /** + * JIT bug in Android 4.2.1 + */ + private static final boolean DISTANCE_BROKEN = Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1; + + private final double latitude; + private final double longitude; + + /** + * Creates new Geopoint with given latitude and longitude (both degree). + * + * @param lat + * latitude + * @param lon + * longitude + */ + public Geopoint(final double lat, final double lon) { + latitude = lat; + longitude = lon; + } + + /** + * Creates new Geopoint with latitude and longitude parsed from string. + * + * @param text + * string to parse + * @throws Geopoint.ParseException + * if the string cannot be parsed + * @see GeopointParser#parse(String) + */ + public Geopoint(@NonNull final String text) { + final Geopoint parsed = GeopointParser.parse(text); + latitude = parsed.latitude; + longitude = parsed.longitude; + } + + /** + * Creates new Geopoint with latitude and longitude parsed from strings. + * + * @param latText + * latitude string to parse + * @param lonText + * longitude string to parse + * @throws Geopoint.ParseException + * if any argument string cannot be parsed + */ + public Geopoint(final String latText, final String lonText) { + this(GeopointParser.parseLatitude(latText), GeopointParser.parseLongitude(lonText)); + } + + /** + * Creates new Geopoint with given Location. + * + * @param loc + * the Location to clone + */ + public Geopoint(final Location loc) { + this(loc.getLatitude(), loc.getLongitude()); + } + + /** + * Create new Geopoint from Parcel. + * + * @param in + * a Parcel to read the saved data from + */ + public Geopoint(final Parcel in) { + latitude = in.readDouble(); + longitude = in.readDouble(); + } + + /** + * Create new Geopoint from individual textual components. + * + * @param latDir + * @param latDeg + * @param latDegFrac + * @param lonDir + * @param lonDeg + * @param lonDegFrac + */ + public Geopoint(final String latDir, final String latDeg, final String latDegFrac, + final String lonDir, final String lonDeg, final String lonDegFrac) { + this(getLatSign(latDir) + latDeg + "." + addZeros(latDegFrac, 5), + getLonSign(lonDir) + lonDeg + "." + addZeros(lonDegFrac, 5)); + } + + /** + * Create new Geopoint from individual textual components. + * + * @param latDir + * @param latDeg + * @param latMin + * @param latMinFrac + * @param lonDir + * @param lonDeg + * @param lonMin + * @param lonMinFrac + */ + public Geopoint(final String latDir, final String latDeg, final String latMin, final String latMinFrac, + final String lonDir, final String lonDeg, final String lonMin, final String lonMinFrac) { + this(latDir + " " + latDeg + " " + latMin + "." + addZeros(latMinFrac, 3), + lonDir + " " + lonDeg + " " + lonMin + "." + addZeros(lonMinFrac, 3)); + } + + /** + * Create new Geopoint from individual textual components. + * + * @param latDir + * @param latDeg + * @param latMin + * @param latSec + * @param latSecFrac + * @param lonDir + * @param lonDeg + * @param lonMin + * @param lonSec + * @param lonSecFrac + */ + public Geopoint(final String latDir, final String latDeg, final String latMin, final String latSec, final String latSecFrac, + final String lonDir, final String lonDeg, final String lonMin, final String lonSec, final String lonSecFrac) { + this(latDir + " " + latDeg + " " + latMin + " " + latSec + "." + addZeros(latSecFrac, 3), + lonDir + " " + lonDeg + " " + lonMin + " " + lonSec + "." + addZeros(lonSecFrac, 3)); + } + + /** + * Get latitude in degree. + * + * @return latitude + */ + public double getLatitude() { + return latitude; + } + + /** + * Get latitude in microdegree. + * + * @return latitude + */ + public int getLatitudeE6() { + return (int) Math.round(latitude * 1E6); + } + + /** + * Get longitude in degree. + * + * @return longitude + */ + public double getLongitude() { + return longitude; + } + + /* + * Return a waypoint which is the copy of this one rounded to the given limit. + * For example, to get a waypoint adapter to a display with 3 digits after the + * seconds decimal point, a rounding factor of 3600*1000 would be appropriate. + */ + Geopoint roundedAt(final long factor) { + return new Geopoint(((double) Math.round(latitude * factor)) / factor, + ((double) Math.round(longitude * factor)) / factor); + } + + /** + * Get longitude in microdegree. + * + * @return longitude + */ + public int getLongitudeE6() { + return (int) Math.round(longitude * 1E6); + } + + /** + * Get distance and bearing from the current point to a target. + * + * @param target + * The target + * @return An array of floats: the distance in meters, then the bearing in degrees + */ + private float[] pathTo(final Geopoint target) { + float[] results = new float[2]; + android.location.Location.distanceBetween(latitude, longitude, target.latitude, target.longitude, results); + return results; + } + + /** + * Calculates distance to given Geopoint in km. + * + * @param point + * target + * @return distance in km + * @throws GeopointException + * if there is an error in distance calculation + */ + public float distanceTo(@NonNull final ICoordinates point) { + final Geopoint otherCoords = point.getCoords(); + if (DISTANCE_BROKEN) { + return (float) (getDistance(latitude, longitude, otherCoords.latitude, otherCoords.longitude) / 1000); + } + return pathTo(otherCoords)[0] / 1000; + } + + /** + * Calculates bearing to given Geopoint in degree. + * + * @param point + * target + * @return bearing in degree, in the [0,360[ range + */ + public float bearingTo(final ICoordinates point) { + // Android library returns a bearing in the [-180;180] range + final float bearing = pathTo(point.getCoords())[1]; + return bearing < 0 ? bearing + 360 : bearing; + } + + /** + * Calculates geopoint from given bearing and distance. + * + * @param bearing + * bearing in degree + * @param distance + * distance in km + * @return the projected geopoint + */ + public Geopoint project(final double bearing, final double distance) { + final double rlat1 = latitude * DEG_TO_RAD; + final double rlon1 = longitude * DEG_TO_RAD; + final double rbearing = bearing * DEG_TO_RAD; + final double rdistance = distance / EARTH_RADIUS; + + final double rlat = Math.asin(Math.sin(rlat1) * Math.cos(rdistance) + Math.cos(rlat1) * Math.sin(rdistance) * Math.cos(rbearing)); + final double rlon = rlon1 + Math.atan2(Math.sin(rbearing) * Math.sin(rdistance) * Math.cos(rlat1), Math.cos(rdistance) - Math.sin(rlat1) * Math.sin(rlat)); + + return new Geopoint(rlat * RAD_TO_DEG, rlon * RAD_TO_DEG); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof Geopoint)) { + return false; + } + final Geopoint gp = (Geopoint) obj; + return getLatitudeE6() == gp.getLatitudeE6() && getLongitudeE6() == gp.getLongitudeE6(); + } + + @Override + public int hashCode() { + return getLatitudeE6() ^ getLongitudeE6(); + } + + /** + * Returns formatted coordinates. + * + * @param format + * the desired format + * @see GeopointFormatter + * @return formatted coordinates + */ + public String format(GeopointFormatter.Format format) { + return GeopointFormatter.format(format, this); + } + + /** + * Returns formatted coordinates with default format. + * Default format is decimalminutes, e.g. N 52° 36.123 E 010° 03.456 + * + * @return formatted coordinates + */ + @Override + public String toString() { + return format(GeopointFormatter.Format.LAT_LON_DECMINUTE); + } + + abstract public static class GeopointException extends NumberFormatException { + private static final long serialVersionUID = 1L; + + protected GeopointException(String msg) { + super(msg); + } + } + + public static class ParseException extends GeopointException { + private static final long serialVersionUID = 1L; + public final int resource; + + public ParseException(final String msg, final GeopointParser.LatLon faulty) { + super(msg); + resource = faulty == GeopointParser.LatLon.LAT ? R.string.err_parse_lat : R.string.err_parse_lon; + } + } + + @Override + public Geopoint getCoords() { + return this; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(final Parcel dest, final int flags) { + dest.writeDouble(latitude); + dest.writeDouble(longitude); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public Geopoint createFromParcel(final Parcel in) { + return new Geopoint(in); + } + + @Override + public Geopoint[] newArray(final int size) { + return new Geopoint[size]; + } + }; + + /** + * Get latitude character (N or S). + * + * @return + */ + public char getLatDir() { + return latitude >= 0 ? 'N' : 'S'; + } + + /** + * Get longitude character (E or W). + * + * @return + */ + public char getLonDir() { + return longitude >= 0 ? 'E' : 'W'; + } + + /** + * Get the integral non-negative latitude degrees. + * + * @return + */ + public int getLatDeg() { + return getDeg(latitude); + } + + /** + * Get the integral non-negative longitude degrees. + * + * @return + */ + public int getLonDeg() { + return getDeg(longitude); + } + + private static int getDeg(final double deg) { + return (int) Math.abs(deg); + } + + /** + * Get the fractional part of the latitude degrees scaled up by 10^5. + * + * @return + */ + public int getLatDegFrac() { + return getDegFrac(latitude); + } + + /** + * Get the fractional part of the longitude degrees scaled up by 10^5. + * + * @return + */ + public int getLonDegFrac() { + return getDegFrac(longitude); + } + + private static int getDegFrac(final double deg) { + return (int) (Math.round(Math.abs(deg) * 100000) % 100000); + } + + /** + * Get the integral latitude minutes. + * + * @return + */ + public int getLatMin() { + return getMin(latitude); + } + + /** + * Get the integral longitude minutes. + * + * @return + */ + public int getLonMin() { + return getMin(longitude); + } + + private static int getMin(final double deg) { + return ((int) Math.abs(deg * 60)) % 60; + } + + /** + * Get the fractional part of the latitude minutes scaled up by 1000. + * + * @return + */ + public int getLatMinFrac() { + return getMinFrac(latitude); + } + + /** + * Get the fractional part of the longitude minutes scaled up by 1000. + * + * @return + */ + public int getLonMinFrac() { + return getMinFrac(longitude); + } + + private static int getMinFrac(final double deg) { + return (int) (Math.round(Math.abs(deg) * 60000) % 1000); + } + + /** + * Get the latitude minutes. + * + * @return + */ + public double getLatMinRaw() { + return getMinRaw(latitude); + } + + /** + * Get the longitude minutes. + * + * @return + */ + public double getLonMinRaw() { + return getMinRaw(longitude); + } + + private static double getMinRaw(final double deg) { + return (Math.abs(deg) * 60) % 60; + } + + /** + * Get the integral part of the latitude seconds. + * + * @return + */ + public int getLatSec() { + return getSec(latitude); + } + + /** + * Get the integral part of the longitude seconds. + * + * @return + */ + public int getLonSec() { + return getSec(longitude); + } + + private static int getSec(final double deg) { + return ((int) Math.abs(deg * 3600)) % 60; + } + + /** + * Get the fractional part of the latitude seconds scaled up by 1000. + * + * @return + */ + + public int getLatSecFrac() { + return getSecFrac(latitude); + } + + /** + * Get the fractional part of the longitude seconds scaled up by 1000. + * + * @return + */ + + public int getLonSecFrac() { + return getSecFrac(longitude); + } + + private static int getSecFrac(final double deg) { + return (int) (Math.round(Math.abs(deg) * 3600000) % 1000); + } + + /** + * Get the latitude seconds. + * + * @return + */ + public double getLatSecRaw() { + return getSecRaw(latitude); + } + + /** + * Get the longitude seconds. + * + * @return + */ + public double getLonSecRaw() { + return getSecRaw(longitude); + } + + private static double getSecRaw(final double deg) { + return (Math.abs(deg) * 3600) % 60; + } + + private static String addZeros(final String value, final int len) { + return StringUtils.leftPad(value.trim(), len, '0'); + } + + private static String getLonSign(final String lonDir) { + return "W".equalsIgnoreCase(lonDir) ? "-" : ""; + } + + private static String getLatSign(final String latDir) { + return "S".equalsIgnoreCase(latDir) ? "-" : ""; + } + + /** + * Gets distance in meters (workaround for 4.2.1 JIT bug). + */ + public static double getDistance(double lat1, double lon1, double lat2, double lon2) { + // for haversine use R = 6372.8 km instead of 6371 km + double earthRadius = 6372.8; + double dLat = toRadians(lat2 - lat1); + double dLon = toRadians(lon2 - lon1); + double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) * + Math.sin(dLon / 2) * Math.sin(dLon / 2); + // simplify haversine + return (2 * earthRadius * 1000 * Math.asin(Math.sqrt(a))); + } + + private static double toRadians(double angdeg) { + return angdeg * DEG_TO_RAD; + } + + /** + * Check whether a latitude built from user supplied data is valid. We accept both N90/S90. + * + * @return true if the latitude looks valid, false otherwise + */ + public static boolean isValidLatitude(final double latitude) { + return latitude >= -90 && latitude <= 90; + } + + /** + * Check whether a longitude from user supplied data is valid. We accept both E180/W180. + * + * @return true if the longitude looks valid, false otherwise + */ + public static boolean isValidLongitude(final double longitude) { + return longitude >= -180 && longitude <= 180; + } + + /** + * Check whether a geopoint built from user supplied data is valid. We accept both N90/S90 and E180/W180. + * + * @return true if the geopoint looks valid, false otherwise + */ + public boolean isValid() { + return isValidLatitude(latitude) && isValidLongitude(longitude); + } + +} diff --git a/main/src/cgeo/geocaching/location/GeopointFormatter.java b/main/src/cgeo/geocaching/location/GeopointFormatter.java new file mode 100644 index 0000000..599b6c7 --- /dev/null +++ b/main/src/cgeo/geocaching/location/GeopointFormatter.java @@ -0,0 +1,116 @@ +package cgeo.geocaching.location; + +import java.util.Locale; + +/** + * Formatting of Geopoint. + */ +public class GeopointFormatter { + /** + * Predefined formats. + */ + public enum Format { + /** Example: "10,123456 -0,123456" */ + LAT_LON_DECDEGREE, + + /** Example: "10.123456,-0.123456" (unlocalized) */ + LAT_LON_DECDEGREE_COMMA, + + /** Example: "N 10° 12,345 · W 5° 12,345" */ + LAT_LON_DECMINUTE, + + /** Example: "N 10° 12.345 W 5° 12.345" */ + LAT_LON_DECMINUTE_RAW, + + /** Example: "N 10° 12' 34" W 5° 12' 34" */ + LAT_LON_DECSECOND, + + /** Example: "-0.123456" (unlocalized latitude) */ + LAT_DECDEGREE_RAW, + + /** Example: "N 10° 12,345" */ + LAT_DECMINUTE, + + /** Example: "N 10 12,345" */ + LAT_DECMINUTE_RAW, + + /** Example: "-0.123456" (unlocalized longitude) */ + LON_DECDEGREE_RAW, + + /** Example: "W 5° 12,345" */ + LON_DECMINUTE, + + /** Example: "W 5 12,345" */ + LON_DECMINUTE_RAW; + } + + /** + * Formats a Geopoint. + * + * @param gp + * the Geopoint to format + * @param format + * one of the predefined formats + * @return the formatted coordinates + */ + public static String format(final Format format, final Geopoint gp) { + final double latSigned = gp.getLatitude(); + final double lonSigned = gp.getLongitude(); + + switch (format) { + case LAT_LON_DECDEGREE: + return String.format(Locale.getDefault(), "%.6f %.6f", latSigned, lonSigned); + + case LAT_LON_DECDEGREE_COMMA: + return String.format((Locale) null, "%.6f,%.6f", latSigned, lonSigned); + + case LAT_LON_DECMINUTE: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %02d° %06.3f · %c %03d° %06.3f", + rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw(), rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); + } + + case LAT_LON_DECMINUTE_RAW: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format((Locale) null, "%c %02d° %06.3f %c %03d° %06.3f", + rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw(), rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); + } + + case LAT_LON_DECSECOND: { + final Geopoint rgp = gp.roundedAt(3600 * 1000); + return String.format(Locale.getDefault(), "%c %02d° %02d' %06.3f\" · %c %03d° %02d' %06.3f\"", + rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMin(), rgp.getLatSecRaw(), + rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMin(), rgp.getLonSecRaw()); + } + + case LAT_DECDEGREE_RAW: + return String.format((Locale) null, "%.6f", latSigned); + + case LAT_DECMINUTE: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %02d° %06.3f", rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw()); + } + + case LAT_DECMINUTE_RAW: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %02d %06.3f", rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw()); + } + + case LON_DECDEGREE_RAW: + return String.format((Locale) null, "%.6f", lonSigned); + + case LON_DECMINUTE: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %03d° %06.3f", rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); + } + + case LON_DECMINUTE_RAW: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %03d %06.3f", rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); + } + + } + throw new IllegalStateException(); // cannot happen, if switch case is enum complete + } + +} diff --git a/main/src/cgeo/geocaching/location/GeopointParser.java b/main/src/cgeo/geocaching/location/GeopointParser.java new file mode 100644 index 0000000..85a74e1 --- /dev/null +++ b/main/src/cgeo/geocaching/location/GeopointParser.java @@ -0,0 +1,163 @@ +package cgeo.geocaching.location; + +import cgeo.geocaching.utils.MatcherWrapper; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.annotation.NonNull; + +import java.util.regex.Pattern; + +/** + * Parse coordinates. + */ +class GeopointParser { + + private static class ResultWrapper { + final double result; + final int matcherPos; + final int matcherLength; + + public ResultWrapper(final double result, int matcherPos, int stringLength) { + this.result = result; + this.matcherPos = matcherPos; + this.matcherLength = stringLength; + } + } + + // ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 ) + private static final Pattern PATTERN_LAT = Pattern.compile("\\b([NS]|)\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE); + private static final Pattern PATTERN_LON = Pattern.compile("\\b([WE]|)\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE); + + private static final Pattern PATTERN_BAD_BLANK = Pattern.compile("(\\d)[,.] (\\d{2,})"); + + enum LatLon { + LAT, + LON + } + + /** + * Parses a pair of coordinates (latitude and longitude) out of a String. + * Accepts following formats and combinations of it: + * X DD + * X DD° + * X DD° MM + * X DD° MM.MMM + * X DD° MM SS + * + * as well as: + * DD.DDDDDDD + * + * Both . and , are accepted, also variable count of spaces (also 0) + * + * @param text + * the string to parse + * @return an Geopoint with parsed latitude and longitude + * @throws Geopoint.ParseException + * if lat or lon could not be parsed + */ + public static Geopoint parse(@NonNull final String text) { + final ResultWrapper latitudeWrapper = parseHelper(text, LatLon.LAT); + // cut away the latitude part when parsing the longitude + final ResultWrapper longitudeWrapper = parseHelper(text.substring(latitudeWrapper.matcherPos + latitudeWrapper.matcherLength), LatLon.LON); + + if (longitudeWrapper.matcherPos - (latitudeWrapper.matcherPos + latitudeWrapper.matcherLength) >= 10) { + throw new Geopoint.ParseException("Distance between latitude and longitude text is to large.", LatLon.LON); + } + + final double lat = latitudeWrapper.result; + final double lon = longitudeWrapper.result; + if (!Geopoint.isValidLatitude(lat)) { + throw new Geopoint.ParseException(text, LatLon.LAT); + } + if (!Geopoint.isValidLongitude(lon)) { + throw new Geopoint.ParseException(text, LatLon.LON); + } + return new Geopoint(lat, lon); + } + + /** + * Helper for coordinates-parsing + * + * @param text + * @param latlon + * @return + */ + private static ResultWrapper parseHelper(final String text, final LatLon latlon) { + + MatcherWrapper matcher = new MatcherWrapper(PATTERN_BAD_BLANK, text); + String replaceSpaceAfterComma = matcher.replaceAll("$1.$2"); + + final Pattern pattern = LatLon.LAT == latlon ? PATTERN_LAT : PATTERN_LON; + matcher = new MatcherWrapper(pattern, replaceSpaceAfterComma); + + try { + return new ResultWrapper(Double.valueOf(replaceSpaceAfterComma), 0, text.length()); + } catch (NumberFormatException ignored) { + // fall through to advanced parsing + } + + if (matcher.find()) { + final double sign = matcher.group(1).equalsIgnoreCase("S") || matcher.group(1).equalsIgnoreCase("W") ? -1.0 : 1.0; + final double degree = Integer.valueOf(matcher.group(2)).doubleValue(); + + double minutes = 0.0; + double seconds = 0.0; + + if (null != matcher.group(3)) { + minutes = Integer.valueOf(matcher.group(3)).doubleValue(); + + if (null != matcher.group(4)) { + seconds = Double.parseDouble("0." + matcher.group(4)) * 60.0; + } else if (null != matcher.group(5)) { + seconds = Double.parseDouble(matcher.group(5).replace(",", ".")); + } + } + + return new ResultWrapper(sign * (degree + minutes / 60.0 + seconds / 3600.0), matcher.start(), matcher.group().length()); + + } + + // Nothing found with "N 52...", try to match string as decimal degree parts (i.e. multiple doubles) + try { + final String[] items = StringUtils.split(text.trim()); + if (items.length > 0 && items.length <= 2) { + final int index = (latlon == LatLon.LON ? items.length - 1 : 0); + final String textPart = items[index]; + final int pos = (latlon == LatLon.LON ? text.lastIndexOf(textPart) : text.indexOf(textPart)); + return new ResultWrapper(Double.parseDouble(textPart), pos, textPart.length()); + } + } catch (NumberFormatException ignored) { + // The right exception will be raised below. + } + + throw new Geopoint.ParseException("Could not parse coordinates as " + latlon + ": \"" + text + "\"", latlon); + } + + /** + * Parses latitude out of a given string. + * + * @see #parse(String) + * @param text + * the string to be parsed + * @return the latitude as decimal degree + * @throws Geopoint.ParseException + * if latitude could not be parsed + */ + public static double parseLatitude(final String text) { + return parseHelper(text, LatLon.LAT).result; + } + + /** + * Parses longitude out of a given string. + * + * @see #parse(String) + * @param text + * the string to be parsed + * @return the longitude as decimal degree + * @throws Geopoint.ParseException + * if longitude could not be parsed + */ + public static double parseLongitude(final String text) { + return parseHelper(text, LatLon.LON).result; + } +} diff --git a/main/src/cgeo/geocaching/location/IConversion.java b/main/src/cgeo/geocaching/location/IConversion.java new file mode 100644 index 0000000..f7f0e36 --- /dev/null +++ b/main/src/cgeo/geocaching/location/IConversion.java @@ -0,0 +1,13 @@ +package cgeo.geocaching.location; + +public interface IConversion { + public static final float MILES_TO_KILOMETER = 1.609344f; + public static final float FEET_TO_KILOMETER = 0.0003048f; + public static final float YARDS_TO_KILOMETER = 0.0009144f; + /** + * Factor used to calculate distance from meters to foot; + *

+ * ft = m * METERS_TO_FEET; + */ + public static final double METERS_TO_FEET = 3.2808399d; +} diff --git a/main/src/cgeo/geocaching/location/Units.java b/main/src/cgeo/geocaching/location/Units.java new file mode 100644 index 0000000..511537a --- /dev/null +++ b/main/src/cgeo/geocaching/location/Units.java @@ -0,0 +1,62 @@ +package cgeo.geocaching.location; + +import cgeo.geocaching.settings.Settings; + +import org.apache.commons.lang3.tuple.ImmutablePair; + +import java.util.Locale; + +public class Units { + + public static ImmutablePair scaleDistance(final double distanceKilometers) { + double distance; + String units; + if (Settings.useImperialUnits()) { + distance = distanceKilometers / IConversion.MILES_TO_KILOMETER; + if (distance >= 0.1) { + units = "mi"; + } else { + distance *= 5280; + units = "ft"; + } + } else { + if (distanceKilometers >= 1) { + distance = distanceKilometers; + units = "km"; + } else { + distance = distanceKilometers * 1000; + units = "m"; + } + } + return new ImmutablePair<>(distance, units); + } + + public static String getDistanceFromKilometers(final Float distanceKilometers) { + if (distanceKilometers == null) { + return "?"; + } + + final ImmutablePair scaled = scaleDistance(distanceKilometers); + String formatString; + if (scaled.left >= 100) { + formatString = "%.0f"; + } else if (scaled.left >= 10) { + formatString = "%.1f"; + } else { + formatString = "%.2f"; + } + + return String.format(formatString + " %s", scaled.left, scaled.right); + } + + public static String getDistanceFromMeters(float meters) { + return getDistanceFromKilometers(meters / 1000f); + } + + public static String getSpeed(final float kilometersPerHour) { + if (Settings.useImperialUnits()) { + return String.format(Locale.US, "%.0f mph", kilometersPerHour / IConversion.MILES_TO_KILOMETER); + } + return String.format(Locale.US, "%.0f km/h", kilometersPerHour); + } +} diff --git a/main/src/cgeo/geocaching/location/Viewport.java b/main/src/cgeo/geocaching/location/Viewport.java new file mode 100644 index 0000000..e482828 --- /dev/null +++ b/main/src/cgeo/geocaching/location/Viewport.java @@ -0,0 +1,192 @@ +package cgeo.geocaching.location; + +import cgeo.geocaching.ICoordinates; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.Collection; + +public final class Viewport { + + public final @NonNull Geopoint center; + public final @NonNull Geopoint bottomLeft; + public final @NonNull Geopoint topRight; + + public Viewport(final @NonNull ICoordinates point1, final @NonNull ICoordinates point2) { + final Geopoint gp1 = point1.getCoords(); + final Geopoint gp2 = point2.getCoords(); + this.bottomLeft = new Geopoint(Math.min(gp1.getLatitude(), gp2.getLatitude()), + Math.min(gp1.getLongitude(), gp2.getLongitude())); + this.topRight = new Geopoint(Math.max(gp1.getLatitude(), gp2.getLatitude()), + Math.max(gp1.getLongitude(), gp2.getLongitude())); + this.center = new Geopoint((gp1.getLatitude() + gp2.getLatitude()) / 2, + (gp1.getLongitude() + gp2.getLongitude()) / 2); + } + + public Viewport(final @NonNull ICoordinates center, final double latSpan, final double lonSpan) { + this.center = center.getCoords(); + final double centerLat = this.center.getLatitude(); + final double centerLon = this.center.getLongitude(); + final double latHalfSpan = Math.abs(latSpan) / 2; + final double lonHalfSpan = Math.abs(lonSpan) / 2; + bottomLeft = new Geopoint(centerLat - latHalfSpan, centerLon - lonHalfSpan); + topRight = new Geopoint(centerLat + latHalfSpan, centerLon + lonHalfSpan); + } + + public double getLatitudeMin() { + return bottomLeft.getLatitude(); + } + + public double getLatitudeMax() { + return topRight.getLatitude(); + } + + public double getLongitudeMin() { + return bottomLeft.getLongitude(); + } + + public double getLongitudeMax() { + return topRight.getLongitude(); + } + + public @NonNull + Geopoint getCenter() { + return center; + } + + public double getLatitudeSpan() { + return getLatitudeMax() - getLatitudeMin(); + } + + public double getLongitudeSpan() { + return getLongitudeMax() - getLongitudeMin(); + } + + /** + * Check whether a point is contained in this viewport. + * + * @param point + * the coordinates to check + * @return true if the point is contained in this viewport, false otherwise or if the point contains no coordinates + */ + public boolean contains(final @NonNull ICoordinates point) { + final Geopoint coords = point.getCoords(); + return coords != null + && coords.getLongitudeE6() >= bottomLeft.getLongitudeE6() + && coords.getLongitudeE6() <= topRight.getLongitudeE6() + && coords.getLatitudeE6() >= bottomLeft.getLatitudeE6() + && coords.getLatitudeE6() <= topRight.getLatitudeE6(); + } + + /** + * Count the number of points present in the viewport. + * + * @param points a collection of (possibly null) points + * @return the number of non-null points in the viewport + */ + public int count(final @NonNull Collection points) { + int total = 0; + for (ICoordinates point: points) { + if (point != null && contains(point)) { + total += 1; + } + } + return total; + } + + @Override + public String toString() { + return "(" + bottomLeft.toString() + "," + topRight.toString() + ")"; + } + + /** + * Check whether another viewport is fully included into the current one. + * + * @param vp + * the other viewport + * @return true if the viewport is fully included into this one, false otherwise + */ + public boolean includes(final @NonNull Viewport vp) { + return contains(vp.bottomLeft) && contains(vp.topRight); + } + + /** + * Return the "where" part of the string appropriate for a SQL query. + * + * @param dbTable + * the database table to use as prefix, or null if no prefix is required + * @return the string without the "where" keyword + */ + public StringBuilder sqlWhere(@Nullable final String dbTable) { + final String prefix = dbTable == null ? "" : (dbTable + "."); + return new StringBuilder(prefix).append("latitude >= ").append(getLatitudeMin()).append(" and ") + .append(prefix).append("latitude <= ").append(getLatitudeMax()).append(" and ") + .append(prefix).append("longitude >= ").append(getLongitudeMin()).append(" and ") + .append(prefix).append("longitude <= ").append(getLongitudeMax()); + } + + /** + * Return a widened or shrunk viewport. + * + * @param factor + * multiplicative factor for the latitude and longitude span (> 1 to widen, < 1 to shrink) + * @return a widened or shrunk viewport + */ + public @NonNull + Viewport resize(final double factor) { + return new Viewport(getCenter(), getLatitudeSpan() * factor, getLongitudeSpan() * factor); + } + + /** + * Return the smallest viewport containing all the given points. + * + * @param points + * a set of points. Point with null coordinates (or null themselves) will be ignored + * @return the smallest viewport containing the non-null coordinates, or null if no coordinates are non-null + */ + static public @Nullable + Viewport containing(final Collection points) { + boolean valid = false; + double latMin = Double.MAX_VALUE; + double latMax = -Double.MAX_VALUE; + double lonMin = Double.MAX_VALUE; + double lonMax = -Double.MAX_VALUE; + for (final ICoordinates point : points) { + if (point != null) { + final Geopoint coords = point.getCoords(); + if (coords != null) { + valid = true; + final double latitude = coords.getLatitude(); + final double longitude = coords.getLongitude(); + latMin = Math.min(latMin, latitude); + latMax = Math.max(latMax, latitude); + lonMin = Math.min(lonMin, longitude); + lonMax = Math.max(lonMax, longitude); + } + } + } + if (!valid) { + return null; + } + return new Viewport(new Geopoint(latMin, lonMin), new Geopoint(latMax, lonMax)); + } + + @Override + public boolean equals(final Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Viewport)) { + return false; + } + final Viewport vp = (Viewport) other; + return bottomLeft.equals(vp.bottomLeft) && topRight.equals(vp.topRight); + } + + @Override + public int hashCode() { + return bottomLeft.hashCode() ^ topRight.hashCode(); + } + +} diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 25d4785..0f3337c 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -20,9 +20,9 @@ import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapActivityImpl; diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java index 3c6109e..96912ab 100644 --- a/main/src/cgeo/geocaching/maps/CachesOverlay.java +++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java @@ -10,7 +10,7 @@ import cgeo.geocaching.activity.Progress; import cgeo.geocaching.connector.gc.GCMap; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl; diff --git a/main/src/cgeo/geocaching/maps/PositionDrawer.java b/main/src/cgeo/geocaching/maps/PositionDrawer.java index 08244ef..6a45e62 100644 --- a/main/src/cgeo/geocaching/maps/PositionDrawer.java +++ b/main/src/cgeo/geocaching/maps/PositionDrawer.java @@ -2,7 +2,7 @@ package cgeo.geocaching.maps; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapItemFactory; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; diff --git a/main/src/cgeo/geocaching/maps/ScaleDrawer.java b/main/src/cgeo/geocaching/maps/ScaleDrawer.java index 95c987d..04398b4 100644 --- a/main/src/cgeo/geocaching/maps/ScaleDrawer.java +++ b/main/src/cgeo/geocaching/maps/ScaleDrawer.java @@ -1,8 +1,8 @@ package cgeo.geocaching.maps; import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java index 2f540ad..7fbfac2 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.google.v1; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import com.google.android.maps.GeoPoint; diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java index d7e9380..5fedf69 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.google.v1; import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapItemFactory; diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java index b07f561..d474e1d 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java @@ -2,7 +2,7 @@ package cgeo.geocaching.maps.google.v1; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java b/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java index 22c6698..f69de03 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.interfaces; import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; public interface MapItemFactory { diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java index 4a6d733..0560ad4 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.interfaces; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java index 197bd76..298cb90 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.mapsforge; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import org.mapsforge.core.GeoPoint; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java index 4ade09c..ccfd023 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapItemFactory; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index 81dafb4..73d87b0 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java index c801e3f..72aceb0 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.mapsforge.v024; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import org.mapsforge.android.mapsold.GeoPoint; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java index 4f1d34c..23d94d9 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge.v024; import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapItemFactory; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index 8dd15fc..42c55fe 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge.v024; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; diff --git a/main/src/cgeo/geocaching/sensors/GeoData.java b/main/src/cgeo/geocaching/sensors/GeoData.java index 13f5450..a7dc03d 100644 --- a/main/src/cgeo/geocaching/sensors/GeoData.java +++ b/main/src/cgeo/geocaching/sensors/GeoData.java @@ -1,7 +1,7 @@ package cgeo.geocaching.sensors; import cgeo.geocaching.enumerations.LocationProviderType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.Log; import org.eclipse.jdt.annotation.Nullable; diff --git a/main/src/cgeo/geocaching/sensors/IGeoData.java b/main/src/cgeo/geocaching/sensors/IGeoData.java index b78b805..e6b7685 100644 --- a/main/src/cgeo/geocaching/sensors/IGeoData.java +++ b/main/src/cgeo/geocaching/sensors/IGeoData.java @@ -1,7 +1,7 @@ package cgeo.geocaching.sensors; import cgeo.geocaching.enumerations.LocationProviderType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.location.Location; diff --git a/main/src/cgeo/geocaching/settings/Settings.java b/main/src/cgeo/geocaching/settings/Settings.java index a3421cb..241d036 100644 --- a/main/src/cgeo/geocaching/settings/Settings.java +++ b/main/src/cgeo/geocaching/settings/Settings.java @@ -9,8 +9,8 @@ import cgeo.geocaching.connector.gc.GCConstants; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.CGeoMap.MapMode; import cgeo.geocaching.maps.MapProviderFactory; import cgeo.geocaching.maps.google.v1.GoogleMapProvider; diff --git a/main/src/cgeo/geocaching/sorting/DistanceComparator.java b/main/src/cgeo/geocaching/sorting/DistanceComparator.java index 3da5736..f400583 100644 --- a/main/src/cgeo/geocaching/sorting/DistanceComparator.java +++ b/main/src/cgeo/geocaching/sorting/DistanceComparator.java @@ -1,7 +1,7 @@ package cgeo.geocaching.sorting; import cgeo.geocaching.Geocache; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import java.util.ArrayList; import java.util.List; diff --git a/main/src/cgeo/geocaching/speech/SpeechService.java b/main/src/cgeo/geocaching/speech/SpeechService.java index 11e10c1..4eb50e3 100644 --- a/main/src/cgeo/geocaching/speech/SpeechService.java +++ b/main/src/cgeo/geocaching/speech/SpeechService.java @@ -3,7 +3,7 @@ package cgeo.geocaching.speech; import cgeo.geocaching.Intents; import cgeo.geocaching.R; import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; diff --git a/main/src/cgeo/geocaching/speech/TextFactory.java b/main/src/cgeo/geocaching/speech/TextFactory.java index 4b87f1a..4d59b72 100644 --- a/main/src/cgeo/geocaching/speech/TextFactory.java +++ b/main/src/cgeo/geocaching/speech/TextFactory.java @@ -2,8 +2,8 @@ package cgeo.geocaching.speech; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.IConversion; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.IConversion; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.AngleUtils; diff --git a/main/src/cgeo/geocaching/twitter/Twitter.java b/main/src/cgeo/geocaching/twitter/Twitter.java index 253d91f..c6f4ee6 100644 --- a/main/src/cgeo/geocaching/twitter/Twitter.java +++ b/main/src/cgeo/geocaching/twitter/Twitter.java @@ -6,8 +6,8 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.LogEntry; import cgeo.geocaching.Trackable; import cgeo.geocaching.enumerations.LoadFlags; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter.Format; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter.Format; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.OAuth; import cgeo.geocaching.network.OAuthTokens; diff --git a/main/src/cgeo/geocaching/ui/AddressListAdapter.java b/main/src/cgeo/geocaching/ui/AddressListAdapter.java index 81b6c23..691c8d2 100644 --- a/main/src/cgeo/geocaching/ui/AddressListAdapter.java +++ b/main/src/cgeo/geocaching/ui/AddressListAdapter.java @@ -5,8 +5,8 @@ import butterknife.InjectView; import cgeo.geocaching.CacheListActivity; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; import org.apache.commons.lang3.StringUtils; diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java index 7db3592..1834b4e 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -7,7 +7,7 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; import cgeo.geocaching.connector.ConnectorFactory; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Units; import cgeo.geocaching.utils.Formatter; import org.apache.commons.lang3.StringUtils; diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 8cb2177..ae449ec 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -9,7 +9,7 @@ import cgeo.geocaching.R; import cgeo.geocaching.enumerations.CacheListType; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.filter.IFilter; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.sorting.CacheComparator; diff --git a/main/src/cgeo/geocaching/ui/CompassMiniView.java b/main/src/cgeo/geocaching/ui/CompassMiniView.java index 50823fd..a811fa0 100644 --- a/main/src/cgeo/geocaching/ui/CompassMiniView.java +++ b/main/src/cgeo/geocaching/ui/CompassMiniView.java @@ -1,7 +1,7 @@ package cgeo.geocaching.ui; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.AngleUtils; diff --git a/main/src/cgeo/geocaching/ui/CoordinatesFormatSwitcher.java b/main/src/cgeo/geocaching/ui/CoordinatesFormatSwitcher.java index 299256c..581942a 100644 --- a/main/src/cgeo/geocaching/ui/CoordinatesFormatSwitcher.java +++ b/main/src/cgeo/geocaching/ui/CoordinatesFormatSwitcher.java @@ -1,7 +1,7 @@ package cgeo.geocaching.ui; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; import android.view.View; import android.view.View.OnClickListener; diff --git a/main/src/cgeo/geocaching/ui/DistanceView.java b/main/src/cgeo/geocaching/ui/DistanceView.java index a61fc4d..b5e47e1 100644 --- a/main/src/cgeo/geocaching/ui/DistanceView.java +++ b/main/src/cgeo/geocaching/ui/DistanceView.java @@ -1,7 +1,7 @@ package cgeo.geocaching.ui; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; import org.eclipse.jdt.annotation.NonNull; diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java index 283b7fd..cc3bff5 100644 --- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java +++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java @@ -6,9 +6,9 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.Keyboard; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Geopoint.ParseException; -import cgeo.geocaching.geopoint.GeopointFormatter; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; +import cgeo.geocaching.location.Geopoint.ParseException; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.Settings.CoordInputFormatEnum; diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java index 5344742..2b04a48 100644 --- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java @@ -13,10 +13,10 @@ import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.StatusCode; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.loaders.RecaptchaReceiver; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.TestSettings; import cgeo.geocaching.test.RegExPerformanceTest; diff --git a/tests/src/cgeo/geocaching/DataStoreTest.java b/tests/src/cgeo/geocaching/DataStoreTest.java index 3579cc5..03713ac 100644 --- a/tests/src/cgeo/geocaching/DataStoreTest.java +++ b/tests/src/cgeo/geocaching/DataStoreTest.java @@ -8,9 +8,9 @@ import cgeo.geocaching.connector.gc.Tile; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import org.apache.commons.lang3.StringUtils; diff --git a/tests/src/cgeo/geocaching/DestinationTest.java b/tests/src/cgeo/geocaching/DestinationTest.java index 00249c4..9883a32 100644 --- a/tests/src/cgeo/geocaching/DestinationTest.java +++ b/tests/src/cgeo/geocaching/DestinationTest.java @@ -2,7 +2,7 @@ package cgeo.geocaching; import static org.assertj.core.api.Assertions.assertThat; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.test.AndroidTestCase; diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java index 722e1cf..954b492 100644 --- a/tests/src/cgeo/geocaching/GeocacheTest.java +++ b/tests/src/cgeo/geocaching/GeocacheTest.java @@ -5,8 +5,8 @@ import static org.assertj.core.api.Assertions.assertThat; import cgeo.CGeoTestCase; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; import org.apache.commons.lang3.StringUtils; diff --git a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java index 42ad2c5..b107912 100644 --- a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java +++ b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java @@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.files.LocalStorage; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.TestSettings; import cgeo.geocaching.utils.RxUtils; diff --git a/tests/src/cgeo/geocaching/WaypointTest.java b/tests/src/cgeo/geocaching/WaypointTest.java index a3dabbf..9e14146 100644 --- a/tests/src/cgeo/geocaching/WaypointTest.java +++ b/tests/src/cgeo/geocaching/WaypointTest.java @@ -3,7 +3,7 @@ package cgeo.geocaching; import static org.assertj.core.api.Assertions.assertThat; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.test.AndroidTestCase; diff --git a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java index 63924ab..f7dbe72 100644 --- a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java @@ -2,8 +2,8 @@ package cgeo.geocaching.connector.gc; import static org.assertj.core.api.Assertions.assertThat; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import java.util.Set; diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java index 811c0e4..24f65fd 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java @@ -6,8 +6,8 @@ import cgeo.geocaching.SearchResult; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.trackable.TravelBugConnector; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.TestSettings; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index be96cf3..bfd5cb1 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -11,7 +11,7 @@ import cgeo.geocaching.Waypoint; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; diff --git a/tests/src/cgeo/geocaching/export/ExportTest.java b/tests/src/cgeo/geocaching/export/ExportTest.java index 848a1f7..7dc4ed9 100644 --- a/tests/src/cgeo/geocaching/export/ExportTest.java +++ b/tests/src/cgeo/geocaching/export/ExportTest.java @@ -8,7 +8,7 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.LogEntry; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.FileUtils; import java.io.File; diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java index 7c72a61..4bbfbff 100644 --- a/tests/src/cgeo/geocaching/files/GPXParserTest.java +++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java @@ -11,7 +11,7 @@ import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.LoadFlag; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; import cgeo.geocaching.utils.SynchronizedDateFormat; diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java index d87b593..7d5ccee 100644 --- a/tests/src/cgeo/geocaching/files/LocParserTest.java +++ b/tests/src/cgeo/geocaching/files/LocParserTest.java @@ -5,7 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import cgeo.geocaching.Geocache; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; diff --git a/tests/src/cgeo/geocaching/geopoint/DistanceParserTest.java b/tests/src/cgeo/geocaching/geopoint/DistanceParserTest.java deleted file mode 100644 index 621d268..0000000 --- a/tests/src/cgeo/geocaching/geopoint/DistanceParserTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package cgeo.geocaching.geopoint; - -import android.test.AndroidTestCase; - -public class DistanceParserTest extends AndroidTestCase { - - static private final double MM = 1e-6; // 1mm, in kilometers - - public static void testFormats() { - assertEquals(1.2, DistanceParser.parseDistance("1200 m", true), MM); - assertEquals(1.2, DistanceParser.parseDistance("1.2 km", true), MM); - assertEquals(0.36576, DistanceParser.parseDistance("1200 ft", true), MM); - assertEquals(1.09728, DistanceParser.parseDistance("1200 yd", true), MM); - assertEquals(1.9312128, DistanceParser.parseDistance("1.2 mi", true), MM); - } - - public static void testImplicit() { - assertEquals(1.2, DistanceParser.parseDistance("1200", true), MM); - assertEquals(0.36576, DistanceParser.parseDistance("1200", false), MM); - } - - public static void testComma() { - assertEquals(1.2, DistanceParser.parseDistance("1,2km", true), MM); - } - - public static void testCase() { - assertEquals(0.36576, DistanceParser.parseDistance("1200 FT", true), MM); - } - -} \ No newline at end of file diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java b/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java deleted file mode 100644 index 2816664..0000000 --- a/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package cgeo.geocaching.geopoint; - -import static org.assertj.core.api.Assertions.assertThat; - -import cgeo.geocaching.utils.Formatter; - -import android.test.AndroidTestCase; - -public class GeoPointFormatterTest extends AndroidTestCase { - - public static void testConfluence() { - // From issue #2624: coordinate is wrong near to a confluence point - final Geopoint point = new Geopoint(49.9999999999999, 5.0); - final String format = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECDEGREE_COMMA, point); - assertThat(format).isEqualTo("50.000000,5.000000"); - final String formatMinute = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_RAW, point); - assertThat(formatMinute).isEqualTo("N 50° 00.000 E 005° 00.000"); - final String formatSecond = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECSECOND, point).replaceAll(",", "."); - assertEquals(formatSecond, "N 50° 00' 00.000\"" + Formatter.SEPARATOR + "E 005° 00' 00.000\"", formatSecond); - } - - public static void testFormat() { - // taken from GC30R6G - final Geopoint point = new Geopoint("N 51° 21.104 E 010° 15.369"); - final String format = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECDEGREE_COMMA, point); - assertEquals(format, "51.351733,10.256150", format); - final String formatMinute = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_RAW, point); - assertEquals(formatMinute, "N 51° 21.104 E 010° 15.369", formatMinute); - final String formatSecond = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECSECOND, point).replaceAll(",", "."); - assertEquals(formatSecond, "N 51° 21' 06.240\"" + Formatter.SEPARATOR + "E 010° 15' 22.140\"", formatSecond); - } - -} diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java deleted file mode 100644 index f8a3bb2..0000000 --- a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package cgeo.geocaching.geopoint; - -import static org.assertj.core.api.Assertions.assertThat; - -import cgeo.geocaching.utils.Formatter; - -import android.test.AndroidTestCase; - -public class GeoPointParserTest extends AndroidTestCase { - - private static final double refLongitude = 8.0 + 38.564 / 60.0; - private static final double refLatitude = 49.0 + 56.031 / 60.0; - - public static void testParseLatitude() { - assertEquals(refLatitude, GeopointParser.parseLatitude("N 49° 56.031"), 1e-8); - } - - public static void testParseLongitude() { - assertEquals(refLongitude, GeopointParser.parseLongitude("E 8° 38.564"), 1e-8); - } - - public static void testFullCoordinates() { - final Geopoint goal = new Geopoint(refLatitude, refLongitude); - assertEquals(goal, GeopointParser.parse("N 49° 56.031 | E 8° 38.564"), 1e-6); - } - - private static void assertEquals(final Geopoint expected, Geopoint actual, double tolerance) { - assertThat(expected).isNotNull(); - assertThat(actual).isNotNull(); - assertThat(expected.distanceTo(actual) <= tolerance).isTrue(); - } - - public static void testCoordinateMissingPart() { - // we are trying to parse a _point_, but have only a latitude. Don't accept the numerical part as longitude! - Geopoint point = null; - try { - point = GeopointParser.parse("N 49° 56.031"); - } catch (Geopoint.ParseException e) { - // expected - } - assertThat(point).isNull(); - } - - public static void testSouth() { - assertEquals(-refLatitude, GeopointParser.parseLatitude("S 49° 56.031"), 1e-8); - } - - public static void testWest() { - assertEquals(-refLongitude, GeopointParser.parseLongitude("W 8° 38.564"), 1e-8); - } - - public static void testLowerCase() { - assertEquals(refLongitude, GeopointParser.parseLongitude("e 8° 38.564"), 1e-8); - } - - public static void testVariousFormats() { - final Geopoint goal1 = GeopointParser.parse("N 49° 43' 57\" | E 2 12' 35"); - final Geopoint goal2 = GeopointParser.parse("N 49 43.95 E2°12.5833333333"); - assertEquals(goal1, goal2, 1e-6); - } - - public static void testParseOurOwnSeparator() { - final Geopoint separator = GeopointParser.parse("N 49° 43' 57\"" + Formatter.SEPARATOR + "E 2 12' 35"); - final Geopoint noSeparator = GeopointParser.parse("N 49 43.95 E2°12.5833333333"); - assertEquals(separator, noSeparator, 1e-6); - } - - public static void testInSentence() { - final Geopoint p1 = GeopointParser.parse("Station3: N51 21.523 / E07 02.680"); - final Geopoint p2 = GeopointParser.parse("N51 21.523 E07 02.680"); - assertThat(p1).isNotNull(); - assertThat(p2).isNotNull(); - assertThat(p2).isEqualTo(p1); - } - - public static void testUnrelatedParts() { - Geopoint point = null; - try { - point = GeopointParser.parse("N51 21.523 and some words in between, so there is no relation E07 02.680"); - } catch (Geopoint.ParseException e) { - // expected - } - assertThat(point).isNull(); - } - - public static void testComma() { - final Geopoint pointComma = GeopointParser.parse("N 46° 27' 55,65''\n" + - "E 15° 53' 41,68''"); - final Geopoint pointDot = GeopointParser.parse("N 46° 27' 55.65''\n" + - "E 15° 53' 41.68''"); - assertThat(pointComma).isNotNull(); - assertThat(pointDot).isNotNull(); - assertThat(pointDot).isEqualTo(pointComma); - } - - public static void testBlankAddedByAutocorrectionDot() { - assertEquals(refLatitude, GeopointParser.parseLatitude("N 49° 56. 031"), 1e-8); - } - - public static void testBlankAddedByAutocorrectionComma() { - assertEquals(refLatitude, GeopointParser.parseLatitude("N 49° 56, 031"), 1e-8); - } - - public static void testNonTrimmed() { - assertEquals(refLatitude, GeopointParser.parseLatitude(" N 49° 56, 031 "), 1e-8); - } - - public static void testEquatorGC53() { - assertEquals(new Geopoint(0, 36), GeopointParser.parse("00° 00.000 E 036° 00.000")); - } - - public static void testMeridian() { - assertEquals(new Geopoint(23, 0), GeopointParser.parse("N 23° 00.000 00° 00.000")); - } - - public static void testEquatorMeridian() { - assertThat(GeopointParser.parse("00° 00.000 00° 00.000")).isEqualTo(Geopoint.ZERO); - } -} diff --git a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java deleted file mode 100644 index 5db877a..0000000 --- a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java +++ /dev/null @@ -1,306 +0,0 @@ -package cgeo.geocaching.geopoint; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.offset; - -import android.os.Build; -import android.os.Bundle; -import android.test.AndroidTestCase; - -public class GeopointTest extends AndroidTestCase { - - public static void testCreation() { - final Geopoint gp = new Geopoint(48.2, 3.5); - assertThat(gp.getLatitude()).isEqualTo(48.2, offset(1e-8)); - assertThat(gp.getLongitude()).isEqualTo(3.5, offset(1e-8)); - } - - public static void testCreationWithParsing() { - final Geopoint gp = new Geopoint("N 52° 25,111 E 009° 39,111"); - assertThat(gp.getLatitude()).isEqualTo(52.41852, offset(1e-4)); - assertThat(gp.getLongitude()).isEqualTo(9.65185, offset(1e-4)); - } - - public static void testCreationAtLimit() { - // No exception should be raised. - final Geopoint gp1 = new Geopoint(90.0, 10.0); - assertThat(gp1.getLatitude()).isEqualTo(90, offset(1e-8)); - - final Geopoint gp2 = new Geopoint(-90.0, 10.0); - assertThat(gp2.getLatitude()).isEqualTo(-90, offset(1e-8)); - - final Geopoint gp3 = new Geopoint(10.0, 180.0); - assertThat(gp3.getLongitude()).isEqualTo(180, offset(1e-8)); - } - - public static void testEqual() { - final Geopoint gp1 = new Geopoint(48.2, 2.31); - assertThat(gp1.equals(gp1)).isTrue(); - final Geopoint gp2 = new Geopoint(48.3, 2.31); - assertThat(gp1.equals(gp2)).isFalse(); - } - - public static void testGetE6() { - final Geopoint gp = new Geopoint(41.2, -3.4); - assertThat((double) gp.getLatitudeE6()).isEqualTo(41200000.0, offset(1e-6)); - assertThat((double) gp.getLongitudeE6()).isEqualTo(-3400000.0, offset(1e-6)); - } - - public static void testBearingDistance() { - final Geopoint gp1 = new Geopoint(-30.4, -1.2); - final Geopoint gp2 = new Geopoint(-30.1, -2.3); - - final float d12 = gp1.distanceTo(gp2); - - // broken distance calculation in 4.2.1 - if (Build.VERSION.SDK_INT == 17) { - assertThat((double) d12).isEqualTo(110.83107, offset(1e-6)); - } - else { - assertThat((double) d12).isEqualTo(110.967995, offset(1e-6)); - } - - assertThat((double) gp2.distanceTo(gp1)).isEqualTo(d12, offset(1e-6)); - - // Bearing in both directions cannot be added, as this is - // the initial bearing of the path in both cases. - assertThat((double) gp1.bearingTo(gp2)).isEqualTo(287.162, offset(1e-3)); - assertThat((double) gp2.bearingTo(gp1)).isEqualTo(107.715, offset(1e-3)); - } - - public static void testParcelable() { - final Geopoint gp = new Geopoint(1.2, 3.4); - final String KEY = "geopoint"; - final Bundle bundle = new Bundle(); - bundle.putParcelable(KEY, gp); - assertThat(bundle.getParcelable(KEY)).isEqualTo(gp); - } - - public static void testDDD() { - // case 1 - final Geopoint gp1 = new Geopoint(51.3d, 13.8d); - - checkDDD(gp1, 'N', 51, 30000, 'E', 13, 80000); - - final Geopoint gp1a = new Geopoint(String.valueOf(gp1.getLatDir()), String.valueOf(gp1.getLatDeg()), String.valueOf(gp1.getLatDegFrac()), - String.valueOf(gp1.getLonDir()), String.valueOf(gp1.getLonDeg()), String.valueOf(gp1.getLonDegFrac())); - - assertThat(gp1a).isEqualTo(gp1); - - // case 2 - final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d); - - checkDDD(gp2, 'N', 51, 34567, 'E', 13, 87654); - - final Geopoint gp2a = new Geopoint(String.valueOf(gp2.getLatDir()), String.valueOf(gp2.getLatDeg()), String.valueOf(gp2.getLatDegFrac()), - String.valueOf(gp2.getLonDir()), String.valueOf(gp2.getLonDeg()), String.valueOf(gp2.getLonDegFrac())); - - assertThat(gp2a).isEqualTo(gp2); - - // case 3 - final Geopoint gp3 = new Geopoint(51.29999833333333d, 13.8d); - - checkDDD(gp3, 'N', 51, 30000, 'E', 13, 80000); - - final Geopoint gp3a = new Geopoint(String.valueOf(gp3.getLatDir()), String.valueOf(gp3.getLatDeg()), String.valueOf(gp3.getLatDegFrac()), - String.valueOf(gp3.getLonDir()), String.valueOf(gp3.getLonDeg()), String.valueOf(gp3.getLonDegFrac())); - - checkTolerance(gp3, gp3a, 5e-5); - - // case 4 - final Geopoint gp4 = new Geopoint(51.00012d, 13.00089d); - - checkDDD(gp4, 'N', 51, 12, 'E', 13, 89); - - final Geopoint gp4a = new Geopoint(String.valueOf(gp4.getLatDir()), String.valueOf(gp4.getLatDeg()), String.valueOf(gp4.getLatDegFrac()), - String.valueOf(gp4.getLonDir()), String.valueOf(gp4.getLonDeg()), String.valueOf(gp4.getLonDegFrac())); - - checkTolerance(gp4, gp4a, 5e-5); - } - - private static void checkDDD(Geopoint gp, char latDir, int latDeg, int latDegFrac, char lonDir, int lonDeg, int lonDegFrac) { - assertThat(gp.getLatDir()).isEqualTo(latDir); - assertThat(gp.getLatDeg()).isEqualTo(latDeg); - assertThat(gp.getLatDegFrac()).isEqualTo(latDegFrac); - assertThat(gp.getLonDir()).isEqualTo(lonDir); - assertThat(gp.getLonDeg()).isEqualTo(lonDeg); - assertThat(gp.getLonDegFrac()).isEqualTo(lonDegFrac); - } - - private static void checkTolerance(Geopoint gp1, Geopoint gp2, double tolerance) { - assertThat(Math.abs(gp1.getLatitude() - gp2.getLatitude()) <= tolerance).isTrue(); - assertThat(Math.abs(gp1.getLongitude() - gp2.getLongitude()) <= tolerance).isTrue(); - } - - public static void testDMM() { - // case 1 - final Geopoint gp1 = new Geopoint(51.3d, 13.8d); - - checkDMM(gp1, 'N', 51, 18, 0, 'E', 13, 48, 0); - - final Geopoint gp1a = new Geopoint(String.valueOf(gp1.getLatDir()), String.valueOf(gp1.getLatDeg()), String.valueOf(gp1.getLatMin()), String.valueOf(gp1.getLatMinFrac()), - String.valueOf(gp1.getLonDir()), String.valueOf(gp1.getLonDeg()), String.valueOf(gp1.getLonMin()), String.valueOf(gp1.getLonMinFrac())); - - assertThat(gp1a).isEqualTo(gp1); - - // case 2 - final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d); - - checkDMM(gp2, 'N', 51, 20, 740, 'E', 13, 52, 592); - - final Geopoint gp2a = new Geopoint(String.valueOf(gp2.getLatDir()), String.valueOf(gp2.getLatDeg()), String.valueOf(gp2.getLatMin()), String.valueOf(gp2.getLatMinFrac()), - String.valueOf(gp2.getLonDir()), String.valueOf(gp2.getLonDeg()), String.valueOf(gp2.getLonMin()), String.valueOf(gp2.getLonMinFrac())); - - checkTolerance(gp2, gp2a, 5e-5); - - // case 3 - final Geopoint gp3 = new Geopoint(51.3d, 13.8d); - - checkDMM(gp3, 'N', 51, 18, 0, 'E', 13, 48, 0); - - final Geopoint gp3a = new Geopoint(String.valueOf(gp3.getLatDir()), String.valueOf(gp3.getLatDeg()), String.valueOf(gp3.getLatMin()), String.valueOf(gp3.getLatMinFrac()), - String.valueOf(gp3.getLonDir()), String.valueOf(gp3.getLonDeg()), String.valueOf(gp3.getLonMin()), String.valueOf(gp3.getLonMinFrac())); - - checkTolerance(gp3, gp3a, 5e-5); - - // case 4 - final Geopoint gp4 = new Geopoint(51.00012d, 13.00089d); - - checkDMM(gp4, 'N', 51, 0, 7, 'E', 13, 0, 53); - - final Geopoint gp4a = new Geopoint(String.valueOf(gp4.getLatDir()), String.valueOf(gp4.getLatDeg()), String.valueOf(gp4.getLatMin()), String.valueOf(gp4.getLatMinFrac()), - String.valueOf(gp4.getLonDir()), String.valueOf(gp4.getLonDeg()), String.valueOf(gp4.getLonMin()), String.valueOf(gp4.getLonMinFrac())); - - checkTolerance(gp4, gp4a, 5e-5); - } - - private static void checkDMM(Geopoint gp, char latDir, int latDeg, int latMin, int latMinFrac, char lonDir, int lonDeg, int lonMin, int lonMinFrac) { - assertThat(gp.getLatDir()).isEqualTo(latDir); - assertThat(gp.getLatDeg()).isEqualTo(latDeg); - assertThat(gp.getLatMin()).isEqualTo(latMin); - assertThat(gp.getLatMinFrac()).isEqualTo(latMinFrac); - assertThat(gp.getLonDir()).isEqualTo(lonDir); - assertThat(gp.getLonDeg()).isEqualTo(lonDeg); - assertThat(gp.getLonMin()).isEqualTo(lonMin); - assertThat(gp.getLonMinFrac()).isEqualTo(lonMinFrac); - } - - public static void testDMS() { - // case 1 - final Geopoint gp1 = new Geopoint(51.3d, 13.8d); - - checkDMS(gp1, 'N', 51, 18, 0, 0, 'E', 13, 48, 0, 0); - - final Geopoint gp1a = new Geopoint(String.valueOf(gp1.getLatDir()), String.valueOf(gp1.getLatDeg()), String.valueOf(gp1.getLatMin()), String.valueOf(gp1.getLatSec()), String.valueOf(gp1.getLatSecFrac()), - String.valueOf(gp1.getLonDir()), String.valueOf(gp1.getLonDeg()), String.valueOf(gp1.getLonMin()), String.valueOf(gp1.getLonSec()), String.valueOf(gp1.getLonSecFrac())); - - assertThat(gp1a).isEqualTo(gp1); - - // case 2 - final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d); - - checkDMS(gp2, 'N', 51, 20, 44, 412, 'E', 13, 52, 35, 544); - - final Geopoint gp2a = new Geopoint(String.valueOf(gp2.getLatDir()), String.valueOf(gp2.getLatDeg()), String.valueOf(gp2.getLatMin()), String.valueOf(gp2.getLatSec()), String.valueOf(gp2.getLatSecFrac()), - String.valueOf(gp2.getLonDir()), String.valueOf(gp2.getLonDeg()), String.valueOf(gp2.getLonMin()), String.valueOf(gp2.getLonSec()), String.valueOf(gp2.getLonSecFrac())); - - checkTolerance(gp2, gp2a, 5e-6); - - // case 3 - final Geopoint gp3 = new Geopoint(51.29999833333333d, 13.8d); - - checkDMS(gp3, 'N', 51, 17, 59, 994, 'E', 13, 48, 0, 0); - - final Geopoint gp3a = new Geopoint(String.valueOf(gp3.getLatDir()), String.valueOf(gp3.getLatDeg()), String.valueOf(gp3.getLatMin()), String.valueOf(gp3.getLatSec()), String.valueOf(gp3.getLatSecFrac()), - String.valueOf(gp3.getLonDir()), String.valueOf(gp3.getLonDeg()), String.valueOf(gp3.getLonMin()), String.valueOf(gp3.getLonSec()), String.valueOf(gp3.getLonSecFrac())); - - checkTolerance(gp3, gp3a, 5e-6); - - // case 4 - final Geopoint gp4 = new Geopoint(51.00012d, 13.00089d); - - checkDMS(gp4, 'N', 51, 0, 0, 432, 'E', 13, 0, 3, 204); - - final Geopoint gp4a = new Geopoint(String.valueOf(gp4.getLatDir()), String.valueOf(gp4.getLatDeg()), String.valueOf(gp4.getLatMin()), String.valueOf(gp4.getLatSec()), String.valueOf(gp4.getLatSecFrac()), - String.valueOf(gp4.getLonDir()), String.valueOf(gp4.getLonDeg()), String.valueOf(gp4.getLonMin()), String.valueOf(gp4.getLonSec()), String.valueOf(gp4.getLonSecFrac())); - - checkTolerance(gp4, gp4a, 5e-6); - } - - private static void checkDMS(Geopoint gp, char latDir, int latDeg, int latMin, int latSec, int latSecFrac, char lonDir, int lonDeg, int lonMin, int lonSec, int lonSecFrac) { - assertThat(gp.getLatDir()).isEqualTo(latDir); - assertThat(gp.getLatDeg()).isEqualTo(latDeg); - assertThat(gp.getLatMin()).isEqualTo(latMin); - assertThat(gp.getLatSec()).isEqualTo(latSec); - assertThat(gp.getLatSecFrac()).isEqualTo(latSecFrac); - assertThat(gp.getLonDir()).isEqualTo(lonDir); - assertThat(gp.getLonDeg()).isEqualTo(lonDeg); - assertThat(gp.getLonMin()).isEqualTo(lonMin); - assertThat(gp.getLonSec()).isEqualTo(lonSec); - assertThat(gp.getLonSecFrac()).isEqualTo(lonSecFrac); - } - - private static void assertParseException(Runnable runnable) { - try { - runnable.run(); - fail("Should have thrown Geopoint.ParseException"); - } catch (Geopoint.ParseException e) { - //success - } - } - - public static void testParseParam1() { - assertParseException(new Runnable() { - - @SuppressWarnings("unused") - @Override - public void run() { - new Geopoint("some nonsense text"); - } - }); - } - - public static void testParseParam2() { - assertParseException(new Runnable() { - - @SuppressWarnings("unused") - @Override - public void run() { - new Geopoint("latitude", "longitude"); - } - }); - } - - public static void testParseParam6() { - assertParseException(new Runnable() { - - @SuppressWarnings("unused") - @Override - public void run() { - new Geopoint("latDir", "latDeg", "latDegFrac", "lonDir", "lonDeg", "lonDegFrac"); - } - }); - } - - public static void testParseParam8() { - assertParseException(new Runnable() { - - @SuppressWarnings("unused") - @Override - public void run() { - new Geopoint("latDir", "latDeg", "latMin", "latMinFrac", "lonDir", "lonDeg", "lonMin", "lonMinFrac"); - } - }); - } - - public static void testParseParam10() { - assertParseException(new Runnable() { - - @SuppressWarnings("unused") - @Override - public void run() { - new Geopoint("latDir", "latDeg", "latMin", "latSec", "latSecFrac", "lonDir", "lonDeg", "lonMin", "lonSec", "lonSecFrac"); - } - }); - } -} diff --git a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java b/tests/src/cgeo/geocaching/geopoint/UnitsTest.java deleted file mode 100644 index 7f3bdab..0000000 --- a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package cgeo.geocaching.geopoint; - -import static org.assertj.core.api.Assertions.assertThat; - -import cgeo.CGeoTestCase; -import cgeo.geocaching.settings.Settings; -import cgeo.geocaching.settings.TestSettings; - -import org.apache.commons.lang3.StringUtils; - -public class UnitsTest extends CGeoTestCase { - - private static void assertDistance(final String expected, final float distance) { - final String actual = Units.getDistanceFromKilometers(distance); - if (!StringUtils.equals(expected, actual.replace(',', '.'))) { // make 1.2 the same as 1,2 - fail("getHumanDistance(" + distance + - ") [metric: " + (!Settings.useImperialUnits() ? "yes" : "no") + - "] fails to match " + expected + ": " + actual); - } - } - - // Make method non-static so that Settings is initialized - @SuppressWarnings("static-method") - public void testDistance() { - assertThat(Units.getDistanceFromKilometers(null)).isEqualTo("?"); - final boolean savedImperial = Settings.useImperialUnits(); - try { - TestSettings.setUseImperialUnits(false); - assertDistance("123 km", 122.782f); - assertDistance("123 km", 123.456f); - assertDistance("12.3 km", 12.3456f); - assertDistance("1.23 km", 1.23456f); - assertDistance("123 m", 0.123456f); - TestSettings.setUseImperialUnits(true); - assertDistance("76.7 mi", 123.456f); - assertDistance("7.67 mi", 12.3456f); - assertDistance("0.77 mi", 1.23456f); - assertDistance("405 ft", 0.123456f); - assertDistance("40.5 ft", 0.0123456f); - } finally { - TestSettings.setUseImperialUnits(savedImperial); - } - } - - // Make method non-static so that Settings is initialized - @SuppressWarnings("static-method") - public void testSpeed() { - assertThat(Units.getDistanceFromKilometers(null)).isEqualTo("?"); - final boolean savedImperial = Settings.useImperialUnits(); - try { - TestSettings.setUseImperialUnits(false); - assertSpeed("123 km/h", 122.782f); - assertSpeed("123 km/h", 123.456f); - assertSpeed("12 km/h", 12.3456f); - assertSpeed("1 km/h", 1.23456f); - assertSpeed("0 km/h", 0.123456f); - TestSettings.setUseImperialUnits(true); - assertSpeed("77 mph", 123.456f); - assertSpeed("8 mph", 12.3456f); - assertSpeed("1 mph", 1.23456f); - } finally { - TestSettings.setUseImperialUnits(savedImperial); - } - } - - private static void assertSpeed(final String expected, final float kilometersPerHour) { - final String actual = Units.getSpeed(kilometersPerHour); - if (!StringUtils.equals(expected, actual.replace(',', '.'))) { - fail("speed " + actual + " does not match expected " + expected); - } - } - -} diff --git a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java b/tests/src/cgeo/geocaching/geopoint/ViewportTest.java deleted file mode 100644 index ace0356..0000000 --- a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package cgeo.geocaching.geopoint; - -import static org.assertj.core.api.Assertions.assertThat; - -import cgeo.geocaching.ICoordinates; - -import org.eclipse.jdt.annotation.NonNull; - -import android.annotation.SuppressLint; -import android.test.AndroidTestCase; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Locale; -import java.util.Set; - -public class ViewportTest extends AndroidTestCase { - - final private static @NonNull - Viewport vpRef = new Viewport(new Geopoint(-1.0, -2.0), new Geopoint(3.0, 4.0)); - - public static void assertBounds(final Viewport vp) { - assertEquals(new Geopoint(1.0, 1.0), vp.center); - assertEquals(new Geopoint(3.0, 4.0), vp.topRight); - assertEquals(new Geopoint(-1.0, -2.0), vp.bottomLeft); - } - - public static void testCreationBounds() { - assertBounds(new Viewport(new Geopoint(-1.0, -2.0), new Geopoint(3.0, 4.0))); - assertBounds(new Viewport(new Geopoint(3.0, 4.0), new Geopoint(-1.0, -2.0))); - assertBounds(new Viewport(new Geopoint(-1.0, 4.0), new Geopoint(3.0, -2.0))); - assertBounds(new Viewport(new Geopoint(3.0, -2.0), new Geopoint(-1.0, 4.0))); - } - - public static void testCreationCenter() { - assertBounds(new Viewport(new Geopoint(1.0, 1.0), 4.0, 6.0)); - } - - public static void testCreationSeparate() { - assertBounds(vpRef); - } - - public static void testMinMax() { - assertThat(vpRef.getLatitudeMin()).isEqualTo(-1.0); - assertThat(vpRef.getLatitudeMax()).isEqualTo(3.0); - assertThat(vpRef.getLongitudeMin()).isEqualTo(-2.0); - assertThat(vpRef.getLongitudeMax()).isEqualTo(4.0); - } - - public static void testSpans() { - assertThat(vpRef.getLatitudeSpan()).isEqualTo(4.0); - assertThat(vpRef.getLongitudeSpan()).isEqualTo(6.0); - } - - public static void testInViewport() { - assertThat(vpRef.contains(new Geopoint(-2.0, -2.0))).isFalse(); - assertThat(vpRef.contains(new Geopoint(4.0, 4.0))).isFalse(); - assertThat(vpRef.contains(Geopoint.ZERO)).isTrue(); - assertThat(vpRef.contains(new Geopoint(-1.0, -2.0))).isTrue(); - assertThat(vpRef.contains(new Geopoint(3.0, 4.0))).isTrue(); - } - - @SuppressLint("DefaultLocale") - public static void testSqlWhere() { - assertThat(vpRef.sqlWhere(null).toString()).isEqualTo("latitude >= -1.0 and latitude <= 3.0 and longitude >= -2.0 and longitude <= 4.0"); - assertThat(vpRef.sqlWhere("t").toString()).isEqualTo("t.latitude >= -1.0 and t.latitude <= 3.0 and t.longitude >= -2.0 and t.longitude <= 4.0"); - Locale current = null; - try { - current = Locale.getDefault(); - Locale.setDefault(Locale.FRENCH); - assertThat(String.format("%.2g", 1.0d)).isEqualTo("1,0"); // Control that we are in a locale with comma separator - assertThat(vpRef.sqlWhere("t").toString()).isEqualTo("t.latitude >= -1.0 and t.latitude <= 3.0 and t.longitude >= -2.0 and t.longitude <= 4.0"); - } finally { - Locale.setDefault(current); - } - } - - public static void testEquals() { - assertThat(vpRef).isEqualTo(vpRef); - assertEquals(vpRef, new Viewport(vpRef.bottomLeft, vpRef.topRight)); - assertThat(vpRef.equals(new Viewport(new Geopoint(0.0, 0.0), 1.0, 1.0))).isFalse(); - } - - public static void testResize() { - assertThat(vpRef.resize(1.0)).isEqualTo(vpRef); - assertEquals(new Viewport(new Geopoint(-3.0, -5.0), new Geopoint(5.0, 7.0)), vpRef.resize(2.0)); - assertEquals(new Viewport(new Geopoint(0.0, -0.5), new Geopoint(2.0, 2.5)), vpRef.resize(0.5)); - } - - public static void testIncludes() { - assertThat(vpRef.includes(vpRef)).isTrue(); - assertThat(vpRef.includes(vpRef.resize(0.5))).isTrue(); - assertThat(vpRef.includes(vpRef.resize(2.0))).isFalse(); - } - - public static void testContaining() { - assertThat(Viewport.containing(Collections.singleton((ICoordinates) null))).isNull(); - final Set points = new HashSet(); - points.add(vpRef.bottomLeft); - assertEquals(new Viewport(vpRef.bottomLeft, vpRef.bottomLeft), Viewport.containing(points)); - points.add(vpRef.topRight); - assertThat(Viewport.containing(points)).isEqualTo(vpRef); - points.add(vpRef.center); - assertThat(Viewport.containing(points)).isEqualTo(vpRef); - } - -} diff --git a/tests/src/cgeo/geocaching/location/DistanceParserTest.java b/tests/src/cgeo/geocaching/location/DistanceParserTest.java new file mode 100644 index 0000000..4d9e5a5 --- /dev/null +++ b/tests/src/cgeo/geocaching/location/DistanceParserTest.java @@ -0,0 +1,32 @@ +package cgeo.geocaching.location; + +import cgeo.geocaching.location.DistanceParser; + +import android.test.AndroidTestCase; + +public class DistanceParserTest extends AndroidTestCase { + + static private final double MM = 1e-6; // 1mm, in kilometers + + public static void testFormats() { + assertEquals(1.2, DistanceParser.parseDistance("1200 m", true), MM); + assertEquals(1.2, DistanceParser.parseDistance("1.2 km", true), MM); + assertEquals(0.36576, DistanceParser.parseDistance("1200 ft", true), MM); + assertEquals(1.09728, DistanceParser.parseDistance("1200 yd", true), MM); + assertEquals(1.9312128, DistanceParser.parseDistance("1.2 mi", true), MM); + } + + public static void testImplicit() { + assertEquals(1.2, DistanceParser.parseDistance("1200", true), MM); + assertEquals(0.36576, DistanceParser.parseDistance("1200", false), MM); + } + + public static void testComma() { + assertEquals(1.2, DistanceParser.parseDistance("1,2km", true), MM); + } + + public static void testCase() { + assertEquals(0.36576, DistanceParser.parseDistance("1200 FT", true), MM); + } + +} \ No newline at end of file diff --git a/tests/src/cgeo/geocaching/location/GeoPointFormatterTest.java b/tests/src/cgeo/geocaching/location/GeoPointFormatterTest.java new file mode 100644 index 0000000..9ae54fa --- /dev/null +++ b/tests/src/cgeo/geocaching/location/GeoPointFormatterTest.java @@ -0,0 +1,35 @@ +package cgeo.geocaching.location; + +import static org.assertj.core.api.Assertions.assertThat; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointFormatter; +import cgeo.geocaching.utils.Formatter; + +import android.test.AndroidTestCase; + +public class GeoPointFormatterTest extends AndroidTestCase { + + public static void testConfluence() { + // From issue #2624: coordinate is wrong near to a confluence point + final Geopoint point = new Geopoint(49.9999999999999, 5.0); + final String format = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECDEGREE_COMMA, point); + assertThat(format).isEqualTo("50.000000,5.000000"); + final String formatMinute = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_RAW, point); + assertThat(formatMinute).isEqualTo("N 50° 00.000 E 005° 00.000"); + final String formatSecond = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECSECOND, point).replaceAll(",", "."); + assertEquals(formatSecond, "N 50° 00' 00.000\"" + Formatter.SEPARATOR + "E 005° 00' 00.000\"", formatSecond); + } + + public static void testFormat() { + // taken from GC30R6G + final Geopoint point = new Geopoint("N 51° 21.104 E 010° 15.369"); + final String format = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECDEGREE_COMMA, point); + assertEquals(format, "51.351733,10.256150", format); + final String formatMinute = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_RAW, point); + assertEquals(formatMinute, "N 51° 21.104 E 010° 15.369", formatMinute); + final String formatSecond = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECSECOND, point).replaceAll(",", "."); + assertEquals(formatSecond, "N 51° 21' 06.240\"" + Formatter.SEPARATOR + "E 010° 15' 22.140\"", formatSecond); + } + +} diff --git a/tests/src/cgeo/geocaching/location/GeoPointParserTest.java b/tests/src/cgeo/geocaching/location/GeoPointParserTest.java new file mode 100644 index 0000000..e9e002d --- /dev/null +++ b/tests/src/cgeo/geocaching/location/GeoPointParserTest.java @@ -0,0 +1,121 @@ +package cgeo.geocaching.location; + +import static org.assertj.core.api.Assertions.assertThat; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.GeopointParser; +import cgeo.geocaching.utils.Formatter; + +import android.test.AndroidTestCase; + +public class GeoPointParserTest extends AndroidTestCase { + + private static final double refLongitude = 8.0 + 38.564 / 60.0; + private static final double refLatitude = 49.0 + 56.031 / 60.0; + + public static void testParseLatitude() { + assertEquals(refLatitude, GeopointParser.parseLatitude("N 49° 56.031"), 1e-8); + } + + public static void testParseLongitude() { + assertEquals(refLongitude, GeopointParser.parseLongitude("E 8° 38.564"), 1e-8); + } + + public static void testFullCoordinates() { + final Geopoint goal = new Geopoint(refLatitude, refLongitude); + assertEquals(goal, GeopointParser.parse("N 49° 56.031 | E 8° 38.564"), 1e-6); + } + + private static void assertEquals(final Geopoint expected, Geopoint actual, double tolerance) { + assertThat(expected).isNotNull(); + assertThat(actual).isNotNull(); + assertThat(expected.distanceTo(actual) <= tolerance).isTrue(); + } + + public static void testCoordinateMissingPart() { + // we are trying to parse a _point_, but have only a latitude. Don't accept the numerical part as longitude! + Geopoint point = null; + try { + point = GeopointParser.parse("N 49° 56.031"); + } catch (Geopoint.ParseException e) { + // expected + } + assertThat(point).isNull(); + } + + public static void testSouth() { + assertEquals(-refLatitude, GeopointParser.parseLatitude("S 49° 56.031"), 1e-8); + } + + public static void testWest() { + assertEquals(-refLongitude, GeopointParser.parseLongitude("W 8° 38.564"), 1e-8); + } + + public static void testLowerCase() { + assertEquals(refLongitude, GeopointParser.parseLongitude("e 8° 38.564"), 1e-8); + } + + public static void testVariousFormats() { + final Geopoint goal1 = GeopointParser.parse("N 49° 43' 57\" | E 2 12' 35"); + final Geopoint goal2 = GeopointParser.parse("N 49 43.95 E2°12.5833333333"); + assertEquals(goal1, goal2, 1e-6); + } + + public static void testParseOurOwnSeparator() { + final Geopoint separator = GeopointParser.parse("N 49° 43' 57\"" + Formatter.SEPARATOR + "E 2 12' 35"); + final Geopoint noSeparator = GeopointParser.parse("N 49 43.95 E2°12.5833333333"); + assertEquals(separator, noSeparator, 1e-6); + } + + public static void testInSentence() { + final Geopoint p1 = GeopointParser.parse("Station3: N51 21.523 / E07 02.680"); + final Geopoint p2 = GeopointParser.parse("N51 21.523 E07 02.680"); + assertThat(p1).isNotNull(); + assertThat(p2).isNotNull(); + assertThat(p2).isEqualTo(p1); + } + + public static void testUnrelatedParts() { + Geopoint point = null; + try { + point = GeopointParser.parse("N51 21.523 and some words in between, so there is no relation E07 02.680"); + } catch (Geopoint.ParseException e) { + // expected + } + assertThat(point).isNull(); + } + + public static void testComma() { + final Geopoint pointComma = GeopointParser.parse("N 46° 27' 55,65''\n" + + "E 15° 53' 41,68''"); + final Geopoint pointDot = GeopointParser.parse("N 46° 27' 55.65''\n" + + "E 15° 53' 41.68''"); + assertThat(pointComma).isNotNull(); + assertThat(pointDot).isNotNull(); + assertThat(pointDot).isEqualTo(pointComma); + } + + public static void testBlankAddedByAutocorrectionDot() { + assertEquals(refLatitude, GeopointParser.parseLatitude("N 49° 56. 031"), 1e-8); + } + + public static void testBlankAddedByAutocorrectionComma() { + assertEquals(refLatitude, GeopointParser.parseLatitude("N 49° 56, 031"), 1e-8); + } + + public static void testNonTrimmed() { + assertEquals(refLatitude, GeopointParser.parseLatitude(" N 49° 56, 031 "), 1e-8); + } + + public static void testEquatorGC53() { + assertEquals(new Geopoint(0, 36), GeopointParser.parse("00° 00.000 E 036° 00.000")); + } + + public static void testMeridian() { + assertEquals(new Geopoint(23, 0), GeopointParser.parse("N 23° 00.000 00° 00.000")); + } + + public static void testEquatorMeridian() { + assertThat(GeopointParser.parse("00° 00.000 00° 00.000")).isEqualTo(Geopoint.ZERO); + } +} diff --git a/tests/src/cgeo/geocaching/location/GeopointTest.java b/tests/src/cgeo/geocaching/location/GeopointTest.java new file mode 100644 index 0000000..6f5dd78 --- /dev/null +++ b/tests/src/cgeo/geocaching/location/GeopointTest.java @@ -0,0 +1,308 @@ +package cgeo.geocaching.location; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import cgeo.geocaching.location.Geopoint; + +import android.os.Build; +import android.os.Bundle; +import android.test.AndroidTestCase; + +public class GeopointTest extends AndroidTestCase { + + public static void testCreation() { + final Geopoint gp = new Geopoint(48.2, 3.5); + assertThat(gp.getLatitude()).isEqualTo(48.2, offset(1e-8)); + assertThat(gp.getLongitude()).isEqualTo(3.5, offset(1e-8)); + } + + public static void testCreationWithParsing() { + final Geopoint gp = new Geopoint("N 52° 25,111 E 009° 39,111"); + assertThat(gp.getLatitude()).isEqualTo(52.41852, offset(1e-4)); + assertThat(gp.getLongitude()).isEqualTo(9.65185, offset(1e-4)); + } + + public static void testCreationAtLimit() { + // No exception should be raised. + final Geopoint gp1 = new Geopoint(90.0, 10.0); + assertThat(gp1.getLatitude()).isEqualTo(90, offset(1e-8)); + + final Geopoint gp2 = new Geopoint(-90.0, 10.0); + assertThat(gp2.getLatitude()).isEqualTo(-90, offset(1e-8)); + + final Geopoint gp3 = new Geopoint(10.0, 180.0); + assertThat(gp3.getLongitude()).isEqualTo(180, offset(1e-8)); + } + + public static void testEqual() { + final Geopoint gp1 = new Geopoint(48.2, 2.31); + assertThat(gp1.equals(gp1)).isTrue(); + final Geopoint gp2 = new Geopoint(48.3, 2.31); + assertThat(gp1.equals(gp2)).isFalse(); + } + + public static void testGetE6() { + final Geopoint gp = new Geopoint(41.2, -3.4); + assertThat((double) gp.getLatitudeE6()).isEqualTo(41200000.0, offset(1e-6)); + assertThat((double) gp.getLongitudeE6()).isEqualTo(-3400000.0, offset(1e-6)); + } + + public static void testBearingDistance() { + final Geopoint gp1 = new Geopoint(-30.4, -1.2); + final Geopoint gp2 = new Geopoint(-30.1, -2.3); + + final float d12 = gp1.distanceTo(gp2); + + // broken distance calculation in 4.2.1 + if (Build.VERSION.SDK_INT == 17) { + assertThat((double) d12).isEqualTo(110.83107, offset(1e-6)); + } + else { + assertThat((double) d12).isEqualTo(110.967995, offset(1e-6)); + } + + assertThat((double) gp2.distanceTo(gp1)).isEqualTo(d12, offset(1e-6)); + + // Bearing in both directions cannot be added, as this is + // the initial bearing of the path in both cases. + assertThat((double) gp1.bearingTo(gp2)).isEqualTo(287.162, offset(1e-3)); + assertThat((double) gp2.bearingTo(gp1)).isEqualTo(107.715, offset(1e-3)); + } + + public static void testParcelable() { + final Geopoint gp = new Geopoint(1.2, 3.4); + final String KEY = "geopoint"; + final Bundle bundle = new Bundle(); + bundle.putParcelable(KEY, gp); + assertThat(bundle.getParcelable(KEY)).isEqualTo(gp); + } + + public static void testDDD() { + // case 1 + final Geopoint gp1 = new Geopoint(51.3d, 13.8d); + + checkDDD(gp1, 'N', 51, 30000, 'E', 13, 80000); + + final Geopoint gp1a = new Geopoint(String.valueOf(gp1.getLatDir()), String.valueOf(gp1.getLatDeg()), String.valueOf(gp1.getLatDegFrac()), + String.valueOf(gp1.getLonDir()), String.valueOf(gp1.getLonDeg()), String.valueOf(gp1.getLonDegFrac())); + + assertThat(gp1a).isEqualTo(gp1); + + // case 2 + final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d); + + checkDDD(gp2, 'N', 51, 34567, 'E', 13, 87654); + + final Geopoint gp2a = new Geopoint(String.valueOf(gp2.getLatDir()), String.valueOf(gp2.getLatDeg()), String.valueOf(gp2.getLatDegFrac()), + String.valueOf(gp2.getLonDir()), String.valueOf(gp2.getLonDeg()), String.valueOf(gp2.getLonDegFrac())); + + assertThat(gp2a).isEqualTo(gp2); + + // case 3 + final Geopoint gp3 = new Geopoint(51.29999833333333d, 13.8d); + + checkDDD(gp3, 'N', 51, 30000, 'E', 13, 80000); + + final Geopoint gp3a = new Geopoint(String.valueOf(gp3.getLatDir()), String.valueOf(gp3.getLatDeg()), String.valueOf(gp3.getLatDegFrac()), + String.valueOf(gp3.getLonDir()), String.valueOf(gp3.getLonDeg()), String.valueOf(gp3.getLonDegFrac())); + + checkTolerance(gp3, gp3a, 5e-5); + + // case 4 + final Geopoint gp4 = new Geopoint(51.00012d, 13.00089d); + + checkDDD(gp4, 'N', 51, 12, 'E', 13, 89); + + final Geopoint gp4a = new Geopoint(String.valueOf(gp4.getLatDir()), String.valueOf(gp4.getLatDeg()), String.valueOf(gp4.getLatDegFrac()), + String.valueOf(gp4.getLonDir()), String.valueOf(gp4.getLonDeg()), String.valueOf(gp4.getLonDegFrac())); + + checkTolerance(gp4, gp4a, 5e-5); + } + + private static void checkDDD(Geopoint gp, char latDir, int latDeg, int latDegFrac, char lonDir, int lonDeg, int lonDegFrac) { + assertThat(gp.getLatDir()).isEqualTo(latDir); + assertThat(gp.getLatDeg()).isEqualTo(latDeg); + assertThat(gp.getLatDegFrac()).isEqualTo(latDegFrac); + assertThat(gp.getLonDir()).isEqualTo(lonDir); + assertThat(gp.getLonDeg()).isEqualTo(lonDeg); + assertThat(gp.getLonDegFrac()).isEqualTo(lonDegFrac); + } + + private static void checkTolerance(Geopoint gp1, Geopoint gp2, double tolerance) { + assertThat(Math.abs(gp1.getLatitude() - gp2.getLatitude()) <= tolerance).isTrue(); + assertThat(Math.abs(gp1.getLongitude() - gp2.getLongitude()) <= tolerance).isTrue(); + } + + public static void testDMM() { + // case 1 + final Geopoint gp1 = new Geopoint(51.3d, 13.8d); + + checkDMM(gp1, 'N', 51, 18, 0, 'E', 13, 48, 0); + + final Geopoint gp1a = new Geopoint(String.valueOf(gp1.getLatDir()), String.valueOf(gp1.getLatDeg()), String.valueOf(gp1.getLatMin()), String.valueOf(gp1.getLatMinFrac()), + String.valueOf(gp1.getLonDir()), String.valueOf(gp1.getLonDeg()), String.valueOf(gp1.getLonMin()), String.valueOf(gp1.getLonMinFrac())); + + assertThat(gp1a).isEqualTo(gp1); + + // case 2 + final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d); + + checkDMM(gp2, 'N', 51, 20, 740, 'E', 13, 52, 592); + + final Geopoint gp2a = new Geopoint(String.valueOf(gp2.getLatDir()), String.valueOf(gp2.getLatDeg()), String.valueOf(gp2.getLatMin()), String.valueOf(gp2.getLatMinFrac()), + String.valueOf(gp2.getLonDir()), String.valueOf(gp2.getLonDeg()), String.valueOf(gp2.getLonMin()), String.valueOf(gp2.getLonMinFrac())); + + checkTolerance(gp2, gp2a, 5e-5); + + // case 3 + final Geopoint gp3 = new Geopoint(51.3d, 13.8d); + + checkDMM(gp3, 'N', 51, 18, 0, 'E', 13, 48, 0); + + final Geopoint gp3a = new Geopoint(String.valueOf(gp3.getLatDir()), String.valueOf(gp3.getLatDeg()), String.valueOf(gp3.getLatMin()), String.valueOf(gp3.getLatMinFrac()), + String.valueOf(gp3.getLonDir()), String.valueOf(gp3.getLonDeg()), String.valueOf(gp3.getLonMin()), String.valueOf(gp3.getLonMinFrac())); + + checkTolerance(gp3, gp3a, 5e-5); + + // case 4 + final Geopoint gp4 = new Geopoint(51.00012d, 13.00089d); + + checkDMM(gp4, 'N', 51, 0, 7, 'E', 13, 0, 53); + + final Geopoint gp4a = new Geopoint(String.valueOf(gp4.getLatDir()), String.valueOf(gp4.getLatDeg()), String.valueOf(gp4.getLatMin()), String.valueOf(gp4.getLatMinFrac()), + String.valueOf(gp4.getLonDir()), String.valueOf(gp4.getLonDeg()), String.valueOf(gp4.getLonMin()), String.valueOf(gp4.getLonMinFrac())); + + checkTolerance(gp4, gp4a, 5e-5); + } + + private static void checkDMM(Geopoint gp, char latDir, int latDeg, int latMin, int latMinFrac, char lonDir, int lonDeg, int lonMin, int lonMinFrac) { + assertThat(gp.getLatDir()).isEqualTo(latDir); + assertThat(gp.getLatDeg()).isEqualTo(latDeg); + assertThat(gp.getLatMin()).isEqualTo(latMin); + assertThat(gp.getLatMinFrac()).isEqualTo(latMinFrac); + assertThat(gp.getLonDir()).isEqualTo(lonDir); + assertThat(gp.getLonDeg()).isEqualTo(lonDeg); + assertThat(gp.getLonMin()).isEqualTo(lonMin); + assertThat(gp.getLonMinFrac()).isEqualTo(lonMinFrac); + } + + public static void testDMS() { + // case 1 + final Geopoint gp1 = new Geopoint(51.3d, 13.8d); + + checkDMS(gp1, 'N', 51, 18, 0, 0, 'E', 13, 48, 0, 0); + + final Geopoint gp1a = new Geopoint(String.valueOf(gp1.getLatDir()), String.valueOf(gp1.getLatDeg()), String.valueOf(gp1.getLatMin()), String.valueOf(gp1.getLatSec()), String.valueOf(gp1.getLatSecFrac()), + String.valueOf(gp1.getLonDir()), String.valueOf(gp1.getLonDeg()), String.valueOf(gp1.getLonMin()), String.valueOf(gp1.getLonSec()), String.valueOf(gp1.getLonSecFrac())); + + assertThat(gp1a).isEqualTo(gp1); + + // case 2 + final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d); + + checkDMS(gp2, 'N', 51, 20, 44, 412, 'E', 13, 52, 35, 544); + + final Geopoint gp2a = new Geopoint(String.valueOf(gp2.getLatDir()), String.valueOf(gp2.getLatDeg()), String.valueOf(gp2.getLatMin()), String.valueOf(gp2.getLatSec()), String.valueOf(gp2.getLatSecFrac()), + String.valueOf(gp2.getLonDir()), String.valueOf(gp2.getLonDeg()), String.valueOf(gp2.getLonMin()), String.valueOf(gp2.getLonSec()), String.valueOf(gp2.getLonSecFrac())); + + checkTolerance(gp2, gp2a, 5e-6); + + // case 3 + final Geopoint gp3 = new Geopoint(51.29999833333333d, 13.8d); + + checkDMS(gp3, 'N', 51, 17, 59, 994, 'E', 13, 48, 0, 0); + + final Geopoint gp3a = new Geopoint(String.valueOf(gp3.getLatDir()), String.valueOf(gp3.getLatDeg()), String.valueOf(gp3.getLatMin()), String.valueOf(gp3.getLatSec()), String.valueOf(gp3.getLatSecFrac()), + String.valueOf(gp3.getLonDir()), String.valueOf(gp3.getLonDeg()), String.valueOf(gp3.getLonMin()), String.valueOf(gp3.getLonSec()), String.valueOf(gp3.getLonSecFrac())); + + checkTolerance(gp3, gp3a, 5e-6); + + // case 4 + final Geopoint gp4 = new Geopoint(51.00012d, 13.00089d); + + checkDMS(gp4, 'N', 51, 0, 0, 432, 'E', 13, 0, 3, 204); + + final Geopoint gp4a = new Geopoint(String.valueOf(gp4.getLatDir()), String.valueOf(gp4.getLatDeg()), String.valueOf(gp4.getLatMin()), String.valueOf(gp4.getLatSec()), String.valueOf(gp4.getLatSecFrac()), + String.valueOf(gp4.getLonDir()), String.valueOf(gp4.getLonDeg()), String.valueOf(gp4.getLonMin()), String.valueOf(gp4.getLonSec()), String.valueOf(gp4.getLonSecFrac())); + + checkTolerance(gp4, gp4a, 5e-6); + } + + private static void checkDMS(Geopoint gp, char latDir, int latDeg, int latMin, int latSec, int latSecFrac, char lonDir, int lonDeg, int lonMin, int lonSec, int lonSecFrac) { + assertThat(gp.getLatDir()).isEqualTo(latDir); + assertThat(gp.getLatDeg()).isEqualTo(latDeg); + assertThat(gp.getLatMin()).isEqualTo(latMin); + assertThat(gp.getLatSec()).isEqualTo(latSec); + assertThat(gp.getLatSecFrac()).isEqualTo(latSecFrac); + assertThat(gp.getLonDir()).isEqualTo(lonDir); + assertThat(gp.getLonDeg()).isEqualTo(lonDeg); + assertThat(gp.getLonMin()).isEqualTo(lonMin); + assertThat(gp.getLonSec()).isEqualTo(lonSec); + assertThat(gp.getLonSecFrac()).isEqualTo(lonSecFrac); + } + + private static void assertParseException(Runnable runnable) { + try { + runnable.run(); + fail("Should have thrown Geopoint.ParseException"); + } catch (Geopoint.ParseException e) { + //success + } + } + + public static void testParseParam1() { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("some nonsense text"); + } + }); + } + + public static void testParseParam2() { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("latitude", "longitude"); + } + }); + } + + public static void testParseParam6() { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("latDir", "latDeg", "latDegFrac", "lonDir", "lonDeg", "lonDegFrac"); + } + }); + } + + public static void testParseParam8() { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("latDir", "latDeg", "latMin", "latMinFrac", "lonDir", "lonDeg", "lonMin", "lonMinFrac"); + } + }); + } + + public static void testParseParam10() { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("latDir", "latDeg", "latMin", "latSec", "latSecFrac", "lonDir", "lonDeg", "lonMin", "lonSec", "lonSecFrac"); + } + }); + } +} diff --git a/tests/src/cgeo/geocaching/location/UnitsTest.java b/tests/src/cgeo/geocaching/location/UnitsTest.java new file mode 100644 index 0000000..f03f6f0 --- /dev/null +++ b/tests/src/cgeo/geocaching/location/UnitsTest.java @@ -0,0 +1,74 @@ +package cgeo.geocaching.location; + +import static org.assertj.core.api.Assertions.assertThat; + +import cgeo.CGeoTestCase; +import cgeo.geocaching.location.Units; +import cgeo.geocaching.settings.Settings; +import cgeo.geocaching.settings.TestSettings; + +import org.apache.commons.lang3.StringUtils; + +public class UnitsTest extends CGeoTestCase { + + private static void assertDistance(final String expected, final float distance) { + final String actual = Units.getDistanceFromKilometers(distance); + if (!StringUtils.equals(expected, actual.replace(',', '.'))) { // make 1.2 the same as 1,2 + fail("getHumanDistance(" + distance + + ") [metric: " + (!Settings.useImperialUnits() ? "yes" : "no") + + "] fails to match " + expected + ": " + actual); + } + } + + // Make method non-static so that Settings is initialized + @SuppressWarnings("static-method") + public void testDistance() { + assertThat(Units.getDistanceFromKilometers(null)).isEqualTo("?"); + final boolean savedImperial = Settings.useImperialUnits(); + try { + TestSettings.setUseImperialUnits(false); + assertDistance("123 km", 122.782f); + assertDistance("123 km", 123.456f); + assertDistance("12.3 km", 12.3456f); + assertDistance("1.23 km", 1.23456f); + assertDistance("123 m", 0.123456f); + TestSettings.setUseImperialUnits(true); + assertDistance("76.7 mi", 123.456f); + assertDistance("7.67 mi", 12.3456f); + assertDistance("0.77 mi", 1.23456f); + assertDistance("405 ft", 0.123456f); + assertDistance("40.5 ft", 0.0123456f); + } finally { + TestSettings.setUseImperialUnits(savedImperial); + } + } + + // Make method non-static so that Settings is initialized + @SuppressWarnings("static-method") + public void testSpeed() { + assertThat(Units.getDistanceFromKilometers(null)).isEqualTo("?"); + final boolean savedImperial = Settings.useImperialUnits(); + try { + TestSettings.setUseImperialUnits(false); + assertSpeed("123 km/h", 122.782f); + assertSpeed("123 km/h", 123.456f); + assertSpeed("12 km/h", 12.3456f); + assertSpeed("1 km/h", 1.23456f); + assertSpeed("0 km/h", 0.123456f); + TestSettings.setUseImperialUnits(true); + assertSpeed("77 mph", 123.456f); + assertSpeed("8 mph", 12.3456f); + assertSpeed("1 mph", 1.23456f); + } finally { + TestSettings.setUseImperialUnits(savedImperial); + } + } + + private static void assertSpeed(final String expected, final float kilometersPerHour) { + final String actual = Units.getSpeed(kilometersPerHour); + if (!StringUtils.equals(expected, actual.replace(',', '.'))) { + fail("speed " + actual + " does not match expected " + expected); + } + } + +} diff --git a/tests/src/cgeo/geocaching/location/ViewportTest.java b/tests/src/cgeo/geocaching/location/ViewportTest.java new file mode 100644 index 0000000..be15458 --- /dev/null +++ b/tests/src/cgeo/geocaching/location/ViewportTest.java @@ -0,0 +1,109 @@ +package cgeo.geocaching.location; + +import static org.assertj.core.api.Assertions.assertThat; + +import cgeo.geocaching.ICoordinates; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; + +import org.eclipse.jdt.annotation.NonNull; + +import android.annotation.SuppressLint; +import android.test.AndroidTestCase; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; + +public class ViewportTest extends AndroidTestCase { + + final private static @NonNull + Viewport vpRef = new Viewport(new Geopoint(-1.0, -2.0), new Geopoint(3.0, 4.0)); + + public static void assertBounds(final Viewport vp) { + assertEquals(new Geopoint(1.0, 1.0), vp.center); + assertEquals(new Geopoint(3.0, 4.0), vp.topRight); + assertEquals(new Geopoint(-1.0, -2.0), vp.bottomLeft); + } + + public static void testCreationBounds() { + assertBounds(new Viewport(new Geopoint(-1.0, -2.0), new Geopoint(3.0, 4.0))); + assertBounds(new Viewport(new Geopoint(3.0, 4.0), new Geopoint(-1.0, -2.0))); + assertBounds(new Viewport(new Geopoint(-1.0, 4.0), new Geopoint(3.0, -2.0))); + assertBounds(new Viewport(new Geopoint(3.0, -2.0), new Geopoint(-1.0, 4.0))); + } + + public static void testCreationCenter() { + assertBounds(new Viewport(new Geopoint(1.0, 1.0), 4.0, 6.0)); + } + + public static void testCreationSeparate() { + assertBounds(vpRef); + } + + public static void testMinMax() { + assertThat(vpRef.getLatitudeMin()).isEqualTo(-1.0); + assertThat(vpRef.getLatitudeMax()).isEqualTo(3.0); + assertThat(vpRef.getLongitudeMin()).isEqualTo(-2.0); + assertThat(vpRef.getLongitudeMax()).isEqualTo(4.0); + } + + public static void testSpans() { + assertThat(vpRef.getLatitudeSpan()).isEqualTo(4.0); + assertThat(vpRef.getLongitudeSpan()).isEqualTo(6.0); + } + + public static void testInViewport() { + assertThat(vpRef.contains(new Geopoint(-2.0, -2.0))).isFalse(); + assertThat(vpRef.contains(new Geopoint(4.0, 4.0))).isFalse(); + assertThat(vpRef.contains(Geopoint.ZERO)).isTrue(); + assertThat(vpRef.contains(new Geopoint(-1.0, -2.0))).isTrue(); + assertThat(vpRef.contains(new Geopoint(3.0, 4.0))).isTrue(); + } + + @SuppressLint("DefaultLocale") + public static void testSqlWhere() { + assertThat(vpRef.sqlWhere(null).toString()).isEqualTo("latitude >= -1.0 and latitude <= 3.0 and longitude >= -2.0 and longitude <= 4.0"); + assertThat(vpRef.sqlWhere("t").toString()).isEqualTo("t.latitude >= -1.0 and t.latitude <= 3.0 and t.longitude >= -2.0 and t.longitude <= 4.0"); + Locale current = null; + try { + current = Locale.getDefault(); + Locale.setDefault(Locale.FRENCH); + assertThat(String.format("%.2g", 1.0d)).isEqualTo("1,0"); // Control that we are in a locale with comma separator + assertThat(vpRef.sqlWhere("t").toString()).isEqualTo("t.latitude >= -1.0 and t.latitude <= 3.0 and t.longitude >= -2.0 and t.longitude <= 4.0"); + } finally { + Locale.setDefault(current); + } + } + + public static void testEquals() { + assertThat(vpRef).isEqualTo(vpRef); + assertEquals(vpRef, new Viewport(vpRef.bottomLeft, vpRef.topRight)); + assertThat(vpRef.equals(new Viewport(new Geopoint(0.0, 0.0), 1.0, 1.0))).isFalse(); + } + + public static void testResize() { + assertThat(vpRef.resize(1.0)).isEqualTo(vpRef); + assertEquals(new Viewport(new Geopoint(-3.0, -5.0), new Geopoint(5.0, 7.0)), vpRef.resize(2.0)); + assertEquals(new Viewport(new Geopoint(0.0, -0.5), new Geopoint(2.0, 2.5)), vpRef.resize(0.5)); + } + + public static void testIncludes() { + assertThat(vpRef.includes(vpRef)).isTrue(); + assertThat(vpRef.includes(vpRef.resize(0.5))).isTrue(); + assertThat(vpRef.includes(vpRef.resize(2.0))).isFalse(); + } + + public static void testContaining() { + assertThat(Viewport.containing(Collections.singleton((ICoordinates) null))).isNull(); + final Set points = new HashSet(); + points.add(vpRef.bottomLeft); + assertEquals(new Viewport(vpRef.bottomLeft, vpRef.bottomLeft), Viewport.containing(points)); + points.add(vpRef.topRight); + assertThat(Viewport.containing(points)).isEqualTo(vpRef); + points.add(vpRef.center); + assertThat(Viewport.containing(points)).isEqualTo(vpRef); + } + +} diff --git a/tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java b/tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java index 0cfee49..51e7dae 100644 --- a/tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java +++ b/tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java @@ -1,7 +1,7 @@ package cgeo.geocaching.sorting; import cgeo.geocaching.Geocache; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import android.test.AndroidTestCase; diff --git a/tests/src/cgeo/geocaching/speech/TextFactoryTest.java b/tests/src/cgeo/geocaching/speech/TextFactoryTest.java index 1f309ba..c01fbd0 100644 --- a/tests/src/cgeo/geocaching/speech/TextFactoryTest.java +++ b/tests/src/cgeo/geocaching/speech/TextFactoryTest.java @@ -3,7 +3,7 @@ package cgeo.geocaching.speech; import static org.assertj.core.api.Assertions.assertThat; import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.TestSettings; diff --git a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java index ddd2310..34422ff 100644 --- a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java +++ b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java @@ -4,7 +4,7 @@ import cgeo.geocaching.connector.gc.GCLogin; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import java.text.ParseException; import java.util.Date; diff --git a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java index 781810e..bf01f61 100644 --- a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java +++ b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java @@ -4,7 +4,7 @@ import cgeo.geocaching.connector.gc.GCLogin; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.settings.Settings; import java.text.ParseException; diff --git a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java index be27a2e..cfccc3a 100644 --- a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java +++ b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java @@ -6,7 +6,7 @@ import cgeo.geocaching.connector.gc.GCLogin; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import java.text.ParseException; import java.util.ArrayList; diff --git a/tests/src/cgeo/geocaching/test/mock/GC3XX5J.java b/tests/src/cgeo/geocaching/test/mock/GC3XX5J.java index 65de80c..9f69e8e 100644 --- a/tests/src/cgeo/geocaching/test/mock/GC3XX5J.java +++ b/tests/src/cgeo/geocaching/test/mock/GC3XX5J.java @@ -4,7 +4,7 @@ import cgeo.geocaching.connector.gc.GCLogin; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import java.text.ParseException; import java.util.Date; diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java index 0ef6488..6fb249d 100644 --- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java +++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java @@ -6,7 +6,7 @@ import cgeo.geocaching.ICache; import cgeo.geocaching.Image; import cgeo.geocaching.Trackable; import cgeo.geocaching.connector.gc.GCConstants; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.utils.TextUtils; import org.apache.commons.lang3.StringUtils; -- cgit v1.1