Skip to content
Open
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
15 changes: 15 additions & 0 deletions lib/cartopy/tests/test_line_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ def test_multi_linestring_return_type(self):
shapely.MultiLineString(), ccrs.PlateCarree())
assert isinstance(multi_line_string, shapely.MultiLineString)

def test_start_end_project_equal(self):
# Here the start and end points project to the same point in the target domain,
# but we should get a line that encircles the equator.
tgt_proj = ccrs.NorthPolarStereo(central_longitude=180)
src_proj = ccrs.PlateCarree(central_longitude=180)
start = [-180, 0]
end = [180, 0]

# Verify these points project to same point, otherwise the test is invalid
assert (tgt_proj.transform_point(*start, src_proj) ==
tgt_proj.transform_point(*end, src_proj))

line_string = shapely.LineString([start, end])
assert tgt_proj.project_geometry(line_string, src_proj).length > 7e7


class FakeProjection(ccrs.PlateCarree):
def __init__(self, left_offset=0, right_offset=0):
Expand Down
9 changes: 8 additions & 1 deletion lib/cartopy/trace.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,13 @@ cdef bool straightAndDomain(double t_start, const Point &p_start,
along = (seg_dx*mid_dx + seg_dy*mid_dy) / seg_hypot_sq

if isnan(along):
valid = True
mid_hypot_sq = mid_dx*mid_dx + mid_dy*mid_dy
if mid_hypot_sq > 0.0 and seg_hypot_sq == 0.0:
# End points project to the same location, but the midpoint is
# elsewhere.
valid = False
else:
valid = True
else:
valid = 0.0 < along < 1.0
if valid:
Expand Down Expand Up @@ -476,6 +482,7 @@ cdef void _project_segment(double[:] src_from, double[:] src_to,
print(" => ", t_min, "to", t_max)
print(" => (", p_min.x, ", ", p_min.y, ") to (",
p_max.x, ", ", p_max.y, ")")
print("p_current.x", p_current.x, "p_current.y", p_current.y)

if state == POINT_IN:
lines.add_point_if_empty(p_current)
Expand Down
Loading