예제 #1
0
def calculate_bit_metrics(bit_size, bit_glyphs):
    (width, height) = bit_size
    units_per_pixel = 100
    units_per_em = units_per_pixel * height
    x_height = units_per_pixel * (find_x_height(bit_size, bit_glyphs))
    stems = list(
        units_per_pixel * (i + 1)
        for i in range(0, 4))
    distinct_heights = distinct([
        0,
        x_height,
        units_per_em])
    values = list(flatten(
        (height - 5, height + 5) for height in distinct_heights))
    scale = 4.0 / units_per_pixel
    return BitMetrics(
        width=width,
        height=height,
        units_per_pixel=units_per_pixel,
        units_per_em=units_per_em,
        ascender=units_per_pixel * (height + 1),
        descender=units_per_pixel * (-1),
        x_height=x_height,
        line_gap=units_per_pixel * 2,
        left_advance=0,
        total_advance=units_per_pixel * (width + 1),
        stems=stems,
        values=values,
        scale=scale)
예제 #2
0
def findBestChords(notes):
    print "findBestChords", notes
    chords = (Chord(notes, paths)
              for paths in generateAllPathCombinations(notes))
    chords = utils.findBestItems(chords, lambda c: c.getRate())
    chords = utils.distinct(chords, key=lambda c: c.structId)
    return chords
예제 #3
0
def joinTrees(tree, treeCut, steps= None):
    if steps == None:
        steps = getSteps(tree.note, treeCut.note)

    #print 'joinTrees', tree.note, '<-', treeCut.note, steps
    #print tree.format()
    #print treeCut.format()
    
    childFound = False
    for (s,child) in tree.children.items():
        if s in steps:
            ss = removeStep(steps, s)
            for t in joinTrees(child, treeCut, ss):
                tt = tree.copy()
                tt.children[s] = t  # replace the child
                yield tt
            childFound = True
    #
    if not childFound:
        for w in utils.distinct(itertools.permutations(steps)):
            child = treeCut.copy()
            for s in w[:0:-1]:
                child = Tree(stepFromNote(child.note, -s), {s: child})
            tt = tree.copy()
            tt.children[w[0]] = child
            yield tt
예제 #4
0
def genrate_tree(t_head, t_body, maj="yes"):
    n = {}
    ds = distinct(t_head.index("class"), t_body)
    if len(ds["outcomes"]) == 1:
        return ds["outcomes"][0]
    if len(t_head) == 0:
        return maj
    split_point = best(t_head, t_body)
    new_t_head, div = select_dist(t_head.index(split_point), t_head, t_body)
    n[split_point] = {}
    for i in div:
        if len(i) == 0:
            return maj
        n[split_point][i] = genrate_tree(new_t_head[:], div[i], maj)
    return n
예제 #5
0
 def get_camera_position_generator(self, folder):
     hashes_w_filenames = [(fp.split("_")[1], os.path.join(folder, fp))
                           for fp in os.listdir(folder)]
     for h_fn in utils.distinct(hashes_w_filenames):
         yield self.get_camera_position(h_fn[1])
예제 #6
0
def distinctById(trees):
    return utils.distinct(trees, key= lambda t: t.getId())
예제 #7
0
 def get_camera_position_generator(self, folder):
     hashes = [filepath.split("_")[0] for filepath in os.listdir(folder)]
     for h in utils.distinct(hashes):
         filename = os.path.join(folder, h + "_pose_0_0.txt")
         yield self.get_camera_position(filename)