jpd236 / kotwords

Collection of crossword puzzle file format converters and other utilities, written in Kotlin.
Apache License 2.0
25 stars 6 forks source link

Non-square spiral grids #35

Closed boisvert42 closed 1 year ago

boisvert42 commented 1 year ago

Unusual request here, but I'd like to have the option of non-square spiral grids. I don't think they should go super non-square, maybe something like this?

def is_spiral_size(my_num):
    my_sqrt = math.sqrt(my_num)
    (row, col) = (None, None)
    return_value = False
    for i in (0,1):
        potential_factor = int(my_sqrt - i)
        if my_num % potential_factor == 0:
            return_value = True
            factor2 = my_num // potential_factor
            row, col = min(potential_factor, factor2), max(potential_factor, factor2)
            break
    return return_value, (row, col)

and you can take the minimum value at or above the current spiral length to use as the final size. Thoughts? I have no concept of how big a change this would be.

jpd236 commented 1 year ago

I'm not so sure about trying to infer a particular non-square size (for one, how would you know whether to make the grid taller or wider?) or how you'd expose such an option, but it seems reasonable to provide an advanced option to specify the grid dimensions manually and then just fill that space, with black squares as needed in the middle, and failing if the grid isn't big enough. Would that work?

boisvert42 commented 1 year ago

You know, after I posted the issue I thought of that and wished I had posted that request instead, so yes, if that's feasible, let's do that!

jpd236 commented 1 year ago

Width and height are now available as optional fields in the Spiral, Jelly Roll, and Two Tone forms.

LMK if you run into any issues/strangeness.

boisvert42 commented 1 year ago

Thanks!