SolidCode / SolidPython

A python frontend for solid modelling that compiles to OpenSCAD
1.11k stars 173 forks source link

Utility request: direction specific cube centering #98

Closed hephaisto closed 5 years ago

hephaisto commented 5 years ago

I often use cubes that should be centered on one or two axes, but not the other ones. It would be nice to have something like this in the utilities:

def centeredcube(size=None, center=None):
    if center is None or isinstance(center, bool):
        return cube(size, center)
    else:
        translation = [-size[i]/2 if center[i] else 0.0 for i in range(3)]
        return translate(translation)(cube(size, False))`

This can be used as

centeredcube((10, 10, 10), (False,True, False))

to generate a cube that is centered on the Y-Axis, but not on X and Z.

This is basically finished except for the decision where to put it / how to name it I guess.

etjones commented 5 years ago

This could be good, but what about making it more general? If you want to submit a PR for something like: def center_on_axes(bounding_box=None, axes=None): , that would be usable via centered_shape = center_on_axes(bounding_box=[10,5,4], axes=[True, True, False])( my_shape), I'd take that gratefully.