merlin.geometry

merlin.geometry.coordinates(points, grid, snap_fn)[source]

Returns grid coordinates contained within points.

Points may be specified as dicts, tuples, lists, or sets.

  • dict with keys ulx, uly, lrx, lry
  • sequence of sequences: ((0,0), (100, 167), (-212, 6621))

Irregular perimeters may be specified in sequences as points will be minboxed.

Points as dicts are an implicit minbox.

Parameters:
  • points (collection) – Points outlining an area
  • grid (dict) – The target grid: {‘name’: ‘chip’, ‘sx’: 3000, ‘sy’: 3000, ‘rx’: 1, ‘ry’: -1}
  • snap_fn (func) – A function that accepts x, y and returns a snapped x, y
Returns:

tuple of tuples of grid coordinates ((x1,y1), (x2,y2) …)

Return type:

tuple

Example

>>> grid = {'name': 'chip', 'sx': 500, 'sy': 500, 'rx': 1, 'ry': 1}
>>> sfn = partial(chipmunk.snap, url='http://localhost:5656')
>>> coordinates({'ulx': -1001, 'uly': 1000, 'lrx': -500, 'lry': 500},
                grid=grid,
                snap_fn=sfn)
((-3585.0, 2805.0),
 (-3085.0, 2805.0),
 (-2585.0, 2805.0),
 (-2085.0, 2805.0),
 (-1585.0, 2805.0),
 (-1085.0, 2805.0),
 (-585.0, 2805.0))
>>> grid = {'name': 'chip', 'sx': 3000, 'sy': 3000, 'rx': 1, 'ry': -1}
>>> coordinates(((112, 443), (112, 500), (100, 443)),
                grid=grid,
                snap_fn=sfn})
((-585.0, 2805.0),)
merlin.geometry.extents(ulx, uly, grid)[source]

Given an ulx, uly and grid, returns the grid extents.

ulx and uly are not translated during this calculation.

Parameters:
  • ulx (float) – 0
  • uly (float) – 0
  • grid (dict) – {‘rx’, ‘ry’, ‘sx’, ‘sy’}
Returns:

{‘ulx’, ‘uly’, ‘lrx’, ‘lry’}

Return type:

dict

Example

>>> extents(ulx=0,
            uly=0,
            grid={'rx': 1, 'ry': -1, 'sx': 3000, 'sy': 3000}
{'ulx': 0, 'uly': 0, 'lrx': 2999, 'lry': -2999}
merlin.geometry.minbox(points)[source]

Returns the minimal bounding box necessary to contain points

Parameters:points (tuple, list, set) – ((0,0), (40, 55), (66, 22))
Returns:{ulx, uly, lrx, lry}
Return type:dict

Example

>>> minbox((0, 0), (40, 55), (66,22))
{'ulx': 0, 'uly': 55, 'lrx': 66, 'lry': 0}