summaryrefslogtreecommitdiff
path: root/sql/item_geofunc.cc
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2022-11-02 21:43:42 +0100
committerOleksandr Byelkin <sanja@mariadb.com>2022-11-02 21:43:42 +0100
commit7fef00fdd791fe37590782ac52c8038a88da6c1b (patch)
tree53b532b44abfac271c6f2dab89618b32efb4e402 /sql/item_geofunc.cc
parentebf2121529fcf06971b4c0fc28f40654ef8dd99f (diff)
parent63a3dffeb62d7b4b39453ac2a01f992ba2795240 (diff)
downloadmariadb-git-7fef00fdd791fe37590782ac52c8038a88da6c1b.tar.gz
Merge branch '10.8' into 10.9
Diffstat (limited to 'sql/item_geofunc.cc')
-rw-r--r--sql/item_geofunc.cc42
1 files changed, 21 insertions, 21 deletions
diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc
index b9aa39b98cf..fc1a4b20e8c 100644
--- a/sql/item_geofunc.cc
+++ b/sql/item_geofunc.cc
@@ -2586,56 +2586,58 @@ double Item_func_sphere_distance::spherical_distance_points(Geometry *g1,
double res= 0.0;
// Length for the single point (25 Bytes)
uint32 len= SRID_SIZE + POINT_DATA_SIZE + WKB_HEADER_SIZE;
- int error= 0;
+ int err_hv= 0, err_sph= 0;
switch (g2->get_class_info()->m_type_id)
{
case Geometry::wkb_point:
- // Optimization for point-point case
+ {
+ Gis_point *g2p= static_cast<Gis_point *>(g2);
+ // Optimization for point-point case
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, &err_hv);
}
else
{
// Optimization for single point in Multipoint
if (g1->get_data_size() == len)
{
- res= static_cast<Gis_point *>(g2)->calculate_haversine(g1, r, &error);
+ res= g2p->calculate_haversine(g1, r, &err_hv);
}
else
{
// There are multipoints in g1
// g1 is MultiPoint and calculate MP.sphericaldistance from g2 Point
if (g1->get_data_size() != GET_SIZE_ERROR)
- static_cast<Gis_point *>(g2)->spherical_distance_multipoints(
- (Gis_multi_point *)g1, r, &res, &error);
+ err_sph= g2p->spherical_distance_multipoints(g1, r, &res, &err_hv);
}
}
break;
+ }
case Geometry::wkb_multipoint:
// Optimization for point-point case
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
if (g2->get_data_size() == len)
{
- res= static_cast<Gis_point *>(g1)->calculate_haversine(g2, r, &error);
+ res= g1p->calculate_haversine(g2, r, &err_hv);
}
else
{
if (g2->get_data_size() != GET_SIZE_ERROR)
// g1 is a point (casted to multi_point) and g2 multipoint
- static_cast<Gis_point *>(g1)->spherical_distance_multipoints(
- (Gis_multi_point *)g2, r, &res, &error);
+ err_sph= g1p->spherical_distance_multipoints(g2, r, &res, &err_hv);
}
}
else
{
+ Gis_multi_point *g1mp= static_cast<Gis_multi_point *>(g1);
// Multipoints in g1 and g2 - no optimization
- static_cast<Gis_multi_point *>(g1)->spherical_distance_multipoints(
- (Gis_multi_point *)g2, r, &res, &error);
+ err_sph= g1mp->spherical_distance_multipoints(g2, r, &res, &err_hv);
}
break;
@@ -2644,16 +2646,14 @@ double Item_func_sphere_distance::spherical_distance_points(Geometry *g1,
break;
}
- if (res < 0)
- goto handle_error;
-
- handle_error:
- if (error > 0)
- my_error(ER_STD_OUT_OF_RANGE_ERROR, MYF(0),
- "Longitude should be [-180,180]", "ST_Distance_Sphere");
- else if(error < 0)
- my_error(ER_STD_OUT_OF_RANGE_ERROR, MYF(0),
- "Latitude should be [-90,90]", "ST_Distance_Sphere");
+ if (err_hv == 1)
+ my_error(ER_STD_OUT_OF_RANGE_ERROR, MYF(0),
+ "Longitude should be [-180,180]", "ST_Distance_Sphere");
+ else if(err_hv < 0)
+ my_error(ER_STD_OUT_OF_RANGE_ERROR, MYF(0),
+ "Latitude should be [-90,90]", "ST_Distance_Sphere");
+ else if (err_sph || err_hv == 2)
+ my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0));
return res;
}