Commit 72e79eaa authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: put casts in a separate statement

remove useless if()
parent 1ff476b4
...@@ -2601,51 +2601,53 @@ double Item_func_sphere_distance::spherical_distance_points(Geometry *g1, ...@@ -2601,51 +2601,53 @@ double Item_func_sphere_distance::spherical_distance_points(Geometry *g1,
switch (g2->get_class_info()->m_type_id) switch (g2->get_class_info()->m_type_id)
{ {
case Geometry::wkb_point: case Geometry::wkb_point:
{
Gis_point *g2p= static_cast<Gis_point *>(g2);
// Optimization for point-point case // Optimization for point-point case
if (g1->get_class_info()->m_type_id == Geometry::wkb_point) if (g1->get_class_info()->m_type_id == Geometry::wkb_point)
{ {
res= static_cast<Gis_point *>(g2)->calculate_haversine(g1, r, &error); res= g2p->calculate_haversine(g1, r, &error);
} }
else else
{ {
// Optimization for single point in Multipoint // Optimization for single point in Multipoint
if (g1->get_data_size() == len) if (g1->get_data_size() == len)
{ {
res= static_cast<Gis_point *>(g2)->calculate_haversine(g1, r, &error); res= g2p->calculate_haversine(g1, r, &error);
} }
else else
{ {
// There are multipoints in g1 // There are multipoints in g1
// g1 is MultiPoint and calculate MP.sphericaldistance from g2 Point // g1 is MultiPoint and calculate MP.sphericaldistance from g2 Point
if (g1->get_data_size() != GET_SIZE_ERROR) if (g1->get_data_size() != GET_SIZE_ERROR)
static_cast<Gis_point *>(g2)->spherical_distance_multipoints( g2p->spherical_distance_multipoints(g1, r, &res, &error);
(Gis_multi_point *)g1, r, &res, &error);
} }
} }
break; break;
}
case Geometry::wkb_multipoint: case Geometry::wkb_multipoint:
// Optimization for point-point case // Optimization for point-point case
if (g1->get_class_info()->m_type_id == Geometry::wkb_point) if (g1->get_class_info()->m_type_id == Geometry::wkb_point)
{ {
Gis_point *g1p= static_cast<Gis_point *>(g1);
// Optimization for single point in Multipoint g2 // Optimization for single point in Multipoint g2
if (g2->get_data_size() == len) if (g2->get_data_size() == len)
{ {
res= static_cast<Gis_point *>(g1)->calculate_haversine(g2, r, &error); res= g1p->calculate_haversine(g2, r, &error);
} }
else else
{ {
if (g2->get_data_size() != GET_SIZE_ERROR) if (g2->get_data_size() != GET_SIZE_ERROR)
// g1 is a point (casted to multi_point) and g2 multipoint // g1 is a point (casted to multi_point) and g2 multipoint
static_cast<Gis_point *>(g1)->spherical_distance_multipoints( g1p->spherical_distance_multipoints(g2, r, &res, &error);
(Gis_multi_point *)g2, r, &res, &error);
} }
} }
else else
{ {
Gis_multi_point *g1mp= static_cast<Gis_multi_point *>(g1);
// Multipoints in g1 and g2 - no optimization // Multipoints in g1 and g2 - no optimization
static_cast<Gis_multi_point *>(g1)->spherical_distance_multipoints( g1mp->spherical_distance_multipoints(g2, r, &res, &error);
(Gis_multi_point *)g2, r, &res, &error);
} }
break; break;
...@@ -2654,10 +2656,6 @@ double Item_func_sphere_distance::spherical_distance_points(Geometry *g1, ...@@ -2654,10 +2656,6 @@ double Item_func_sphere_distance::spherical_distance_points(Geometry *g1,
break; break;
} }
if (res < 0)
goto handle_error;
handle_error:
if (error > 0) if (error > 0)
my_error(ER_STD_OUT_OF_RANGE_ERROR, MYF(0), my_error(ER_STD_OUT_OF_RANGE_ERROR, MYF(0),
"Longitude should be [-180,180]", "ST_Distance_Sphere"); "Longitude should be [-180,180]", "ST_Distance_Sphere");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment