Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix projected line strings getting truncated early. #1146

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/cartopy/_trace.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
# (C) British Crown Copyright 2010 - 2016, Met Office
# (C) British Crown Copyright 2010 - 2018, Met Office
#
# This file is part of cartopy.
#
Expand Down Expand Up @@ -563,7 +563,8 @@ void _project_segment(GEOSContextHandle_t handle,
t_current = 0.0;
state = get_state(p_current, gp_domain, handle);

while(t_current < 1.0 && lines.size() < 500)
size_t old_lines_size = lines.size();
while(t_current < 1.0 && (lines.size() - old_lines_size) < 100)
{
//std::cerr << "Bisecting" << std::endl;
#ifdef DEBUG
Expand Down
45 changes: 45 additions & 0 deletions lib/cartopy/tests/test_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import (absolute_import, division, print_function)

import numpy as np
import pytest
import shapely.geometry as sgeom
import shapely.wkt

Expand Down Expand Up @@ -135,6 +136,50 @@ def test_project_previous_infinite_loop(self):
src = ccrs.PlateCarree()
src._attach_lines_to_boundary(multi_line_strings, True)

@pytest.mark.parametrize('proj',
[ccrs.InterruptedGoodeHomolosine, ccrs.Mollweide])
def test_infinite_loop_bounds(self, proj):
# test a polygon which used to get stuck in an infinite loop but is now
# erroneously clipped.
# see https://github.com/SciTools/cartopy/issues/1131

# These names are for IGH; effectively the same for Mollweide.
bottom = [0., 70.]
right = [0., 90.]
top = [-180., 90.]
left = [-180., 70.]
verts = np.array([
bottom,
right,
top,
left,
bottom,
])
bad_path = sgeom.Polygon(verts)

target = proj()
source = ccrs.PlateCarree()

projected = target.project_geometry(bad_path, source)

# When transforming segments was broken, the resulting path did not
# close, and either filled most of the domain, or a smaller portion
# than it should. Check that the bounds match the individual points at
# the expected edges.
projected_left = target.transform_point(left[0], left[1], source)
assert projected.bounds[0] == pytest.approx(projected_left[0],
rel=target.threshold)
projected_bottom = target.transform_point(bottom[0], bottom[1], source)
assert projected.bounds[1] == pytest.approx(projected_bottom[1],
rel=target.threshold)
projected_right = target.transform_point(right[0], right[1], source)
assert projected.bounds[2] == pytest.approx(projected_right[0],
rel=target.threshold,
abs=1e-8)
projected_top = target.transform_point(top[0], top[1], source)
assert projected.bounds[3] == pytest.approx(projected_top[1],
rel=target.threshold)

def test_3pt_poly(self):
projection = ccrs.OSGB()
polygon = sgeom.Polygon([(-1000, -1000),
Expand Down