<jupyter_start><jupyter_text>depth dependentgetting pretty dumb to keep repeating this, hard to handle namespace tho it should probs be a class<jupyter_code>def recursive_split_frac_buffer_depth(poly, p_continue=0.7, depth=0, depth_limit=15, buffer_kwargs=None, buffer_frac=-0.1):
    try:
        if buffer_kwargs is None:
            buffer_kwargs = {'join_style':2, 'cap_style':2}
        xgen = ss.uniform(loc=0.2 + 0.00*depth, scale=0.8+0.00*depth).rvs
        split_func = functools.partial(split_along_longest_side_of_min_rectangle, xgen=xgen)
        polys = list(poly.difference(split_func(poly).buffer(1e-6)))
        split_polys = []

        for i, p in enumerate(polys):
            continue_draw = np.random.binomial(n=1, p=p_continue)
            distance=p.centroid.distance(p.boundary)*buffer_frac
            bp = p.buffer(distance=distance, **buffer_kwargs)
            if continue_draw and (depth<depth_limit):

                split_polys += recursive_split_frac_buffer(
                    bp, split_func=split_func, p_continue=p_continue, 
                    depth=depth+1, depth_limit=depth_limit,
                    buffer_kwargs=buffer_kwargs, buffer_frac=buffer_frac
                ) 
            else:

                split_polys.append(bp)
        return split_polys
    except:
        return [poly]
xgen = ss.uniform(loc=0.45, scale=0.3).rvs
split_func = functools.partial(split_along_longest_side_of_min_rectangle, xgen=xgen)
splits = recursive_split_frac_buffer(
    drawbox, 
    split_func=split_func,
    p_continue=0.93, 
    depth=0, 
    depth_limit=12,
    buffer_frac=-0.02
)

bps = MultiPolygon([p for p in splits])
stp = gp.ScaleTransPrms(n_iters = 20, d_buffer=-0.15, d_translate_factor=0.2)

big_bps = [gp.Poly(p) for p in bps if p.area>100]

for p in big_bps:
    p.fill_scale_trans(**stp.prms)

fills = gp.merge_LineStrings([p.fill for p in big_bps])
sk = vsketch.Vsketch()
sk.size(paper.page_format_mm)
sk.scale('1mm')
sk.penWidth('0.5mm')
sk.stroke(1)
sk.geometry(bps.boundary)
sk.stroke(2)
sk.geometry(fills)

sk.display(color_mode='none')

sk.vpype('linemerge --tolerance 0.1 linemerge --tolerance 0.1 linesort')
sk.save('/mnt/c/code/side/plotter_images/oned_outputs/204_subdivide.svg')
xgen = ss.uniform(loc=0.4, scale=0.4).rvs
split_func = functools.partial(split_along_longest_side_of_min_rectangle, xgen=xgen)
splits = recursive_split_frac_buffer(
    drawbox, 
    split_func=split_func,
    p_continue=0.97, 
    depth=0, 
    depth_limit=12,
    buffer_frac=-0.0
)

bps = MultiPolygon([p for p in splits])

nbps = []
for p in bps:
    xbounds = drawbox.bounds[0], drawbox.bounds[2]
    d = np.interp(p.centroid.x, xbounds,  [-0.1, -1.1],)
    nbps.append(p.buffer(d, cap_style=2, join_style=2))
bps = MultiPolygon(nbps)    
sk = vsketch.Vsketch()
sk.size(paper.page_format_mm)
sk.scale('1mm')
sk.penWidth('0.5mm')
sk.stroke(1)
sk.geometry(bps.boundary)
sk.stroke(2)
# sk.geometry(fills)

sk.display(color_mode='none')

sk.vpype('linemerge --tolerance 0.1 linemerge --tolerance 0.1 linesort')
sk.save('/mnt/c/code/side/plotter_images/oned_outputs/205_subdivide.svg')
xgen = ss.uniform(loc=0.5, scale=0.3).rvs
split_func = functools.partial(split_along_longest_side_of_min_rectangle, xgen=xgen)
splits = recursive_split_frac_buffer(
    drawbox, 
    split_func=split_func,
    p_continue=0.96, 
    depth=0, 
    depth_limit=13,
    buffer_frac=-0.01
)

