Code Duplication    Length = 14-14 lines in 2 locations

tcod/libtcodpy.py 2 locations

@@ 537-550 (lines=14) @@
534
def console_fill_background(con,r,g,b):
535
    if len(r) != len(g) or len(r) != len(b):
536
        raise TypeError('R, G and B must all have the same size.')
537
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
538
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
539
        #numpy arrays, use numpy's ctypes functions
540
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
541
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
542
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
543
        cr = ffi.cast('int *', r.ctypes.data)
544
        cg = ffi.cast('int *', g.ctypes.data)
545
        cb = ffi.cast('int *', b.ctypes.data)
546
    else:
547
        # otherwise convert using ffi arrays
548
        cr = ffi.new('int[]', r)
549
        cg = ffi.new('int[]', g)
550
        cb = ffi.new('int[]', b)
551
552
    lib.TCOD_console_fill_background(con or ffi.NULL, cr, cg, cb)
553
@@ 517-530 (lines=14) @@
514
def console_fill_foreground(con,r,g,b):
515
    if len(r) != len(g) or len(r) != len(b):
516
        raise TypeError('R, G and B must all have the same size.')
517
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
518
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
519
        #numpy arrays, use numpy's ctypes functions
520
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
521
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
522
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
523
        cr = ffi.cast('int *', r.ctypes.data)
524
        cg = ffi.cast('int *', g.ctypes.data)
525
        cb = ffi.cast('int *', b.ctypes.data)
526
    else:
527
        # otherwise convert using ffi arrays
528
        cr = ffi.new('int[]', r)
529
        cg = ffi.new('int[]', g)
530
        cb = ffi.new('int[]', b)
531
532
    lib.TCOD_console_fill_foreground(con or ffi.NULL, cr, cg, cb)
533