I'm using the packages
\usepackage{algpseudocode}
\usepackage{algorithm}
to produce a pseudocode of the following algorithm:
\begin{algorithm}
\centering
\caption{Octree based search algorithm}
\label{alg:octree-search}
{\small
\begin{algorithmic}
\Function{octree-search}{node=root, point, squaredDistance, nearestPoint=distant point}
\For{octants of node}
\State get subNode
\State pointSphere = sphere around point using squaredDistance
\If{subNode has child nodes}
\State subNodeBox = Axis Aligned Bound Box (subNode)
\If{subNodeBox overlaps with pointSphere}
\State \Call{octree-search}{subNode, point, squaredDistance, nearestPoint}
\EndIf
\ElsIf{subNode is a leaf node}
\State leafNodeBox = Axis Aligned Bounding Box (node)
\If{leafNodeBox overlaps with pointSphere}
\State minimalPoint = distant point
\For{shape in node shapes}
\State distanceToShape, shapePoint = \Call{signed distance}{shape, point}
\If{$\|\text{distanceToShape}\| < \|\text{minimalDistance}\|$}
\State minimalPoint = shapePoint
\EndIf
\EndFor
\State nearestPoint = minimalPoint \Comment return point of the recursive search
\EndIf
\EndIf
\EndFor
\EndFunction
\end{algorithmic}
}
\end{algorithm}
And I'm using \small
as the algorithm font size. Unfortunately, the page width causes problems and introduces line breaks like this:
As the whole point of the pseudocode (and clean code in general) is to use sensible names (for example squaredDistance in stead of sqD), I would like to re-format the output generated by the algpseudocode, for the function declaration so that it looks like this:
function OCTREE-SEARCH(
node = root,
point,
squaredDistance,
nearestPoint = distant point
)
without the ugly looking line break.
Programming side-note
I'm aware that the functions should ideally be monadic/diadic, but I'm interfacing my code with legacy code at this point and I cannot change the function signature. Reducing the argument number is therefore not an option.
Edit
Also, can the large horizontal space that comes before the Comment
be somehow shortened?