Skip to content

Commit

Permalink
MDEV-7510 GIS: IsRing returns false for a primitive triangle.
Browse files Browse the repository at this point in the history
The problem is in the IsSimple function. If the first and the last points
of a curve coincide it's and exception and the line is still 'simple'.
  • Loading branch information
Alexey Botchkov committed Mar 13, 2015
1 parent 75d65b5 commit 702fba1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
11 changes: 10 additions & 1 deletion mysql-test/r/gis.result
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ SELECT IsRing(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
FROM named_places
WHERE name = 'Goose Island';
IsRing(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary)))
0
1
# Conformance Item T21
SELECT GLength(centerline)
FROM road_segments
Expand Down Expand Up @@ -1765,3 +1765,12 @@ SRID
0
0
drop table t1;
#
# MDEV-7510 GIS: IsRing returns false for a primitive triangle.
#
select ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,0 0)'));
ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,0 0)'))
1
select ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,-10 -10, 0 -10, 0 0)'));
ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,-10 -10, 0 -10, 0 0)'))
0
6 changes: 6 additions & 0 deletions mysql-test/t/gis.test
Original file line number Diff line number Diff line change
Expand Up @@ -1486,3 +1486,9 @@ ALTER TABLE t1 ADD fid INT NOT NULL;
select SRID from information_schema.geometry_columns where F_TABLE_NAME='t1';
drop table t1;

--echo #
--echo # MDEV-7510 GIS: IsRing returns false for a primitive triangle.
--echo #
select ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,0 0)'));
select ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,-10 -10, 0 -10, 0 0)'));

16 changes: 12 additions & 4 deletions sql/item_geofunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,6 @@ longlong Item_func_issimple::val_int()
Gcalc_operation_transporter trn(&func, &collector);
Geometry *g;
int result= 1;
const Gcalc_scan_iterator::event_point *ev;
MBR mbr;
const char *c_end;

Expand All @@ -1892,18 +1891,27 @@ longlong Item_func_issimple::val_int()

while (scan_it.more_points())
{
const Gcalc_scan_iterator::event_point *ev, *next_ev;

if (scan_it.step())
goto mem_error;

ev= scan_it.get_events();
if (ev->simple_event())
continue;

if ((ev->event == scev_thread || ev->event == scev_single_point) &&
!ev->get_next())
next_ev= ev->get_next();
if ((ev->event & (scev_thread | scev_single_point)) && !next_ev)
continue;

if ((ev->event == scev_two_threads) && !next_ev->get_next())
continue;

if (ev->event == scev_two_threads && !ev->get_next()->get_next())
/* If the first and last points of a curve coincide - that is */
/* an exception to the rule and the line is considered as simple. */
if ((next_ev && !next_ev->get_next()) &&
(ev->event & (scev_thread | scev_end)) &&
(next_ev->event & (scev_thread | scev_end)))
continue;

result= 0;
Expand Down

0 comments on commit 702fba1

Please sign in to comment.