Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
d25fe342
Commit
d25fe342
authored
Apr 06, 2018
by
LEFEBVREJP email
Browse files
Adding CoordinateConversion::validate(std::pair()) and adding templates.
parent
fb03d022
Pipeline
#12884
passed with stages
in 9 minutes and 37 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
radixgeo/coordinateconversion.hh
View file @
d25fe342
...
...
@@ -10,19 +10,46 @@ namespace radix
class
RADIX_PUBLIC
CoordinateConversion
{
public:
static
void
validate
(
double
latitude
,
double
longitude
)
{
if
(
latitude
<
-
90.0
||
latitude
>
90.0
||
longitude
<
-
180.0
||
longitude
>=
180.0
)
/**
* @brief validate Validates coordinate
* @param latitude latitude coordinate
* @param longitude longitude coordinate
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
template
<
typename
data_type
>
static
void
validate
(
data_type
latitude
,
data_type
longitude
);
/**
* @brief validate Validates coordinate
* @parm point where point.first is latitutde and point.second is longitude
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
template
<
typename
data_type
>
static
void
validate
(
const
std
::
pair
<
data_type
,
data_type
>&
point
);
};
// class CoordinateConversion
template
<
typename
data_type
>
void
CoordinateConversion
::
validate
(
const
std
::
pair
<
data_type
,
data_type
>&
point
)
{
CoordinateConversion
::
validate
(
point
.
first
,
point
.
second
);
}
template
<
typename
data_type
>
void
CoordinateConversion
::
validate
(
data_type
latitude
,
data_type
longitude
)
{
if
(
latitude
<
data_type
(
-
90.0
)
||
latitude
>
data_type
(
90.0
)
||
longitude
<
data_type
(
-
180.0
)
||
longitude
>=
data_type
(
180.0
))
{
std
::
ostringstream
oss
;
oss
<<
"Invalid coordinate ["
<<
latitude
<<
","
<<
longitude
<<
"].
\n
Latitude must be [-90
.
,90
.
] and longitude must be "
<<
"].
\n
Latitude must be [-90,90] and longitude must be "
"[-180,180)."
;
throw
std
::
out_of_range
(
oss
.
str
());
}
}
};
// class CoordinateConversion
}
}
// namespace radix
#endif
/** RADIX_RADIXGEO_COORDINATECONVERSION_HH_ */
\ No newline at end of file
radixgeo/tests/tstCoordinateConversion.cc
View file @
d25fe342
...
...
@@ -17,7 +17,7 @@ TEST(Radixgeo, CoordinateRange)
{
std
::
string
error_message
(
e
.
what
());
EXPECT_EQ
(
"Invalid coordinate [-91,-179].
\n
Latitude must be [-90
.
,90
.
] and "
"Invalid coordinate [-91,-179].
\n
Latitude must be [-90,90] and "
"longitude must be "
"[-180,180)."
,
error_message
);
...
...
@@ -30,7 +30,7 @@ TEST(Radixgeo, CoordinateRange)
{
std
::
string
error_message
(
e
.
what
());
EXPECT_EQ
(
"Invalid coordinate [91,-179].
\n
Latitude must be [-90
.
,90
.
] and "
"Invalid coordinate [91,-179].
\n
Latitude must be [-90,90] and "
"longitude must be "
"[-180,180)."
,
error_message
);
...
...
@@ -43,7 +43,7 @@ TEST(Radixgeo, CoordinateRange)
{
std
::
string
error_message
(
e
.
what
());
EXPECT_EQ
(
"Invalid coordinate [-80,-190].
\n
Latitude must be [-90
.
,90
.
] and "
"Invalid coordinate [-80,-190].
\n
Latitude must be [-90,90] and "
"longitude must be "
"[-180,180)."
,
error_message
);
...
...
@@ -57,7 +57,64 @@ TEST(Radixgeo, CoordinateRange)
{
std
::
string
error_message
(
e
.
what
());
EXPECT_EQ
(
"Invalid coordinate [-80,190].
\n
Latitude must be [-90.,90.] and "
"Invalid coordinate [-80,190].
\n
Latitude must be [-90,90] and "
"longitude must be "
"[-180,180)."
,
error_message
);
}
//
// Pair api
try
{
CoordinateConversion
::
validate
(
std
::
make_pair
(
-
91.
,
-
179.
));
}
catch
(
std
::
out_of_range
e
)
{
std
::
string
error_message
(
e
.
what
());
EXPECT_EQ
(
"Invalid coordinate [-91,-179].
\n
Latitude must be [-90,90] and "
"longitude must be "
"[-180,180)."
,
error_message
);
}
try
{
CoordinateConversion
::
validate
(
std
::
make_pair
(
91.
,
-
179.
));
}
catch
(
std
::
out_of_range
e
)
{
std
::
string
error_message
(
e
.
what
());
EXPECT_EQ
(
"Invalid coordinate [91,-179].
\n
Latitude must be [-90,90] and "
"longitude must be "
"[-180,180)."
,
error_message
);
}
try
{
CoordinateConversion
::
validate
(
std
::
make_pair
(
-
80.
,
-
190.
));
}
catch
(
std
::
out_of_range
e
)
{
std
::
string
error_message
(
e
.
what
());
EXPECT_EQ
(
"Invalid coordinate [-80,-190].
\n
Latitude must be [-90,90] and "
"longitude must be "
"[-180,180)."
,
error_message
);
}
try
{
CoordinateConversion
::
validate
(
std
::
make_pair
(
-
80.
,
190.
));
}
catch
(
std
::
out_of_range
e
)
{
std
::
string
error_message
(
e
.
what
());
EXPECT_EQ
(
"Invalid coordinate [-80,190].
\n
Latitude must be [-90,90] and "
"longitude must be "
"[-180,180)."
,
error_message
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment