Exemplo n.º 1
0
def buildMutator(items):
    """
        Build a mutator with the (location, obj) pairs in items.
        Determine the bias based on the given locations.
    """
    m = Mutator()
    bias = biasFromLocations([loc for loc, obj in items])
    m.setBias(bias)
    n = None
    ofx = []
    onx = []
    for loc, obj in items:
        if (loc-bias).isOrigin():
            n = obj
    m.setNeutral(n)
    for loc, obj in items:
        lb = loc-bias
        if lb.isOrigin(): continue
        if lb.isOnAxis():
            onx.append((lb, obj-n))
        else:
            ofx.append((lb, obj-n))
    for loc, obj in onx:
        m.addDelta(loc, obj, punch=False,  axisOnly=True)
    for loc, obj in ofx:
        m.addDelta(loc, obj, punch=True,  axisOnly=True)
    return bias, m
Exemplo n.º 2
0
def buildMutator(items):
    """
        Build a mutator with the (location, obj) pairs in items.
        Determine the bias based on the given locations.
    """
    m = Mutator()
    # the order itself does not matter, but we should always build in the same order.
    items.sort()
    bias = biasFromLocations([loc for loc, obj in items], True)
    m.setBias(bias)
    n = None
    ofx = []
    onx = []
    for loc, obj in items:
        if (loc-bias).isOrigin():
            m.setNeutral(obj)
            break
    if m.getNeutral() is None:
        raise MutatorError("Did not find a neutral for this system", m)
    for loc, obj in items:
        lb = loc-bias
        if lb.isOrigin(): continue
        if lb.isOnAxis():
            onx.append((lb, obj-m.getNeutral()))
        else:
            ofx.append((lb, obj-m.getNeutral()))
    for loc, obj in onx:
        m.addDelta(loc, obj, punch=False,  axisOnly=True)
    for loc, obj in ofx:
        m.addDelta(loc, obj, punch=True,  axisOnly=True)
    return bias, m
Exemplo n.º 3
0
def buildMutator(items):
    """
        Build a mutator with the (location, obj) pairs in items.
        Determine the bias based on the given locations.
    """
    m = Mutator()
    bias = biasFromLocations([loc for loc, obj in items])
    m.setBias(bias)
    n = None
    ofx = []
    onx = []
    for loc, obj in items:
        if (loc - bias).isOrigin():
            n = obj
    m.setNeutral(n)
    for loc, obj in items:
        lb = loc - bias
        if lb.isOrigin(): continue
        if lb.isOnAxis():
            onx.append((lb, obj - n))
        else:
            ofx.append((lb, obj - n))
    for loc, obj in onx:
        m.addDelta(loc, obj, punch=False, axisOnly=True)
    for loc, obj in ofx:
        m.addDelta(loc, obj, punch=True, axisOnly=True)
    return bias, m
Exemplo n.º 4
0
 def _makeWarpFromList(self, axisName, warpMap):
     if not warpMap:
         warpMap = [(0, 0), (1000, 1000)]
     self.maps[axisName] = warpMap
     items = []
     for x, y in warpMap:
         items.append((Location(w=x), y))
     m = WarpMutator()
     items.sort()
     bias = biasFromLocations([loc for loc, obj in items], True)
     m.setBias(bias)
     n = None
     ofx = []
     onx = []
     for loc, obj in items:
         if (loc - bias).isOrigin():
             m.setNeutral(obj)
             break
     if m.getNeutral() is None:
         raise MutatorError("Did not find a neutral for this system", m)
     for loc, obj in items:
         lb = loc - bias
         if lb.isOrigin(): continue
         if lb.isOnAxis():
             onx.append((lb, obj - m.getNeutral()))
         else:
             ofx.append((lb, obj - m.getNeutral()))
     for loc, obj in onx:
         m.addDelta(loc, obj, punch=False, axisOnly=True)
     for loc, obj in ofx:
         m.addDelta(loc, obj, punch=True, axisOnly=True)
     self.warps[axisName] = m
