<jupyter_start><jupyter_text>See https://gist.github.com/smidm/b398312a13f60c24449a2c7533877dc0<jupyter_code>import numpy as np
import pylab as plt
import matplotlib.patches
from ipywidgets import interact, interactive, fixed, interact_manual

from pyinverse.ellipse import ellipse_bb, Ellipse
from pyinverse.axis import RegularAxis
from pyinverse.grid import RegularGrid
def plot_ellipse(x=50, y=50, major=30, minor=10, angle_deg=45):
    plt.figure(2)
    plt.clf()
    ax = plt.gca()
    ax.add_patch(matplotlib.patches.Ellipse((x, y), major, minor, angle_deg, 
                 edgecolor='r',
                 facecolor='none'))
    min_x, min_y, max_x, max_y = ellipse_bb(x, y, major/2, minor/2, angle_deg)
    plt.vlines([max_x, min_x], 0, 100)
    plt.hlines([max_y, min_y], 0, 100)
    plt.show()
plot_ellipse()<jupyter_output><empty_output><jupyter_text>interactive_plot = interactive(plot_ellipse,                                x=fixed(50),                                y=fixed(50),                               major=(0, 40),                               minor=(0, 40),                               angle_deg=(-180, 180),                              )output = interactive_plot.children[-1]output.layout.height = '350px'interactive_plot<jupyter_code>#e1 = Ellipse(.01, .2100, .2500,   0,    .35,    0)
#e1 = Ellipse(-.2, .1600, .4100, -.22,    0,     18)
e1 = Ellipse(-.2, .1100, .3100,  .22,    0,    -18)
#e1 = Ellipse(1, 0.69/2, 0.92/2, 0.25, 0.15, 25)
#e1 = Ellipse(1, 0.69, 0.92, 0, 0, 0)
#e1 = Ellipse(-0.8, 0.6624, 0.8740, 0, -0.0184, 0)
#e1 = Ellipse(-.2, .1100, .3100,  .22,    0,    -18)
e1.bounds
N1 = N2 = 32
grid = RegularGrid(RegularAxis.linspace(-1, 1, N1), 
                   RegularAxis.linspace(-1, 1, N2))
min_x, min_y, max_x, max_y = e1.bounds
J1 = max(np.argwhere(grid.axis_x.borders[:-1] >= min_x)[0][0] - 1, 0)
J2 = min(np.argwhere(grid.axis_x.borders[1:] <= max_x)[-1][0] + 1, grid.axis_x.N - 1)

I1 = max(np.argwhere(grid.axis_y.borders[:-1] >= min_y)[0][0] - 1, 0)
I2 = min(np.argwhere(grid.axis_y.borders[1:] <= max_y)[-1][0] + 1, grid.axis_y.N - 1)
ALPHA = 0.1

plt.figure()
ax = plt.gca()
ax.add_patch(matplotlib.patches.Ellipse((e1.x0, e1.y0), 2*e1.a, 2*e1.b, e1.phi_deg, 
             edgecolor='r',
             facecolor='none'))
plt.axvline(min_x)
plt.axvline(max_x)
plt.axhline(min_y)
plt.axhline(max_y)
# plot grid centers
plt.scatter(*[x.flat for x in np.meshgrid(list(grid.axis_x), list(grid.axis_y))], c='g', s=4, alpha=ALPHA)
# plot grid edges
for x in grid.axis_x.borders:
    plt.plot([x, x], [grid.axis_y.borders[0], grid.axis_y.borders[-1]], c='g', alpha=ALPHA)
for y in grid.axis_y.borders:
    plt.plot([grid.axis_x.borders[0], grid.axis_x.borders[-1]], [y, y], c='g', alpha=ALPHA)

plt.axvline(grid.axis_x[J1], c='C1')
plt.axvline(grid.axis_x[J2], c='C1')
plt.axhline(grid.axis_x[I1], c='C1')
plt.axhline(grid.axis_x[I2], c='C1')
plt.xlim(-1, 1)
plt.ylim(-1, 1)
plt.axis('equal');
J1 = max(np.argwhere(grid.axis_x.borders[:-1] >= min_x)[0][0] - 1, 0)
J2 = min(np.argwhere(grid.axis_x.borders[1:] <= max_x)[-1][0] + 1, grid.axis_x.N - 1)
J1, J2
I1 = max(np.argwhere(grid.axis_y.borders[:-1] >= min_y)[0][0] - 1, 0)
I2 = min(np.argwhere(grid.axis_y.borders[1:] <= max_y)[-1][0] + 1, grid.axis_y.N - 1)
I1, I2
min_y, max_y<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19070609535304767, 'fraction_numerical': 0.08026554013277007, 'mean_word_length': 3.1129032258064515, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '531956', 'license': 'MIT', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1468, 'n_words': 257, 'path': 'notebooks/Test ellipse bounding box.ipynb', 'repo_name': 'butala/pyinverse', 'size': '3314'}