How does the method Function::eval(Array<double> val, Array<double> x) work?

Hi, I am trying to figure out how the method

Function::eval(Array val, Array x)


Referring, without loss of generality, to a 2D mesh, I understand that the idea is to look at the closest triangle to the point x by means of a tree search algorithm, and then use the dofs on vertices to compute the value of the function.

I also understand that the considered distance between a point x and a triangle is the distance between the point x and the centroid of the triangle (ref: build_point_search_tree(const Mesh& mesh), line 715 from the dolfin version of the 18th of June 2019).

This kind of distance works for regular enough meshes, namely, if a point x is the closest to the centroid of a triangle T, then x belongs to T. If a mesh is stretched, anisotropic or somehow irregular, this is false.

Is this exact? If it is, is there some protection against irregular meshes? Otherwise, how does the method Function::eval works?