Sometimes when I'm doodling, I draw a rectangle, start with a diagonal from one of the corners, and then just trace out a line by "reflecting" it whenever I hit a side of the rectangle. I continue with this until I hit another corner of the rectangle (and hope that the aspect ratio of my rectangle was not irrational ;)). This is like tracing out the path of a laser shone into a box. You're to produce the result of that with ASCII art.
As an example, consider a box of width 5
and height 3
. We'll always start in the top left corner. The #
marks the boundary of the box. Note that the width and height refer to the inner dimensions.
####### ####### ####### ####### ####### ####### #######
#\ # #\ # #\ \# #\ /\# #\ /\# #\/ /\# #\/\/\#
# \ # # \ /# # \ /# # \/ /# # \/ /# #/\/ /# #/\/\/#
# \ # # \/ # # \/ # # /\/ # #\/\/ # #\/\/ # #\/\/\#
####### ####### ####### ####### ####### ####### #######
The Challenge
Given the (positive) width and height of the box, you should produce the final result of tracing out the laser. You may write a program or function, taking input via STDIN (or closest alternative), command-line argument, function argument and output the result via STDOUT (or closest alternative), or via function return values or arguments.
You may use any convenient list, string or number format for input. The output must be a single string (unless you print it to STDOUT, which you may of course do gradually). This also means you can take the height first and the width second - just specify the exact input format in your answer.
There must be neither leading nor trailing whitespace on any line of the output. You may optionally output a single trailing newline.
You must use space, /
, \
and #
and reproduce the test cases exactly as shown.
Test Cases
2 2
####
#\ #
# \#
####
3 2
#####
#\/\#
#/\/#
#####
6 3
########
#\ /#
# \ / #
# \/ #
########
7 1
#########
#\/\/\/\#
#########
1 3
###
#\#
#/#
#\#
###
7 5
#########
#\/\/\/\#
#/\/\/\/#
#\/\/\/\#
#/\/\/\/#
#\/\/\/\#
#########
22 6
########################
#\ /\ /\ /\ /\ /\ #
# \/ \/ \/ \/ \/ \#
# /\ /\ /\ /\ /\ /#
#/ \/ \/ \/ \/ \/ #
#\ /\ /\ /\ /\ /\ #
# \/ \/ \/ \/ \/ \#
########################
X
would be necessary for crossings. Maybe next time. ;) \$\endgroup\$