Introduction
Kerning means adjusting the spacing between the letters of a text.
As an example, consider the word Top
written with the following three glyphs:
##### ..... .....
..#.. ..... .....
..#.. ..##. .###.
..#.. .#..# .#..#
..#.. .#..# .#..#
..#.. ..##. .###.
..... ..... .#...
..... ..... .#...
We could just fill the gaps between the glyphs with dots and be done with it, but the gaps somehow look too wide. Instead, we slide the glyphs to the left so that they almost touch:
#####........
..#..........
..#..##..###.
..#.#..#.#..#
..#.#..#.#..#
..#..##..###.
.........#...
.........#...
This looks much better!
Note how the bar of T
is on top of the left border of o
.
In this challenge, your task is to implement a simple kerning program for such rectangular glyphs.
The kerning process
Consider two rectangular 2D character arrays of .
and #
of the same shape.
In our simple kerning process, we first place the arrays side by side, with one column of .
s in between.
Then, we move each #
in the right array one step to the left, until some #
s of the left and right array are orthogonally or diagonally adjacent.
The outcome of the kerning is the step before we introduce adjacent #
s.
Your task is to implement this process.
Let's take an example:
Inputs:
..###
#....
#....
..##.
...#.
...##
..###
....#
Process:
..###....#.
#........##
#.......###
..##......#
..###...#.
#.......##
#......###
..##.....#
..###..#.
#......##
#.....###
..##....#
..###.#.
#.....##
#....###
..##...#
..####.
#....##
#...###
..##..#
In the last array, we have new adjacent pairs of #
s, so the second-to-last array is the result of the kerning process.
Input and output
For simplicity, you only need to handle kerning of two glyphs. Your inputs are two rectangular 2D arrays, in one of the following formats:
- 2D arrays of integers, with 0 standing for
.
and 1 for#
. - Multiline strings over
.#
. - Arrays of strings over
.#
. - 2D arrays of the characters
.#
.
If the inputs are taken as a single string, you can use any reasonable delimiter. However, the delimiter should go between the two arrays, meaning that you are not allowed to take the two inputs already paired row-by-row.
Your output is the result of the kerning process applied to these two arrays, which is a rectangular 2D array in the same format as the inputs.
You are allowed to add or remove any number of leading or trailing columns of .
s, but the output must be rectangular and have the same height as the inputs.
It is guaranteed that the kerning process ends before the left edge of the second input slides over the left edge of the first input.
Rules and scoring
The lowest byte count in each programming language wins. Standard code-golf rules apply.
Test cases
To help with copy-pasting, these test cases are given as lists of strings.
["#"] ["#"] -> ["#.#"]
["#.","..",".#"] ["##","..","##"] -> ["#..##",".....",".#.##"]
["..#","#..","#.."] ["...","..#","###"] -> ["..#..","#...#","#.###"]
["###.","##..","#...","...."] ["....","...#","..#.",".#.."] -> ["###..","##..#","#..#.","..#.."]
["..##...","#......","#......"] [".....##",".....##",".#...#."] -> ["..##..##","#.....##","#.#...#."]
["...#.",".....",".....",".....","....#"] [".....","....#","#....",".....","....."] -> ["...#..",".....#",".#....","......","....#."]
["..#..",".....",".....",".....","....#"] [".....","....#","#....",".....","....."] -> ["..#..","....#","#....",".....","....#"]
["######","#.....","#.....","#.....","######"] ["......",".....#",".#...#",".....#","......"] -> ["######..","#......#","#..#...#","#......#","######.."]
["######","#.....","#.....","#.....","######"] ["......","......",".#....","......","......"] -> ["######","#.....","#.#...","#.....","######"]
["#...#","#..#.","#.#..","##...","#.#..","#..#.","#...#"] ["...#.","..#..",".#...",".#...",".#...","..#..","...#."] -> ["#...#..#","#..#..#.","#.#..#..","##...#..","#.#..#..","#..#..#.","#...#..#"]