Example #1
0
    def guide_sort_key (self) :
        """
         s1                                                   s1
                   +--+ +--+      +---+     +--+ +--+
         0         |4 | |5 |      |6  |     |7 | |8 |         0
                   ++-+ +-++      +-+-+     ++-+ +-++
                    |     |         |        |     |
                    |     +-------+ | +------+     |
            +--+    +------------+| | |+-----------+   +--+
        -1  |3 +----------------+|| | ||+--------------+9 |   1
            +--+    +----------+||| | |||+----------+  +--+
                    |     +---+|||| | ||||+---+     |
                   ++-+ +-++ ++++++-+-++++++ ++-+ +-++
        -2         |2 | |1 | |             | |11| |10|        2
                   +--+ +--+ +-------------+ +--+ +--+

        """
        points = self.points
        p0     = points [ 0].free
        q      = points [-1].free
        p0_q   = p0 - q
        side   = self.connector.side
        p0_q_y = getattr (p0_q, side.dim)
        p0_q_x = getattr (p0_q, side.other_dim)
        s1     = 0
        if self.other_connector.side.side == side.side :
            s1 = sign (p0_q_x) * side.sort_sign * 2
        elif self.other_connector.side.dim != side.dim :
            s1 = sign (p0_q_x) * side.sort_sign
        s2     = - sign (s1) * p0_q_x
        result = (s1, s2, p0_q_x * side.sort_sign)
        return result
Example #2
0
 def _directions(self):
     v_map = self.value_map
     x, y = tuple(self)
     sx = sign(x)
     sy = sign(y)
     ax = abs(x)
     ay = abs(y)
     if ax == ay:
         if ax:
             yield (v_map[sx, sy], ax)
         else:
             yield ("(0,0)", 1)
     else:
         if ax:
             yield (v_map[sx, 0], ax)
         if ay:
             yield (v_map[0, sy], ay)
Example #3
0
 def _directions (self) :
     v_map = self.value_map
     x, y  = tuple (self)
     sx    = sign  (x)
     sy    = sign  (y)
     ax    = abs   (x)
     ay    = abs   (y)
     if ax == ay :
         if ax :
             yield (v_map [sx, sy], ax)
         else :
             yield ("(0,0)", 1)
     else :
         if ax :
             yield (v_map [sx,  0], ax)
         if ay :
             yield (v_map [ 0, sy], ay)
Example #4
0
 def improve_connectors(self):
     map = mm_list()
     for r in self.rels:
         if len(r.points) > 3:
             p = r.points[-2]
             key = \
                 ( sign (getattr (r.delta, self.other_dim))
                 , getattr (p, self.dim)
                 )
             map[key].append(r)
     for k, rs in pyk.iteritems(map):
         step = k[0] * self.sort_sign
         if len(rs) > 1:
             for i, r in enumerate(rs[1::step]):
                 r.shift_guide(i + 1)
Example #5
0
def unit_changes(after, before, str_dates, unit, offset=0, limit=5):
    """Yield all elements of `str_dates` closest to `unit` changes."""
    map = mm_list()
    for d, sd in in_range(after, before, str_dates):
        p1, p2 = d.periods[unit]
        if offset:
            p1 += offset
            p2 += offset
        p = p1 if (d - p1 < (p2 - p1) // 2) else (p2 + 1)
        delta = (d - p).days
        a_delta = abs(delta)
        if a_delta <= limit:
            map[p].append((a_delta, -sign(delta), sd))
    result = list(min(v)[-1] for v in pyk.itervalues(map))
    return sorted(result)
Example #6
0
def unit_changes (after, before, str_dates, unit, offset = 0, limit = 5) :
    """Yield all elements of `str_dates` closest to `unit` changes."""
    map = mm_list ()
    for d, sd in in_range (after, before, str_dates) :
        p1, p2  = d.periods [unit]
        if offset :
            p1 += offset
            p2 += offset
        p       = p1 if (d - p1 < (p2 - p1) // 2) else (p2 + 1)
        delta   = (d - p).days
        a_delta = abs (delta)
        if a_delta <= limit :
            map [p].append ((a_delta, - sign (delta), sd))
    result = list (min (v) [-1] for v in pyk.itervalues (map))
    return sorted (result)
Example #7
0
 def improve_connectors (self) :
     map = mm_list ()
     for r in self.rels :
         if len (r.points) > 3 :
             p   = r.points [-2]
             key = \
                 ( sign (getattr (r.delta, self.other_dim))
                 , getattr (p, self.dim)
                 )
             map [key].append (r)
     for k, rs in pyk.iteritems (map) :
         step = k [0] * self.sort_sign
         if len (rs) > 1 :
             for i, r in enumerate (rs [1::step]) :
                 r.shift_guide (i + 1)