8000 Add tests for Issue #493: PDF output with linewidth=0 by Cdiaz1234 · Pull Request #626 · matplotlib/basemap · GitHub
[go: up one dir, main page]

Skip to content

Add tests for Issue #493: PDF output with linewidth=0 #626

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

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Unit test
  • Loading branch information
Kenji7SenSei committed May 6, 2025
commit d233a762d81c53045f83bd0c7195f1cf4d16b38d
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import numpy as np
import pytest
from mpl_toolkits.basemap import Basemap

# Extracted testable version of the core plotting logic
def compute_arc_points(m, lon1, lat1, lon2, lat2, arc_height_ratio=0.15):
t = np.linspace(0, 1, 300)
lons = lon1 + (lon2 - lon1) * t
lats = lat1 + (lat2 - lat1) * t
mid_lat = (lat1 + lat2) / 2
arc_direction = -1 if mid_lat > 0 else 1
arc_height = arc_height_ratio * abs(lat2 - lat1 + 1e-6)
bulge = np.cos(np.pi * (t - 0.5))
lats += arc_direction * arc_height * bulge
lats = np.clip(lats, -85, 85)
x, y = m(lons, lats)
return x, y

# === Unit test ===
def test_better_great_circle():
m = Basemap(projection='merc',
llcrnrlon=-180, urcrnrlon=180,
llcrnrlat=-60, urcrnrlat=80,
lat_ts=20, resolution='c')
# Example input: Anchorage → Moscow
x, y = compute_arc_points(m, -149.9003, 61.2181, 37.6173, 55.7558)

# Test: All values are finite
assert np.all(np.isfinite(x)), "X coordinates contain non-finite values"
assert np.all(np.isfinite(y)), "Y coordinates contain non-finite values"

# Test: Array has expected length
assert len(x) == 300 and len(y) == 300, "Coordinate arrays are incorrect length"

# Test: Latitude transformation is within Mercator-safe bounds
_, test_lats = m(x, y, inverse=True)
assert np.all((test_lats >= -85) & (test_lats <= 85)), "Some latitudes are out of bounds"
0