def test_align(): D = Device() # Create different-sized rectangles and add them to D then distribute them [ D.add_ref( pg.rectangle(size=[n * 15 + 20, n * 15 + 20]).move((n, n * 4))) for n in [0, 2, 3, 1, 2] ] D.distribute(elements='all', direction='x', spacing=5, separation=True) # Align top edges D.align(elements='all', alignment='ymax') h = D.hash_geometry(precision=1e-4) assert (h == '38025959a80e46e47eabcf3f096c6273427dabc3') D = Device() # Create different-sized rectangles and add them to D then distribute them [ D.add_ref( pg.rectangle(size=[n * 15 + 20, n * 15 + 20]).move((n, n * 4))) for n in [0, 2, 3, 1, 2] ] D.distribute(elements='all', direction='x', spacing=5, separation=True) # Align top edges D.align(elements='all', alignment='y') h = D.hash_geometry(precision=1e-4) assert (h == 'ed32ee1ce1f3da8f6216020877d6c1b64097c600')
# or vertically. It is meant to duplicate the alignment functionality present # in Inkscape / Adobe Illustrator: # Say we `distribute()` a few objects, but they're all misaligned. # we can use the `align()` function to align their top edges (`alignment = 'ymax'): D = Device() # Create differents-sized rectangles and add them to D then distribute them [ D.add_ref(pg.rectangle(size=[n * 15 + 20, n * 15 + 20]).move((n, n * 4))) for n in [0, 2, 3, 1, 2] ] D.distribute(elements='all', direction='x', spacing=5, separation=True) # Align top edges D.align(elements='all', alignment='ymax') qp(D) # quickplot the geometry # or align their centers (`alignment = 'y'): D = Device() # Create differents-sized rectangles and add them to D then distribute them [ D.add_ref(pg.rectangle(size=[n * 15 + 20, n * 15 + 20]).move((n, n * 4))) for n in [0, 2, 3, 1, 2] ] D.distribute(elements='all', direction='x', spacing=5, separation=True) # Align top edges D.align(elements='all', alignment='y')