bps = MultiPolygon([p for p in splits])

nbps = []
for p in bps:
    xbounds = drawbox.bounds[0], drawbox.bounds[2]
    d = np.interp(p.centroid.x, xbounds,  [-0.15, -1.6],)
    nbps.append(p.buffer(d, cap_style=2, join_style=2))
bps = MultiPolygon(nbps)    


fbps = []
for _p in bps:
    area = np.log10(_p.area)
    p = gp.Poly(_p)
    n_iters = int(np.interp(area, [-3, 4.3], [1, 230]))
    stp = gp.ScaleTransPrms(n_iters = n_iters, d_buffer=-0.25, d_translate_factor=0.7, angles=np.random.uniform(0,np.pi*2))
    db_mults = gp.gaussian_random_walk(n=stp.d_buffers.shape[0], step_std=4.5, step_mu=0.)
    db_mults[db_mults<0.] = 0.05
    stp.d_buffers *= db_mults
    stp.angles = np.linspace(0, np.radians(360*0.7), len(stp.d_buffers))
    p.fill_scale_trans(**stp.prms)
    fbps.append(p)

fills = gp.merge_LineStrings([p.fill for p in fbps])
sk = vsketch.Vsketch()
sk.size(paper.page_format_mm)
sk.scale('1mm')
sk.penWidth('0.5mm')
sk.stroke(1)
sk.geometry(bps.boundary)
sk.stroke(2)
sk.geometry(fills)

sk.display(color_mode='none')

sk.vpype('linemerge --tolerance 0.1 linemerge --tolerance 0.1 linesimplify --tolerance 0.1 linesort')
sk.save('/mnt/c/code/side/plotter_images/oned_outputs/212_subdivide.svg')
np.

split_func = functools.partial(random_bezier_subdivide, x0=0.3, x1=0.7, n_eval_points=20)
splits = recursive_split_frac_buffer(
    drawbox, 
    split_func=split_func, 
    p_continue=0.99, 
    depth=0, 
    depth_limit=13,
    buffer_frac=-0.01
)


bps = MultiPolygon([p for p in splits])

nbps = []
for p in bps:
    xbounds = drawbox.bounds[0], drawbox.bounds[2]
    d = np.interp(p.centroid.x, xbounds,  [-0.2, -0.45],)
    nbps.append(p.buffer(d, cap_style=2, join_style=2))
bps = MultiPolygon(nbps)    
3 + 4 - 10
3.1 + 4.1 - 9.9
3.2 + 4.2 - 9.8


fbps = []
for _p in bps:
    area = np.log10(_p.area)
    p = gp.Poly(_p)
    n_iters = int(np.interp(area, [-3, 4.3], [1, 230]))
    stp = gp.ScaleTransPrms(n_iters = n_iters, d_buffer=-0.25, d_translate_factor=0.7, angles=np.random.uniform(0,np.pi*2))
    db_mults = gp.gaussian_random_walk(n=stp.d_buffers.shape[0], step_std=4.5, step_mu=0.)
    db_mults[db_mults<0.] = 0.05
    stp.d_buffers *= db_mults
    stp.angles = np.linspace(0, np.radians(360*0.7), len(stp.d_buffers))
    p.fill_scale_trans(**stp.prms)
    fbps.append(p)

fills = gp.merge_LineStrings([p.fill for p in fbps])
sk = vsketch.Vsketch()
sk.size(paper.page_format_mm)
sk.scale('1mm')
sk.penWidth('0.5mm')
sk.stroke(1)
sk.geometry(bps.boundary)
sk.stroke(2)
sk.geometry(fills)

sk.display(color_mode='none')

sk.vpype('linemerge --tolerance 0.1 linemerge --tolerance 0.1 linesimplify --tolerance 0.1 linesort')
sk.save('/mnt/c/code/side/plotter_images/oned_outputs/226_subdivide.svg')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14720155289550307, 'fraction_numerical': 0.03930766742154643, 'mean_word_length': 3.7708333333333335, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '604876', 'license': 'MIT', 'n_tokens_mistral': 2704, 'n_tokens_neox': 2523, 'n_words': 402, 'path': 'scratch/021_subdivide.ipynb', 'repo_name': 'ANaka/genpen', 'size': '6182'}