Skip to content

Instantly share code, notes, and snippets.

@cmosguy
Last active May 4, 2016 22:20
Show Gist options
  • Save cmosguy/7333c5514c8ebffdfedf65c9370de961 to your computer and use it in GitHub Desktop.
Save cmosguy/7333c5514c8ebffdfedf65c9370de961 to your computer and use it in GitHub Desktop.
def getOffsets(big_length, small_length, grid):
"""
return the lowest/highest offsets, if a shape of small length is
rendered and centered inside a larger shape length
Returns:
An OffsetInfo object with the following attributes:
loffset - lowest offset
hoffset - highest offset
"""
offset = big_length - small_length
hoffset = snap2Grid(offset / 2.0, grid)
loffset = snap2Grid(offset - hoffset, grid)
if loffset > hoffset:
(loffset, hoffset) = (hoffset, loffset)
# assemble OffsetInfo object
class OffsetInfo:
pass
oi = ContactInfo()
oi.loffset = loffset
oi.hoffset = hoffset
return oi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment