Your understanding of aspect ratio calculation as the ratio of the longest to the shortest distance is correct.

So the screenshot is the calculation procedure for Quads (2D) when the element is not flat. Point 3 in the screenshot mentions that the aspect ratio is the ratio of a longer side to a shorter side of whichever rectangle is most stretched.

For 3D elements, "the aspect ratio is a measure of the stretching of a cell, and is defined as the ratio of the maximum value to the minimum value of any of the following distances: the normal distances between the cell centroid and face centroids (computed as a dot product of the distance vector and the face normal), and the distances between the cell centroid and nodes."

For more information refer to:

Mesh Quality