Skip to content

Commit

Permalink
Do not remove points when doubling back at zero tolerance, references…
Browse files Browse the repository at this point in the history
… #5654
  • Loading branch information
pramsey committed Apr 17, 2024
1 parent eb50b64 commit 2c68d13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions liblwgeom/cunit/cu_algorithm.c
Expand Up @@ -1813,13 +1813,28 @@ static void test_trim_bits(void)
lwline_free(line);
}

static void test_ptarray_simplify(void)
{
LWGEOM *geom1 = lwgeom_from_wkt("LINESTRING (2 2,3 2,4 1,3 2, 4 4)", LW_PARSER_CHECK_NONE);
LWGEOM *geom2 = lwgeom_from_wkt("LINESTRING (2 2,3 2,4 1,3 2, 4 4)", LW_PARSER_CHECK_NONE);
LWLINE *line1 = (LWLINE*)geom1;
double tolerance = 0.0;
int minpts = 2;
ptarray_simplify_in_place(line1->points, tolerance, minpts);
ASSERT_LWGEOM_EQUAL(geom1, geom2);
lwgeom_free(geom1);
lwgeom_free(geom2);
}


/*
** Used by test harness to register the tests in this file.
*/
void algorithms_suite_setup(void);
void algorithms_suite_setup(void)
{
CU_pSuite suite = CU_add_suite("algorithm", init_cg_suite, clean_cg_suite);
PG_ADD_TEST(suite,test_ptarray_simplify);
PG_ADD_TEST(suite,test_lw_segment_side);
PG_ADD_TEST(suite,test_lw_segment_intersects);
PG_ADD_TEST(suite,test_lwline_crossing_short_lines);
Expand Down
6 changes: 5 additions & 1 deletion liblwgeom/ptarray.c
Expand Up @@ -1689,7 +1689,11 @@ ptarray_simplify_in_place_tolerance0(POINTARRAY *pa)
double dot_ac_ab = ca_x * ba_x + ca_y * ba_y;
double s_numerator = ca_x * ba_y - ca_y * ba_x;

if (dot_ac_ab < 0.0 || dot_ac_ab > ab_length_sqr || s_numerator != 0)
if (p2d_same(kept_pt, next_pt) ||
dot_ac_ab < 0.0 ||
dot_ac_ab > ab_length_sqr ||
s_numerator != 0)

{
kept_it++;
kept_pt = curr_pt;
Expand Down

0 comments on commit 2c68d13

Please sign in to comment.