Exemplo n.º 5
0
 def _makeWarpFromList(self, axisName, warpMap):
     if not warpMap:
         warpMap = [(0,0), (1000,1000)]
     self.maps[axisName] = warpMap
     items = []
     for x, y in warpMap:
         items.append((Location(w=x), y))
     m = WarpMutator()
     items.sort()
     bias = biasFromLocations([loc for loc, obj in items], True)
     m.setBias(bias)
     n = None
     ofx = []
     onx = []
     for loc, obj in items:
         if (loc-bias).isOrigin():
             m.setNeutral(obj)
             break
     if m.getNeutral() is None:
         raise MutatorError("Did not find a neutral for this system", m)
     for loc, obj in items:
         lb = loc-bias
         if lb.isOrigin(): continue
         if lb.isOnAxis():
             onx.append((lb, obj-m.getNeutral()))
         else:
             ofx.append((lb, obj-m.getNeutral()))
     for loc, obj in onx:
         m.addDelta(loc, obj, punch=False,  axisOnly=True)
     for loc, obj in ofx:
         m.addDelta(loc, obj, punch=True,  axisOnly=True)
     self.warps[axisName] = m
Exemplo n.º 6
0
def buildMutator(items):
    """
        Build a mutator with the (location, obj) pairs in items.
        Determine the bias based on the given locations.
    """
    m = Mutator()
    # the order itself does not matter, but we should always build in the same order.
    items.sort()
    bias = biasFromLocations([loc for loc, obj in items], True)
    m.setBias(bias)
    n = None
    ofx = []
    onx = []
    for loc, obj in items:
        if (loc - bias).isOrigin():
            m.setNeutral(obj)
            break
    if m.getNeutral() is None:
        raise MutatorError("Did not find a neutral for this system", m)
    for loc, obj in items:
        lb = loc - bias
        if lb.isOrigin(): continue
        if lb.isOnAxis():
            onx.append((lb, obj - m.getNeutral()))
        else:
            ofx.append((lb, obj - m.getNeutral()))
    for loc, obj in onx:
        m.addDelta(loc, obj, punch=False, axisOnly=True)
    for loc, obj in ofx:
        m.addDelta(loc, obj, punch=True, axisOnly=True)
    return bias, m
Exemplo n.º 7
0
def buildMutator(items, axes=None, bias=None):
    """
        Build a mutator with the (location, obj) pairs in items.
        Determine the bias based on the given locations.
    """
    from mutatorMath.objects.bender import Bender
    items = [(Location(loc), obj) for loc, obj in items]
    if bias is None:
        bias = Location()
    else:
        bias = Location(bias)
    m = Mutator()
    if axes is not None:
        # make a Bender object
        # but do not transform the locations from the items
        bender = Bender(axes)
        m.setBender(bender)
    else:
        bender = noBend
    # the order itself does not matter, but we should always build in the same order.
    items = sorted(items)
    if not bias:
        bias = biasFromLocations([loc for loc, obj in items], True)
    m.setBias(bias)
    n = None
    ofx = []
    onx = []
    for loc, obj in items:
        nn = (loc - bias)
        if nn.isOrigin():
            m.setNeutral(obj)
            break
    if m.getNeutral() is None:
        raise MutatorError("Did not find a neutral for this system", items)
    for loc, obj in items:
        lb = loc - bias
        if lb.isOrigin(): continue
        if lb.isOnAxis():
            onx.append((lb, obj - m.getNeutral()))
        else:
            ofx.append((lb, obj - m.getNeutral()))
    for loc, obj in onx:
        m.addDelta(loc, obj, punch=False, axisOnly=True)
    for loc, obj in ofx:
        m.addDelta(loc, obj, punch=True, axisOnly=True)
    return bias, m
Exemplo n.º 8
0
def buildMutator(items, axes=None, bias=None):
    """
        Build a mutator with the (location, obj) pairs in items.
        Determine the bias based on the given locations.
    """
    from mutatorMath.objects.bender import Bender
    m = Mutator()
    if axes is not None:
        bender = Bender(axes)
        m.setBender(bender)
    else:
        bender = noBend
    # the order itself does not matter, but we should always build in the same order.
    items = sorted(items)
    if not bias:
        bias = biasFromLocations([bender(loc) for loc, obj in items], True)
    else:
        # note: this means that the actual bias might be different from the initial value. 
        bias = bender(bias)
    m.setBias(bias)
    n = None
    ofx = []
    onx = []
    for loc, obj in items:
        loc = bender(loc)
        if (loc-bias).isOrigin():
            m.setNeutral(obj)
            break
    if m.getNeutral() is None:
        raise MutatorError("Did not find a neutral for this system", m)
    for loc, obj in items:
        locbent = bender(loc)
        #lb = loc-bias
        lb = locbent-bias
        if lb.isOrigin(): continue
        if lb.isOnAxis():
            onx.append((lb, obj-m.getNeutral()))
        else:
            ofx.append((lb, obj-m.getNeutral()))
    for loc, obj in onx:
        m.addDelta(loc, obj, punch=False,  axisOnly=True)
    for loc, obj in ofx:
        m.addDelta(loc, obj, punch=True,  axisOnly=True)
    return bias, m
