[Question]
  [
## Introduction
[Kerning](https://en.wikipedia.org/wiki/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](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply.
## Test cases
To help with copy-pasting, these test cases are given as lists of strings.
```
["#"] ["#"] -> ["#.#"]
["#.","..",".#"] ["##","..","##"] -> ["#..##",".....",".#.##"]
["..#","#..","#.."] ["...","..#","###"] -> ["..#..","#...#","#.###"]
["###.","##..","#...","...."] ["....","...#","..#.",".#.."] -> ["###..","##..#","#..#.","..#.."]
["..##...","#......","#......"] [".....##",".....##",".#...#."] -> ["..##..##","#.....##","#.#...#."]
["...#.",".....",".....",".....","....#"] [".....","....#","#....",".....","....."] -> ["...#..",".....#",".#....","......","....#."]
["..#..",".....",".....",".....","....#"] [".....","....#","#....",".....","....."] -> ["..#..","....#","#....",".....","....#"]
["######","#.....","#.....","#.....","######"] ["......",".....#",".#...#",".....#","......"] -> ["######..","#......#","#..#...#","#......#","######.."]
["######","#.....","#.....","#.....","######"] ["......","......",".#....","......","......"] -> ["######","#.....","#.#...","#.....","######"]
["#...#","#..#.","#.#..","##...","#.#..","#..#.","#...#"] ["...#.","..#..",".#...",".#...",".#...","..#..","...#."] -> ["#...#..#","#..#..#.","#.#..#..","##...#..","#.#..#..","#..#..#.","#...#..#"]
```
  
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), ~~40~~ 39 bytes
-1 thanks to Erik the Outgolfer
```
{⌈⌿↑⍺(⍉(1-⌈/+⌿+∘×⍨2⌈/0,+/⌈\↑(⌽⍺)⍵)↑⍉⍵)}
```
[Try it online!](https://tio.run/##tVM9T8MwEN37Kyrd4Fht3dKdgQGxMHUFhihNP6RIrdpUokJdAEVtaRAdEPwExN4FCTHwT/xHwiV2zk4/xAKLfX73/O5dfHGHQa09dYNBt@YF7njc9xL5@NwfyOipkXRwvZGruVx9yWgt4w9HxgvnqIZQvYJgRc5fv19k/NZMkUa1Usf9EqmOXH0inct4w7ObizSaJUmYKo5wkcu7Tp0BO25m@Y18uMe6mGCMQoQdJoBdjK74rMTO/U54FkyHvXKr3@3p8PR66Huh327540kQlk@8cOIG6sBKIfp9xyLc7NG6Kpe3DFCWp/lojTErM5EtmsIAcggIEkKjQnPTc66ByZSsruDKNaqksxwp4Tnn6VtgKWGs6hJHFzWaGlFuQJsRZF3fBPKkG8w4xq@WBpF3lEemjtWxijLLhgH5RwHDASJRqdyA6WV7B7soYVp35w43ugSSPUJIp9C1@B8r8Cu38MJgfbX9geJYVnY7hQJi@1G37UelSbAM0lwq7h/ZEwcfYsteURgOVKB/tDjNIMyUF86UL7yk9Qdod/t284o042qWrc9nqlsGQGyjNlcr8NIP "APL (Dyalog Classic) – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 154 bytes
```
lambda a,b,p=".":[c.rstrip(p)+d.lstrip(p).rjust(max(len((d+c).strip(p))for(c,d)in zip((a*3)[1:],b[:-1]+b+b[1:]))+1-len(c.rstrip(p)),p)for(c,d)in zip(a,b)]
```
[Try it online!](https://tio.run/##tVJNb4MwDL33V0TkEo/UEuoNqb@EckiAaqyURsCkbX@ehXxC6XHLIbGf7fecOOp7en/0p/lGzpe5E3dZCyK45OqcYJIXFQ7jNLSKKUhr7LyNw8fnOLG7@GJd0zNWpxWgD8L1MbCK19D25EcjTLydoMjykssiP2ZlKlO5uABpdlzKVyLA1XO57gbKuW6upBJjo10iIT8QvXQi6YhOuzmUqKHtJ9aBCVsHDgdTVyQ0KTkxBwQIE56g2XyUeoSuExEXnNqA3k0u2kob2qRrz1L4Apu4KnSAVbNtGN61oqtbjq0VSNC1G6wlg25pHHvU3J10RRggp7Yr2XSI/0RNzQo3fm3YnMgfiOJLbJC/FfEje0J2IvHG9ku4R4vDDX@EeuWo50ZHo9qrM87BjH7@BQ "Python 3 – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina), 223 bytes
```
+`(.+)¶(¶(.+¶)*)(\W+(¶|$))
$2$1i$4
T`.`i`\.*i\.*
+`(¶(.)*#.*i.*¶(?<-2>.)*)i
$1@
+`(¶(.)*)i(.*¶(?<-2>.)*(?(2)(?!))#.*i)
$1@$3
T`i@`.`i*[#@]+i
mT`.`i`\.+i+$
msT`i`.`.*^\W+$.*
+`(\b(i+)\W+\2i*)i
$1.
+s`\bi((i+).+\b\2\b)
.$1
i
```
[Try it online!](https://tio.run/##rVFLTsMwEN3PKUpsJE9cRmpgiWgPUYlFXTCRuvCiLChLzpUD5GJhnPGH0i4bJWP7@X3szNfhO3x@TPdm65e7Zu/H4R0WMA7jMFlvyOI4GH7JjgO2aNyr5eWPRgTd6VXQT7D15IN31Ab@gEWRjq1igFqer58fuhcGMIBebSoBgznbN2vToVnfIUYpRrJ@ZPewiQHtTm32NsAxx9lgNRxPvM8AtW98Mi35rjfBIq9dFySVwJ6864OJG2Rd7zrXI5BeQYBp2jWq2S/mClypWTY0lwSrDChhEEVECcQ1kkgUspN4PIoqM4VSFWkt/pI7@0lGEsThfJbVlE5WZpGgsj4Z1piLUVWngqSUC0U6E93aU81Pudz1iXCKcXGolz5DbuSe@/EP@eNebyeNTv@ndq50XuXIEpS6o2rMtbH@8djXXw "Retina – Try It Online") Link includes test cases plus header script to reformat them to its preferred input format of two newline-delimited strings. This seems overly long yet there's probably an edge case that I've overlooked, but it does at least pass all of the test cases now. Explanation:
```
+`(.+)¶(¶(.+¶)*)(\W+(¶|$))
$2$1i$4
```
Join the two input arrays together using a letter `i` as a separator. (This allows use of `\W` and `\b` later on.)
```
T`.`i`\.*i\.*
```
Change all the `.`s to `i`s at the join.
```
+`(¶(.)*#.*i.*¶(?<-2>.)*)i
$1@
```
Change all `i`s below `#`s to `@`s.
```
+`(¶(.)*)i(.*¶(?<-2>.)*(?(2)(?!))#.*i)
$1@$3
```
Change all `i`s above `#`s to `@`s.
```
T`i@`.`i*[#@]+i
```
Change all the `@`s to `.`s, plus all the `i`s adjacent to `@`s or `#`s.
```
mT`.`i`\.+i+$
```
If there is no `#` after an `i`, then change the adjacent `.` back to an `i` again.
```
msT`i`.`.*^\W+$.*
```
If there is a line with no `i`s, change all the `i`s to `.`s, as there is nothing to do here.
```
+`(\b(i+)\W+\2i*)i
$1.
```
Calculate the minimum number of `i`s on any line.
```
+s`\bi((i+).+\b\2\b)
.$1
```
Propagate to the other lines.
```
i
```
Delete the `i`s, thus performing the required kerning.
]