Background: I am working on a 2D geometry algorithm where I need to insert a list of 2D points into another list of 2D points. Somewhat to my surprise I found no Mathematica function capable of doing this. My requirement is for a function that when provided for example:
{{1,1},{2,2},{3,3},{4,4},{5,5}}
and
{{100,100}, {200,200}}
returns
{{1,1},{2,2}, {100,100}, {200,200},{3,3},{4,4},{5,5}}
I looked at various Mathematica functions where Insert seemed the candidate to use, now
Insert[{{1,1},{2,2},{3,3},{4,4},{5,5}},{{100,100}, {200,200}},3]
returns
{{1, 1}, {2, 2}, {{100, 100}, {200, 200}}, {3, 3}, {4, 4}, {5, 5}}
note the extra braces around
{100, 100}, {200, 200}
Inspired by this question/answers I created insertM.
insertM[list_, values_, at_] := Module[{i = 0},
Insert[list, "mark", Array[{at} &, Length[values]]] /. "mark" :> (++i; values[[i]])]
which gives
insertM[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}, {{100, 100}, {200, 200}}, 3]
{{1, 1}, {2, 2}, {100, 100}, {200, 200}, {3, 3}, {4, 4}, {5, 5}}
Although insertM does the job, I have this ' there must be a better way ' feeling.
Now my question(s): Is there a Mathematica function that performs my requirement? If not, is there a better function then insertM to do this? In better I rank beautiful code (short, functional) highest unless it is significantly slower than a less beautiful alternative.