def container(self, pt, k=<NUM_LIT:2>, n_jobs=-<NUM_LIT:1>):
pt = np.asarray(pt)<EOL>if len(pt.shape) == <NUM_LIT:1>:<EOL><INDENT>return self.container([pt], k=k, n_jobs=n_jobs)[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>if pt.shape[<NUM_LIT:0>] == self.coordinates.shape[<NUM_LIT:0>]: pt = pt.T<EOL>tcount = self.tess.faces.shape[<NUM_LIT:1>]<EOL>max_k = <NUM_LIT> if tcount > <NUM_LIT> else tcount<EOL>if k > tcount: k = tcount<EOL>def try_nearest(sub_pts, cur_k=k, top_i=<NUM_LIT:0>, near=None):<EOL><INDENT>res = np.full(len(sub_pts), None, dtype=np.object)<EOL>if k != cur_k and cur_k > max_k: return res<EOL>if near is None:<EOL><INDENT>try:              near = self.face_hash.query(sub_pts, k=cur_k, n_jobs=n_jobs)[<NUM_LIT:1>]<EOL>except Exception: near = self.face_hash.query(sub_pts, k=cur_k)[<NUM_LIT:1>]<EOL><DEDENT>guesses = near[:, top_i]<EOL>in_tri_q = self.is_point_in_face(guesses, sub_pts)<EOL>res[in_tri_q] = guesses[in_tri_q]<EOL>if in_tri_q.all(): return res<EOL>out_tri_q = np.logical_not(in_tri_q)<EOL>sub_pts = sub_pts[out_tri_q]<EOL>top_i += <NUM_LIT:1><EOL>res[out_tri_q] = (try_nearest(sub_pts, cur_k*<NUM_LIT:2>, top_i, None)<EOL>if top_i == cur_k else<EOL>try_nearest(sub_pts, cur_k, top_i, near[out_tri_q]))<EOL>return res<EOL><DEDENT>res = np.full(len(pt), None, dtype=np.object)<EOL>(dmins, dmaxs) = [[f(x[np.isfinite(x)]) for x in self.coordinates]<EOL>for f in [np.min, np.max]]<EOL>finpts = np.isfinite(np.sum(pt, axis=<NUM_LIT:1>))<EOL>if finpts.all():<EOL><INDENT>if pt.shape[<NUM_LIT:1>] == <NUM_LIT:2>:<EOL><INDENT>inside_q = reduce(np.logical_and,<EOL>[(x >= mn)&(x <= mx) for (x,mn,mx) in zip(pt.T,dmins,dmaxs)])<EOL><DEDENT>else:<EOL><INDENT>inside_q = np.full(len(pt), True, dtype=np.bool)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>inside_q = np.full(len(pt), False, dtype=np.bool)<EOL>if pt.shape[<NUM_LIT:1>] == <NUM_LIT:2>:<EOL><INDENT>inside_q[finpts] = reduce(<EOL>np.logical_and,<EOL>[(x >= mn)&(x <= mx) for (x,mn,mx) in zip(pt[finpts].T,dmins,dmaxs)])<EOL><DEDENT>else:<EOL><INDENT>inside_q[finpts] = True<EOL><DEDENT><DEDENT>if not inside_q.any(): return res<EOL>res[inside_q] = try_nearest(pt[inside_q])<EOL>return res<EOL><DEDENT>
mesh.container(pt) yields the id number of the nearest triangle in the given
mesh to the given point pt. If pt is an (n x dims) matrix of points, an id is given
for each column of pt.

Implementation Note:
  This method will fail to find the container triangle of a point if you have a very odd
  geometry; the requirement for this condition is that, for a point p contained in a
  triangle t with triangle center x0, there are at least n triangles whose centers are
  closer to p than x0 is to p. The value n depends on your starting parameter k, but is
  approximately 256.