Background
A snake is a path over the cells of a square grid, such that it doesn't touch itself on a side of a unit square. Touching at a corner is allowed.
An example snake:
##.#.
.#.##
##..#
#.###
###..
Some example non-snakes:
###.#
#.#.#
#####
.#...
.####
###
.#.
##
##
Challenge
Given an empty grid with the two endpoints of a snake marked on it, find the longest possible snake that fits on the grid. If there are multiple answers having the same length, you may choose to output one or all of them.
The input can be given as a character matrix (or equivalent) with two endpoints marked on it, or the dimensions (width, height) and the coordinates of the endpoints. You may choose to output the grid containing the snake or a list of coordinates of cells occupied by the snake (or equivalent).
Standard code-golf rules apply. The shortest code in bytes wins.
Example I/O
Each I/O example is given as a character matrix, #
being the part of the snake.
Input:
..#...#...
Output:
..#####...
Input: (corner case)
......
......
..##..
......
......
......
Output: same as input (no way to get longer without violating no-touch condition)
Input:
..#.#
.....
.....
.....
Output:
###.#
#...#
#...#
#####
Input:
#....
.....
.....
.....
....#
Output:
#####
....#
#####
#....
#####
x+w*y
(that is, their positions in row-major order)? \$\endgroup\$