Skip to content

Commit

Permalink
Fix incorrect output for coordinates in the decimal degrees format.
Browse files Browse the repository at this point in the history
The corresponding unit test is aslo added.
  • Loading branch information
vahancho committed Feb 21, 2024
1 parent 0e7ac11 commit b5a6580
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/coordinate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ std::string Coordinate::toBaseString(Format format, int precision) const
break;
case Format::DD:
ss << std::setw(2)
<< m_degrees << degreeSign;
<< std::abs(m_degrees) << degreeSign;
break;
default:
break;
Expand Down
75 changes: 75 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,81 @@ int main()
}
}

// Coordinates to string DD
{
static const std::vector<std::pair<std::string, std::string>> lonVariants =
{
{ "45.76260" , "45.7626° E" },
{ "-45.76260" , "45.7626° W" },
{ " 45.76260 " , "45.7626° E" },
{ "45.76260°" , "45.7626° E" },
{ "45.76260° W " , "45.7626° W" },
{ "45 E" , "45° E" },
{ ".76260" , "0.7626° E" },

{ "45° 46.1' " , "45.7683° E" },
{ " 45° 46.1' E " , "45.7683° E" },
{ "45°46.756′E" , "45.7793° E" },
{ "45° 46.756′ E" , "45.7793° E" },
{ "45 46.756 W" , "45.7793° W" },
{ "45 46 W" , "45.7667° W" },
{ "45 .756 W" , "45.0126° W" },
{ "45 59.9999 W" , "46° W" },

{ "45°46′45.36″ " , "45.7793° E" },
{ "45°46′45.36″ E" , "45.7793° E" },
{ "45º46'47.36\" e" , "45.7798° E" },
{ "45º 46' 47.36\" e", "45.7798° E" },
{ "45°46’47.36” E" , "45.7798° E" },
{ "45 46 47.36 W" , "45.7798° W" },
{ "45° 46′ 47.36″ e" , "45.7798° E" },
{ "45° 46’ 47.36” w" , "45.7798° W" },
{ "45° 46’ 47” W" , "45.7797° W" },
{ "45° 46’ .36” w" , "45.7668° W" },
};

static const std::vector<std::pair<std::string, std::string>> latVariants =
{
{ "45.76260" , "45.7626° N" },
{ "-45.76260" , "45.7626° S" },
{ " 45.76260 " , "45.7626° N" },
{ "45.76260°" , "45.7626° N" },
{ "45.76260° N " , "45.7626° N" },
{ "45" , "45° N" },
{ ".76260 S" , "0.7626° S" },

{ "45° 46.1' " , "45.7683° N" },
{ " 45° 46.1' N " , "45.7683° N" },
{ "45°46.756′N" , "45.7793° N" },
{ "45° 46.756′ N" , "45.7793° N" },
{ "45 46.756 S" , "45.7793° S" },
{ "45 46 S" , "45.7667° S" },
{ "45 .756 S" , "45.0126° S" },
{ "45 59.9999 S" , "46° S" },

{ "45°46′45.36″ " , "45.7793° N" },
{ "45°46′45.36″ N" , "45.7793° N" },
{ "45º46'47.36\" S" , "45.7798° S" },
{ "45º 46' 47.36\" n", "45.7798° N" },
{ "45°46’47.36” N" , "45.7798° N" },
{ "45 46 47.36 S" , "45.7798° S" },
{ "45° 46′ 47.36″ n" , "45.7798° N" },
{ "45° 46’ 47.36” s" , "45.7798° S" },
{ "45° 46’ 47” S" , "45.7797° S" },
{ "45° 46’ .36” s" , "45.7668° S" },
};

for (auto &&v : lonVariants) {
const auto lon = Longitude::fromString(v.first);
verifyString(v.second, lon.toString(Coordinate::Format::DD, 3));
}

for (auto &&v : latVariants) {
const auto lat = Latitude::fromString(v.first);
verifyString(v.second, lat.toString(Coordinate::Format::DD, 3));
}
}

// Compass Points
{
verifyString( "N", Coordinate::compassPoint(1));
Expand Down

0 comments on commit b5a6580

Please sign in to comment.