Exemplo n.º 9
0
def buildMutator(items, axes=None, bias=None):
    """
        Build a mutator with the (location, obj) pairs in items.
        Determine the bias based on the given locations.
    """
    from mutatorMath.objects.bender import Bender
    items = [(Location(loc),obj) for loc, obj in items]
    m = Mutator()
    if axes is not None:
        bender = Bender(axes)
        m.setBender(bender)
    else:
        bender = noBend
    # the order itself does not matter, but we should always build in the same order.
    items = sorted(items)
    if not bias:
        bias = biasFromLocations([bender(loc) for loc, obj in items], True)
    else:
        # note: this means that the actual bias might be different from the initial value. 
        bias = bender(bias)
    m.setBias(bias)
    n = None
    ofx = []
    onx = []
    for loc, obj in items:
        loc = bender(loc)
        if (loc-bias).isOrigin():
            m.setNeutral(obj)
            break
    if m.getNeutral() is None:
        raise MutatorError("Did not find a neutral for this system", m)
    for loc, obj in items:
        locbent = bender(loc)
        lb = locbent-bias
        if lb.isOrigin(): continue
        if lb.isOnAxis():
            onx.append((lb, obj-m.getNeutral()))
        else:
            ofx.append((lb, obj-m.getNeutral()))
    for loc, obj in onx:
        m.addDelta(loc, obj, punch=False,  axisOnly=True)
    for loc, obj in ofx:
        m.addDelta(loc, obj, punch=True,  axisOnly=True)
    return bias, m
Exemplo n.º 10
0
def buildMutator(items, warpDict=None):
    """
        Build a mutator with the (location, obj) pairs in items.
        Determine the bias based on the given locations.
    """
    from mutatorMath.objects.bender import Bender
    m = Mutator()
    if warpDict is not None:
        bender = Bender(warpDict)
        m.setBender(bender)
    else:
        bender = noBend
    # the order itself does not matter, but we should always build in the same order.
    items = sorted(items)
    bias = biasFromLocations([bender(loc) for loc, obj in items], True)
    m.setBias(bias)
    n = None
    ofx = []
    onx = []
    for loc, obj in items:
        loc = bender(loc)
        if (loc-bias).isOrigin():
            m.setNeutral(obj)
            break
    if m.getNeutral() is None:
        raise MutatorError("Did not find a neutral for this system", m)
    for loc, obj in items:
        lb = loc-bias
        if lb.isOrigin(): continue
        if lb.isOnAxis():
            onx.append((lb, obj-m.getNeutral()))
        else:
            ofx.append((lb, obj-m.getNeutral()))
    for loc, obj in onx:
        m.addDelta(loc, obj, punch=False,  axisOnly=True)
    for loc, obj in ofx:
        m.addDelta(loc, obj, punch=True,  axisOnly=True)
    return bias, m
Exemplo n.º 11
0
 def _makeWarpFromList(self, axisName, warpMap, minimum, maximum):
     if not warpMap:
         warpMap = [(minimum,minimum), (maximum,maximum)]
     self.warps[axisName] = warpMap
     # check for the extremes, add if necessary
     if not sum([a==minimum for a, b in warpMap]):
         warpMap = [(minimum,minimum)] + warpMap
     if not sum([a==maximum for a, b in warpMap]):
         warpMap.append((maximum,maximum))
     items = []
     for x, y in warpMap:
         items.append((Location(w=x), y))
     m = WarpMutator()
     items.sort()
     bias = biasFromLocations([loc for loc, obj in items], True)
     m.setBias(bias)
     n = None
     ofx = []
     onx = []
     for loc, obj in items:
         if (loc-bias).isOrigin():
             m.setNeutral(obj)
             break
     if m.getNeutral() is None:
         raise MutatorError("Did not find a neutral for this system", m)
     for loc, obj in items:
         lb = loc-bias
         if lb.isOrigin(): continue
         if lb.isOnAxis():
             onx.append((lb, obj-m.getNeutral()))
         else:
             ofx.append((lb, obj-m.getNeutral()))
     for loc, obj in onx:
         m.addDelta(loc, obj, punch=False,  axisOnly=True)
     for loc, obj in ofx:
         m.addDelta(loc, obj, punch=True,  axisOnly=True)
     self.warps[axisName] = m